Commit 3b04b650 authored by JonathanMM's avatar JonathanMM

Merge branch 'interface' into 'master'

Nouvelle interface

See merge request !2
parents b77b8c10 dd8e3ec8
...@@ -6,4 +6,6 @@ script/__pycache__/ ...@@ -6,4 +6,6 @@ script/__pycache__/
script/fixStation.py script/fixStation.py
*.zip *.zip
*.db *.db
.vscode .vscode
\ No newline at end of file templates_c/*
!templates_c/README.md
\ No newline at end of file
...@@ -2,15 +2,31 @@ ...@@ -2,15 +2,31 @@
require_once('config.php'); require_once('config.php');
include_once('functions.php'); include_once('functions.php');
error_reporting(E_ALL);
if(!isset($_GET['action']) || strlen($_GET['action']) == 0) if(!isset($_GET['action']) || strlen($_GET['action']) == 0)
exit(); exit();
if(!isset($_GET['codeStation']) || intval($_GET['codeStation']) == 0) if((!isset($_GET['codeStation']) || intval($_GET['codeStation']) == 0) && (!isset($_GET['idConso']) || intval($_GET['idConso']) == 0))
exit(); exit();
header('Content-Type: application/json'); header('Content-Type: application/json');
$codeStation = intval($_GET['codeStation']); if(isset($_GET['codeStation']))
$codeStation = intval($_GET['codeStation']);
if(isset($_GET['idConso']))
$idConso = intval($_GET['idConso']);
if(isset($_GET['lat']))
$latitude = floatval($_GET['lat']);
else
$latitude = null;
if(isset($_GET['long']))
$longitude = floatval($_GET['long']);
else
$longitude = null;
switch($_GET['action']) switch($_GET['action'])
{ {
...@@ -98,6 +114,14 @@ switch($_GET['action']) ...@@ -98,6 +114,14 @@ switch($_GET['action'])
echo json_encode(getConsoBikeResume("-1month", 360)); echo json_encode(getConsoBikeResume("-1month", 360));
exit(); exit();
break; break;
case 'getDataConso':
echo json_encode(getDataConso($idConso, $longitude, $latitude));
exit();
break;
case 'getDataStation':
echo json_encode(getDataStation($codeStation));
exit();
break;
} }
function getBikeInstantane($codeStation) function getBikeInstantane($codeStation)
...@@ -729,4 +753,66 @@ function getDataConsoBikeResume($filtre, $periode) ...@@ -729,4 +753,66 @@ function getDataConsoBikeResume($filtre, $periode)
) )
); );
} }
function getDataConso($idConso, $longitude = null, $latitude = null)
{
global $pdo;
$whereCoord = '';
if(!is_null($longitude) && !is_null($latitude))
{
$whereCoord = ' AND '.implode(' AND ', array(
'stations.longitude >= '.($longitude - 0.015),
'stations.longitude <= '.($longitude + 0.015),
'stations.latitude >= '.($latitude - 0.01),
'stations.latitude <= '.($latitude + 0.01)
));
}
$requete = $pdo->query('SELECT * FROM status inner join `stations` on stations.code = status.code WHERE idConso = '.$idConso.$whereCoord.' order by status.code asc');
$data = $requete->fetchAll(PDO::FETCH_ASSOC);
$retour = [];
foreach($data as $station)
{
$retour[] = array(
'code' => $station['code'],
'codeStr' => displayCodeStation($station['code']),
'name' => $station['name'],
'dateOuverture' => is_null($station['dateOuverture']) ? 'Non ouvert' : $station['dateOuverture'],
'state' => (($station['state'] == 'Operative' && $station['nbEDock'] != 0) ? 'Ouverte' : 'En travaux'),
'nbBike' => $station['nbBike'],
'nbEbike' => $station['nbEBike'],
'nbFreeEDock' => $station['nbFreeEDock'],
'nbEDock' => $station['nbEDock']
);
}
return array('data' => $retour);
}
function getDataStation($codeStation)
{
global $pdo;
//Filtre 24 heures
$hier = new DateTime("-1day");
$filtreDate = $hier->format('Y-m-d H:i:s');
//Stations
$requete = $pdo->query('SELECT c.id, c.date, s.nbBike, s.nbEBike, s.nbFreeEDock, s.nbEDock
FROM status s
INNER JOIN statusConso c ON c.id = s.idConso
WHERE s.code = '.$codeStation.' AND c.date >= "'.$filtreDate.'"
ORDER BY c.id ASC');
$statusStation = $requete->fetchAll(PDO::FETCH_ASSOC);
$retour = [];
foreach($statusStation as $statut)
{
$retour[] = array(
'idConso' => $statut['id'],
'date' => $statut['date'],
'nbBike' => $statut['nbBike'],
'nbEbike' => $statut['nbEBike'],
'nbFreeEDock' => $statut['nbFreeEDock'],
'nbEDock' => $statut['nbEDock']
);
}
return array('data' => $retour);
}
?> ?>
\ No newline at end of file
<div id="credits">
Ce site n'est pas un site officiel de vélib métropole. Les données utilisées proviennent de
<a href="http://www.velib-metropole.fr">www.velib-metropole.fr</a> et appartienne à leur propriétaire. -
<a href="https://framagit.org/JonathanMM/velibstats">Site du projet</a> -
Auteur : JonathanMM (<a href="https://twitter.com/Jonamaths">@Jonamaths</a>)
</div>
\ No newline at end of file
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>Vélib Stats (site non officiel)</title>
<script type="application/javascript" src="Chart.min.js"></script>
<script type="application/javascript" src="jquery-3.2.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="datatables.min.css"/>
<link rel="stylesheet" type="text/css" href="style.css"/>
<script type="text/javascript" src="datatables.min.js"></script>
<script type="text/javascript" src="script.js"></script>
</head>
<body>
\ No newline at end of file
<?php <?php
require_once('config.php'); require_once('config.php');
include_once('functions.php'); include_once('functions.php');
require_once('libs/Smarty.class.php');
$smarty = new Smarty();
//Filtre 24 heures //Filtre 24 heures
$hier = new DateTime("-1day"); $hier = new DateTime("-1day");
...@@ -10,127 +13,17 @@ $filtreDate = $hier->format('Y-m-d H:i:s'); ...@@ -10,127 +13,17 @@ $filtreDate = $hier->format('Y-m-d H:i:s');
$requete = $pdo->query('SELECT * FROM `statusConso` where nbStation Is not null and date >= "'.$filtreDate.'" Order by id desc limit 0,1'); $requete = $pdo->query('SELECT * FROM `statusConso` where nbStation Is not null and date >= "'.$filtreDate.'" Order by id desc limit 0,1');
$conso = $requete->fetch(); $conso = $requete->fetch();
//Stations $smarty->assign(array(
if(is_null($conso['id'])) 'idConso' => $conso['id'],
$statusStation = array(); 'nbStation' => $conso['nbStation'],
else 'nbStationDetecte' => $conso['nbStationDetecte'],
{ 'nbBike' => $conso['nbBike'],
$requete = $pdo->query('SELECT * FROM status inner join `stations` on stations.code = status.code WHERE idConso = '.$conso['id'].' order by status.code asc'); 'nbEbike' => $conso['nbEbike'],
$statusStation = $requete->fetchAll(); 'nbEDock' => $conso['nbEDock'],
} 'nbFreeEDock' => $conso['nbFreeEDock'],
?> 'dateDerniereConso' => (new DateTime($conso['date']))->format('d/m/Y à H:i')
<!DOCTYPE html> ));
<html>
<head>
<title>Vélib Stats (site non officiel)</title>
<script type="application/javascript" src="Chart.min.js"></script>
<script type="application/javascript" src="jquery-3.2.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="datatables.min.css"/>
<script type="text/javascript" src="datatables.min.js"></script>
<script type="text/javascript" src="script.js"></script>
<style type="text/css">
table, tr, td, th
{
border: 1px solid black;
}
td
{
text-align: center;
}
</style>
</head>
<body>
<h1>Vélib Stats (site non officiel)</h1>
<ul>
<li>Nombre de stations ouvertes annoncées (<abbr title="Stations affichées comme étant ouverte">définition</abbr>) : <?php echo $conso['nbStation']; ?></li>
<li>Nombre de stations ouvertes détectées (<abbr title="Stations avec un nombre de bornes positifs avec au moins un vélo ou une borne libre">définition</abbr>) : <?php echo $conso['nbStationDetecte']; ?></li>
<li>Nombre de vélos mécaniques disponible : <?php echo $conso['nbBike']; ?></li>
<li>Nombre de vélos électriques disponible : <?php echo $conso['nbEbike']; ?></li>
<li>Nombre de bornes libres : <?php echo $conso['nbFreeEDock']; ?></li>
<li>Nombre de bornes total : <?php echo $conso['nbEDock']; ?></li>
</ul>
<i>Dernière mise à jour : <?php echo $conso['date']; ?></i><br />
<select id="typeGraphiqueSelect" style="display: none">
<option value="_double">Conso</option>
</select>
<select id="dureeGraphiqueSelect">
<option value="instantanee">Une heure - Instantanée</option>
<option value="troisHeures">Trois heures - Période de 5 minutes</option>
<option value="unJour">Un jour - Période de 15 minutes</option>
<option value="septJours" selected>Une semaine - Période d'une heure</option>
<option value="unMois">Un mois - Période de six heures</option>
</select> Graphique issu du site velib.nocle.fr
<canvas id="chartNbStations" width="1000" height="400"></canvas>
<canvas id="chartBikes" width="1000" height="400"></canvas>
<i>Ce site n'est pas un site officiel de vélib métropole. Les données utilisées proviennent de <a href="http://www.velib-metropole.fr">www.velib-metropole.fr</a> et appartienne à leur propriétaire. - <a href="https://framagit.org/JonathanMM/velibstats">Site du projet</a> -
Auteur : JonathanMM (<a href="https://twitter.com/Jonamaths">@Jonamaths</a>)</i>
<h2>Stations</h2>
Fitrer : État
<select id="filtreEtat">
<option value="toutes">Toutes</option>
<option value="ouverte" selected>Ouverte</option>
<option value="travaux">En travaux</option>
</select>
<table id="stations">
<thead>
<tr>
<th>Code</th>
<th>Nom</th>
<th>Date d'ouverture</th>
<th>Statut</th>
<th>Vélos mécaniques dispo</th>
<th>Vélos électriques dispo</th>
<th>Bornes libres</th>
</tr>
</thead>
<tbody>
<?php
foreach($statusStation as $station)
{
echo '<tr>';
echo '<td><a href="station.php?code='.$station['code'].'">'.displayCodeStation($station['code']).'</a></td>';
echo '<td>'.$station['name'].'</td>';
echo '<td>'.$station['dateOuverture'].'</td>';
echo '<td>'.(($station['state'] == 'Operative' && $station['nbEDock'] != 0) ? 'Ouverte' : 'En travaux').'</td>';
echo '<td>'.$station['nbBike'].'</td>';
echo '<td>'.$station['nbEBike'].'</td>';
echo '<td>'.$station['nbFreeEDock'].'/'.$station['nbEDock'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
<script type="text/javascript">
var codeStation = -1;
</script>
<script type="application/javascript">
function filtreDataTable()
{
var valeur = $("#filtreEtat").val();
var dt = $('#stations').DataTable();
switch (valeur) {
case "ouverte":
dt.column(3).search("Ouverte").draw();
break;
case "travaux":
dt.column(3).search("En travaux").draw();
break;
default:
dt.column(3).search("").draw();
break;
}
}
$(document).ready( function () { $smarty->display('index.tpl');
var dt = $('#stations').DataTable({ exit();
language: dtTraduction ?>
}); \ No newline at end of file
filtreDataTable();
$("#filtreEtat").change(filtreDataTable);
} );
</script>
</body>
</html>
\ No newline at end of file
{include file='header.tpl'}
<header>
<h1>Vélib Stats (site non officiel)</h1>
</header>
<div id="content">
<div id="statsConsoArea">
<table id="statsConso">
<tr>
<th colspan="2">Stations ouvertes</th>
<th colspan="2">Vélos disponibles</th>
<th colspan="2">Bornes</th>
</tr>
<tr>
<td>{$nbStation}</td>
<td>{$nbStationDetecte}</td>
<td>{$nbBike}</td>
<td>{$nbEbike}</td>
<td>{$nbFreeEDock}</td>
<td>{$nbEDock}</td>
</tr>
<tr>
<td><abbr title="Stations affichées comme étant ouverte">annoncées</abbr></td>
<td><abbr title="Stations avec un nombre de bornes positifs avec au moins un vélo ou une borne libre">détectées</abbr></td>
<td>mécaniques</td>
<td>électriques</td>
<td>libres</td>
<td>totales</td>
</tr>
</table>
<i>Dernière mise à jour : {$dateDerniereConso}</i>
</div>
<select id="typeGraphiqueSelect" style="display: none">
<option value="_double">Conso</option>
</select>
<select id="dureeGraphiqueSelect">
<option value="instantanee">Une heure - Instantanée</option>
<option value="troisHeures">Trois heures - Période de 5 minutes</option>
<option value="unJour">Un jour - Période de 15 minutes</option>
<option value="septJours" selected>Une semaine - Période d'une heure</option>
<option value="unMois">Un mois - Période de six heures</option>
</select> - Graphique issu du site velib.nocle.fr
<div id="chartArea">
<canvas id="chartNbStations" height="500px" width="800px"></canvas>
<canvas id="chartBikes" height="500px" width="800px"></canvas>
</div>
{include file="credits.tpl"}
<h2>Stations</h2>
Fitrer : État
<select id="filtreEtat">
<option value="toutes">Toutes</option>
<option value="ouverte" selected>Ouverte</option>
<option value="travaux">En travaux</option>
</select> -
Position
<select id="filtrePosition">
<option value="toutes" selected>Indifféramment</option>
<option value="proximite">À proximité</option>
</select>
<table id="stations">
<thead>
<tr>
<th>Code</th>
<th>Nom</th>
<th>Date d'ouverture</th>
<th>Statut</th>
<th>Vélos mécaniques dispo</th>
<th>Vélos électriques dispo</th>
<th>Bornes libres</th>
</tr>
</thead>
</table>
<script type="text/javascript">
var codeStation = -1;
</script>
<script type="application/javascript">
function filtreDataTable()
{
var valeur = $("#filtreEtat").val();
var dt = $('#stations').DataTable();
switch (valeur) {
case "ouverte":
dt.column(3).search("Ouverte").draw();
break;
case "travaux":
dt.column(3).search("En travaux").draw();
break;
default:
dt.column(3).search("").draw();
break;
}
}
$(document).ready( function () {
var dt = $('#stations').DataTable({
ajax: 'api.php?action=getDataConso&idConso={$idConso}',
columns: [{
data: 'codeStr',
render: function(data, type, row, meta)
{
return '<a href="station.php?code='+row.code+'">'+data+'</a>';
}
},{
data: 'name',
render: function(data, type, row, meta)
{
return '<a href="station.php?code='+row.code+'">'+data+'</a>';
}
},{
data: 'dateOuverture',
render: function(data, type, row, meta)
{
if(data == 'Non ouvert')
return data;
var date = new Date(data);
return putZero(date.getDate()) + '/' + putZero(date.getMonth()+1) + '/' + date.getFullYear();
}
},{
data: 'state'
},{
data: 'nbBike'
},{
data: 'nbEbike'
},{
data: 'nbFreeEDock',
render: function(data, type, row, meta)
{
return data+'/'+row.nbEDock;
}
}],
language: dtTraduction
});
filtreDataTable();
$("#filtreEtat").change(filtreDataTable);
$("#filtrePosition").change(filtrePosition);
});
function filtrePosition()
{
var valeur = $("#filtrePosition").val();
if(valeur == 'proximite')
obtenirLocalisation();
else
resetLocalisation();
}
function obtenirLocalisation()
{
if (navigator.geolocation)
navigator.geolocation.getCurrentPosition(traiterLocalisation);
else
alert("Votre navigateur ne supporte pas la fonction localisation");
}
function traiterLocalisation(position)
{
var dt = $('#stations').DataTable();
dt.ajax.url('api.php?action=getDataConso&idConso={$idConso}&lat='+position.coords.latitude+'&long='+position.coords.longitude).load();
}
function resetLocalisation()
{
var dt = $('#stations').DataTable();
dt.ajax.url('api.php?action=getDataConso&idConso={$idConso}').load();
}
</script>
</div>
{include file="footer.tpl"}
\ No newline at end of file
<?php
/**
* Smarty Autoloader
*
* @package Smarty
*/
/**
* Smarty Autoloader
*
* @package Smarty
* @author Uwe Tews
* Usage:
* require_once '...path/Autoloader.php';
* Smarty_Autoloader::register();
* $smarty = new Smarty();
* Note: This autoloader is not needed if you use Composer.
* Composer will automatically add the classes of the Smarty package to it common autoloader.
*/
class Smarty_Autoloader
{
/**
* Filepath to Smarty root
*
* @var string
*/
public static $SMARTY_DIR = '';
/**
* Filepath to Smarty internal plugins
*
* @var string
*/
public static $SMARTY_SYSPLUGINS_DIR = '';
/**
* Array with Smarty core classes and their filename
*
* @var array
*/
public static $rootClasses = array('smarty' => 'Smarty.class.php', 'smartybc' => 'SmartyBC.class.php',);
/**
* Registers Smarty_Autoloader backward compatible to older installations.
*
* @param bool $prepend Whether to prepend the autoloader or not.
*/
public static function registerBC($prepend = false)
{
/**
* register the class autoloader
*/
if (!defined('SMARTY_SPL_AUTOLOAD')) {
define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD &&
set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false
) {
$registeredAutoLoadFunctions = spl_autoload_functions();
if (!isset($registeredAutoLoadFunctions[ 'spl_autoload' ])) {
spl_autoload_register();
}
} else {
self::register($prepend);
}
}
/**
* Registers Smarty_Autoloader as an SPL autoloader.
*
* @param bool $prepend Whether to prepend the autoloader or not.
*/
public static function register($prepend = false)
{
self::$SMARTY_DIR = defined('SMARTY_DIR') ? SMARTY_DIR : dirname(__FILE__) . DIRECTORY_SEPARATOR;
self::$SMARTY_SYSPLUGINS_DIR = defined('SMARTY_SYSPLUGINS_DIR') ? SMARTY_SYSPLUGINS_DIR :
self::$SMARTY_DIR . 'sysplugins' . DIRECTORY_SEPARATOR;
if (version_compare(phpversion(), '5.3.0', '>=')) {
spl_autoload_register(array(__CLASS__, 'autoload'), true, $prepend);
} else {
spl_autoload_register(array(__CLASS__, 'autoload'));
}
}
/**
* Handles auto loading of classes.
*
* @param string $class A class name.
*/
public static function autoload($class)
{
$_class = strtolower($class);
if (strpos($_class, 'smarty') !== 0) {
return;
}
$file = self::$SMARTY_SYSPLUGINS_DIR . $_class . '.php';
if (is_file($file)) {
include $file;
} else if (isset(self::$rootClasses[ $_class ])) {
$file = self::$SMARTY_DIR . self::$rootClasses[ $_class ];
if (is_file($file)) {
include $file;
}
}
return;
}
}
This diff is collapsed.
This diff is collapsed.
{capture name='_smarty_debug' assign=debug_output}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Smarty Debug Console</title>
<style type="text/css">
{literal}
body, h1, h2, h3, td, th, p {
font-family: sans-serif;
font-weight: normal;
font-size: 0.9em;
margin: 1px;
padding: 0;
}
h1 {
margin: 0;
text-align: left;
padding: 2px;
background-color: #f0c040;
color: black;
font-weight: bold;
font-size: 1.2em;
}
h2 {
background-color: #9B410E;
color: white;
text-align: left;
font-weight: bold;
padding: 2px;
border-top: 1px solid black;
}
h3 {
text-align: left;
font-weight: bold;
color: black;
font-size: 0.7em;
padding: 2px;
}
body {
background: black;
}
p, table, div {