Skip to content

Commit 4a11c57

Browse files
authored
Using real calculated risk scores for each department to be displayed on the map (#34)
* added a graphs.py file that will contain several indicators graphs objects to be used in the homepage.py file ; changed the layout of the homepage in order to better fit our needs * flake8 style corrections * blank line at the beginning of graphs.py * styling errors * styling errors * Add files via upload * using actual risk data to get a colormap with risk * risk json import * minor changes * line too long * deleted commented line
1 parent 4efb68c commit 4a11c57

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

app/assets/up_arrow_png.png

54.6 KB
Loading

app/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
API_URL: str = os.getenv('API_URL')
99
API_LOGIN: str = os.getenv('API_LOGIN')
1010
API_PWD: str = os.getenv('API_PWD')
11+
PYRORISK_FALLBACK: str = "https://github.com/pyronear/pyro-risks/releases/download/v0.1.0-data/pyrorisk_20200901.json"

app/risks.py

+14-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
# NumPy to generate the random scores from 0 to 1 that we are using so far, as well as the classes
1111
import numpy as np
1212

13-
# Useful imports to open and read the GeoJSON file
13+
# Useful imports to open and read the GeoJSON file, and to get risk data from the API
1414
from pathlib import Path
1515
import json
16+
import requests
17+
import config as cfg
1618

1719
# Various modules provided by Dash to build the page layout
1820
import dash_core_components as dcc
@@ -34,10 +36,19 @@
3436
with open(Path(__file__).parent.joinpath('data', 'departements.geojson'), 'rb') as response:
3537
departments = json.load(response)
3638

39+
# We fetch the deparment risk score json and store it in the risk_json variable
40+
# When everything is validated, we'll request the data directly from the API
41+
risk_json = requests.get(cfg.PYRORISK_FALLBACK).json()
3742

38-
# We add to each department in the geojson a new property called "score" that corresponds to the random risk level
43+
# We add to each department in the geojson a new property called "score" that corresponds to the risk level
3944
for department in departments['features']:
40-
department['properties']['score'] = np.random.rand()
45+
dpt_name = department['properties']['nom']
46+
geocode_list = [dpt['geocode'] for dpt in risk_json]
47+
if dpt_name in geocode_list:
48+
risk_json_index = geocode_list.index(dpt_name)
49+
department['properties']['score'] = risk_json[risk_json_index]['score']
50+
else:
51+
department['properties']['score'] = 0
4152

4253

4354
# Preparing the choropleth map, fetching the departments GeoJSON and building the related map attribute

0 commit comments

Comments
 (0)