-
Notifications
You must be signed in to change notification settings - Fork 1
/
read_data.py
119 lines (103 loc) · 4.35 KB
/
read_data.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import json
import openai
import csv
openai.api_key = open("API_KEY.txt", 'r').read()
def get_stand_data():
shops_list = []
id_list = []
csv_file = open("RawFiles/export_stands20230922 (1).csv")
headers = next(csv_file)[:-1].split(';')
for row in csv_file:
row_data = row[:-1].split(';')
temp = {}
for i in range(1, len(headers)):
temp[headers[i]] = (row_data[i] if ', ' not in row_data[i] else row_data[i].split(', ')) if row_data[i] != '' else None
shops_list.append(temp)
id_list.append(row_data[0])
json_file = open('RawFiles/fdv_stands20230920.geojson', "r")
stand_list = json.loads(json_file.read())['features']
for stand in stand_list:
try:
stand['properties']['details'] = shops_list[id_list.index(stand['properties']['numero'])]
except ValueError:
continue
json_object = json.dumps({'stand_list': stand_list}, indent=4)
with open("DataFiles/stand_data.json", "w") as outfile:
outfile.write(json_object)
def get_location_lists():
json_file = open("DataFiles/stand_data.json", "r")
stand_list = json.loads(json_file.read())['stand_list']
beverages = []
foods = []
urgency = []
stages = []
toilets = []
buses = []
trains = []
recycle = []
streets = []
other = []
for stand in stand_list:
ok = False
if 'details' in stand['properties']:
if stand['properties']['details']['food_types'] is not None:
foods.append(stand)
ok = True
if stand['properties']['details']['drink_categories'] is not None:
beverages.append(stand)
ok = True
if 'eau' in stand['properties']['numero']:
beverages.append(stand)
ok = True
if 'GSN' in stand['properties']['numero']:
urgency.append(stand)
ok = True
if 'voirie' in stand['properties']['numero']:
streets.append(stand)
ok = True
if 'TransN' in stand['properties']['numero']:
trains.append(stand)
ok = True
if 'scène' in stand['properties']['numero']:
stages.append(stand)
ok = True
if 'camion' in stand['properties']['numero']:
buses.append(stand)
ok = True
if 'WC' in stand['properties']['numero']:
toilets.append(stand)
ok = True
if 'Centre tri' in stand['properties']['numero']:
recycle.append(stand)
ok = True
if ok is False:
other.append(stand)
return beverages, foods, urgency, stages, toilets, buses, trains, recycle, streets, other
def get_pins(loc_list):
return [{"coordinates": [loc['properties']['centerpoint'].split(', ')[1], loc['properties']['centerpoint'].split(', ')[0]],
"popupText": loc_list.index(loc)} for loc in loc_list]
def get_route_info():
routes_info = "Routes are structured as follows: each route can be found encapsulated between \"\", and follow this structure "
with open('DataFiles/Routes.csv', newline='') as file:
csvfile = csv.reader(file, delimiter=',', quotechar='|')
for row in csvfile:
if routes_info[-1] is '\"':
routes_info += ', \"'
routes_info += row.__str__() + ('\"' if routes_info[-1] is not ' ' else '')
routes_info += '. The following information is regarding closed routes, each of them encapsulated between \"\", and follow this structure '
with open('DataFiles/Modified Routes.csv', newline='') as file:
csvfile = csv.reader(file, delimiter=',', quotechar='|')
for row in csvfile:
if routes_info[-1] is '\"':
routes_info += ', \"'
routes_info += row.__str__() + ('\"' if routes_info[-1] is not ' ' else '')
return routes_info
def get_recycle_info():
recycle_info = "Recycling rules are split as follows: each of them encapsulated between \"\", and follow this structure "
with open('DataFiles/Recycle.csv', newline='') as file:
csvfile = csv.reader(file, delimiter=',', quotechar='|')
for row in csvfile:
if recycle_info[-1] is '\"':
recycle_info += ', \"'
recycle_info += row.__str__() + ('\"' if recycle_info[-1] is not ' ' else '')
return recycle_info