Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit a8fbaf22 authored by Samuël Weber's avatar Samuël Weber
Browse files

ménage dans le code des fois que des gens regarderaient...

parent d3655ff4
This diff is collapsed.
This diff is collapsed.
......@@ -15,7 +15,21 @@ class SharedComponent():
"""Component shared by several app.
"""
def get_layout(self, list_station, df):
def get_layout(self, df, list_station=None):
if list_station is None:
conn = sqlite3.connect(settings.BDDPM) # BDDPM must be defined in local_settings.py
sqlquery = """
SELECT DISTINCT Station FROM
(
SELECT Station FROM PMF_contributions
UNION ALL
SELECT Station FROM values_all
)
ORDER BY Station;
"""
list_station = pd.read_sql(sqlquery, con=conn)["Station"].tolist()
conn.close()
layout = dbc.Container(
id="container-main",
fluid=True,
......
import dash_core_components as dcc
import dash_html_components as html
import dash_table_experiments as dt
import plotly.graph_objs as go
from datetime import datetime, timedelta
def datetime2fractionaldate(date):
"""
Convert a datetime object to fractional date (2012.7)
"""
year = date.year
boy = datetime(year, 1, 1)
eoy = datetime(year+1, 1, 1)
result = year + (date- boy).total_seconds() / (eoy - boy).total_seconds()
return result
def get_map_data(dfmap):
"""Get the map data given by dfmap
:dfmap: pandas DataFrame
:returns: list of plotly trace
"""
DATA_MAP = [ dict(
type= 'scattergeo',
lon=dfmap['longitude'],
lat=dfmap['latitude'],
text=dfmap['abbrv'],
mode = 'markers',
name = ''
)
]
return DATA_MAP
def get_map_layout():
"""Return the layout for the map.
:returns: dict
"""
LAYOUT_MAP = dict(
showlegend = False,
margin = go.layout.Margin(l=20, r=20, b=20, t=20, pad=2),
geo = dict(
scope = 'world',
showland = True,
landcolor = "rgb(212, 212, 212)",
subunitcolor = "rgb(255, 255, 255)",
countrycolor = "rgb(255, 255, 255)",
showlakes = False,
lakecolor = "rgb(255, 255, 255)",
showsubunits = True,
showcountries = True,
resolution = 50,
projection = dict(
type = 'equirectangular',
rotation = dict(
lon = 0
)
),
lonaxis = dict(
showgrid = True,
gridwidth = 0.5,
range= [ -5.0, 15.0 ],
dtick = 5
),
lataxis = dict (
showgrid = True,
gridwidth = 0.5,
range= [ 40.0, 55.0 ],
dtick = 5
)
),
)
return LAYOUT_MAP
station_dropdown_component = html.Div(
children=[
html.Label('Station'),
dcc.Dropdown(
id="station-dropdown",
options=[],
multi=True,
value=["ANDRA-PM10"]
)
],
style={"position": "relative"}
)
specie_dropdown_component = html.Div(
children=[
html.Label('Species'),
dcc.Dropdown(
id='specie-dropdown',
options=[],
multi=True,
value=["PM10"]
)
],
style={"position": "relative"}
)
source_dropdown_component = html.Div(
children=[
html.Label('Sources'),
dcc.Dropdown(
id='source-dropdown',
options=[],
multi=True,
value=[]
)
],
style={"position": "relative"},
)
options_component = html.Div(children=[
html.Div(
id="nb_sample",
children=[
"""# sample > to""",
dcc.Input(
id='nbsample-slider',
min=0,
max=300,
value=50,
style={"width": "40px"}
),
],
style={'display': 'inline-block'}
),
html.Div(
children=[
dcc.Checklist(
id='options_check',
className='options-select-items',
options=[
{'label': 'With OP', 'value': 'hasOP'},
{'label': 'Use labels to group by', 'value': 'uselabel'},
{'label': 'PM 10 fraction', 'value': 'PM10'},
{'label': 'PM 2.5 fraction', 'value': 'PM2.5'},
{'label': 'PM fraction unknown', 'value': 'PMX'},
],
values=["PM10", "PM2.5", "PMX"],
labelStyle={'display': 'inline-block',
'margin': '0 5px'}
)
],
style={'display': 'inline-block',
'margin': '0 10px'}
)
])
datatable_component = html.Div(
id="datatable-component",
children=[
html.Div(
dt.DataTable(
rows=[{}], # initialise the rows
row_selectable=True,
filterable=True,
sortable=True,
editable=False,
selected_row_indices=[],
id='datatable'
),
),
html.Br(),
html.Div(
children=[
html.Button(id='refresh-button', className="btn btn-primary", children="Refresh"),
html.A(children='Download',
id='download-data',
download="rawdata.csv",
href="",
target="_blank",
style={"padding":"10px"}
)
], style={"margin":"3px"}
),
],
)
gettinghelp_component = html.Div(
id="help-component",
children=[
dcc.Markdown('''
### Getting help
#### Dash
This app is written with [Dash](https://plot.ly/dash/), so the graph are
interactive and responsive. *Hover* over points to see their values, *click* on
legend items to toggle traces, *click and drag* to zoom, *hold down shift, and
click and drag* to pan.
#### This app
Check the [README file](https://gricad-gitlab.univ-grenoble-alpes.fr/webersa/apli_pmall)
on the UGA gitlab for an example on how to use this app.
'''
)
],
)
boxplot_options = html.Div(
id="boxplot-options",
children=[
html.Div([
html.Label('Graph type: '),
dcc.RadioItems(
id='boxplot-options-graph-type',
className='boxplot-options-items',
options=[
{'label': 'boxplot', 'value': 'boxplot'},
{'label': 'barplot (mean)', 'value': 'barplot'}
],
value='boxplot',
)
]),
html.Div([
html.Label('Group by: '),
dcc.RadioItems(
id='boxplot-options-groubpy',
className='boxplot-options-items',
options=[
{'label': 'date', 'value': 'date'},
{'label': 'site', 'value': 'site'}
],
value='date',
)
])
],
)
timeserie_component = html.Div(
children=[
# plots_options,
html.Div(children=[
dcc.Graph(
id='ts-graph',
figure={'data': [], 'layout': {'title': 'Time serie(s)'}}
)
]),
html.Div(children=[
dcc.Tabs(
value=1,
id="tab-boxplot",
children=[
dcc.Tab(label="Seasonal", value=1),
dcc.Tab(label="Monthly", value=2),
]
),
boxplot_options,
dcc.Graph(
id='box-graph',
figure={'data': [], 'layout': {'title': 'Seasonal variation'}}
),
])
]
)
def get_daterange_slider(dates):
years = sorted(dates.apply(lambda x: x.year).unique())
slider = dcc.RangeSlider(
id="date_minmax",
min=dates.apply(lambda x: x.year).min(),
max=dates.apply(lambda x: x.year).max()+1,
value=[datetime2fractionaldate(dates.min()),
datetime2fractionaldate(dates.max())+1],
step=1/12,
marks={str(year): str(year) for year in
range(min(years),max(years)+1)}
)
return slider
This diff is collapsed.
This diff is collapsed.
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