Skip to content

Commit

Permalink
MAJ classement villes.plus
Browse files Browse the repository at this point in the history
  • Loading branch information
mquandalle committed Sep 9, 2023
1 parent 32abff6 commit 9c87237
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 88 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ node_modules
data-fetch/miniatures/aides-jeunes-repo

# Generated at build time
src/data
src/lib/data
src/lib/data/*
!src/lib/data/classement-villeplus.json
Binary file added bun.lockb
Binary file not shown.
28 changes: 28 additions & 0 deletions data-fetch/maj-villesplus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { JSDOM } from 'jsdom';
import epci from '@etalab/decoupage-administratif/data/epci.json' assert { type: 'json' };
import { slugify } from '../src/lib/utils.js';
import { writeJsonData } from '../src/scripts/writeData.js';

const source = await fetch('https://www.villes.plus/cyclables/metropoles');
const { document } = new JSDOM(await source.text()).window;

const rawMetropoles = [...document.querySelectorAll('h3')].map((h3) => h3.textContent);

const simplify = (s) =>
slugify(s)
.replace(/[0-9]/g, '')
.replace(/((euro)?metropole|de|)/g, '')
.replace(/(^-+|-+$)/g, '');

const normalizedEpciNames = rawMetropoles.map(
(line) => epci.find(({ nom }) => simplify(nom).includes(simplify(line)))?.nom
);

if (normalizedEpciNames.find((n) => !n)) {
console.log('❌ Missing EPCI:');
console.log(normalizedEpciNames.filter(Boolean).join('\n'));
} else {
console.log("✅ All EPCI's found:");
console.log(normalizedEpciNames.join('\n'));
writeJsonData('classement-villeplus.json', normalizedEpciNames);
}
34 changes: 0 additions & 34 deletions data-fetch/villes.plus/index.js

This file was deleted.

93 changes: 47 additions & 46 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,49 @@
{
"name": "mesaidesvelo",
"version": "1.0.0",
"scripts": {
"postinstall": "node ./src/scripts/postinstall.js",
"dev": "VITE_SITE=mesaidesvelo.fr vite dev",
"dev:retrofit": "VITE_SITE=aideretrofit.fr vite dev",
"build": "VITE_SITE=mesaidesvelo.fr vite build",
"build:retrofit": "VITE_SITE=aideretrofit.fr vite build",
"preview": "VITE_SITE=mesaidesvelo.fr vite preview",
"sync-entreprises": "node ./data-fetch/entreprises/download-gsheet-data.js",
"sync": "svelte-kit sync",
"test": "npm run test:playwright && npm run test:vitest -- run",
"test:playwright": "npx playwright test tests/navigation.spec.js",
"test:vitest": "vitest",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"type": "module",
"private": true,
"devDependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@playwright/test": "^1.35.1",
"@rollup/plugin-yaml": "^4.1.1",
"@sveltejs/adapter-vercel": "^3.0.1",
"@sveltejs/kit": "^1.21.0",
"mdsvex": "^0.11.0",
"node-fetch": "^3.3.1",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"sharp": "=0.32.1",
"svelte": "^4.0.1",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vite-plugin-windicss": "^1.9.0",
"vitest": "^0.32.2",
"wget-improved": "^3.4.0",
"yaml": "^2.3.1"
},
"dependencies": {
"@etalab/decoupage-administratif": "^3.0.0",
"fuzzysort": "^2.0.4",
"playwright-aws-lambda": "^0.10.0",
"playwright-core": "^1.35.1",
"publicodes": "^1.0.0-beta.70"
}
"name": "mesaidesvelo",
"version": "1.0.0",
"scripts": {
"postinstall": "node ./src/scripts/postinstall.js",
"dev": "VITE_SITE=mesaidesvelo.fr vite dev",
"dev:retrofit": "VITE_SITE=aideretrofit.fr vite dev",
"build": "VITE_SITE=mesaidesvelo.fr vite build",
"build:retrofit": "VITE_SITE=aideretrofit.fr vite build",
"preview": "VITE_SITE=mesaidesvelo.fr vite preview",
"sync-entreprises": "node ./data-fetch/entreprises/download-gsheet-data.js",
"sync": "svelte-kit sync",
"test": "npm run test:playwright && npm run test:vitest -- run",
"test:playwright": "npx playwright test tests/navigation.spec.js",
"test:vitest": "vitest",
"lint": "prettier --ignore-path .gitignore --check --plugin-search-dir=. .",
"format": "prettier --ignore-path .gitignore --write --plugin-search-dir=. ."
},
"type": "module",
"private": true,
"devDependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@playwright/test": "^1.35.1",
"@rollup/plugin-yaml": "^4.1.1",
"@sveltejs/adapter-vercel": "^3.0.1",
"@sveltejs/kit": "^1.21.0",
"mdsvex": "^0.11.0",
"node-fetch": "^3.3.1",
"prettier": "^2.8.8",
"prettier-plugin-svelte": "^2.10.1",
"sharp": "=0.32.1",
"svelte": "^4.0.1",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vite-plugin-windicss": "^1.9.0",
"vitest": "^0.32.2",
"wget-improved": "^3.4.0",
"yaml": "^2.3.1"
},
"dependencies": {
"@etalab/decoupage-administratif": "^3.0.0",
"fuzzysort": "^2.0.4",
"jsdom": "^22.1.0",
"playwright-aws-lambda": "^0.10.0",
"playwright-core": "^1.35.1",
"publicodes": "^1.0.0-beta.70"
}
}
24 changes: 24 additions & 0 deletions src/lib/data/classement-villeplus.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[
"Eurométropole de Strasbourg",
"Bordeaux Métropole",
"Grenoble-Alpes-Métropole",
"Toulouse Métropole",
"Montpellier Méditerranée Métropole",
"Métropole Toulon-Provence-Méditerranée",
"Orléans Métropole",
"CC du Bassin de Marennes",
"Métropole du Grand Paris",
"CC de la Plaine Dijonnaise",
"Métropole de Lyon",
"Tours Métropole Val de Loire",
"Nantes Métropole",
"Brest Métropole",
"Métropole du Grand Nancy",
"Métropole Européenne de Lille",
"Clermont Auvergne Métropole",
"Metz Métropole",
"Métropole Rouen Normandie",
"Métropole Nice Côte d'Azur",
"Métropole d'Aix-Marseille-Provence",
"Saint-Etienne Métropole"
]
11 changes: 10 additions & 1 deletion src/routes/(front)/(search)/ville/[slug]/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,16 @@ export async function load({ params }) {
};
}

infos.classementVillePlus = classementVilleplus.findIndex((epci) => epci === localisation.epci);
const posClassementVillePlus = classementVilleplus.findIndex(
(epci) => epci === localisation.epci
);

if (posClassementVillePlus > -1) {
infos.classementVillePlus = {
position: posClassementVillePlus + 1,
total: classementVilleplus.length,
};
}

if (barometreFubPerCity[localisation.codeInsee]) {
const labelsFub = {
Expand Down
11 changes: 6 additions & 5 deletions src/routes/(front)/(search)/ville/[slug]/ExplanationsText.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,13 @@
Vous pouvez consultez le détail des notes sur le
<a href="https://barometre.parlons-velo.fr/2021/palmares/">site du baromètre</a>.
</p>
{#if infos.classementVillePlus > -1}
{#if infos.classementVillePlus}
<p>
Par ailleurs {leEPCI} se classe {infos.classementVillePlus + 1}<sup
>{infos.classementVillePlus === 0 ? 'ère' : 'ème'}</sup
>/20 au <a href="https://villes.plus/cyclables">classement ville.plus</a> des villes cyclables.
Ce classement mesure la part de pistes cyclables sécurisées pour relier les différentes mairies
Par ailleurs {leEPCI} se classe {infos.classementVillePlus.position}<sup
>{infos.classementVillePlus === 1 ? 'ère' : 'ème'}</sup
>/{infos.classementVillePlus.total} au
<a href="https://villes.plus/cyclables">classement ville.plus</a> des villes cyclables. Ce
classement mesure la part de pistes cyclables sécurisées pour relier les différentes mairies
de la métropole.
</p>
{/if}
Expand Down

0 comments on commit 9c87237

Please sign in to comment.