import_stats.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. module Import
  2. module OTRS
  3. module ImportStats
  4. # rubocop:disable Style/ModuleFunction
  5. extend self
  6. def current_state
  7. {
  8. Base: {
  9. done: base_done,
  10. total: base_total,
  11. },
  12. User: {
  13. done: user_done,
  14. total: user_total,
  15. },
  16. Ticket: {
  17. done: ticket_done,
  18. total: ticket_total,
  19. },
  20. }
  21. end
  22. def statistic
  23. # check cache
  24. cache = Cache.get('import_otrs_stats')
  25. return cache if cache
  26. # retrive statistic
  27. statistic = Import::OTRS::Requester.list
  28. return statistic if !statistic
  29. Cache.write('import_otrs_stats', statistic)
  30. statistic
  31. end
  32. private
  33. def base_done
  34. ::Group.count + ::Ticket::State.count + ::Ticket::Priority.count
  35. end
  36. def base_total
  37. sum_stat(%w[Queue State Priority])
  38. end
  39. def user_done
  40. ::User.count
  41. end
  42. def user_total
  43. sum_stat(%w[User CustomerUser])
  44. end
  45. def ticket_done
  46. ::Ticket.count
  47. end
  48. def ticket_total
  49. sum_stat(%w[Ticket])
  50. end
  51. def sum_stat(objects)
  52. data = statistic
  53. sum = 0
  54. objects.each do |object|
  55. sum += data[object]
  56. end
  57. sum
  58. end
  59. end
  60. end
  61. end