commit ff7b992aac2cc0c966cf7767e188b8e3147d8139 Author: Brandon Dyck Date: Tue Apr 18 20:36:51 2023 -0600 Import some CSVs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c5855b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.venv +*.db diff --git a/createdb.sh b/createdb.sh new file mode 100644 index 0000000..836dc07 --- /dev/null +++ b/createdb.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +set -e + +DB=francecrime.db +DEPT=department +REG=region +DEPT_CRIMES=department_crimes +rm -f "$DB" +sqlite-utils create-database "$DB" + +# Region lookup table +curl -L https://www.insee.fr/fr/statistiques/fichier/6800675/v_region_2023.csv | \ + sqlite-utils insert "$DB" "$REG" - --csv --convert 'return {"code": row["REG"], "name": row["NCCENR"]}' +sqlite-utils transform "$DB" "$REG" --pk code + +# Department lookup table +curl -L https://www.insee.fr/fr/statistiques/fichier/6800675/v_departement_2023.csv | \ + sqlite-utils insert "$DB" "$DEPT" - --csv --convert 'return {"code": row["DEP"], "name": row["NCCENR"]}' +sqlite-utils transform "$DB" "$DEPT" --pk code +# TODO Add a way to filter out island possessions + +# Crimes by department +curl -L https://www.data.gouv.fr/fr/datasets/r/acc332f6-92be-42af-9721-f3609bea8cfc | gzip -d | \ + sqlite-utils insert "$DB" "$DEPT_CRIMES" - --csv --delimiter=";" --convert ' + def full_year(year): + return "20" + year + def comma_float(s): + return float(s.replace(",", ".")) + return { + "class": row["classe"], + "year": full_year(row["annee"]), + "department": row["Code.département"], + "region": row["Code.région"], + "cases": int(row["faits"]), + "population": int(row["POP"]), + "rate_per_thousand": comma_float(row["tauxpourmille"])}' +sqlite-utils extract "$DB" "$DEPT_CRIMES" class +sqlite-utils transform "$DB" "$DEPT_CRIMES" --pk class_id --pk year --pk department +sqlite-utils add-foreign-keys "$DB" \ + "$DEPT_CRIMES" department "$DEPT" code \ + "$DEPT_CRIMES" region "$REG" code +# TODO Rename class_id to class and show English text using crime_classes.csv + +datasette "$DB" -o diff --git a/crime_classes.csv b/crime_classes.csv new file mode 100644 index 0000000..91fcc9e --- /dev/null +++ b/crime_classes.csv @@ -0,0 +1,13 @@ +class,class_french +Intentional blows and injuries,Coups et blessures volontaires +Intrafamilial intentional blows and injuries,Coups et blessures volontaires intrafamiliaux +Other intentional blows and injuries,Autres coups et blessures volontaires +Sexual violence,Violences sexuelles +Armed robberies,Vols avec armes +Violent robberies without a weapon,Vols violents sans arme +Nonviolent thefts,Vols sans violence contre des personnes +Home burglaries,Cambriolages de logement +Thefts of vehicles,Vols de véhicules +Thefts from vehicles,Vols dans les véhicules +Thefts of vehicle accessories,Vols d'accessoires sur véhicules +Intentional destruction and damage,Destructions et dégradations volontaires \ No newline at end of file diff --git a/department.csv b/department.csv new file mode 100644 index 0000000..4c52561 Binary files /dev/null and b/department.csv differ diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..f0c5e98 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,33 @@ +aiofiles==23.1.0 +anyio==3.6.2 +asgi-csrf==0.9 +asgiref==3.6.0 +certifi==2022.12.7 +click==8.1.3 +click-default-group-wheel==1.2.2 +datasette==0.64.1 +h11==0.14.0 +httpcore==0.16.3 +httpx==0.23.3 +hupper==1.11 +idna==3.4 +itsdangerous==2.1.2 +janus==1.0.0 +Jinja2==3.1.2 +lxml==4.9.2 +MarkupSafe==2.1.2 +mergedeep==1.3.4 +Pint==0.20.1 +pluggy==1.0.0 +python-dateutil==2.8.2 +python-multipart==0.0.5 +PyYAML==6.0 +rfc3986==1.5.0 +six==1.16.0 +sniffio==1.3.0 +sqlglot==11.0.1 +sqlite-fts4==1.0.3 +sqlite-utils==3.30 +tabulate==0.9.0 +typing_extensions==4.4.0 +uvicorn==0.20.0