-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathClassGetFiles.py
More file actions
68 lines (54 loc) · 1.73 KB
/
ClassGetFiles.py
File metadata and controls
68 lines (54 loc) · 1.73 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
import json
import os
import pandas as pd
class CsvFiles():
def __init__(self, path) -> None:
self.name = self.getName(path)
self.data = self.prepareData(path)
self.lat = self.data['lat']
self.lon = self.data['lon']
self.type = self.data['type']
def getName(self, path):
return path.split('_')[0].split('/')[1]
def prepareData(self, path):
data = pd.read_csv(path)
data = data.drop(['link'], axis=1)
return data
def getData():
data_list, files = [], []
path = 'data/'
for r, d, f in os.walk(path):
for file in f:
files.append(os.path.join(r, file))
for f in files:
d = CsvFiles(f)
data_list.append(d)
return data_list
# for i in data_list:
# length = length + (len(i.data))
# print(i.lat,i.lon,i.type)
# print(length)
# lat_1 = 54.35379183893733
# lon_1 = 18.592863067989025
# lat_2 = 54.35516237294401
# lon_2 = 18.64964134202087
# # call the OSMR API
# distances = []
# for i in range(len(data_list[0].type)):
# lat_2 = data_list[0].lat[i]
# lon_2 = data_list[0].lon[i]
# r = requests.get(f"http://router.project-osrm.org/route/v1/driving/{lon_1},{lat_1};{lon_2},{lat_2}?overview=false""")
# routes = json.loads(r.content)
# distance = routes.get("routes")[0].get("distance")
# distances.append(distance)
# # print(distance)
# print(data_list[0].type.shape)
# print(distances)
# print(distances.sort(distances))
# distances.sort(distances)
# then you load the response using the json libray
# by default you get only one alternative so you access 0-th element of the `routes`
# routes = json.loads(r.content)
# print(routes)
# print(routes.get("routes")[0])