Add pedestrian streets dataset

This commit is contained in:
coolneng 2020-06-13 18:23:34 +02:00
parent 4f5013460f
commit ffe9009d1b
Signed by: coolneng
GPG Key ID: 9893DA236405AF57
3 changed files with 12 additions and 0 deletions

View File

@ -4,6 +4,7 @@ from wtforms import SelectField, SubmitField
from wtforms.validators import DataRequired from wtforms.validators import DataRequired
# NOTE The choices should be shorter
class DatasetForm(FlaskForm): class DatasetForm(FlaskForm):
dataset = SelectField(validators=[DataRequired()], choices=DATASETS) dataset = SelectField(validators=[DataRequired()], choices=DATASETS)
submit = SubmitField("Submit") submit = SubmitField("Submit")

View File

@ -3,6 +3,7 @@ from json import load
from pandas import DataFrame, json_normalize from pandas import DataFrame, json_normalize
from constants import COLUMNS, FILES from constants import COLUMNS, FILES
from app.data_request import request_dataset
def open_json(dataset) -> dict: def open_json(dataset) -> dict:
@ -18,6 +19,7 @@ def create_dataframe(dataset) -> DataFrame:
""" """
Creates a DataFrame from a JSON file Creates a DataFrame from a JSON file
""" """
request_dataset(dataset)
json = open_json(dataset) json = open_json(dataset)
df = json_normalize(data=json, record_path=["records"], errors="ignore",) df = json_normalize(data=json, record_path=["records"], errors="ignore",)
filtered_df = df.filter(items=COLUMNS[dataset]) filtered_df = df.filter(items=COLUMNS[dataset])

View File

@ -2,12 +2,14 @@ DATASETS = [
"coronavirus-commercants-parisiens-livraison-a-domicile", "coronavirus-commercants-parisiens-livraison-a-domicile",
"deconfinement-pistes-cyclables-temporaires", "deconfinement-pistes-cyclables-temporaires",
"deconfinement-parking-relais-doublement-des-places", "deconfinement-parking-relais-doublement-des-places",
"deconfinement-rues-amenagees-pour-pietons",
] ]
URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&rows=-1" URL = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&rows=-1"
FILES = { FILES = {
"deconfinement-pistes-cyclables-temporaires": "data/cycling-paths.json", "deconfinement-pistes-cyclables-temporaires": "data/cycling-paths.json",
"deconfinement-parking-relais-doublement-des-places": "data/relay-parking.json", "deconfinement-parking-relais-doublement-des-places": "data/relay-parking.json",
"coronavirus-commercants-parisiens-livraison-a-domicile": "data/home-delivery.json", "coronavirus-commercants-parisiens-livraison-a-domicile": "data/home-delivery.json",
"deconfinement-rues-amenagees-pour-pietons": "data/pedestrian-streets.json",
} }
COLUMNS = { COLUMNS = {
"deconfinement-pistes-cyclables-temporaires": [ "deconfinement-pistes-cyclables-temporaires": [
@ -37,5 +39,12 @@ COLUMNS = {
"fields.telephone", "fields.telephone",
"fields.mail", "fields.mail",
], ],
"deconfinement-rues-amenagees-pour-pietons": [
"fields.geo_shape.coordinates",
"fields.nom_voie",
"fields.categorie",
"fields.statut",
"record_timestamp",
],
} }
SECRET_KEY = "trolaso" SECRET_KEY = "trolaso"