Commit d2d21ddd authored by JonathanMM's avatar JonathanMM

WIP : Extrait du code gérant les graphs

parent 79c5d2a3
......@@ -126,6 +126,10 @@ switch($_GET['action'])
echo json_encode(getCommunesCarte($idConso));
exit();
break;
case 'getFullConsoResumeSeptJours':
echo json_encode(getFullConsoResume("-7days", 60));
exit();
break;
}
function getBikeInstantane($codeStation)
......@@ -689,6 +693,61 @@ function getDataConsoResume($filtre, $periode)
);
}
function getFullConsoResume($filtre, $periode)
{
global $pdo;
//Filtre date
$date = new DateTime($filtre);
$filtreDate = $date->format('Y-m-d H:i:s');
$requete = $pdo->query('SELECT *
FROM resumeConso
WHERE `date` >= "'.$filtreDate.'" AND duree = '.$periode.'
ORDER BY date ASC');
$resumeStatusStation = $requete->fetchAll();
$datesResume = [];
$nbStationsData = [];
$nbStationsDetecteData = [];
$nbBikeData = [];
$nbEbikeData = [];
foreach($resumeStatusStation as $statut)
{
$datesResume[] = (new DateTime($statut['date']))->format("d/m H\hi");
$nbStationsData[] = $statut['nbStation'];
$nbStationsDetecteData[] = $statut['nbStationDetecte'];
$nbBikeData[] = $c['nbBikeMoyenne'];
$nbEbikeData[] = $c['nbEBikeMoyenne'];
}
return array(
'labels' => $datesResume,
'datasets' => array(
array(
'label' => 'Stations annoncées',
'backgroundColor' => 'rgba(173,0,130,0.5)',
'data' => $nbStationsData
),
array(
'label' => 'Stations détectées',
'backgroundColor' => 'rgba(208,74,5,0.5)',
'data' => $nbStationsDetecteData
),
array(
'label' => 'Vélos mécaniques',
'backgroundColor' => 'rgba(104,221,46,0.5)',
'data' => $nbBikeData
),
array(
'label' => 'Vélos électriques',
'backgroundColor' => 'rgba(76, 213, 233, 0.5)',
'data' => $nbEbikeData
)
)
);
}
function getConsoBikeResume($filtreDate, $periode)
{
$data = getDataConsoBikeResume($filtreDate, $periode);
......
var graphInstance = {};
var graphData = null;
var graphDataSets = null;
function changerGraphe()
{
var choixType = $("#typeGraphiqueSelect").val();
if(choixType == '_double')
listeType = ['Conso', 'ConsoBike'];
else
listeType = [choixType];
var choixPeriode = $("#dureeGraphiqueSelect").val();
for(i in listeType)
{
var choixType = listeType[i];
var choix = 'get' + choixType;
switch (choixPeriode) {
case "instantanee":
$("#displayDetailsArea").hide();
displayGraph(choix+"Instantane", choixType);
break;
case "troisHeures":
$("#displayDetailsArea").show();
displayGraph(choix+"ResumeTroisHeures", choixType);
break;
case "unJour":
$("#displayDetailsArea").show();
displayGraph(choix+"ResumeUnJour", choixType);
break;
case "septJours":
$("#displayDetailsArea").show();
displayGraph(choix+"ResumeSeptJours", choixType);
break;
case "unMois":
$("#displayDetailsArea").show();
displayGraph(choix+"ResumeUnMois", choixType);
break;
}
}
}
function displayGraph(actionUrl, choixType)
{
getData('api.php?action='+actionUrl+'&codeStation='+codeStation).then(function(data)
{
updateGraph(data, choixType);
});
}
function updateGraph(data, choixType)
{
if(graphInstance != null && choixType != 'ConsoBike')
{
for(i in graphInstance)
{
var instance = graphInstance[i];
instance.destroy();
}
graphInstance = {};
}
var idChart = "#chartBikes";
var isBike;
var isInstantanne;
var isStation;
if(choixType == 'Conso')
{
idChart = '#chartNbStations';
isBike = false;
isInstantanne = $("#dureeGraphiqueSelect").val() == 'instantanee';
isStation = true;
} else if(choixType == 'ConsoBike')
{
isBike = true;
isInstantanne = true;
}
else
{
isBike = $("#typeGraphiqueSelect").val() == 'Bike';
isInstantanne = $("#dureeGraphiqueSelect").val() == 'instantanee';
}
var chartBikes = $(idChart)[0].getContext('2d');
if(data != undefined)
{
graphData = data;
graphDataSets = data.data.datasets;
}
graphInstance[choixType] = new Chart(chartBikes, getDisplayData(isBike, isInstantanne, isStation));
}
function getDisplayData(displayBike, displayInstantanne, displayStations)
{
var dataDisplay = graphData;
var displayDetails = $("#displayDetails").prop('checked');
if(displayInstantanne == undefined)
displayInstantanne = $("#dureeGraphiqueSelect").val() == 'instantanee';
if(displayBike == undefined)
displayBike = $("#typeGraphiqueSelect").val() == 'Bike';
if(displayStations == undefined)
displayStations = false;
if(displayInstantanne || !displayDetails)
{
if(displayBike) //Vélos
{
if(displayInstantanne)
dataDisplay.data.datasets = graphDataSets;
else
dataDisplay.data.datasets = [graphDataSets[0], graphDataSets[5]];
//On ajuste les couleurs des vélos mécaniques
dataDisplay.data.datasets[0].backgroundColor = 'rgba(104,221,46,0.5)';
dataDisplay.data.datasets[0].fill = true;
delete dataDisplay.data.datasets[0].borderColor;
//Et électriques
dataDisplay.data.datasets[1].backgroundColor = 'rgba(76, 213, 233,0.5)';
dataDisplay.data.datasets[1].fill = true;
delete dataDisplay.data.datasets[1].borderColor;
dataDisplay.options.scales.yAxes[0].stacked = true;
}
else if(displayStations) // Stations
{
dataDisplay.data.datasets = [graphDataSets[0], graphDataSets[1]];
//On ajuste les couleurs
dataDisplay.data.datasets[0].backgroundColor = 'rgba(173,0,130,0.5)';
dataDisplay.data.datasets[0].fill = true;
delete dataDisplay.data.datasets[0].borderColor;
dataDisplay.data.datasets[1].backgroundColor = 'rgba(208,74,5,0.5)';
dataDisplay.data.datasets[1].fill = true;
delete dataDisplay.data.datasets[1].borderColor;
dataDisplay.options.scales.yAxes[0].stacked = false;
dataDisplay.options.scales.yAxes[0].ticks = {min: 0};
}
else //Bornes
{
dataDisplay.data.datasets = [graphDataSets[0]];
//On ajuste les couleurs
dataDisplay.data.datasets[0].backgroundColor = 'rgba(173,0,130,0.5)';
dataDisplay.data.datasets[0].fill = true;
dataDisplay.options.scales.yAxes[0].stacked = true;
delete dataDisplay.data.datasets[0].borderColor;
}
} else {
dataDisplay.data.datasets = graphDataSets;
if(displayBike) // Vélos
{
//On ajuste les couleurs des vélos mécaniques
dataDisplay.data.datasets[0].borderColor = 'rgba(104,221,46,0.7)';
dataDisplay.data.datasets[0].fill = false;
delete dataDisplay.data.datasets[0].backgroundColor;
//Et électriques
dataDisplay.data.datasets[5].borderColor = 'rgba(76, 213, 233,0.7)';
dataDisplay.data.datasets[5].fill = false;
delete dataDisplay.data.datasets[5].backgroundColor;
dataDisplay.options.scales.yAxes[0].stacked = false;
} else { //Bornes
//On ajuste les couleurs
dataDisplay.data.datasets[0].borderColor = 'rgba(173,0,130,0.5)';
dataDisplay.data.datasets[0].fill = false;
delete dataDisplay.data.datasets[0].backgroundColor;
dataDisplay.options.scales.yAxes[0].stacked = false;
}
}
return dataDisplay;
}
\ No newline at end of file
......@@ -9,6 +9,7 @@
<script type="text/javascript" src="datatables.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript" src="graph.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
\ No newline at end of file
......@@ -189,6 +189,12 @@
$("#carteArea").html(svg);
});
}
$(document).ready( function () {
$("#dureeGraphiqueSelect").change(changerGraphe);
$("#typeGraphiqueSelect").change(changerGraphe);
changerGraphe();
});
</script>
</div>
{include file="footer.tpl"}
\ No newline at end of file
......@@ -17,7 +17,7 @@ function getData(url)
}
);
}
/*
function changerGraphe()
{
var choixType = $("#typeGraphiqueSelect").val();
......@@ -53,19 +53,19 @@ function changerGraphe()
break;
}
}
}
}*/
/*
var graphInstance = {};
var graphData = null;
var graphDataSets = null;
function displayGraph(actionUrl, choixType)
var graphDataSets = null;*/
/*function displayGraph(actionUrl, choixType)
{
getData('api.php?action='+actionUrl+'&codeStation='+codeStation).then(function(data)
{
updateGraph(data, choixType);
});
}
}*/
/*
function getDisplayData(displayBike, displayInstantanne, displayStations)
{
var dataDisplay = graphData;
......@@ -139,8 +139,8 @@ function getDisplayData(displayBike, displayInstantanne, displayStations)
}
}
return dataDisplay;
}
}*/
/*
function updateGraph(data, choixType)
{
if(graphInstance != null && choixType != 'ConsoBike')
......@@ -186,7 +186,7 @@ function displayDetails()
{
if(graphInstance != null)
updateGraph();
}
}*/
function voteOui()
{
......@@ -244,14 +244,14 @@ function initBoutonsVote()
hideBoutonsVote();
}
}
/*
$(document).ready( function () {
$("#dureeGraphiqueSelect").change(changerGraphe);
$("#typeGraphiqueSelect").change(changerGraphe);
$("#displayDetails").change(displayDetails);
initBoutonsVote();
changerGraphe();
});
});*/
var dtTraduction = {
"sProcessing": "Traitement en cours...",
......
......@@ -140,6 +140,14 @@
language: dtTraduction
});
}
$(document).ready( function () {
$("#dureeGraphiqueSelect").change(changerGraphe);
$("#typeGraphiqueSelect").change(changerGraphe);
$("#displayDetails").change(displayDetails);
initBoutonsVote();
changerGraphe();
});
</script>
</div>
{include file="footer.tpl"}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment