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

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:
rd[ind[n]]=elem
n += 1
result.append(rd)
return result
else:
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.lat, d.lon], popup=f"{d.station}").add_to(m)
folium.Marker([d['lat'], d['lon']], popup=f"{d['station']}").add_to(m)
# Save map
m.save(file_name)
print(f"La carte a été enregistrée à {file_name}")
......@@ -57,5 +70,5 @@ if __name__ == '__main__':
session = cluster.connect()
session.set_keyspace("bazinsim_roisinos_metar")
print()
mapIndicator('2009-03-10', numeric_columns)
mapIndicator('2010-03-10', numeric_columns)
print()
\ No newline at end of file
Markdown is supported
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