report.rb 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. class Report
  2. def self.enabled?
  3. !Setting.get('es_url').empty?
  4. end
  5. def self.config
  6. config = {}
  7. config[:metric] = {}
  8. config[:metric][:count] = {
  9. name: 'count',
  10. display: 'Ticket Count',
  11. default: true,
  12. prio: 10_000,
  13. }
  14. backend = [
  15. {
  16. name: 'created',
  17. display: 'Created',
  18. selected: true,
  19. dataDownload: true,
  20. adapter: Report::TicketGenericTime,
  21. params: { field: 'created_at' },
  22. },
  23. {
  24. name: 'closed',
  25. display: 'Closed',
  26. selected: true,
  27. dataDownload: true,
  28. adapter: Report::TicketGenericTime,
  29. params: { field: 'close_at' },
  30. },
  31. {
  32. name: 'backlog',
  33. display: 'Backlog',
  34. selected: true,
  35. dataDownload: false,
  36. adapter: Report::TicketBacklog,
  37. },
  38. {
  39. name: 'first_solution',
  40. display: 'First Solution',
  41. selected: false,
  42. dataDownload: true,
  43. adapter: Report::TicketFirstSolution,
  44. },
  45. {
  46. name: 'reopened',
  47. display: 'Reopened',
  48. selected: false,
  49. dataDownload: true,
  50. adapter: Report::TicketReopened,
  51. },
  52. {
  53. name: 'movedin',
  54. display: 'Moved in',
  55. selected: false,
  56. dataDownload: true,
  57. adapter: Report::TicketMoved,
  58. params: { type: 'in' },
  59. },
  60. {
  61. name: 'movedout',
  62. display: 'Moved out',
  63. selected: false,
  64. dataDownload: true,
  65. adapter: Report::TicketMoved,
  66. params: { type: 'out' },
  67. },
  68. ]
  69. config[:metric][:count][:backend] = backend
  70. config[:metric][:create_channels] = {
  71. name: 'create_channels',
  72. display: 'Create Channels',
  73. prio: 9000,
  74. }
  75. backend = [
  76. {
  77. name: 'phone_in',
  78. display: 'Phone (in)',
  79. selected: true,
  80. dataDownload: true,
  81. adapter: Report::TicketGenericTime,
  82. params: {
  83. field: 'created_at',
  84. selector: {
  85. 'create_article_type_id' => {
  86. 'operator' => 'is',
  87. 'value' => Ticket::Article::Type.lookup(name: 'phone').id,
  88. },
  89. 'create_article_sender_id' => {
  90. 'operator' => 'is',
  91. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  92. },
  93. },
  94. },
  95. },
  96. {
  97. name: 'phone_out',
  98. display: 'Phone (out)',
  99. selected: true,
  100. dataDownload: true,
  101. adapter: Report::TicketGenericTime,
  102. params: {
  103. field: 'created_at',
  104. selector: {
  105. 'create_article_type_id' => {
  106. 'operator' => 'is',
  107. 'value' => Ticket::Article::Type.lookup(name: 'phone').id,
  108. },
  109. 'create_article_sender_id' => {
  110. 'operator' => 'is',
  111. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  112. },
  113. }
  114. },
  115. },
  116. {
  117. name: 'email_in',
  118. display: 'Email (in)',
  119. selected: true,
  120. dataDownload: true,
  121. adapter: Report::TicketGenericTime,
  122. params: {
  123. field: 'created_at',
  124. selector: {
  125. 'create_article_type_id' => {
  126. 'operator' => 'is',
  127. 'value' => Ticket::Article::Type.lookup(name: 'email').id,
  128. },
  129. 'create_article_sender_id' => {
  130. 'operator' => 'is',
  131. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  132. },
  133. },
  134. },
  135. },
  136. {
  137. name: 'email_out',
  138. display: 'Email (out)',
  139. selected: true,
  140. dataDownload: true,
  141. adapter: Report::TicketGenericTime,
  142. params: {
  143. field: 'created_at',
  144. selector: {
  145. 'create_article_type_id' => {
  146. 'operator' => 'is',
  147. 'value' => Ticket::Article::Type.lookup(name: 'email').id,
  148. },
  149. 'create_article_sender_id' => {
  150. 'operator' => 'is',
  151. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  152. },
  153. },
  154. },
  155. },
  156. {
  157. name: 'web_in',
  158. display: 'Web (in)',
  159. selected: true,
  160. dataDownload: true,
  161. adapter: Report::TicketGenericTime,
  162. params: {
  163. field: 'created_at',
  164. selector: {
  165. 'create_article_type_id' => {
  166. 'operator' => 'is',
  167. 'value' => Ticket::Article::Type.lookup(name: 'web').id,
  168. },
  169. 'create_article_sender_id' => {
  170. 'operator' => 'is',
  171. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  172. },
  173. },
  174. },
  175. },
  176. {
  177. name: 'twitter_in',
  178. display: 'Twitter (in)',
  179. selected: true,
  180. dataDownload: true,
  181. adapter: Report::TicketGenericTime,
  182. params: {
  183. field: 'created_at',
  184. selector: {
  185. 'create_article_type_id' => {
  186. 'operator' => 'is',
  187. 'value' => Ticket::Article::Type.lookup(name: 'twitter status').id,
  188. },
  189. 'create_article_sender_id' => {
  190. 'operator' => 'is',
  191. 'value' => Ticket::Article::Sender.lookup(name: 'Customer').id,
  192. },
  193. },
  194. },
  195. },
  196. {
  197. name: 'twitter_out',
  198. display: 'Twitter (out)',
  199. selected: true,
  200. dataDownload: true,
  201. adapter: Report::TicketGenericTime,
  202. params: {
  203. field: 'created_at',
  204. selector: {
  205. 'create_article_type_id' => {
  206. 'operator' => 'is',
  207. 'value' => Ticket::Article::Type.lookup(name: 'twitter status').id,
  208. },
  209. 'create_article_sender_id' => {
  210. 'operator' => 'is',
  211. 'value' => Ticket::Article::Sender.lookup(name: 'Agent').id,
  212. },
  213. },
  214. },
  215. },
  216. ]
  217. config[:metric][:create_channels][:backend] = backend
  218. config[:metric][:communication] = {
  219. name: 'communication',
  220. display: 'Communication',
  221. prio: 7000,
  222. }
  223. backend = [
  224. {
  225. name: 'phone_in',
  226. display: 'Phone (in)',
  227. selected: true,
  228. dataDownload: false,
  229. adapter: Report::ArticleByTypeSender,
  230. params: {
  231. type: 'phone',
  232. sender: 'Customer',
  233. },
  234. },
  235. {
  236. name: 'phone_out',
  237. display: 'Phone (out)',
  238. selected: true,
  239. dataDownload: false,
  240. adapter: Report::ArticleByTypeSender,
  241. params: {
  242. type: 'phone',
  243. sender: 'Agent',
  244. },
  245. },
  246. {
  247. name: 'email_in',
  248. display: 'Email (in)',
  249. selected: true,
  250. dataDownload: false,
  251. adapter: Report::ArticleByTypeSender,
  252. params: {
  253. type: 'email',
  254. sender: 'Customer',
  255. },
  256. },
  257. {
  258. name: 'email_out',
  259. display: 'Email (out)',
  260. selected: true,
  261. dataDownload: false,
  262. adapter: Report::ArticleByTypeSender,
  263. params: {
  264. type: 'email',
  265. sender: 'Agent',
  266. },
  267. },
  268. {
  269. name: 'web_in',
  270. display: 'Web (in)',
  271. selected: true,
  272. dataDownload: false,
  273. adapter: Report::ArticleByTypeSender,
  274. params: {
  275. type: 'web',
  276. sender: 'Customer',
  277. },
  278. },
  279. {
  280. name: 'twitter_in',
  281. display: 'Twitter (in)',
  282. selected: true,
  283. dataDownload: false,
  284. adapter: Report::ArticleByTypeSender,
  285. params: {
  286. type: 'twitter status',
  287. sender: 'Customer',
  288. },
  289. },
  290. {
  291. name: 'twitter_out',
  292. display: 'Twitter (out)',
  293. selected: true,
  294. dataDownload: false,
  295. adapter: Report::ArticleByTypeSender,
  296. params: {
  297. type: 'twitter status',
  298. sender: 'Agent',
  299. },
  300. },
  301. ]
  302. config[:metric][:communication][:backend] = backend
  303. config[:metric].each do |metric_key, metric_value|
  304. metric_value[:backend].each do |metric_backend|
  305. metric_backend[:name] = "#{metric_key}::#{metric_backend[:name]}"
  306. end
  307. end
  308. config
  309. end
  310. end