-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataSorter.py
41 lines (33 loc) · 1.22 KB
/
DataSorter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import datetime
import heapq
import csv
class DataSorter(object):
def __init__(self, path):
self.path = path
def topTenOnly(self):
topTen = []
heapq.heapify(topTen)
output = open('topTen.csv', mode='w', newline='')
output_writer = csv.writer(output)
with open(self.path) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line = 0
for row in csv_reader:
if line == 0:
line += 1
continue
elif 0 < line < 11:
heapq.heappush(topTen, [-float(row[2]), row[0], row[1]])
else:
heapq.heappushpop(topTen, [-float(row[2]), row[0], row[1]])
line += 1
latest = self.latestDate(topTen)
# run[0] is time, 1 is user, 2 is date
# Still not getting the correct data
for run in topTen:
time = float(-run[0])
output_writer.writerow([latest, run[1], time])
output.close()
def latestDate(self, runs):
dates = [datetime.datetime.fromisoformat(run[2]) for run in runs]
return max(dates)