import_stats.rb 1.3 KB

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