File size: 1,694 Bytes
03df0fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import folium
from folium import IFrame
import plotly.graph_objects as go
from APIs.geolocation import get_geolocation, get_risques
from APIs.meteo import get_info_meteo


def get_and_plot_meteo(lat, lon):
    df = get_info_meteo(lat, lon)
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=df['date'], y=df['daily_temperature_2m_max_C'],
                  name="Température °C", mode="lines+markers"))
    fig.add_trace(go.Scatter(x=df['date'], y=df['avg_hourly_relative_humidity_2m_%'],
                  name="Humidité moyenne en %", mode="lines+markers", yaxis="y2"))
    fig.update_layout(
        title="Température maximale et humidité moyenne journalière",
        xaxis_title="Date",
        yaxis_title="Température (°C)",
        yaxis2=dict(
            title="Humidity (%)",
            overlaying="y",
            side="right"
        )
    )
    return fig


def show_map(lat, lon, address):
    if address:
        lat_tmp, lon_tmp, code_insee = get_geolocation(address, None, None)
        risques = get_risques(code_insee=code_insee)
        if lat_tmp or lon_tmp:
            lat, lon = lat_tmp, lon_tmp
        else:
            return "Adress not found. Please enter a valid address", ""
    if lat and lon:
        lat_tmp, lon_tmp, code_insee = get_geolocation(None, lat, lon)
        risques = get_risques(code_insee=code_insee)
        # Create a map centered at the input coordinates
        location_map = folium.Map(location=[lat, lon], zoom_start=14)
        folium.Marker([lat, lon], popup=risques).add_to(location_map)
        map_html = location_map._repr_html_()
        fig = get_and_plot_meteo(lat, lon)
    return map_html, fig