Guest User

Untitled

a guest
Apr 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. files = sorted(glob.glob("../data/*/*_2016-03-07_*.csv"))
  2. with open("trends.full.txt", "w") as fo, open("error.txt", "w") as fe:
  3. for afile in files:
  4. print (afile)
  5.  
  6. filename = os.path.basename(afile)
  7. source = iso2desc[os.path.basename(os.path.dirname(afile))]
  8. destination = filename.split("_")[0]
  9. others = []
  10. uss = []
  11. times = []
  12. with open(afile) as fi:
  13. next(fi) # strip header
  14. for line in fi:
  15. # print (line)
  16. day, other, us, garbage = [term.strip() for term in line.split(",")]
  17. others.append(int(other)+1)
  18. uss.append(int(us)+1)
  19. times.append(day)
  20.  
  21. try:
  22. ref = uss[-1]
  23. multiplier = 100/ref
  24. others = [other*multiplier for other in others]
  25. uss = [us*multiplier for us in uss]
  26.  
  27. for idx, time in enumerate(times):
  28. fo.write("%s\t%s\t%s\t%s\n" % (time, source, destination, others[idx]))
  29. # print (uss[idx])
  30. except:
  31. fe.write("%s\t%s\n" % (os.path.basename(os.path.dirname(afile)),filename))
  32.  
  33. others = []
  34. uss = []
  35. times = []
  36. with open(afile.split("_")[0] + "_2016-10-07_2017-05-07.csv") as fi:
  37. next(fi) # strip header
  38. for line in fi:
  39. # print (line)
  40. day, other, us, garbage = [term.strip() for term in line.split(",")]
  41. others.append(int(other)+1)
  42. uss.append(int(us)+1)
  43. times.append(day)
  44.  
  45. try:
  46. ref = uss[0]
  47. multiplier = 100/ref
  48. others = [other*multiplier for other in others]
  49. uss = [us*multiplier for us in uss]
  50.  
  51. for idx, time in enumerate(times):
  52. fo.write("%s\t%s\t%s\t%s\n" % (time, source, destination, others[idx]))
  53. # print (uss[idx])
  54. except:
  55. fe.write("%s\t%s\n" % (os.path.basename(os.path.dirname(afile)),filename))
Add Comment
Please, Sign In to add comment