naive.nim 935 B

12345678910111213141516171819202122232425262728293031323334
  1. discard """
  2. action: compile
  3. """
  4. # See this page for info about the format https://wikitech.wikimedia.org/wiki/Analytics/Data/Pagecounts-all-sites
  5. import tables, parseutils, strutils
  6. const filename = "pagecounts-20150101-050000"
  7. proc parse(filename: string): tuple[projectName, pageTitle: string,
  8. requests, contentSize: int] =
  9. # Each line looks like: en Main_Page 242332 4737756101
  10. var file = open(filename)
  11. for line in file.lines:
  12. var i = 0
  13. var projectName = ""
  14. i.inc parseUntil(line, projectName, Whitespace, i)
  15. i.inc
  16. var pageTitle = ""
  17. i.inc parseUntil(line, pageTitle, Whitespace, i)
  18. i.inc
  19. var requests = 0
  20. i.inc parseInt(line, requests, i)
  21. i.inc
  22. var contentSize = 0
  23. i.inc parseInt(line, contentSize, i)
  24. if requests > result[2] and projectName == "en":
  25. result = (projectName, pageTitle, requests, contentSize)
  26. file.close()
  27. when true:
  28. echo parse(filename)