Commit 8d19f306 authored by JonathanMM's avatar JonathanMM

Ajout du calcul du nombre de bornes perdues dans les conso

parent 158c9be3
......@@ -173,7 +173,10 @@ def creerDumpConso(dateDebut):
`nbEBikeOverflowMin` int(3) NOT NULL,
`nbEBikeOverflowMax` int(3) NOT NULL,
`nbEBikeOverflowMoyenne` decimal(5,2) NOT NULL,
`maxBikeOverflow` int(3) NOT NULL
`maxBikeOverflow` int(3) NOT NULL,
`nbEDockPerdusMin` int(3) DEFAULT NULL,
`nbEDockPerdusMax` int(3) DEFAULT NULL,
`nbEDockPerdusMoyenne` decimal(5,2) DEFAULT NULL
);
''')
conn.commit()
......@@ -196,7 +199,7 @@ def creerDumpConso(dateDebut):
c = conn.cursor()
requete = mysql.cursor()
requete.execute('SELECT id, code, date, duree, nbBikeMin, nbBikeMax, nbBikeMoyenne, nbBikePris, nbBikeRendu, nbEBikeMin, nbEBikeMax, nbEBikeMoyenne, nbEBikePris, nbEBikeRendu, nbFreeEDockMin, nbFreeEDockMax, nbFreeEDockMoyenne, nbEDock, nbBikeOverflowMin, nbBikeOverflowMax, nbBikeOverflowMoyenne, nbEBikeOverflowMin, nbEBikeOverflowMax, nbEBikeOverflowMoyenne, maxBikeOverflow \
requete.execute('SELECT id, code, date, duree, nbBikeMin, nbBikeMax, nbBikeMoyenne, nbBikePris, nbBikeRendu, nbEBikeMin, nbEBikeMax, nbEBikeMoyenne, nbEBikePris, nbEBikeRendu, nbFreeEDockMin, nbFreeEDockMax, nbFreeEDockMoyenne, nbEDock, nbBikeOverflowMin, nbBikeOverflowMax, nbBikeOverflowMoyenne, nbEBikeOverflowMin, nbEBikeOverflowMax, nbEBikeOverflowMoyenne, maxBikeOverflow, nbEDockPerdusMin, nbEDockPerdusMax, nbEDockPerdusMoyenne \
FROM resumeStatus \
WHERE date >= "'+dateDebutStr+'" AND date < "'+dateFinStr+'"')
stations = requete.fetchall()
......@@ -204,7 +207,7 @@ def creerDumpConso(dateDebut):
values = []
for cell in station:
values.append(val(cell))
c.execute('INSERT INTO resumeStatus (id, code, date, duree, nbBikeMin, nbBikeMax, nbBikeMoyenne, nbBikePris, nbBikeRendu, nbEBikeMin, nbEBikeMax, nbEBikeMoyenne, nbEBikePris, nbEBikeRendu, nbFreeEDockMin, nbFreeEDockMax, nbFreeEDockMoyenne, nbEDock, nbBikeOverflowMin, nbBikeOverflowMax, nbBikeOverflowMoyenne, nbEBikeOverflowMin, nbEBikeOverflowMax, nbEBikeOverflowMoyenne, maxBikeOverflow) VALUES \
c.execute('INSERT INTO resumeStatus (id, code, date, duree, nbBikeMin, nbBikeMax, nbBikeMoyenne, nbBikePris, nbBikeRendu, nbEBikeMin, nbEBikeMax, nbEBikeMoyenne, nbEBikePris, nbEBikeRendu, nbFreeEDockMin, nbFreeEDockMax, nbFreeEDockMoyenne, nbEDock, nbBikeOverflowMin, nbBikeOverflowMax, nbBikeOverflowMoyenne, nbEBikeOverflowMin, nbEBikeOverflowMax, nbEBikeOverflowMoyenne, maxBikeOverflow, nbEDockPerdusMin, nbEDockPerdusMax, nbEDockPerdusMoyenne) VALUES \
('+', '.join(values)+')')
conn.commit()
......
......@@ -36,10 +36,17 @@ def calculerResume(dateConsoDT, dureeConso):
ORDER BY c.id ASC")
statusConso = requete.fetchall()
bikeList = {}
#On insert ici les valeurs que l'on va calculer
proprietes.append('nbEDockPerdus')
for row in statusConso:
codeStation = int(row[0])
for i, cle in enumerate(proprietes):
valeurProp = int(row[i+1])
if cle == 'nbEDockPerdus':
valeurProp = int(row[proprietes.index('nbEDock') + 1]) - int(row[proprietes.index('nbBike') + 1]) - int(row[proprietes.index('nbEBike') + 1]) - int(row[proprietes.index('nbFreeEDock') + 1])
else:
valeurProp = int(row[i+1])
if cle in ['nbEDock', 'maxBikeOverflow']:
bikeList[codeStation][cle] = valeurProp
else:
......@@ -81,8 +88,8 @@ def calculerResume(dateConsoDT, dureeConso):
for codeStation in bikeList:
valeurs = bikeList[codeStation]
requete = mysql.cursor()
requete.execute('INSERT INTO `resumeStatus` (`id`, `code`, `date`, `duree`, `nbBikeMin`, `nbBikeMax`, `nbBikeMoyenne`, `nbBikePris`, `nbBikeRendu`, `nbEBikeMin`, `nbEBikeMax`, `nbEBikeMoyenne`, `nbEBikePris`, `nbEBikeRendu`, `nbFreeEDockMin`, `nbFreeEDockMax`, `nbFreeEDockMoyenne`, `nbEDock`, `nbBikeOverflowMin`, `nbBikeOverflowMax`, `nbBikeOverflowMoyenne`, `nbEBikeOverflowMin`, `nbEBikeOverflowMax`, `nbEBikeOverflowMoyenne`, `maxBikeOverflow`) VALUES \
(NULL, '+str(codeStation)+', "'+dateConso+'", '+str(dureeConso)+', '+str(valeurs['nbBike']['min'])+', '+str(valeurs['nbBike']['max'])+', '+str(valeurs['nbBike']['moyenne'])+', '+str(valeurs['nbBike']['pris'])+', '+str(valeurs['nbBike']['remis'])+', '+str(valeurs['nbEBike']['min'])+', '+str(valeurs['nbEBike']['max'])+', '+str(valeurs['nbEBike']['moyenne'])+', '+str(valeurs['nbEBike']['pris'])+', '+str(valeurs['nbEBike']['remis'])+', '+str(valeurs['nbFreeEDock']['min'])+', '+str(valeurs['nbFreeEDock']['max'])+', '+str(valeurs['nbFreeEDock']['moyenne'])+', '+str(valeurs['nbEDock'])+', '+str(valeurs['nbBikeOverflow']['min'])+', '+str(valeurs['nbBikeOverflow']['max'])+', '+str(valeurs['nbBikeOverflow']['moyenne'])+', '+str(valeurs['nbEBikeOverflow']['min'])+', '+str(valeurs['nbEBikeOverflow']['max'])+', '+str(valeurs['nbEBikeOverflow']['moyenne'])+', '+str(valeurs['maxBikeOverflow'])+')')
requete.execute('INSERT INTO `resumeStatus` (`id`, `code`, `date`, `duree`, `nbBikeMin`, `nbBikeMax`, `nbBikeMoyenne`, `nbBikePris`, `nbBikeRendu`, `nbEBikeMin`, `nbEBikeMax`, `nbEBikeMoyenne`, `nbEBikePris`, `nbEBikeRendu`, `nbFreeEDockMin`, `nbFreeEDockMax`, `nbFreeEDockMoyenne`, `nbEDock`, `nbBikeOverflowMin`, `nbBikeOverflowMax`, `nbBikeOverflowMoyenne`, `nbEBikeOverflowMin`, `nbEBikeOverflowMax`, `nbEBikeOverflowMoyenne`, `maxBikeOverflow`, nbEDockPerdusMin, nbEDockPerdusMax, nbEDockPerdusMoyenne) VALUES \
(NULL, '+str(codeStation)+', "'+dateConso+'", '+str(dureeConso)+', '+str(valeurs['nbBike']['min'])+', '+str(valeurs['nbBike']['max'])+', '+str(valeurs['nbBike']['moyenne'])+', '+str(valeurs['nbBike']['pris'])+', '+str(valeurs['nbBike']['remis'])+', '+str(valeurs['nbEBike']['min'])+', '+str(valeurs['nbEBike']['max'])+', '+str(valeurs['nbEBike']['moyenne'])+', '+str(valeurs['nbEBike']['pris'])+', '+str(valeurs['nbEBike']['remis'])+', '+str(valeurs['nbFreeEDock']['min'])+', '+str(valeurs['nbFreeEDock']['max'])+', '+str(valeurs['nbFreeEDock']['moyenne'])+', '+str(valeurs['nbEDock'])+', '+str(valeurs['nbBikeOverflow']['min'])+', '+str(valeurs['nbBikeOverflow']['max'])+', '+str(valeurs['nbBikeOverflow']['moyenne'])+', '+str(valeurs['nbEBikeOverflow']['min'])+', '+str(valeurs['nbEBikeOverflow']['max'])+', '+str(valeurs['nbEBikeOverflow']['moyenne'])+', '+str(valeurs['maxBikeOverflow'])+', '+str(valeurs['nbEDockPerdus']['min'])+', '+str(valeurs['nbEDockPerdus']['max'])+', '+str(valeurs['nbEDockPerdus']['moyenne'])+')')
def calculerResumeOfResume(dateConsoDT, dureeConsoOrigine, dureeConsoFinale):
dateConso = dateConsoDT.strftime("%Y-%m-%d %H:%M:%S")
......@@ -90,7 +97,7 @@ def calculerResumeOfResume(dateConsoDT, dureeConsoOrigine, dureeConsoFinale):
dateConsoFin = finConso.strftime("%Y-%m-%d %H:%M:%S")
#On récupère les conso
proprietes = ['nbBikeMin', 'nbBikeMax', 'nbBikeMoyenne', 'nbBikePris', 'nbBikeRendu', 'nbEBikeMin', 'nbEBikeMax', 'nbEBikeMoyenne', 'nbEBikePris', 'nbEBikeRendu', 'nbFreeEDockMin', 'nbFreeEDockMax', 'nbFreeEDockMoyenne', 'nbEDock', 'nbBikeOverflowMin', 'nbBikeOverflowMax', 'nbBikeOverflowMoyenne', 'nbEBikeOverflowMin', 'nbEBikeOverflowMax', 'nbEBikeOverflowMoyenne', 'maxBikeOverflow']
proprietes = ['nbBikeMin', 'nbBikeMax', 'nbBikeMoyenne', 'nbBikePris', 'nbBikeRendu', 'nbEBikeMin', 'nbEBikeMax', 'nbEBikeMoyenne', 'nbEBikePris', 'nbEBikeRendu', 'nbFreeEDockMin', 'nbFreeEDockMax', 'nbFreeEDockMoyenne', 'nbEDock', 'nbBikeOverflowMin', 'nbBikeOverflowMax', 'nbBikeOverflowMoyenne', 'nbEBikeOverflowMin', 'nbEBikeOverflowMax', 'nbEBikeOverflowMoyenne', 'maxBikeOverflow', 'nbEDockPerdusMin', 'nbEDockPerdusMax', 'nbEDockPerdusMoyenne']
mysql = getMysqlConnection()
requete = mysql.cursor()
......
......@@ -69,7 +69,10 @@ CREATE TABLE `resumeStatus` (
`nbEBikeOverflowMin` int(3) NOT NULL,
`nbEBikeOverflowMax` int(3) NOT NULL,
`nbEBikeOverflowMoyenne` decimal(5,2) NOT NULL,
`maxBikeOverflow` int(3) NOT NULL
`maxBikeOverflow` int(3) NOT NULL,
`nbEDockPerdusMin` int(3) DEFAULT NULL,
`nbEDockPerdusMax` int(3) DEFAULT NULL,
`nbEDockPerdusMoyenne` decimal(5,2) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
-- --------------------------------------------------------
......
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