2022-08-29 17:34:09 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Clean the existing statistics
|
|
|
|
class Statistics::CleanerService
|
|
|
|
include Statistics::Concerns::HelpersConcern
|
|
|
|
|
|
|
|
class << self
|
|
|
|
def clean_stat(options = default_options)
|
|
|
|
client = Elasticsearch::Model.client
|
2022-10-11 17:23:45 +02:00
|
|
|
%w[Account Event Machine Project Subscription Training User Space Order].each do |o|
|
2022-08-29 17:34:09 +02:00
|
|
|
model = "Stats::#{o}".constantize
|
|
|
|
client.delete_by_query(
|
|
|
|
index: model.index_name,
|
|
|
|
type: model.document_type,
|
2022-10-10 12:20:39 +02:00
|
|
|
body: {
|
|
|
|
query: {
|
|
|
|
terms: {
|
|
|
|
date: (to_date(options[:start_date]).to_date..to_date(options[:end_date]).to_date)
|
|
|
|
.to_a
|
|
|
|
.map { |d| format_date(d) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-29 17:34:09 +02:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|