From d0da955c33eb06c2242092870d0e00d695c5cd4e Mon Sep 17 00:00:00 2001 From: Morph01 <145839520+Morph01@users.noreply.github.com> Date: Sun, 7 Apr 2024 17:07:24 +0200 Subject: [PATCH] FINISH SQL scripts for dataset migration and creation --- sql/script_creation_dataset.sql | 4 +- sql/script_migration_data.sql | 86 +++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 17 deletions(-) diff --git a/sql/script_creation_dataset.sql b/sql/script_creation_dataset.sql index e88d14f..1a19b61 100644 --- a/sql/script_creation_dataset.sql +++ b/sql/script_creation_dataset.sql @@ -1,4 +1,5 @@ START TRANSACTION; + CREATE TABLE carte ( PRIMARY KEY (idcarte), @@ -125,7 +126,7 @@ CREATE TABLE PRIMARY KEY (idclassement_composee, idclassement_composante), idclassement_composee INTEGER, idclassement_composante INTEGER, - quantite VARCHAR(42) + hierarchie VARCHAR(42) ); CREATE TABLE @@ -338,4 +339,5 @@ ALTER TABLE tente_validation ADD FOREIGN KEY (idpartie, num_tour) REFERENCES tou ALTER TABLE tour ADD FOREIGN KEY (idpartie) REFERENCES partie (idpartie); ALTER TABLE valide ADD FOREIGN KEY (idcontrainte) REFERENCES contrainte (idcontrainte); + COMMIT; \ No newline at end of file diff --git a/sql/script_migration_data.sql b/sql/script_migration_data.sql index 0a73f49..a98ddd3 100644 --- a/sql/script_migration_data.sql +++ b/sql/script_migration_data.sql @@ -1,4 +1,5 @@ START TRANSACTION; + INSERT INTO `contrainte` (`idcontrainte`, `couleur`) SELECT DISTINCT @@ -34,6 +35,9 @@ SELECT DISTINCT FROM donnees_fournies.équipe; +INSERT INTO `equipe`(`nom`) +SELECT DISTINCT équipe FROM donnees_fournies.instances1 WHERE équipe IS NOT NULL; + INSERT INTO `tournoi` (`idtournoi`, `nom`, `date_deb`, `date_fin`) SELECT @@ -243,7 +247,40 @@ FROM WHERE nom = 'seuil_de_dé'; -/*INSERT INTO +SET @row_number = 0; + +INSERT INTO `comprend`(`idpartie`, `num_tour`, `idlancer`) SELECT `id_partie`, `numTour`, @row_number:=@row_number+1 AS idlancers +FROM donnees_fournies.instances3 t; + +SET @row_number = 0; +INSERT INTO `effectue`(`idjoueur`, `idlancer`) +SELECT inst3.id_joueur, @row_number:=@row_number+1 AS idlancer +FROM donnees_fournies.instances3 inst3; + +SET @idlancer = 0; +INSERT INTO `de_lance`(`idlancer`, `rang_couleur_valeur`) +SELECT @idlancer:=@idlancer+1 AS idlancer, CONCAT('1;', de1) AS rang_couleur_valeur FROM `donnees_fournies`.`instances3` +UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('2;', de2) FROM `donnees_fournies`.`instances3` +UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('3;', de3) FROM `donnees_fournies`.`instances3` +UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('4;', de4) FROM `donnees_fournies`.`instances3` +UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('5;', de5) FROM `donnees_fournies`.`instances3` +UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('6;', de6) FROM `donnees_fournies`.`instances3`; + +INSERT INTO `joue`(`idjoueur`, `idpartie`, `couleur_pion`, `rang`) +SELECT `id_joueur`, `id_partie`, NULL, `rang_arrivee` FROM donnees_fournies.instances1; + +SET @row_number = 0; + +INSERT INTO `valide`(`idlancer`, `idcontrainte`) +SELECT max_idlancer_table.max_idlancer, est_contrainte.idcontrainte +FROM ( + SELECT `id_partie`, `id_joueur`, `carteAvalider`, MAX(@row_number:=@row_number+1) as max_idlancer + FROM donnees_fournies.instances3 + GROUP BY `id_partie`, `id_joueur`, `carteAvalider` +) as max_idlancer_table +JOIN `est_contrainte` ON max_idlancer_table.carteAvalider = est_contrainte.idcarte; + +INSERT INTO `tente_validation` ( `idpartie`, `num_tour`, @@ -262,25 +299,42 @@ FROM GROUP BY `id_partie`, `id_joueur`, - `carteAvalider`;*/ + `carteAvalider`; + SET @row_number = 0; -INSERT INTO `comprend`(`idpartie`, `num_tour`, `idlancer`) SELECT `id_partie`, `numTour`, @row_number:=@row_number+1 AS idlancers -FROM donnees_fournies.instances3 t; +CREATE TEMPORARY TABLE unique_plateau AS +SELECT @row_number:=@row_number+1 AS idplateau, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12 +FROM donnees_fournies.instances1 +GROUP BY c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12; -SET @row_number = 0; -INSERT INTO `effectue`(`idjoueur`, `idlancer`) +INSERT INTO plateau (idplateau, taille) +SELECT idplateau, 12 FROM unique_plateau; -SELECT inst3.id_joueur, @row_number:=@row_number+1 AS idlancer -FROM donnees_fournies.instances3 inst3; +INSERT INTO est_compose (idcarte, idplateau, rang) +SELECT c1, idplateau, 1 FROM unique_plateau +UNION ALL +SELECT c2, idplateau, 2 FROM unique_plateau +UNION ALL +SELECT c3, idplateau, 3 FROM unique_plateau +UNION ALL +SELECT c4, idplateau, 4 FROM unique_plateau +UNION ALL +SELECT c5, idplateau, 5 FROM unique_plateau +UNION ALL +SELECT c6, idplateau, 6 FROM unique_plateau +UNION ALL +SELECT c7, idplateau, 7 FROM unique_plateau +UNION ALL +SELECT c8, idplateau, 8 FROM unique_plateau +UNION ALL +SELECT c9, idplateau, 9 FROM unique_plateau +UNION ALL +SELECT c10, idplateau, 10 FROM unique_plateau +UNION ALL +SELECT c11, idplateau, 11 FROM unique_plateau +UNION ALL +SELECT c12, idplateau, 12 FROM unique_plateau; -SET @idlancer = 0; -INSERT INTO `de_lance`(`idlancer`, `rang_couleur_valeur`) -SELECT @idlancer:=@idlancer+1 AS idlancer, CONCAT('1;', de1) AS rang_couleur_valeur FROM `donnees_fournies`.`instances3` -UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('2;', de2) FROM `donnees_fournies`.`instances3` -UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('3;', de3) FROM `donnees_fournies`.`instances3` -UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('4;', de4) FROM `donnees_fournies`.`instances3` -UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('5;', de5) FROM `donnees_fournies`.`instances3` -UNION ALL SELECT @idlancer:=@idlancer+1, CONCAT('6;', de6) FROM `donnees_fournies`.`instances3`; COMMIT; \ No newline at end of file