Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- files = sorted(glob.glob("../data/*/*_2016-03-07_*.csv"))
- with open("trends.full.txt", "w") as fo, open("error.txt", "w") as fe:
- for afile in files:
- print (afile)
- filename = os.path.basename(afile)
- source = iso2desc[os.path.basename(os.path.dirname(afile))]
- destination = filename.split("_")[0]
- others = []
- uss = []
- times = []
- with open(afile) as fi:
- next(fi) # strip header
- for line in fi:
- # print (line)
- day, other, us, garbage = [term.strip() for term in line.split(",")]
- others.append(int(other)+1)
- uss.append(int(us)+1)
- times.append(day)
- try:
- ref = uss[-1]
- multiplier = 100/ref
- others = [other*multiplier for other in others]
- uss = [us*multiplier for us in uss]
- for idx, time in enumerate(times):
- fo.write("%s\t%s\t%s\t%s\n" % (time, source, destination, others[idx]))
- # print (uss[idx])
- except:
- fe.write("%s\t%s\n" % (os.path.basename(os.path.dirname(afile)),filename))
- others = []
- uss = []
- times = []
- with open(afile.split("_")[0] + "_2016-10-07_2017-05-07.csv") as fi:
- next(fi) # strip header
- for line in fi:
- # print (line)
- day, other, us, garbage = [term.strip() for term in line.split(",")]
- others.append(int(other)+1)
- uss.append(int(us)+1)
- times.append(day)
- try:
- ref = uss[0]
- multiplier = 100/ref
- others = [other*multiplier for other in others]
- uss = [us*multiplier for us in uss]
- for idx, time in enumerate(times):
- fo.write("%s\t%s\t%s\t%s\n" % (time, source, destination, others[idx]))
- # print (uss[idx])
- except:
- fe.write("%s\t%s\n" % (os.path.basename(os.path.dirname(afile)),filename))
Add Comment
Please, Sign In to add comment