mirror of
https://forge.chapril.org/tykayn/osm-commerces
synced 2025-10-04 17:04:53 +02:00
follow up graphs
This commit is contained in:
parent
4b4a46c3f7
commit
ab1b9a9d3d
11 changed files with 580 additions and 41 deletions
|
@ -37,6 +37,7 @@ import {
|
||||||
updateMapHeightForLargeScreens
|
updateMapHeightForLargeScreens
|
||||||
} from './utils.js';
|
} from './utils.js';
|
||||||
import tableSortJs from 'table-sort-js/table-sort.js';
|
import tableSortJs from 'table-sort-js/table-sort.js';
|
||||||
|
import 'chartjs-adapter-date-fns';
|
||||||
console.log('TableSort', tableSortJs)
|
console.log('TableSort', tableSortJs)
|
||||||
|
|
||||||
// Charger table-sortable (version non minifiée locale)
|
// Charger table-sortable (version non minifiée locale)
|
||||||
|
@ -270,4 +271,90 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||||
}
|
}
|
||||||
//updateMapHeightForLargeScreens();
|
//updateMapHeightForLargeScreens();
|
||||||
|
|
||||||
|
console.log('window.followupSeries',window.followupSeries)
|
||||||
|
if (!window.followupSeries) return;
|
||||||
|
|
||||||
|
const series = window.followupSeries;
|
||||||
|
|
||||||
|
// Données bornes de recharge
|
||||||
|
const chargingStationCount = (series['charging_station_count'] || []).map(point => ({ x: point.date, y: point.value }));
|
||||||
|
const chargingStationCompletion = (series['charging_station_completion'] || []).map(point => ({ x: point.date, y: point.value }));
|
||||||
|
|
||||||
|
// Données bornes incendie
|
||||||
|
const fireHydrantCount = (series['fire_hydrant_count'] || []).map(point => ({ x: point.date, y: point.value }));
|
||||||
|
const fireHydrantCompletion = (series['fire_hydrant_completion'] || []).map(point => ({ x: point.date, y: point.value }));
|
||||||
|
|
||||||
|
// Graphique bornes de recharge
|
||||||
|
const chargingStationChart = document.getElementById('chargingStationChart');
|
||||||
|
if (chargingStationChart) {
|
||||||
|
new Chart(chargingStationChart, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Nombre de bornes de recharge',
|
||||||
|
data: chargingStationCount,
|
||||||
|
borderColor: 'blue',
|
||||||
|
backgroundColor: 'rgba(0,0,255,0.1)',
|
||||||
|
fill: false,
|
||||||
|
yAxisID: 'y',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Complétion (%)',
|
||||||
|
data: chargingStationCompletion,
|
||||||
|
borderColor: 'green',
|
||||||
|
backgroundColor: 'rgba(0,255,0,0.1)',
|
||||||
|
fill: false,
|
||||||
|
yAxisID: 'y1',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
parsing: false,
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
||||||
|
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
||||||
|
y1: { beginAtZero: true, position: 'right', title: { display: true, text: 'Complétion (%)' }, grid: { drawOnChartArea: false } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Graphique bornes incendie
|
||||||
|
const fireHydrantChart = document.getElementById('fireHydrantChart');
|
||||||
|
if (fireHydrantChart) {
|
||||||
|
new Chart(fireHydrantChart, {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Nombre de bornes incendie',
|
||||||
|
data: fireHydrantCount,
|
||||||
|
borderColor: 'red',
|
||||||
|
backgroundColor: 'rgba(255,0,0,0.1)',
|
||||||
|
fill: false,
|
||||||
|
yAxisID: 'y',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Complétion (%)',
|
||||||
|
data: fireHydrantCompletion,
|
||||||
|
borderColor: 'orange',
|
||||||
|
backgroundColor: 'rgba(255,165,0,0.1)',
|
||||||
|
fill: false,
|
||||||
|
yAxisID: 'y1',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
parsing: false,
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
||||||
|
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
||||||
|
y1: { beginAtZero: true, position: 'right', title: { display: true, text: 'Complétion (%)' }, grid: { drawOnChartArea: false } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
59
migrations/Version20250629130159.php
Normal file
59
migrations/Version20250629130159.php
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250629130159 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE city_follow_up (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, measure DOUBLE PRECISION NOT NULL, date DATETIME NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE place CHANGE email email VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE note note VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE name name VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE note_content note_content VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE street street VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE housenumber housenumber VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE siret siret VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE osm_user osm_user VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE email_content email_content LONGTEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats ADD city_follow_ups_id INT DEFAULT NULL
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats ADD CONSTRAINT FK_574767AAA543722E FOREIGN KEY (city_follow_ups_id) REFERENCES city_follow_up (id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_574767AAA543722E ON stats (city_follow_ups_id)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE city_follow_up
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats DROP FOREIGN KEY FK_574767AAA543722E
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP INDEX IDX_574767AAA543722E ON stats
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats DROP city_follow_ups_id
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE place CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE note note VARCHAR(255) DEFAULT NULL, CHANGE name name VARCHAR(255) DEFAULT NULL, CHANGE note_content note_content VARCHAR(255) DEFAULT NULL, CHANGE street street VARCHAR(255) DEFAULT NULL, CHANGE housenumber housenumber VARCHAR(255) DEFAULT NULL, CHANGE siret siret VARCHAR(255) DEFAULT NULL, CHANGE osm_user osm_user VARCHAR(255) DEFAULT NULL, CHANGE email_content email_content LONGTEXT DEFAULT NULL
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
}
|
71
migrations/Version20250629130947.php
Normal file
71
migrations/Version20250629130947.php
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250629130947 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE city_follow_up ADD stats_id INT DEFAULT NULL
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE city_follow_up ADD CONSTRAINT FK_DFE8468970AA3482 FOREIGN KEY (stats_id) REFERENCES stats (id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_DFE8468970AA3482 ON city_follow_up (stats_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE place CHANGE email email VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE note note VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE name name VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE note_content note_content VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE street street VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE housenumber housenumber VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE siret siret VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE osm_user osm_user VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`, CHANGE email_content email_content LONGTEXT CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_0900_ai_ci`
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats DROP FOREIGN KEY FK_574767AAA543722E
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP INDEX IDX_574767AAA543722E ON stats
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats DROP city_follow_ups_id
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats ADD city_follow_ups_id INT DEFAULT NULL
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE stats ADD CONSTRAINT FK_574767AAA543722E FOREIGN KEY (city_follow_ups_id) REFERENCES city_follow_up (id) ON UPDATE NO ACTION ON DELETE NO ACTION
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_574767AAA543722E ON stats (city_follow_ups_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE city_follow_up DROP FOREIGN KEY FK_DFE8468970AA3482
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP INDEX IDX_DFE8468970AA3482 ON city_follow_up
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE city_follow_up DROP stats_id
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
ALTER TABLE place CHANGE email email VARCHAR(255) DEFAULT NULL, CHANGE note note VARCHAR(255) DEFAULT NULL, CHANGE name name VARCHAR(255) DEFAULT NULL, CHANGE note_content note_content VARCHAR(255) DEFAULT NULL, CHANGE street street VARCHAR(255) DEFAULT NULL, CHANGE housenumber housenumber VARCHAR(255) DEFAULT NULL, CHANGE siret siret VARCHAR(255) DEFAULT NULL, CHANGE osm_user osm_user VARCHAR(255) DEFAULT NULL, CHANGE email_content email_content LONGTEXT DEFAULT NULL
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
}
|
30
package-lock.json
generated
30
package-lock.json
generated
|
@ -6,6 +6,8 @@
|
||||||
"": {
|
"": {
|
||||||
"license": "UNLICENSED",
|
"license": "UNLICENSED",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"charjs": "^0.0.1-security",
|
||||||
|
"chartjs-adapter-date-fns": "^3.0.0",
|
||||||
"jquery": "^3.7.1",
|
"jquery": "^3.7.1",
|
||||||
"table-sort": "^1.0.16"
|
"table-sort": "^1.0.16"
|
||||||
},
|
},
|
||||||
|
@ -1707,7 +1709,6 @@
|
||||||
"version": "0.3.4",
|
"version": "0.3.4",
|
||||||
"resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.4.tgz",
|
"resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.4.tgz",
|
||||||
"integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==",
|
"integrity": "sha512-M5UknZPHRu3DEDWoipU6sE8PdkZ6Z/S+v4dD+Ke8IaNlpdSQah50lz1KtcFBa2vsdOnwbbnxJwVM4wty6udA5w==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@mapbox/geojson-rewind": {
|
"node_modules/@mapbox/geojson-rewind": {
|
||||||
|
@ -2623,11 +2624,15 @@
|
||||||
"node": ">=4"
|
"node": ">=4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/charjs": {
|
||||||
|
"version": "0.0.1-security",
|
||||||
|
"resolved": "https://registry.npmjs.org/charjs/-/charjs-0.0.1-security.tgz",
|
||||||
|
"integrity": "sha512-O3j2a0oEM2LXTyFdAq5Y2ntGaSekgeAW7FtjOGU78PNe5GReNGQvoEpyGmd8Xv3/8VS+2HbgWnxntMvVGrY4Cg=="
|
||||||
|
},
|
||||||
"node_modules/chart.js": {
|
"node_modules/chart.js": {
|
||||||
"version": "4.5.0",
|
"version": "4.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.5.0.tgz",
|
||||||
"integrity": "sha512-aYeC/jDgSEx8SHWZvANYMioYMZ2KX02W6f6uVfyteuCGcadDLcYVHdfdygsTQkQ4TKn5lghoojAsPj5pu0SnvQ==",
|
"integrity": "sha512-aYeC/jDgSEx8SHWZvANYMioYMZ2KX02W6f6uVfyteuCGcadDLcYVHdfdygsTQkQ4TKn5lghoojAsPj5pu0SnvQ==",
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@kurkle/color": "^0.3.0"
|
"@kurkle/color": "^0.3.0"
|
||||||
|
@ -2636,6 +2641,16 @@
|
||||||
"pnpm": ">=8"
|
"pnpm": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/chartjs-adapter-date-fns": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/chartjs-adapter-date-fns/-/chartjs-adapter-date-fns-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-Rs3iEB3Q5pJ973J93OBTpnP7qoGwvq3nUnoMdtxO+9aoJof7UFcRbWcIDteXuYd1fgAvct/32T9qaLyLuZVwCg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peerDependencies": {
|
||||||
|
"chart.js": ">=2.8.0",
|
||||||
|
"date-fns": ">=2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/chartjs-plugin-datalabels": {
|
"node_modules/chartjs-plugin-datalabels": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/chartjs-plugin-datalabels/-/chartjs-plugin-datalabels-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/chartjs-plugin-datalabels/-/chartjs-plugin-datalabels-2.2.0.tgz",
|
||||||
|
@ -3072,6 +3087,17 @@
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "CC0-1.0"
|
"license": "CC0-1.0"
|
||||||
},
|
},
|
||||||
|
"node_modules/date-fns": {
|
||||||
|
"version": "4.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz",
|
||||||
|
"integrity": "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"peer": true,
|
||||||
|
"funding": {
|
||||||
|
"type": "github",
|
||||||
|
"url": "https://github.com/sponsors/kossnocorp"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/debug": {
|
"node_modules/debug": {
|
||||||
"version": "4.4.1",
|
"version": "4.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-4.4.1.tgz",
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
"build": "encore production --progress"
|
"build": "encore production --progress"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"charjs": "^0.0.1-security",
|
||||||
|
"chartjs-adapter-date-fns": "^3.0.0",
|
||||||
"jquery": "^3.7.1",
|
"jquery": "^3.7.1",
|
||||||
"table-sort": "^1.0.16"
|
"table-sort": "^1.0.16"
|
||||||
}
|
}
|
||||||
|
|
7
public/js/chartjs/chartjs-adapter-date-fns.js
Normal file
7
public/js/chartjs/chartjs-adapter-date-fns.js
Normal file
File diff suppressed because one or more lines are too long
110
src/Controller/FollowUpController.php
Normal file
110
src/Controller/FollowUpController.php
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use App\Entity\Stats;
|
||||||
|
use App\Entity\CityFollowUp;
|
||||||
|
use App\Service\Motocultrice;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
|
|
||||||
|
class FollowUpController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/admin/followup/{insee_code}', name: 'admin_followup')]
|
||||||
|
public function followup(
|
||||||
|
string $insee_code,
|
||||||
|
Motocultrice $motocultrice,
|
||||||
|
EntityManagerInterface $em
|
||||||
|
): Response {
|
||||||
|
// Récupérer la stats de la ville
|
||||||
|
$stats = $em->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||||
|
if (!$stats) {
|
||||||
|
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||||
|
return $this->redirectToRoute('app_admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Récupérer les objets OSM
|
||||||
|
$elements = $motocultrice->followUpCity($insee_code);
|
||||||
|
|
||||||
|
// Séparer les objets par type
|
||||||
|
$fire_hydrants = array_filter($elements, fn($el) => ($el['tags']['emergency'] ?? null) === 'fire_hydrant');
|
||||||
|
$charging_stations = array_filter($elements, fn($el) => ($el['tags']['amenity'] ?? null) === 'charging_station');
|
||||||
|
|
||||||
|
// --- Suivi du nombre d'objets ---
|
||||||
|
$now = new \DateTime();
|
||||||
|
$types = [
|
||||||
|
'fire_hydrant' => [
|
||||||
|
'label' => 'Bornes incendie',
|
||||||
|
'objects' => $fire_hydrants
|
||||||
|
],
|
||||||
|
'charging_station' => [
|
||||||
|
'label' => 'Bornes de recharge',
|
||||||
|
'objects' => $charging_stations
|
||||||
|
]
|
||||||
|
];
|
||||||
|
foreach ($types as $type => $data) {
|
||||||
|
// Suivi du nombre
|
||||||
|
$followupCount = new CityFollowUp();
|
||||||
|
$followupCount->setName($type . '_count')
|
||||||
|
->setMeasure(count($data['objects']))
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCount);
|
||||||
|
|
||||||
|
// Suivi de la complétion personnalisé
|
||||||
|
if ($type === 'fire_hydrant') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['ref'] ?? null);
|
||||||
|
});
|
||||||
|
} elseif ($type === 'charging_station') {
|
||||||
|
$completed = array_filter($data['objects'], function($el) {
|
||||||
|
return !empty($el['tags']['charging_station:output'] ?? null) && !empty($el['tags']['capacity'] ?? null);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
$completed = [];
|
||||||
|
}
|
||||||
|
$completion = count($data['objects']) > 0 ? round(count($completed) / count($data['objects']) * 100) : 0;
|
||||||
|
$followupCompletion = new CityFollowUp();
|
||||||
|
$followupCompletion->setName($type . '_completion')
|
||||||
|
->setMeasure($completion)
|
||||||
|
->setDate($now)
|
||||||
|
->setStats($stats);
|
||||||
|
$em->persist($followupCompletion);
|
||||||
|
}
|
||||||
|
$em->flush();
|
||||||
|
|
||||||
|
$this->addFlash('success', 'Suivi enregistré pour la ville.');
|
||||||
|
return $this->redirectToRoute('admin_followup_graph', ['insee_code' => $insee_code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[Route('/admin/followup/{insee_code}/graph', name: 'admin_followup_graph')]
|
||||||
|
public function followupGraph(
|
||||||
|
string $insee_code,
|
||||||
|
EntityManagerInterface $em
|
||||||
|
): Response {
|
||||||
|
$stats = $em->getRepository(Stats::class)->findOneBy(['zone' => $insee_code]);
|
||||||
|
if (!$stats) {
|
||||||
|
$this->addFlash('error', 'Aucune stats trouvée pour ce code INSEE.');
|
||||||
|
return $this->redirectToRoute('app_admin');
|
||||||
|
}
|
||||||
|
$followups = $stats->getCityFollowUps();
|
||||||
|
$followups = $followups->toArray();
|
||||||
|
usort($followups, fn($a, $b) => $a->getDate() <=> $b->getDate());
|
||||||
|
// Grouper par type
|
||||||
|
$series = [];
|
||||||
|
foreach ($followups as $fu) {
|
||||||
|
$series[$fu->getName()][] = [
|
||||||
|
'date' => $fu->getDate()->format('c'),
|
||||||
|
'value' => $fu->getMeasure(),
|
||||||
|
'name' => $fu->getName(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return $this->render('admin/followup_graph.html.twig', [
|
||||||
|
'stats' => $stats,
|
||||||
|
'series' => $series
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -3,8 +3,6 @@
|
||||||
namespace App\Entity;
|
namespace App\Entity;
|
||||||
|
|
||||||
use App\Repository\CityFollowUpRepository;
|
use App\Repository\CityFollowUpRepository;
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
|
||||||
use Doctrine\Common\Collections\Collection;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: CityFollowUpRepository::class)]
|
#[ORM\Entity(repositoryClass: CityFollowUpRepository::class)]
|
||||||
|
@ -24,16 +22,8 @@ class CityFollowUp
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
private ?\DateTime $date = null;
|
private ?\DateTime $date = null;
|
||||||
|
|
||||||
/**
|
#[ORM\ManyToOne(targetEntity: Stats::class, inversedBy: 'cityFollowUps')]
|
||||||
* @var Collection<int, Stats>
|
private ?Stats $stats = null;
|
||||||
*/
|
|
||||||
#[ORM\OneToMany(targetEntity: Stats::class, mappedBy: 'cityFollowUps')]
|
|
||||||
private Collection $stats;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->stats = new ArrayCollection();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
{
|
{
|
||||||
|
@ -76,33 +66,14 @@ class CityFollowUp
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function getStats(): ?Stats
|
||||||
* @return Collection<int, Stats>
|
|
||||||
*/
|
|
||||||
public function getStats(): Collection
|
|
||||||
{
|
{
|
||||||
return $this->stats;
|
return $this->stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addStat(Stats $stat): static
|
public function setStats(?Stats $stats): static
|
||||||
{
|
{
|
||||||
if (!$this->stats->contains($stat)) {
|
$this->stats = $stats;
|
||||||
$this->stats->add($stat);
|
|
||||||
$stat->setCityFollowUps($this);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeStat(Stats $stat): static
|
|
||||||
{
|
|
||||||
if ($this->stats->removeElement($stat)) {
|
|
||||||
// set the owning side to null (unless already changed)
|
|
||||||
if ($stat->getCityFollowUps() === $this) {
|
|
||||||
$stat->setCityFollowUps(null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,8 +98,11 @@ class Stats
|
||||||
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2, nullable: true)]
|
#[ORM\Column(type: Types::DECIMAL, precision: 15, scale: 2, nullable: true)]
|
||||||
private ?string $budget_annuel = null;
|
private ?string $budget_annuel = null;
|
||||||
|
|
||||||
#[ORM\ManyToOne(inversedBy: 'stats')]
|
/**
|
||||||
private ?CityFollowUp $cityFollowUps = null;
|
* @var Collection<int, CityFollowUp>
|
||||||
|
*/
|
||||||
|
#[ORM\OneToMany(mappedBy: 'stats', targetEntity: CityFollowUp::class, cascade: ['persist', 'remove'])]
|
||||||
|
private Collection $cityFollowUps;
|
||||||
|
|
||||||
public function getCTCurlBase(): ?string
|
public function getCTCurlBase(): ?string
|
||||||
{
|
{
|
||||||
|
@ -251,6 +254,7 @@ class Stats
|
||||||
{
|
{
|
||||||
$this->places = new ArrayCollection();
|
$this->places = new ArrayCollection();
|
||||||
$this->statsHistories = new ArrayCollection();
|
$this->statsHistories = new ArrayCollection();
|
||||||
|
$this->cityFollowUps = new ArrayCollection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
|
@ -569,15 +573,30 @@ class Stats
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCityFollowUps(): ?CityFollowUp
|
/**
|
||||||
|
* @return Collection<int, CityFollowUp>
|
||||||
|
*/
|
||||||
|
public function getCityFollowUps(): Collection
|
||||||
{
|
{
|
||||||
return $this->cityFollowUps;
|
return $this->cityFollowUps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setCityFollowUps(?CityFollowUp $cityFollowUps): static
|
public function addCityFollowUp(CityFollowUp $cityFollowUp): static
|
||||||
{
|
{
|
||||||
$this->cityFollowUps = $cityFollowUps;
|
if (!$this->cityFollowUps->contains($cityFollowUp)) {
|
||||||
|
$this->cityFollowUps->add($cityFollowUp);
|
||||||
|
$cityFollowUp->setStats($this);
|
||||||
|
}
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function removeCityFollowUp(CityFollowUp $cityFollowUp): static
|
||||||
|
{
|
||||||
|
if ($this->cityFollowUps->removeElement($cityFollowUp)) {
|
||||||
|
if ($cityFollowUp->getStats() === $this) {
|
||||||
|
$cityFollowUp->setStats(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -556,4 +556,41 @@ out meta;';
|
||||||
'counters' => $counters
|
'counters' => $counters
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Génère la requête Overpass pour les bornes incendie et bornes de recharge
|
||||||
|
*/
|
||||||
|
public function get_followup_query($zone) {
|
||||||
|
return <<<QUERY
|
||||||
|
[out:json][timeout:60];
|
||||||
|
area["ref:INSEE"="$zone"]->.searchArea;
|
||||||
|
(
|
||||||
|
nwr["emergency"="fire_hydrant"](area.searchArea);
|
||||||
|
nwr["amenity"="charging_station"](area.searchArea);
|
||||||
|
);
|
||||||
|
out body;
|
||||||
|
>;
|
||||||
|
out skel qt;
|
||||||
|
QUERY;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère les objets de suivi pour une ville (bornes incendie et bornes de recharge)
|
||||||
|
*/
|
||||||
|
public function followUpCity($zone) {
|
||||||
|
$query = $this->get_followup_query($zone);
|
||||||
|
try {
|
||||||
|
$response = $this->client->request('POST', 'https://overpass-api.de/api/interpreter', [
|
||||||
|
'body' => ['data' => $query],
|
||||||
|
'timeout' => 60
|
||||||
|
]);
|
||||||
|
if ($response->getStatusCode() !== 200) {
|
||||||
|
throw new \Exception('L\'API Overpass a retourné un code de statut non-200 : ' . $response->getStatusCode());
|
||||||
|
}
|
||||||
|
$data = json_decode($response->getContent(), true);
|
||||||
|
return $data['elements'] ?? [];
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
150
templates/admin/followup_graph.html.twig
Normal file
150
templates/admin/followup_graph.html.twig
Normal file
|
@ -0,0 +1,150 @@
|
||||||
|
{% extends 'base.html.twig' %}
|
||||||
|
|
||||||
|
{% block title %}Suivi des objets OSM - {{ stats.name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block body %}
|
||||||
|
<div class="container mt-4">
|
||||||
|
<h1>Suivi des objets OSM pour {{ stats.name }} ({{ stats.zone }})</h1>
|
||||||
|
<p>Historique des bornes incendie et bornes de recharge (nombre et complétion).</p>
|
||||||
|
|
||||||
|
<h2>Bornes de recharge</h2>
|
||||||
|
<canvas id="chargingStationChart" width="600" height="300"></canvas>
|
||||||
|
|
||||||
|
<h2>Bornes incendie</h2>
|
||||||
|
<canvas id="fireHydrantChart" width="600" height="300"></canvas>
|
||||||
|
|
||||||
|
<h2 class="mt-4">Données brutes</h2>
|
||||||
|
<table class="table table-bordered table-striped">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Date</th>
|
||||||
|
<th>Type</th>
|
||||||
|
<th>Label</th>
|
||||||
|
<th>Valeur</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for type, points in series %}
|
||||||
|
{% for point in points %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ point.date }}</td>
|
||||||
|
<td>{{ type }}</td>
|
||||||
|
<td>{{ point.name }}</td>
|
||||||
|
<td>{{ point.value }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<a href="{{ path('app_admin_stats', {'insee_code': stats.zone}) }}" class="btn btn-secondary mt-3"><i class="bi bi-arrow-left"></i> Retour à la fiche ville</a>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block javascripts %}
|
||||||
|
{{ parent() }}
|
||||||
|
<script src="/js/chartjs/chart.umd.js"></script>
|
||||||
|
<script src="/js/chartjs/chartjs-adapter-date-fns.js"></script>
|
||||||
|
<script>
|
||||||
|
// Log du contenu de la variable series
|
||||||
|
console.log('series', {{ series|json_encode|raw }});
|
||||||
|
|
||||||
|
// Données bornes de recharge
|
||||||
|
const chargingStationCount = [
|
||||||
|
{% for point in series['charging_station_count'] ?? [] %}
|
||||||
|
{ x: "{{ point.date }}", y: {{ point.value }} },
|
||||||
|
{% endfor %}
|
||||||
|
];
|
||||||
|
const chargingStationCompletion = [
|
||||||
|
{% for point in series['charging_station_completion'] ?? [] %}
|
||||||
|
{ x: "{{ point.date }}", y: {{ point.value }} },
|
||||||
|
{% endfor %}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Données bornes incendie
|
||||||
|
const fireHydrantCount = [
|
||||||
|
{% for point in series['fire_hydrant_count'] ?? [] %}
|
||||||
|
{ x: "{{ point.date }}", y: {{ point.value }} },
|
||||||
|
{% endfor %}
|
||||||
|
];
|
||||||
|
const fireHydrantCompletion = [
|
||||||
|
{% for point in series['fire_hydrant_completion'] ?? [] %}
|
||||||
|
{ x: "{{ point.date }}", y: {{ point.value }} },
|
||||||
|
{% endfor %}
|
||||||
|
];
|
||||||
|
|
||||||
|
// Log des tableaux JS générés
|
||||||
|
console.log('chargingStationCount', chargingStationCount);
|
||||||
|
console.log('chargingStationCompletion', chargingStationCompletion);
|
||||||
|
console.log('fireHydrantCount', fireHydrantCount);
|
||||||
|
console.log('fireHydrantCompletion', fireHydrantCompletion);
|
||||||
|
|
||||||
|
// Graphique bornes de recharge
|
||||||
|
new Chart(document.getElementById('chargingStationChart'), {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Nombre de bornes de recharge',
|
||||||
|
data: chargingStationCount,
|
||||||
|
borderColor: 'blue',
|
||||||
|
backgroundColor: 'rgba(0,0,255,0.1)',
|
||||||
|
fill: false,
|
||||||
|
yAxisID: 'y',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Complétion (%)',
|
||||||
|
data: chargingStationCompletion,
|
||||||
|
borderColor: 'green',
|
||||||
|
backgroundColor: 'rgba(0,255,0,0.1)',
|
||||||
|
fill: false,
|
||||||
|
yAxisID: 'y1',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
// parsing: false,
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
||||||
|
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
||||||
|
y1: { beginAtZero: true, position: 'right', title: { display: true, text: 'Complétion (%)' }, grid: { drawOnChartArea: false } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Graphique bornes incendie
|
||||||
|
new Chart(document.getElementById('fireHydrantChart'), {
|
||||||
|
type: 'line',
|
||||||
|
data: {
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Nombre de bornes incendie',
|
||||||
|
data: fireHydrantCount,
|
||||||
|
borderColor: 'red',
|
||||||
|
backgroundColor: 'rgba(255,0,0,0.1)',
|
||||||
|
// fill: false,
|
||||||
|
yAxisID: 'y',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: 'Complétion (%)',
|
||||||
|
data: fireHydrantCompletion,
|
||||||
|
borderColor: 'orange',
|
||||||
|
backgroundColor: 'rgba(255,165,0,0.1)',
|
||||||
|
// fill: false,
|
||||||
|
yAxisID: 'y1',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
options: {
|
||||||
|
// parsing: false,
|
||||||
|
responsive: true,
|
||||||
|
scales: {
|
||||||
|
x: { type: 'time', time: { unit: 'day' }, title: { display: true, text: 'Date' } },
|
||||||
|
y: { beginAtZero: true, title: { display: true, text: 'Nombre' } },
|
||||||
|
y1: { beginAtZero: true, position: 'right', title: { display: true, text: 'Complétion (%)' }, grid: { drawOnChartArea: false } }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
Loading…
Add table
Add a link
Reference in a new issue