2016-11-25 16:10:37 +00:00
|
|
|
module Import
|
|
|
|
module OTRS
|
|
|
|
module ImportStats
|
|
|
|
extend self
|
|
|
|
|
|
|
|
def current_state
|
|
|
|
{
|
2018-12-19 17:31:51 +00:00
|
|
|
Base: {
|
2016-11-25 16:10:37 +00:00
|
|
|
done: base_done,
|
|
|
|
total: base_total,
|
|
|
|
},
|
2018-12-19 17:31:51 +00:00
|
|
|
User: {
|
2016-11-25 16:10:37 +00:00
|
|
|
done: user_done,
|
|
|
|
total: user_total,
|
|
|
|
},
|
|
|
|
Ticket: {
|
|
|
|
done: ticket_done,
|
|
|
|
total: ticket_total,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def statistic
|
|
|
|
|
|
|
|
# check cache
|
2021-05-31 13:05:54 +00:00
|
|
|
cache = Cache.read('import_otrs_stats')
|
2016-11-25 16:10:37 +00:00
|
|
|
return cache if cache
|
|
|
|
|
2019-07-31 08:23:48 +00:00
|
|
|
# retrieve statistic
|
2016-11-25 16:10:37 +00:00
|
|
|
statistic = Import::OTRS::Requester.list
|
|
|
|
return statistic if !statistic
|
|
|
|
|
|
|
|
Cache.write('import_otrs_stats', statistic)
|
|
|
|
statistic
|
|
|
|
end
|
|
|
|
|
2016-12-09 15:12:39 +00:00
|
|
|
private
|
|
|
|
|
2016-11-25 16:10:37 +00:00
|
|
|
def base_done
|
2016-11-28 10:44:56 +00:00
|
|
|
::Group.count + ::Ticket::State.count + ::Ticket::Priority.count
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def base_total
|
2017-11-23 08:09:44 +00:00
|
|
|
sum_stat(%w[Queue State Priority])
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_done
|
2016-11-28 10:44:56 +00:00
|
|
|
::User.count
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_total
|
2017-11-23 08:09:44 +00:00
|
|
|
sum_stat(%w[User CustomerUser])
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def ticket_done
|
2016-11-28 10:44:56 +00:00
|
|
|
::Ticket.count
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def ticket_total
|
2017-11-23 08:09:44 +00:00
|
|
|
sum_stat(%w[Ticket])
|
2016-11-25 16:10:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def sum_stat(objects)
|
|
|
|
data = statistic
|
|
|
|
sum = 0
|
2017-10-01 12:25:52 +00:00
|
|
|
objects.each do |object|
|
2016-11-25 16:10:37 +00:00
|
|
|
sum += data[object]
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2016-11-25 16:10:37 +00:00
|
|
|
sum
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|