/Count.groovy

http://groovy-log-analyzer.googlecode.com/ · Groovy · 38 lines · 34 code · 4 blank · 0 comment · 5 complexity · 4e1765c5e38fb33334c76a3f4423f3cd MD5 · raw file

  1. def countTypesTable = [ : ]
  2. count = {ln, type, categorizationFunction ->
  3. def c = categorizationFunction(ln)
  4. def table = countTypesTable[type]
  5. if(!table){
  6. table = [:]
  7. countTypesTable[type]=table
  8. }
  9. if(c)
  10. {
  11. table[c]=(table[c]?:0)+1
  12. }
  13. }
  14. countResult= {type ->
  15. def res = countTypesTable[type]
  16. def total = 0
  17. res.each{total+=it.value}
  18. res["total"]=total
  19. return res
  20. }
  21. printUnknownRequests = { ln, categorizationFunction ->
  22. def c = categorizationFunction(ln)
  23. if (c == "UNKNOWN_REQUEST")
  24. println ln
  25. }
  26. def accumulateTypesTable = [ : ]
  27. accumulate = {ln, type, numberFunction ->
  28. def n = numberFunction(ln)
  29. if(!n) return
  30. accumulateTypesTable[type] = n + accumulateTypesTable[type]?:0
  31. }
  32. accumulateResult = {type ->
  33. return accumulateTypesTable[type]
  34. }