sequential_counts.nim 979 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. discard """
  2. action: compile
  3. """
  4. import os, parseutils
  5. proc parse(line: string, domainCode, pageTitle: var string,
  6. countViews, totalSize: var int) =
  7. var i = 0
  8. domainCode.setLen(0)
  9. i.inc parseUntil(line, domainCode, {' '}, i)
  10. i.inc
  11. pageTitle.setLen(0)
  12. i.inc parseUntil(line, pageTitle, {' '}, i)
  13. i.inc
  14. countViews = 0
  15. i.inc parseInt(line, countViews, i)
  16. i.inc
  17. totalSize = 0
  18. i.inc parseInt(line, totalSize, i)
  19. proc readPageCounts(filename: string) =
  20. var domainCode = ""
  21. var pageTitle = ""
  22. var countViews = 0
  23. var totalSize = 0
  24. var mostPopular = ("", "", 0, 0)
  25. for line in filename.lines:
  26. parse(line, domainCode, pageTitle, countViews, totalSize)
  27. if domainCode == "en" and countViews > mostPopular[2]:
  28. mostPopular = (domainCode, pageTitle, countViews, totalSize)
  29. echo("Most popular is: ", mostPopular)
  30. when true:
  31. const file = "pagecounts-20160101-050000"
  32. let filename = getCurrentDir() / file
  33. readPageCounts(filename)