Commit 945531b3 authored by Oscar Roisin's avatar Oscar Roisin
Browse files

cast query result to list of dict

parent 580e696e
......@@ -22,7 +22,21 @@ def getDailyIndicator(year, month, day, indicators):
# Format indicators for request
ind = list(map(lambda i: f", avg({i}) as {i}", indicators))
datas = session.execute(f"SELECT station, avg(lat) as lat, avg(lon) as lon {''.join(ind)} FROM {table_name_date} WHERE year = {year} AND month = {month} AND day = {day} GROUP BY year, month, day, station")
return datas
# Reset indicators
ind = indicators.copy()
ind.insert(0, 'lon')
ind.insert(0, 'lat')
ind.insert(0, 'station')
# Create list of dict
result = []
for row in datas:
rd = dict()
n = 0
for elem in row:
n += 1
return result
return []
......@@ -32,7 +46,6 @@ def mapIndicator(date, indicators):
indicators = list(filter(lambda i: i in numeric_columns, indicators))
# Get data for date and filtered indicators
data = getDailyIndicator(year, month, day, indicators)
data = list(data)
# Verify if date components are integers
year = int(year)
month = int(month)
......@@ -47,7 +60,7 @@ def mapIndicator(date, indicators):
m = folium.Map(location=[64.2815, 27.6753])
# Add Marker for each station
for d in data:
folium.Marker([, d.lon], popup=f"{d.station}").add_to(m)
folium.Marker([d['lat'], d['lon']], popup=f"{d['station']}").add_to(m)
# Save map
print(f"La carte a été enregistrée à {file_name}")
......@@ -57,5 +70,5 @@ if __name__ == '__main__':
session = cluster.connect()
mapIndicator('2009-03-10', numeric_columns)
mapIndicator('2010-03-10', numeric_columns)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment