mirror of
https://git.roussel.pro/telecom-paris/pact.git
synced 2026-02-09 10:30:17 +01:00
ajout fonction js pour update les stats
This commit is contained in:
@@ -1,6 +1,21 @@
|
||||
import conn from '../database';
|
||||
import conn from '../database.js';
|
||||
import fs from "fs";
|
||||
|
||||
export const udpateDay = () => {
|
||||
const sql = "SELECT AVG(note_principale) INTO @moyenne_globale FROM borne_avis WHERE date > DATE_ADD(NOW(), INTERVAL -1 DAY);";
|
||||
export const computeStats = async (timePeriod, generalTableName, otherTableName) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
let sql = fs.readFileSync("stats/update_stats.sql").toString();
|
||||
sql = sql
|
||||
.replace(new RegExp("DAY_COUNT_DELAY",'g'), timePeriod.toString())
|
||||
.replace(new RegExp("STATS_GENERAL_TABLE_NAME", 'g'), generalTableName)
|
||||
.replace(new RegExp('STATS_AUTRES_TABLE_NAME', 'g'), otherTableName)
|
||||
conn.query(sql, (err, res) => {
|
||||
if(err) {
|
||||
reject(err)
|
||||
}else {
|
||||
resolve(res.insertId);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
// computeStats(7,"stats_general_semaine","stats_autres_semaine").then(() => {console.log("OK")});
|
||||
Reference in New Issue
Block a user