support distribution sexes update stats

This commit is contained in:
2022-12-26 11:32:11 +01:00
parent f4bb23df44
commit 3d481f5a74
3 changed files with 151 additions and 32 deletions

View File

@@ -25,7 +25,7 @@ const addAuteur = (author) => {
//Ajoute une note sur un critère spécifique //Ajoute une note sur un critère spécifique
const addSpecificRating = (reviewId, label, value) => { const addSpecificRating = (reviewId, label, value) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const sql = "INSERT INTO borne_notes_autre(critere_id, avis_id, valeur) VALUES ((SELECT id FROM borne_criteres WHERE borne_criteres.nom = ?), ?, ?)" const sql = "INSERT INTO borne_notes_autre(critere_id, avis_id, note) VALUES ((SELECT id FROM borne_criteres WHERE borne_criteres.nom = ?), ?, ?)"
console.log(sql); console.log(sql);
conn.query(sql, [label,reviewId, value], (err, res) => { conn.query(sql, [label,reviewId, value], (err, res) => {
if(err) { if(err) {

View File

@@ -1,5 +1,6 @@
SET @date_limite = DATE_ADD(NOW(), INTERVAL -1 DAY); SET @date_limite = DATE_ADD(NOW(), INTERVAL -1 DAY);
-- On récupère les notes notes moyennes sur la periode, en séparant global, borne et site
SELECT @moyenne_globale:=AVG(note_principale) SELECT @moyenne_globale:=AVG(note_principale)
FROM borne_avis FROM borne_avis
WHERE date > @date_limite; WHERE date > @date_limite;
@@ -14,4 +15,23 @@ SELECT @moyenne_site:=AVG(note_principale)
JOIN sources ON sources.id = borne_avis.source_id JOIN sources ON sources.id = borne_avis.source_id
WHERE date > @date_limite AND sources.nom = "website"; WHERE date > @date_limite AND sources.nom = "website";
INSERT INTO stats_jour (moyenne_globale, moyenne_borne, moyenne_site) VALUES (@moyenne_globale, @moyenne_borne, @moyenne_site); -- On récupère la distribution de sexes
SELECT @stats_f:=COUNT(*) FROM borne_avis
JOIN borne_auteurs ON borne_avis.id_auteur = borne_auteurs.id
WHERE sexe='f' WHERE date > @date_limite;
SELECT @stats_h:=COUNT(*) FROM borne_avis
JOIN borne_auteurs ON borne_avis.id_auteur = borne_auteurs.id
WHERE sexe='h' WHERE date > @date_limite;
SELECT @stats_a:=COUNT(*) FROM borne_avis
JOIN borne_auteurs ON borne_avis.id_auteur = borne_auteurs.id
WHERE sexe='a' WHERE date > @date_limite;
SET @dist_sexe = CONCAT(@stats_f,",",@stats_h,",",@stats_a);
INSERT INTO stats_general_jour (moyenne_globale, moyenne_borne, moyenne_site) VALUES (@moyenne_globale, @moyenne_borne, @moyenne_site);
INSERT INTO stats_autres_jour (critere_id, note)
SELECT critere_id, AVG(note) as moyenne FROM `borne_notes_autre`
GROUP BY critere_id
WHERE date > @date_limite

View File

@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/ -- https://www.phpmyadmin.net/
-- --
-- Host: localhost:3306 -- Host: localhost:3306
-- Generation Time: Dec 25, 2022 at 09:49 PM -- Generation Time: Dec 26, 2022 at 10:31 AM
-- Server version: 8.0.31-0ubuntu0.20.04.1 -- Server version: 8.0.31-0ubuntu0.20.04.1
-- PHP Version: 7.4.3 -- PHP Version: 7.4.3
@@ -21,6 +21,8 @@ SET time_zone = "+00:00";
-- --
-- Database: `telereview` -- Database: `telereview`
-- --
CREATE DATABASE IF NOT EXISTS `telereview` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
USE `telereview`;
-- -------------------------------------------------------- -- --------------------------------------------------------
@@ -77,9 +79,10 @@ INSERT INTO `borne_criteres` (`id`, `nom`) VALUES
CREATE TABLE `borne_notes_autre` ( CREATE TABLE `borne_notes_autre` (
`id` int NOT NULL, `id` int NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`critere_id` int NOT NULL, `critere_id` int NOT NULL,
`avis_id` int NOT NULL, `avis_id` int NOT NULL,
`valeur` int NOT NULL COMMENT 'Note sur 10' `note` int NOT NULL COMMENT 'Note sur 10'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- -------------------------------------------------------- -- --------------------------------------------------------
@@ -134,16 +137,67 @@ INSERT INTO `sources` (`id`, `nom`) VALUES
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `stats_annee` -- Table structure for table `stats_autres_annee`
-- --
CREATE TABLE `stats_annee` ( CREATE TABLE `stats_autres_annee` (
`id` int NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`critere_id` int NOT NULL,
`note` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- Table structure for table `stats_autres_jour`
--
CREATE TABLE `stats_autres_jour` (
`id` int NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`critere_id` int NOT NULL,
`note` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- Table structure for table `stats_autres_mois`
--
CREATE TABLE `stats_autres_mois` (
`id` int NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`critere_id` int NOT NULL,
`note` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- Table structure for table `stats_autres_semaine`
--
CREATE TABLE `stats_autres_semaine` (
`id` int NOT NULL,
`time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`critere_id` int NOT NULL,
`note` float NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
-- --------------------------------------------------------
--
-- Table structure for table `stats_general_annee`
--
CREATE TABLE `stats_general_annee` (
`id` int NOT NULL, `id` int NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`moyenne_globale` float NOT NULL, `moyenne_globale` float NOT NULL,
`moyenne_site` float NOT NULL, `moyenne_site` float NOT NULL,
`moyenne_borne` float NOT NULL, `moyenne_borne` float NOT NULL,
`moyenne_autres` text NOT NULL COMMENT 'Nombres séparés par des ; => moyennes spécifiques',
`dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs', `dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs',
`dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs' `dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
@@ -151,16 +205,15 @@ CREATE TABLE `stats_annee` (
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `stats_jour` -- Table structure for table `stats_general_jour`
-- --
CREATE TABLE `stats_jour` ( CREATE TABLE `stats_general_jour` (
`id` int NOT NULL, `id` int NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`moyenne_globale` float DEFAULT NULL, `moyenne_globale` float DEFAULT NULL,
`moyenne_site` float DEFAULT NULL, `moyenne_site` float DEFAULT NULL,
`moyenne_borne` float DEFAULT NULL, `moyenne_borne` float DEFAULT NULL,
`moyenne_autres` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Nombres séparés par des ; => moyennes spécifiques',
`dist_age` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Distribution de l''age des auteurs', `dist_age` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Distribution de l''age des auteurs',
`dist_sexe` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Distribution du sexe des auteurs' `dist_sexe` text CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci COMMENT 'Distribution du sexe des auteurs'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
@@ -168,16 +221,15 @@ CREATE TABLE `stats_jour` (
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `stats_mois` -- Table structure for table `stats_general_mois`
-- --
CREATE TABLE `stats_mois` ( CREATE TABLE `stats_general_mois` (
`id` int NOT NULL, `id` int NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`moyenne_globale` float NOT NULL, `moyenne_globale` float NOT NULL,
`moyenne_site` float NOT NULL, `moyenne_site` float NOT NULL,
`moyenne_borne` float NOT NULL, `moyenne_borne` float NOT NULL,
`moyenne_autres` text NOT NULL COMMENT 'Nombres séparés par des ; => moyennes spécifiques',
`dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs', `dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs',
`dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs' `dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
@@ -185,16 +237,15 @@ CREATE TABLE `stats_mois` (
-- -------------------------------------------------------- -- --------------------------------------------------------
-- --
-- Table structure for table `stats_semaine` -- Table structure for table `stats_general_semaine`
-- --
CREATE TABLE `stats_semaine` ( CREATE TABLE `stats_general_semaine` (
`id` int NOT NULL, `id` int NOT NULL,
`date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`moyenne_globale` float NOT NULL, `moyenne_globale` float NOT NULL,
`moyenne_site` float NOT NULL, `moyenne_site` float NOT NULL,
`moyenne_borne` float NOT NULL, `moyenne_borne` float NOT NULL,
`moyenne_autres` text NOT NULL COMMENT 'Nombres séparés par des ; => moyennes spécifiques',
`dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs', `dist_age` text NOT NULL COMMENT 'Distribution de l''age des auteurs',
`dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs' `dist_sexe` text NOT NULL COMMENT 'Distribution du sexe des auteurs'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
@@ -246,27 +297,51 @@ ALTER TABLE `sources`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `stats_annee` -- Indexes for table `stats_autres_annee`
-- --
ALTER TABLE `stats_annee` ALTER TABLE `stats_autres_annee`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `stats_jour` -- Indexes for table `stats_autres_jour`
-- --
ALTER TABLE `stats_jour` ALTER TABLE `stats_autres_jour`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `stats_mois` -- Indexes for table `stats_autres_mois`
-- --
ALTER TABLE `stats_mois` ALTER TABLE `stats_autres_mois`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
-- --
-- Indexes for table `stats_semaine` -- Indexes for table `stats_autres_semaine`
-- --
ALTER TABLE `stats_semaine` ALTER TABLE `stats_autres_semaine`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `stats_general_annee`
--
ALTER TABLE `stats_general_annee`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `stats_general_jour`
--
ALTER TABLE `stats_general_jour`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `stats_general_mois`
--
ALTER TABLE `stats_general_mois`
ADD PRIMARY KEY (`id`);
--
-- Indexes for table `stats_general_semaine`
--
ALTER TABLE `stats_general_semaine`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
-- --
@@ -316,27 +391,51 @@ ALTER TABLE `sources`
MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
-- --
-- AUTO_INCREMENT for table `stats_annee` -- AUTO_INCREMENT for table `stats_autres_annee`
-- --
ALTER TABLE `stats_annee` ALTER TABLE `stats_autres_annee`
MODIFY `id` int NOT NULL AUTO_INCREMENT; MODIFY `id` int NOT NULL AUTO_INCREMENT;
-- --
-- AUTO_INCREMENT for table `stats_jour` -- AUTO_INCREMENT for table `stats_autres_jour`
-- --
ALTER TABLE `stats_jour` ALTER TABLE `stats_autres_jour`
MODIFY `id` int NOT NULL AUTO_INCREMENT; MODIFY `id` int NOT NULL AUTO_INCREMENT;
-- --
-- AUTO_INCREMENT for table `stats_mois` -- AUTO_INCREMENT for table `stats_autres_mois`
-- --
ALTER TABLE `stats_mois` ALTER TABLE `stats_autres_mois`
MODIFY `id` int NOT NULL AUTO_INCREMENT; MODIFY `id` int NOT NULL AUTO_INCREMENT;
-- --
-- AUTO_INCREMENT for table `stats_semaine` -- AUTO_INCREMENT for table `stats_autres_semaine`
-- --
ALTER TABLE `stats_semaine` ALTER TABLE `stats_autres_semaine`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `stats_general_annee`
--
ALTER TABLE `stats_general_annee`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `stats_general_jour`
--
ALTER TABLE `stats_general_jour`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `stats_general_mois`
--
ALTER TABLE `stats_general_mois`
MODIFY `id` int NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT for table `stats_general_semaine`
--
ALTER TABLE `stats_general_semaine`
MODIFY `id` int NOT NULL AUTO_INCREMENT; MODIFY `id` int NOT NULL AUTO_INCREMENT;
COMMIT; COMMIT;