Commit 580e696e authored by Oscar Roisin's avatar Oscar Roisin
Browse files

add verification and comments to map function inputs

parent 4b52132f
import folium
map_osm = folium.Map(location=[48.85, 2.34])
import matplotlib.pyplot as plt
from cassandra.cluster import Cluster
from datetime import datetime
import numpy as np
for ind, lat, lon, com in df[['lat', 'long', 'Nom commune']][:50].itertuples():
map_osm.add_child(folium.RegularPolygonMarker(location=[lat,lon], popup=com,
fill_color='#132b5e', radius=5))
from kmeans import verifyDateInPeriod
import loading
\ No newline at end of file
table_name_space = loading.table_name_space
table_name_date = loading.table_name_date
numeric_columns = loading.numeric_columns.copy()
def getDailyIndicator(year, month, day, indicators):
# Verify if date exists in the database
if verifyDateInPeriod(FIRST_DAY, LAST_DAY, year, month, day):
# 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
return []
def mapIndicator(date, indicators):
# Split date and filter indicators
year, month, day = date.split('-')
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)
day = int(day)
# Test if data for the date selected
if not(data):
print(f"Aucune donnée pour pour le jour : {year}-{month}-{day}")
file_name = f"{year}-{month}-{day}.html"
# Create map
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)
# Save map
print(f"La carte a été enregistrée à {file_name}")
if __name__ == '__main__':
cluster = Cluster()
session = cluster.connect()
mapIndicator('2009-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