From eade4992ea8e14e4eddf90741e96f56fd5312faf Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Fri, 10 Nov 2023 08:07:53 +0100 Subject: [PATCH] Indice pour le nombre de sports --- .../src/Components/GraphContainer.tsx | 52 ++++++++++++++++--- cryptide_project/src/Pages/Home.tsx | 29 ----------- cryptide_project/src/Translations/en.json | 3 ++ cryptide_project/src/Translations/fr.json | 5 +- cryptide_project/src/res/names.json | 1 - .../src/source/Factory/IndiceTesterFactory.ts | 5 ++ .../src/source/Graph/GraphCreator.ts | 1 + cryptide_project/src/source/IndiceChooser.ts | 7 +++ .../IndiceTester/NbSportIndiceTester.ts | 24 +++++++++ .../src/source/Indices/NbSportIndice.ts | 23 ++++++++ cryptide_project/src/source/Stub.ts | 6 +++ 11 files changed, 118 insertions(+), 38 deletions(-) create mode 100644 cryptide_project/src/source/IndiceTester/NbSportIndiceTester.ts create mode 100644 cryptide_project/src/source/Indices/NbSportIndice.ts diff --git a/cryptide_project/src/Components/GraphContainer.tsx b/cryptide_project/src/Components/GraphContainer.tsx index 42c9822..a3fa075 100644 --- a/cryptide_project/src/Components/GraphContainer.tsx +++ b/cryptide_project/src/Components/GraphContainer.tsx @@ -9,6 +9,7 @@ import Sport from "../source/Sport"; import Stub from "../source/Stub"; import "./GraphContainer.css"; import NodePerson from "../source/Graph/NodePerson"; +import IndiceTesterFactory from "../source/Factory/IndiceTesterFactory"; const edgesCreator = new EdgesCreator() @@ -16,25 +17,26 @@ const chooser = new IndiceChooser() const indices = Stub.GenerateIndice() -const network = NetworkGenerator.GenerateNetwork(30) +const networkPerson = NetworkGenerator.GenerateNetwork(50) -const rand = Math.floor(Math.random() * 30) -const person = network.getPersons()[rand] +const rand = Math.floor(Math.random() * 50) +const person = networkPerson.getPersons()[rand] -const choosenIndices = chooser.chooseIndice(network, person, indices, 3) +const choosenIndices = chooser.chooseIndice(networkPerson, person, indices, 8) -edgesCreator.CreateAllEdges(network, person, choosenIndices) +edgesCreator.CreateAllEdges(networkPerson, person, choosenIndices) -const graph = GraphCreator.CreateGraph(network) +const graph = GraphCreator.CreateGraph(networkPerson) let indice = new SportIndice(12, [Sport.TENNIS, Sport.BASEBALL]) -console.log(network) +console.log(networkPerson) console.log(graph) choosenIndices.forEach((indice) =>{ console.log(indice.ToString("fr")) }); console.log(person) +const testIndice = choosenIndices[0] interface MyGraphComponentProps { onNodeClick: (shouldShowChoiceBar: boolean) => void; @@ -71,9 +73,27 @@ const MyGraphComponent: React.FC = ({onNodeClick}) => { } }; + const networkData = { nodes: nodes, edges: graph.edges }; const network = new Network(container, networkData, initialOptions); + //TEST POUR MONTRER QU'IL Y EN A QU'UN A CHAQUE FOIS + /* + networkPerson.getPersons().forEach(p => { + let a = 0 + for (let i of choosenIndices){ + let tester = IndiceTesterFactory.Create(i) + if (tester.Works(p)){ + a++ + } + } + if (a==choosenIndices.length){ + networkData.nodes.update({id: p.getId(), label: p.getName() + "\n🔵"}) + } + + }); + */ + // Gérer le changement entre la physique et le déplacement manuel network.on("dragging", (params) => { if (params.nodes.length > 0) { @@ -85,6 +105,24 @@ const MyGraphComponent: React.FC = ({onNodeClick}) => { network.on("click", (params) => { if(params.nodes.length > 0){ + //TEST POUR VOIR SI ON PEUT RAJOUTER DES TRUCS AU LABEL + + const pers = networkPerson.getPersons().find((p) => p.getId() == params.nodes[0]) + if (pers!=undefined){ + const node = nodes.get().find((n) => params.nodes[0] == n.id) + if (node != undefined){ + var tester = IndiceTesterFactory.Create(testIndice) + if (tester.Works(pers)){ + networkData.nodes.update({id: params.nodes[0], label: node.label + "🔵"}) + } + else{ + networkData.nodes.update({id: params.nodes[0], label: node.label + "🟦"}) + } + } + + } + + // Renvoyer un true pour afficher la choice bar onNodeClick(true) } diff --git a/cryptide_project/src/Pages/Home.tsx b/cryptide_project/src/Pages/Home.tsx index 5cc819b..c836fb6 100644 --- a/cryptide_project/src/Pages/Home.tsx +++ b/cryptide_project/src/Pages/Home.tsx @@ -2,39 +2,10 @@ import React from 'react'; import './Home.css'; import '../App.css'; import { Link } from 'react-router-dom'; -import Person from '../source/Person'; -import Color from '../source/Color'; -import Sport from '../source/Sport'; -import PersonNetwork from '../source/PersonsNetwork'; -import AgeIndice from '../source/Indices/AgeIndice'; -import IndiceTesterFactory from '../source/Factory/IndiceTesterFactory'; -import NbEdgesIndice from '../source/Indices/NbEdgesIndice'; -import ColorIndice from '../source/Indices/ColorIndice'; -import EdgesCreator from '../source/EdgesCreator'; -import ColorEdgesIndice from '../source/Indices/ColorEdgesIndice'; -import IndiceChooser from '../source/IndiceChooser'; -import Indice from '../source/Indices/Indice'; -import SportIndice from '../source/Indices/SportIndice'; -import Stub from '../source/Stub'; -import NetworkGenerator from '../source/NetworkGenerator'; -import GraphCreator from '../source/Graph/GraphCreator'; import { FormattedMessage } from 'react-intl'; function Home() { - /* - let person = new Person(0, "test", 23, Color.BLANC, [Sport.CURLING], []); - let p1 = new Person(1, "1", 51, Color.BLOND, [Sport.CURLING], []) - let p2 = new Person(2, "2", 20, Color.NOIR, [Sport.BASKET], []) - let p3 = new Person(3, "3", 25, Color.ROUX, [Sport.TENNIS], []) - let p4 = new Person(5, "5", 51, Color.BLOND, [Sport.FOOT], []) - let p5 = new Person(6, "6", 27, Color.CHATAIN, [Sport.RUGBY], []) - let p6 = new Person(7, "7", 40, Color.ROUX, [Sport.FOOT], []) - let p7 = new Person(8, "8", 51, Color.CHATAIN, [Sport.TENNIS], []) - let p8 = new Person(9, "9", 28, Color.BLANC, [Sport.BASKET], []) - let p9 = new Person(10, "10", 40, Color.ROUX, [Sport.RUGBY], []) - let network = new PersonNetwork([person, p1, p2, p3, p4, p5, p6, p7, p8, p9]) - */ return ( diff --git a/cryptide_project/src/Translations/en.json b/cryptide_project/src/Translations/en.json index 3391909..dd6bacd 100644 --- a/cryptide_project/src/Translations/en.json +++ b/cryptide_project/src/Translations/en.json @@ -58,6 +58,9 @@ "nb_friends_indice_start": "The suspect has at least", "nb_friends_indice_end": "friends", + "nb_sports_indice_start": "The suspect is playing", + "nb_sports_indice_end": "sport", + "sport_start": "The suspect plays at least", "sport_end": "" } \ No newline at end of file diff --git a/cryptide_project/src/Translations/fr.json b/cryptide_project/src/Translations/fr.json index 6d0e711..6d3d1e3 100644 --- a/cryptide_project/src/Translations/fr.json +++ b/cryptide_project/src/Translations/fr.json @@ -57,6 +57,9 @@ "nb_friends_indice_start": "Le suspect a au moins", "nb_friends_indice_end": "amis", - "sport_start": "Le suspect fait au moins du", + "nb_sports_indice_start": "Le suspect pratique", + "nb_sports_indice_end": "sport(s)", + + "sport_start": "Le suspect pratique au moins du", "sport_end": "" } diff --git a/cryptide_project/src/res/names.json b/cryptide_project/src/res/names.json index 6d376b6..f96c31b 100644 --- a/cryptide_project/src/res/names.json +++ b/cryptide_project/src/res/names.json @@ -29,7 +29,6 @@ "Hannah", "Leah", "Victoria", - "Eleanor", "Hazel", "Violet", "Aurora", diff --git a/cryptide_project/src/source/Factory/IndiceTesterFactory.ts b/cryptide_project/src/source/Factory/IndiceTesterFactory.ts index a50df3d..30cd9be 100644 --- a/cryptide_project/src/source/Factory/IndiceTesterFactory.ts +++ b/cryptide_project/src/source/Factory/IndiceTesterFactory.ts @@ -3,12 +3,14 @@ import ColorEdgesIndice from "../Indices/ColorEdgesIndice"; import ColorIndice from "../Indices/ColorIndice"; import Indice from "../Indices/Indice"; import NbEdgesIndice from "../Indices/NbEdgesIndice"; +import NbSportIndice from "../Indices/NbSportIndice"; import SportIndice from "../Indices/SportIndice"; import ColorEdgesIndiceTester from "../IndiceTester/ColorIndiceEdgesTester"; import ColorIndiceTester from "../IndiceTester/ColorIndiceTester"; import IndiceTester from "../IndiceTester/IndiceTester"; import IndiceTesterAge from "../IndiceTester/IndiceTesterAge"; import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester"; +import NbSportIndiceTester from "../IndiceTester/NbSportIndiceTester"; import SportIndiceTester from "../IndiceTester/SportIndiceTester"; class IndiceTesterFactory{ @@ -29,6 +31,9 @@ class IndiceTesterFactory{ if (indice instanceof SportIndice){ return new SportIndiceTester(indice) } + if (indice instanceof NbSportIndice){ + return new NbSportIndiceTester(indice) + } throw new Error("Method not finished."); } } diff --git a/cryptide_project/src/source/Graph/GraphCreator.ts b/cryptide_project/src/source/Graph/GraphCreator.ts index 5b4ad6b..a7df621 100644 --- a/cryptide_project/src/source/Graph/GraphCreator.ts +++ b/cryptide_project/src/source/Graph/GraphCreator.ts @@ -15,6 +15,7 @@ class GraphCreator{ for (let i = 0; i 0) tabIndice.push(ageIndice) if (colorIndice.length > 0) tabIndice.push(colorIndice) if (sportIndice.length > 0) tabIndice.push(sportIndice) + if (nbSportIndice.length > 0) tabIndice.push(nbSportIndice) for (let i = 0; i 0) test.push(ageIndice) if (colorIndice.length > 0) test.push(colorIndice) if (sportIndice.length > 0) test.push(sportIndice) + if (nbSportIndice.length > 0) test.push(nbSportIndice) } const rand = Math.floor(Math.random() * test.length) diff --git a/cryptide_project/src/source/IndiceTester/NbSportIndiceTester.ts b/cryptide_project/src/source/IndiceTester/NbSportIndiceTester.ts new file mode 100644 index 0000000..6adbc4f --- /dev/null +++ b/cryptide_project/src/source/IndiceTester/NbSportIndiceTester.ts @@ -0,0 +1,24 @@ +import AgeIndice from "../Indices/AgeIndice"; +import ColorIndice from "../Indices/ColorIndice"; +import NbSportIndice from "../Indices/NbSportIndice"; +import Person from "../Person"; +import IndiceTester from "./IndiceTester"; + +class NbSportIndiceTester implements IndiceTester{ + + private nbSportIndice: NbSportIndice + + constructor(nbSportIndice: NbSportIndice){ + this.nbSportIndice = nbSportIndice; + } + + Works(person: Person): boolean { + return this.nbSportIndice.getNbSport() == person.getSports().length + } + + TestWorks(person: Person): boolean { + return this.nbSportIndice.getNbSport() == person.getSports().length + } +} + +export default NbSportIndiceTester \ No newline at end of file diff --git a/cryptide_project/src/source/Indices/NbSportIndice.ts b/cryptide_project/src/source/Indices/NbSportIndice.ts new file mode 100644 index 0000000..fe660e7 --- /dev/null +++ b/cryptide_project/src/source/Indices/NbSportIndice.ts @@ -0,0 +1,23 @@ +import { GetJsonFile } from "../EnumExtender"; +import Indice from "./Indice"; + +class NbSportIndice extends Indice { + private nbSport: number; + + constructor(id: number, nbSport: number) { + super(id); + this.nbSport = nbSport; + } + + public getNbSport(): number{ + return this.nbSport + } + + // Implémentation de la méthode abstraite + ToString(lang: string): string { + let json = GetJsonFile(lang) + return `${json.nb_sports_indice_start} ${this.nbSport} ${json.nb_sports_indice_end}`; + } + } + + export default NbSportIndice \ No newline at end of file diff --git a/cryptide_project/src/source/Stub.ts b/cryptide_project/src/source/Stub.ts index 461dd5b..eb32c76 100644 --- a/cryptide_project/src/source/Stub.ts +++ b/cryptide_project/src/source/Stub.ts @@ -4,6 +4,7 @@ import ColorEdgesIndice from "./Indices/ColorEdgesIndice" import ColorIndice from "./Indices/ColorIndice" import Indice from "./Indices/Indice" import NbEdgesIndice from "./Indices/NbEdgesIndice" +import NbSportIndice from "./Indices/NbSportIndice" import SportIndice from "./Indices/SportIndice" import Sport from "./Sport" @@ -44,6 +45,11 @@ class Stub{ indices.push(new ColorEdgesIndice(test, [i])) test++ } + + for (let i=1; i<3; i++){ + indices.push(new NbSportIndice(test, i)) + test++ + } return indices } }