-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort_time.py
50 lines (37 loc) · 1.46 KB
/
sort_time.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
42
43
44
45
46
47
48
49
50
import matplotlib.pyplot as plt
import numpy as np
import csv
import random as rnd
import json
'''
#--------------------------------------------------------------------------------------
# import data from .csv file
csv_file = 'finalProject.csv'
f = open(csv_file, 'r')
reader = csv.reader(f)
next(reader)
data = [[float(i[j]) for j in range(len(i))] for i in reader]
#--------------------------------------------------------------------------------------
data.sort(key=lambda x : x[0])
#---------------------------------------------------------------------------------------
with open('sortedFinalProject.csv', 'w', newline='') as fp:
a = csv.writer(fp)
a.writerows(data)
'''
#-------------------------------------------------------------------------------------
def compute_dist(p1, p2):
x1, y1 = p1
x2, y2 = p2
return abs(x2 - x1) + abs(y2 - y1)
#data = [ obj for obj in data if compute_dist( obj[1:3], obj[3:5] ) < 5000 ]
data = [ obj for obj in data if compute_dist( obj[1:3], obj[3:5] ) > 30000 and compute_dist( obj[1:3], obj[3:5] ) < 35000 ]
#----------------------------------------------------------------------------------------
for obj in data:
plt.plot( [obj[1], obj[3]], [obj[2], obj[4]] )
plt.show()
'''
#---------------------------------------------------------------------------------------
with open('advancedSortedFinalProject.csv', 'w', newline='') as fp:
a = csv.writer(fp)
a.writerows(data)
'''