Merge branch 'master' of https://codefirst.iut.uca.fr/git/Crypteam/Cryptid into leaderboard
commit
aee2d6893e
@ -0,0 +1,22 @@
|
||||
.choice-bar-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.choice-bar-heading {
|
||||
font-size: 1.5em;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.choice-bar-button {
|
||||
margin: 5px;
|
||||
padding: 10px;
|
||||
background-color: lightseagreen;
|
||||
color: #fff;
|
||||
border: 2px solid grey;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
import './ChoiceBar.css';
|
||||
|
||||
const ChoiceBar = () => {
|
||||
const players = ['Player1', 'Player2', 'Player3'];
|
||||
|
||||
return (
|
||||
<div className="choice-bar-container">
|
||||
<h3 className="choice-bar-heading">Quel joueur voulez-vous interroger ?</h3>
|
||||
<div>
|
||||
{players.map((player, index) => (
|
||||
<button key={index} className="choice-bar-button">
|
||||
{player}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ChoiceBar;
|
@ -0,0 +1,10 @@
|
||||
#graph-container {
|
||||
width: 100%;
|
||||
height: 75vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
background-color: #f5f5f5;
|
||||
padding: 20px;
|
||||
box-sizing: border-box;
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
import React, { useEffect } from "react";
|
||||
import { DataSet, Network} from "vis-network/standalone/esm/vis-network";
|
||||
import EdgesCreator from "../source/EdgesCreator";
|
||||
import GraphCreator from "../source/Graph/GraphCreator";
|
||||
import IndiceChooser from "../source/IndiceChooser";
|
||||
import SportIndice from "../source/Indices/SportIndice";
|
||||
import NetworkGenerator from "../source/NetworkGenerator";
|
||||
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()
|
||||
|
||||
const chooser = new IndiceChooser()
|
||||
|
||||
const indices = Stub.GenerateIndice()
|
||||
|
||||
const networkPerson = NetworkGenerator.GenerateNetwork(50)
|
||||
|
||||
const rand = Math.floor(Math.random() * 50)
|
||||
const person = networkPerson.getPersons()[rand]
|
||||
|
||||
const choosenIndices = chooser.chooseIndice(networkPerson, person, indices, 8)
|
||||
|
||||
edgesCreator.CreateAllEdges(networkPerson, person, choosenIndices)
|
||||
|
||||
const graph = GraphCreator.CreateGraph(networkPerson)
|
||||
|
||||
|
||||
let indice = new SportIndice(12, [Sport.TENNIS, Sport.BASEBALL])
|
||||
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;
|
||||
}
|
||||
|
||||
const MyGraphComponent: React.FC<MyGraphComponentProps> = ({onNodeClick}) => {
|
||||
useEffect(() => {
|
||||
const container = document.getElementById('graph-container');
|
||||
if (!container) {
|
||||
console.error("Container not found");
|
||||
return;
|
||||
}
|
||||
|
||||
// Charger les données dans le graph
|
||||
const nodes = new DataSet(graph.nodesPerson);
|
||||
|
||||
// Configuration des options du Graphe
|
||||
const initialOptions = {
|
||||
layout: {
|
||||
improvedLayout: true,
|
||||
hierarchical: {
|
||||
enabled: false,
|
||||
direction: 'LR', // LR (Left to Right) ou autre selon votre préférence
|
||||
sortMethod: 'hubsize'
|
||||
}
|
||||
},
|
||||
physics: {
|
||||
enabled: true,
|
||||
barnesHut: {
|
||||
gravitationalConstant: -1000,
|
||||
springConstant: 0.001,
|
||||
springLength: 100
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
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) {
|
||||
// Un nœud a été cliqué
|
||||
initialOptions.physics.enabled = false;
|
||||
network.setOptions(initialOptions);
|
||||
}
|
||||
});
|
||||
|
||||
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)
|
||||
}
|
||||
else{
|
||||
// Renvoyer un false pour cacher la choice bar
|
||||
onNodeClick(false)
|
||||
}
|
||||
});
|
||||
}, []); // Le tableau vide signifie que cela ne s'exécutera qu'une fois après le premier rendu
|
||||
|
||||
return (
|
||||
<>
|
||||
<div id="graph-container"/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default MyGraphComponent;
|
@ -0,0 +1,23 @@
|
||||
import React, { useState } from 'react';
|
||||
import GraphContainer from '../Components/GraphContainer';
|
||||
import ChoiceBar from '../Components/ChoiceBar';
|
||||
|
||||
const InGame = () => {
|
||||
const [showChoiceBar, setShowChoiceBar] = useState(false);
|
||||
|
||||
const handleNodeClick = (shouldShowChoiceBar: boolean) => {
|
||||
setShowChoiceBar(shouldShowChoiceBar);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<GraphContainer onNodeClick={handleNodeClick} />
|
||||
<div id="bottom-container">
|
||||
{showChoiceBar && <ChoiceBar />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
export default InGame;
|
@ -0,0 +1,36 @@
|
||||
import {
|
||||
Network,
|
||||
Options,
|
||||
Data,
|
||||
Edge,
|
||||
Node
|
||||
} from "vis-network/standalone/esm/vis-network";
|
||||
import React, { useState, useLayoutEffect, useRef } from "react";
|
||||
|
||||
export interface UseVisNetworkOptions {
|
||||
options: Options;
|
||||
nodes: Node[];
|
||||
edges: Edge[];
|
||||
}
|
||||
|
||||
export default (props: UseVisNetworkOptions) => {
|
||||
const { edges, nodes, options } = props;
|
||||
|
||||
const [network, addNetwork] = useState<Network | null>(null);
|
||||
const ref = useRef<HTMLDivElement>(null);
|
||||
|
||||
const data: Data = { nodes, edges };
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (ref.current) {
|
||||
const instance = new Network(ref.current, data, options);
|
||||
addNetwork(instance);
|
||||
}
|
||||
return () => network?.destroy();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
network,
|
||||
ref
|
||||
};
|
||||
};
|
@ -0,0 +1,96 @@
|
||||
{
|
||||
"names": [
|
||||
"Emma",
|
||||
"Olivia",
|
||||
"Sophia",
|
||||
"Ava",
|
||||
"Isabella",
|
||||
"Mia",
|
||||
"Amelia",
|
||||
"Harper",
|
||||
"Evelyn",
|
||||
"Abigail",
|
||||
"Emily",
|
||||
"Charlotte",
|
||||
"Scarlett",
|
||||
"Grace",
|
||||
"Lily",
|
||||
"Aria",
|
||||
"Chloe",
|
||||
"Zoey",
|
||||
"Penelope",
|
||||
"Riley",
|
||||
"Layla",
|
||||
"Stella",
|
||||
"Aurora",
|
||||
"Natalie",
|
||||
"Zoe",
|
||||
"Lucy",
|
||||
"Hannah",
|
||||
"Leah",
|
||||
"Victoria",
|
||||
"Hazel",
|
||||
"Violet",
|
||||
"Aurora",
|
||||
"Ruby",
|
||||
"Ivy",
|
||||
"Eleanor",
|
||||
"Savannah",
|
||||
"Alice",
|
||||
"Claire",
|
||||
"Nora",
|
||||
"Lillian",
|
||||
"Mila",
|
||||
"Peyton",
|
||||
"Aaliyah",
|
||||
"Gabriella",
|
||||
"Eliana",
|
||||
"Bella",
|
||||
"Sadie",
|
||||
"Hailey",
|
||||
"Aurora",
|
||||
"Liam",
|
||||
"Noah",
|
||||
"Oliver",
|
||||
"Elijah",
|
||||
"William",
|
||||
"James",
|
||||
"Benjamin",
|
||||
"Lucas",
|
||||
"Henry",
|
||||
"Alexander",
|
||||
"Jackson",
|
||||
"Aiden",
|
||||
"Sebastian",
|
||||
"Carter",
|
||||
"Daniel",
|
||||
"Matthew",
|
||||
"Wyatt",
|
||||
"Jack",
|
||||
"Jayden",
|
||||
"Owen",
|
||||
"Noah",
|
||||
"Ethan",
|
||||
"Mason",
|
||||
"Logan",
|
||||
"Caden",
|
||||
"Samuel",
|
||||
"David",
|
||||
"Joseph",
|
||||
"Michael",
|
||||
"Gabriel",
|
||||
"Caleb",
|
||||
"Ryan",
|
||||
"Isaac",
|
||||
"Luke",
|
||||
"Andrew",
|
||||
"Nathan",
|
||||
"Dylan",
|
||||
"Adam",
|
||||
"Joshua",
|
||||
"Connor",
|
||||
"Brayden",
|
||||
"Julian"
|
||||
]
|
||||
}
|
||||
|
@ -0,0 +1,9 @@
|
||||
enum Color {
|
||||
WHITE,
|
||||
BLACK,
|
||||
BLOND,
|
||||
REDHEAD,
|
||||
BROWN,
|
||||
}
|
||||
|
||||
export default Color
|
@ -0,0 +1,117 @@
|
||||
import IndiceTesterFactory from "./Factory/IndiceTesterFactory";
|
||||
import EdgesIndice from "./Indices/EdgesIndice";
|
||||
import Indice from "./Indices/Indice";
|
||||
import Person from "./Person";
|
||||
import PersonNetwork from "./PersonsNetwork";
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import IndiceEdgesFactory from "./Factory/IndiceEdgesCreatorFactory";
|
||||
|
||||
|
||||
class EdgesCreator{
|
||||
|
||||
CreateWorkingEdge(personNetwork: PersonNetwork, choosenPerson: Person, indice: Indice, indices: Indice[]){
|
||||
let creator = IndiceEdgesFactory.Create(indice)
|
||||
const nbMaxEdge = Math.floor(Math.random() * 5) + 1
|
||||
|
||||
creator.createWorkingEdges(personNetwork, choosenPerson, indices)
|
||||
|
||||
if (choosenPerson.getFriends().length < nbMaxEdge){
|
||||
for (const p of personNetwork.getPersons()){
|
||||
if (choosenPerson.getFriends().length == nbMaxEdge){
|
||||
return
|
||||
}
|
||||
if (p!=choosenPerson && !choosenPerson.getFriends().includes(p)){
|
||||
let testEdgeWork = 0
|
||||
const p1 = cloneDeep(p);
|
||||
const personEdge = cloneDeep(choosenPerson);
|
||||
p1.addFriend(personEdge)
|
||||
personEdge.addFriend(p1)
|
||||
indices.forEach((indice) => {
|
||||
const tester = IndiceTesterFactory.Create(indice)
|
||||
if (tester.Works(p1)){
|
||||
testEdgeWork ++
|
||||
}
|
||||
});
|
||||
|
||||
if (testEdgeWork < indices.length){
|
||||
p.addFriend(choosenPerson)
|
||||
choosenPerson.addFriend(p)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CreateNotWorkingEdge(personNetwork: PersonNetwork, personToCreateEdge: Person, choosenPerson: Person, indices: Indice[], map: Map<number, number>){
|
||||
const test = [...personNetwork.getPersons()]
|
||||
shuffleArray(test)
|
||||
test.forEach((p) => {
|
||||
if (personToCreateEdge.getFriends().length == map.get(personToCreateEdge.getId())){
|
||||
return
|
||||
}
|
||||
if (p != personToCreateEdge && p != choosenPerson && !personToCreateEdge.getFriends().includes(p)){
|
||||
let testEdgeWork1 = 0
|
||||
let testEdgeWork2 = 0
|
||||
const p1 = cloneDeep(p);
|
||||
const personEdge = cloneDeep(personToCreateEdge);
|
||||
p1.addFriend(personEdge)
|
||||
personEdge.addFriend(p1)
|
||||
indices.forEach((indice) => {
|
||||
const tester = IndiceTesterFactory.Create(indice)
|
||||
if (tester.Works(p1) || map.get(p.getId()) === p.getFriends().length){
|
||||
testEdgeWork1 ++
|
||||
}
|
||||
if (tester.Works(personEdge) || map.get(p.getId()) === p.getFriends().length){
|
||||
testEdgeWork2 ++
|
||||
}
|
||||
});
|
||||
|
||||
if (testEdgeWork1 < indices.length && testEdgeWork2 < indices.length){
|
||||
p.addFriend(personToCreateEdge)
|
||||
personToCreateEdge.addFriend(p)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
CreateAllEdges(personNetwork: PersonNetwork, choosenPerson: Person, indices: Indice[]){
|
||||
const test = new Map<number, number>()
|
||||
const tabEdgesSize: number[] = []
|
||||
for (let i = 0; i<personNetwork.getPersons().length / 4; i++){
|
||||
tabEdgesSize.push(1)
|
||||
tabEdgesSize.push(2)
|
||||
tabEdgesSize.push(3)
|
||||
tabEdgesSize.push(4)
|
||||
}
|
||||
indices.forEach(indice => {
|
||||
if (indice instanceof EdgesIndice){
|
||||
this.CreateWorkingEdge(personNetwork, choosenPerson, indice, indices)
|
||||
}
|
||||
});
|
||||
personNetwork.getPersons().forEach((p) => {
|
||||
if (p != choosenPerson){
|
||||
const rand = Math.floor(Math.random() * 4)
|
||||
test.set(p.getId(), tabEdgesSize[rand] + p.getFriends().length)
|
||||
tabEdgesSize.splice(rand, 1)
|
||||
}
|
||||
});
|
||||
personNetwork.getPersons().forEach((p) => {
|
||||
if (p != choosenPerson){
|
||||
|
||||
this.CreateNotWorkingEdge(personNetwork, p, choosenPerson, indices, test)
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function shuffleArray(array: Person[]) {
|
||||
for (var i = array.length - 1; i > 0; i--) {
|
||||
var j = Math.floor(Math.random() * (i + 1));
|
||||
var temp = array[i];
|
||||
array[i] = array[j];
|
||||
array[j] = temp;
|
||||
}
|
||||
}
|
||||
|
||||
export default EdgesCreator
|
@ -0,0 +1,99 @@
|
||||
import Color from "./Color";
|
||||
import Sport from "./Sport";
|
||||
import React from 'react';
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
||||
import { faFutbol, faBasketballBall } from '@fortawesome/free-solid-svg-icons';
|
||||
import { parseJsonText } from "typescript";
|
||||
|
||||
|
||||
|
||||
function GetJsonFile(lang: string){
|
||||
const response = require(`../Translations/${lang}.json`);
|
||||
const data = response;
|
||||
return data
|
||||
}
|
||||
function ColorToString(color: Color, lang: string): string{
|
||||
let json = GetJsonFile(lang)
|
||||
switch(color){
|
||||
case Color.WHITE:
|
||||
return json.white
|
||||
case Color.BLACK:
|
||||
return json.black
|
||||
case Color.BLOND:
|
||||
return json.blond
|
||||
case Color.REDHEAD:
|
||||
return json.redhead
|
||||
case Color.BROWN:
|
||||
return json.brown
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function ColorToHexa(color: Color): string{
|
||||
switch(color){
|
||||
case Color.WHITE:
|
||||
return "#FFFFFF"
|
||||
case Color.BLACK:
|
||||
return "#000000"
|
||||
case Color.BLOND:
|
||||
return "#E2BC74"
|
||||
case Color.REDHEAD:
|
||||
return "#FF8B00"
|
||||
case Color.BROWN:
|
||||
return "#5B3C11"
|
||||
}
|
||||
}
|
||||
|
||||
function ColorToColorFont(color: Color): string{
|
||||
switch(color){
|
||||
case Color.WHITE:
|
||||
return "#000000"
|
||||
case Color.BLACK:
|
||||
return "#FFFFFF"
|
||||
case Color.BLOND:
|
||||
return "#000000"
|
||||
case Color.REDHEAD:
|
||||
return "#000000"
|
||||
case Color.BROWN:
|
||||
return "#FFFFFF"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function SportToString(sport: Sport, lang: string): string{
|
||||
let json = GetJsonFile(lang)
|
||||
switch(sport){
|
||||
case Sport.FOOT:
|
||||
return json.football
|
||||
case Sport.BASEBALL:
|
||||
return json.baseball
|
||||
case Sport.BASKET:
|
||||
return json.basketball
|
||||
case Sport.TENNIS:
|
||||
return json.tennis
|
||||
case Sport.BOWLING:
|
||||
return json.bowling
|
||||
case Sport.AUCUN:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function SportToIcon(sport: Sport): string{
|
||||
switch(sport){
|
||||
case Sport.FOOT:
|
||||
return "⚽"
|
||||
case Sport.BASEBALL:
|
||||
return "⚾"
|
||||
case Sport.BASKET:
|
||||
return "🏀"
|
||||
case Sport.TENNIS:
|
||||
return "🎾"
|
||||
case Sport.BOWLING:
|
||||
return "🎳"
|
||||
case Sport.AUCUN:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
export {ColorToString, SportToString, ColorToHexa, ColorToColorFont, SportToIcon, GetJsonFile}
|
@ -0,0 +1,27 @@
|
||||
import ColorIndiceEdgesCreator from "../IndiceEdgesCreator.ts/ColorIndiceEdgesCreator";
|
||||
import IndiceEdgesCreator from "../IndiceEdgesCreator.ts/IndiceEdgesCreator";
|
||||
import NbEdgesIndiceEdgesCreator from "../IndiceEdgesCreator.ts/NbEdgesIndiceEdgesCreator";
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
|
||||
import ColorIndice from "../Indices/ColorIndice";
|
||||
import Indice from "../Indices/Indice";
|
||||
import NbEdgesIndice from "../Indices/NbEdgesIndice";
|
||||
import ColorIndiceTester from "../IndiceTester/ColorIndiceTester";
|
||||
import IndiceTester from "../IndiceTester/IndiceTester";
|
||||
import IndiceTesterAge from "../IndiceTester/IndiceTesterAge";
|
||||
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
|
||||
|
||||
class IndiceEdgesFactory{
|
||||
|
||||
static Create(indice: Indice): IndiceEdgesCreator{
|
||||
if (indice instanceof NbEdgesIndice){
|
||||
return new NbEdgesIndiceEdgesCreator(indice)
|
||||
}
|
||||
if (indice instanceof ColorEdgesIndice){
|
||||
return new ColorIndiceEdgesCreator(indice)
|
||||
}
|
||||
throw new Error("Method not finished.");
|
||||
}
|
||||
}
|
||||
|
||||
export default IndiceEdgesFactory
|
@ -0,0 +1,41 @@
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
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{
|
||||
|
||||
static Create(indice: Indice): IndiceTester{
|
||||
if (indice instanceof AgeIndice){
|
||||
return new IndiceTesterAge(indice)
|
||||
}
|
||||
if (indice instanceof NbEdgesIndice){
|
||||
return new NbEdgesIndiceTester(indice)
|
||||
}
|
||||
if (indice instanceof ColorIndice){
|
||||
return new ColorIndiceTester(indice)
|
||||
}
|
||||
if (indice instanceof ColorEdgesIndice){
|
||||
return new ColorEdgesIndiceTester(indice)
|
||||
}
|
||||
if (indice instanceof SportIndice){
|
||||
return new SportIndiceTester(indice)
|
||||
}
|
||||
if (indice instanceof NbSportIndice){
|
||||
return new NbSportIndiceTester(indice)
|
||||
}
|
||||
throw new Error("Method not finished.");
|
||||
}
|
||||
}
|
||||
|
||||
export default IndiceTesterFactory
|
@ -0,0 +1,12 @@
|
||||
class Edge{
|
||||
|
||||
public from: number
|
||||
public to: number
|
||||
|
||||
constructor(from: number, to: number){
|
||||
this.from = from
|
||||
this.to = to
|
||||
}
|
||||
}
|
||||
|
||||
export default Edge
|
@ -0,0 +1,14 @@
|
||||
class Font{
|
||||
public color: string
|
||||
public size: number
|
||||
public align: string
|
||||
|
||||
constructor(color: string, size: number, align: string){
|
||||
this.color=color
|
||||
this.size=size
|
||||
this.align=align
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default Font
|
@ -0,0 +1,35 @@
|
||||
import Edge from "./Edge";
|
||||
import { ColorToColorFont, ColorToHexa, SportToIcon, SportToString } from "../EnumExtender";
|
||||
import GraphPerson from "./GraphPerson";
|
||||
import NodePerson from "./NodePerson";
|
||||
import PersonNetwork from "../PersonsNetwork";
|
||||
import Font from "./Font";
|
||||
|
||||
class GraphCreator{
|
||||
|
||||
static CreateGraph(network: PersonNetwork): GraphPerson{
|
||||
const nodesPerson : NodePerson[] = []
|
||||
const edges: Edge[] = []
|
||||
network.getPersons().forEach((p) =>{
|
||||
let label = p.getName() + "\n" + p.getAge() + "\n"
|
||||
for (let i = 0; i<p.getSports().length; i++){
|
||||
label += SportToIcon(p.getSports()[i])
|
||||
}
|
||||
label += "\n"
|
||||
|
||||
|
||||
const nodePerson = new NodePerson(p.getId(), label, p.getColor(), new Font(ColorToColorFont(p.getColor()), 14, 'center'), 'box')
|
||||
nodesPerson.push(nodePerson)
|
||||
p.getFriends().forEach((f) =>{
|
||||
if(edges.some(edge => (edge.from === f.getId() && edge.to === p.getId()) || (edge.from === p.getId() && edge.to === f.getId()))){
|
||||
return;
|
||||
}
|
||||
edges.push(new Edge(p.getId(), f.getId()))
|
||||
});
|
||||
});
|
||||
|
||||
return new GraphPerson(edges, nodesPerson)
|
||||
}
|
||||
}
|
||||
|
||||
export default GraphCreator
|
@ -0,0 +1,17 @@
|
||||
import Edge from "./Edge";
|
||||
import NodePerson from "./NodePerson";
|
||||
|
||||
class GraphPerson{
|
||||
|
||||
public edges: Edge[]
|
||||
|
||||
public nodesPerson: NodePerson[]
|
||||
|
||||
constructor(edges: Edge[], nodesPerson: NodePerson[]){
|
||||
this.edges = edges
|
||||
this.nodesPerson = nodesPerson
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default GraphPerson
|
@ -0,0 +1,21 @@
|
||||
import Color from "../Color"
|
||||
import { ColorToColorFont, ColorToHexa } from "../EnumExtender"
|
||||
import Font from "./Font"
|
||||
|
||||
class NodePerson{
|
||||
public id: number
|
||||
public label: string
|
||||
public color: string
|
||||
public font: Font
|
||||
public shape: string
|
||||
|
||||
constructor(id: number, label: string, color: Color, font: Font, shape: string){
|
||||
this.id=id
|
||||
this.label=label
|
||||
this.color=ColorToHexa(color)
|
||||
this.font=font
|
||||
this.shape = shape
|
||||
}
|
||||
}
|
||||
|
||||
export default NodePerson
|
@ -0,0 +1,75 @@
|
||||
import IndiceTesterFactory from "./Factory/IndiceTesterFactory";
|
||||
import EdgesIndice from "./Indices/EdgesIndice";
|
||||
import Indice from "./Indices/Indice";
|
||||
import Person from "./Person";
|
||||
import PersonNetwork from "./PersonsNetwork";
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import IndiceEdgesFactory from "./Factory/IndiceEdgesCreatorFactory";
|
||||
import AgeIndice from "./Indices/AgeIndice";
|
||||
import ColorIndice from "./Indices/ColorIndice";
|
||||
import SportIndice from "./Indices/SportIndice";
|
||||
import NbSportIndice from "./Indices/NbSportIndice";
|
||||
|
||||
|
||||
class IndiceChooser{
|
||||
|
||||
chooseIndice(personNetwork: PersonNetwork, choosenPerson: Person, indices: Indice[], nbPlayer: number): Indice[]{
|
||||
const choosenIndices: Indice[] = []
|
||||
const ageIndice : Indice[] = []
|
||||
const sportIndice : Indice[] = []
|
||||
const colorIndice : Indice[] = []
|
||||
const edgeIndice : Indice[] = []
|
||||
const nbSportIndice : Indice[] = []
|
||||
|
||||
const tabIndice: Indice[][] = []
|
||||
|
||||
for (const indice of indices){
|
||||
if (indice instanceof EdgesIndice){
|
||||
edgeIndice.push(indice)
|
||||
continue
|
||||
}
|
||||
const tester = IndiceTesterFactory.Create(indice)
|
||||
if (tester.Works(choosenPerson)){
|
||||
if (indice instanceof AgeIndice){
|
||||
ageIndice.push(indice)
|
||||
}
|
||||
else if(indice instanceof ColorIndice){
|
||||
colorIndice.push(indice)
|
||||
}
|
||||
else if(indice instanceof SportIndice){
|
||||
sportIndice.push(indice)
|
||||
}
|
||||
else if(indice instanceof NbSportIndice){
|
||||
nbSportIndice.push(indice)
|
||||
}
|
||||
}
|
||||
}
|
||||
let test = [...tabIndice]
|
||||
if (ageIndice.length > 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<nbPlayer-1; i++){
|
||||
if (test.length == 0){
|
||||
if (ageIndice.length > 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)
|
||||
const rand2 = Math.floor(Math.random() * test[rand].length)
|
||||
choosenIndices.push(test[rand][rand2])
|
||||
test[rand].splice(rand2, 1)
|
||||
test.splice(rand, 1)
|
||||
|
||||
}
|
||||
const rand = Math.floor(Math.random() * edgeIndice.length)
|
||||
choosenIndices.push(edgeIndice[rand])
|
||||
return choosenIndices
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default IndiceChooser
|
@ -0,0 +1,53 @@
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import IndiceTesterFactory from "../Factory/IndiceTesterFactory";
|
||||
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
|
||||
import ColorIndice from "../Indices/ColorIndice";
|
||||
import EdgesIndice from "../Indices/EdgesIndice";
|
||||
import Indice from "../Indices/Indice";
|
||||
import NbEdgesIndice from "../Indices/NbEdgesIndice";
|
||||
import ColorEdgesIndiceTester from "../IndiceTester/ColorIndiceEdgesTester";
|
||||
import ColorIndiceTester from "../IndiceTester/ColorIndiceTester";
|
||||
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
|
||||
import Person from "../Person";
|
||||
import PersonNetwork from "../PersonsNetwork";
|
||||
import IndiceEdgesCreator from "./IndiceEdgesCreator";
|
||||
|
||||
class ColorIndiceEdgesCreator implements IndiceEdgesCreator{
|
||||
|
||||
private indice: ColorEdgesIndice
|
||||
|
||||
constructor(indice: ColorEdgesIndice){
|
||||
this.indice = indice
|
||||
}
|
||||
|
||||
createWorkingEdges(personNetwork: PersonNetwork, person: Person, indices: Indice[]): number {
|
||||
let indiceTest = new ColorEdgesIndiceTester(this.indice)
|
||||
for (const p of personNetwork.getPersons()){
|
||||
let a = false
|
||||
if (p!=person){
|
||||
let testEdgeWork = 0
|
||||
const p1 = cloneDeep(p)
|
||||
p1.addFriend(person)
|
||||
const choosenOne = cloneDeep(person)
|
||||
choosenOne.addFriend(p1)
|
||||
if (indiceTest.Works(choosenOne)){
|
||||
for (const indice of indices){
|
||||
const tester = IndiceTesterFactory.Create(indice)
|
||||
if (tester.Works(p1)){
|
||||
testEdgeWork ++
|
||||
}
|
||||
}
|
||||
if (testEdgeWork < indices.length){
|
||||
p.addFriend(person)
|
||||
person.addFriend(p)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return person.getFriends().length
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ColorIndiceEdgesCreator
|
@ -0,0 +1,9 @@
|
||||
import Indice from "../Indices/Indice";
|
||||
import Person from "../Person";
|
||||
import PersonNetwork from "../PersonsNetwork";
|
||||
|
||||
interface IndiceEdgesCreator{
|
||||
createWorkingEdges(personNetwork: PersonNetwork, person: Person, indices: Indice[]): number
|
||||
}
|
||||
|
||||
export default IndiceEdgesCreator
|
@ -0,0 +1,47 @@
|
||||
import cloneDeep from "lodash/cloneDeep";
|
||||
import IndiceTesterFactory from "../Factory/IndiceTesterFactory";
|
||||
import EdgesIndice from "../Indices/EdgesIndice";
|
||||
import Indice from "../Indices/Indice";
|
||||
import NbEdgesIndice from "../Indices/NbEdgesIndice";
|
||||
import NbEdgesIndiceTester from "../IndiceTester/NbEdgesIndiceTester";
|
||||
import Person from "../Person";
|
||||
import PersonNetwork from "../PersonsNetwork";
|
||||
import IndiceEdgesCreator from "./IndiceEdgesCreator";
|
||||
|
||||
class NbEdgesIndiceEdgesCreator implements IndiceEdgesCreator{
|
||||
|
||||
private indice: NbEdgesIndice
|
||||
|
||||
constructor(indice: NbEdgesIndice){
|
||||
this.indice = indice
|
||||
}
|
||||
|
||||
createWorkingEdges(personNetwork: PersonNetwork, person: Person, indices: Indice[]): number {
|
||||
let indiceTest = new NbEdgesIndiceTester(this.indice)
|
||||
const nbEdges = this.indice.getNbEdges() + Math.floor(Math.random() * 2)
|
||||
personNetwork.getPersons().forEach(p => {
|
||||
if (person.getFriends().length == nbEdges){
|
||||
return
|
||||
}
|
||||
if (p!=person){
|
||||
let testEdgeWork = 0
|
||||
const p1 = cloneDeep(p)
|
||||
p1.addFriend(person)
|
||||
indices.forEach((indice) => {
|
||||
const tester = IndiceTesterFactory.Create(indice)
|
||||
if (tester.Works(p1)){
|
||||
testEdgeWork ++
|
||||
}
|
||||
});
|
||||
if (testEdgeWork < indices.length){
|
||||
p.addFriend(person)
|
||||
person.addFriend(p)
|
||||
}
|
||||
}
|
||||
});
|
||||
return person.getFriends().length
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default NbEdgesIndiceEdgesCreator
|
@ -0,0 +1,36 @@
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
import ColorEdgesIndice from "../Indices/ColorEdgesIndice";
|
||||
import ColorIndice from "../Indices/ColorIndice";
|
||||
import Person from "../Person";
|
||||
import IndiceTester from "./IndiceTester";
|
||||
|
||||
class ColorEdgesIndiceTester implements IndiceTester{
|
||||
|
||||
private colorEdgesIndice: ColorEdgesIndice
|
||||
|
||||
constructor(colorEdgesIndice: ColorEdgesIndice){
|
||||
this.colorEdgesIndice = colorEdgesIndice;
|
||||
}
|
||||
|
||||
Works(person: Person): boolean {
|
||||
let res = false
|
||||
person.getFriends().forEach(p => {
|
||||
if(this.colorEdgesIndice.getColors().includes(p.getColor())){
|
||||
res = true
|
||||
return true
|
||||
}
|
||||
});
|
||||
return res
|
||||
}
|
||||
|
||||
TestWorks(person: Person): boolean {
|
||||
person.getFriends().forEach(p => {
|
||||
if(this.colorEdgesIndice.getColors().includes(p.getColor())){
|
||||
return true
|
||||
}
|
||||
});
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default ColorEdgesIndiceTester
|
@ -0,0 +1,23 @@
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
import ColorIndice from "../Indices/ColorIndice";
|
||||
import Person from "../Person";
|
||||
import IndiceTester from "./IndiceTester";
|
||||
|
||||
class ColorIndiceTester implements IndiceTester{
|
||||
|
||||
private colorIndice: ColorIndice
|
||||
|
||||
constructor(colorIndice: ColorIndice){
|
||||
this.colorIndice = colorIndice;
|
||||
}
|
||||
|
||||
Works(person: Person): boolean {
|
||||
return this.colorIndice.getColors().includes(person.getColor())
|
||||
}
|
||||
|
||||
TestWorks(person: Person): boolean {
|
||||
return this.colorIndice.getColors().includes(person.getColor())
|
||||
}
|
||||
}
|
||||
|
||||
export default ColorIndiceTester
|
@ -0,0 +1,10 @@
|
||||
import Indice from "../Indices/Indice"
|
||||
import Person from "../Person"
|
||||
|
||||
interface IndiceTester{
|
||||
|
||||
Works(person: Person): boolean
|
||||
TestWorks(person: Person): boolean
|
||||
}
|
||||
|
||||
export default IndiceTester
|
@ -0,0 +1,22 @@
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
import Person from "../Person";
|
||||
import IndiceTester from "./IndiceTester";
|
||||
|
||||
class IndiceTesterAge implements IndiceTester{
|
||||
|
||||
private ageIndice: AgeIndice
|
||||
|
||||
constructor(ageIndice: AgeIndice){
|
||||
this.ageIndice = ageIndice;
|
||||
}
|
||||
|
||||
Works(person: Person): boolean {
|
||||
return person.getAge() >= this.ageIndice.getMinimum() && person.getAge()<= this.ageIndice.getMaximum()
|
||||
}
|
||||
|
||||
TestWorks(person: Person): boolean {
|
||||
return person.getAge() >= this.ageIndice.getMinimum() && person.getAge()<this.ageIndice.getMaximum()
|
||||
}
|
||||
}
|
||||
|
||||
export default IndiceTesterAge
|
@ -0,0 +1,23 @@
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
import NbEdgesIndice from "../Indices/NbEdgesIndice";
|
||||
import Person from "../Person";
|
||||
import IndiceTester from "./IndiceTester";
|
||||
|
||||
class NbEdgesIndiceTester implements IndiceTester{
|
||||
|
||||
private nbEdgesIndice: NbEdgesIndice
|
||||
|
||||
constructor(nbEdgesIndice: NbEdgesIndice){
|
||||
this.nbEdgesIndice = nbEdgesIndice;
|
||||
}
|
||||
|
||||
Works(person: Person): boolean {
|
||||
return person.getFriends().length >= this.nbEdgesIndice.getNbEdges()
|
||||
}
|
||||
|
||||
TestWorks(person: Person): boolean {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
export default NbEdgesIndiceTester
|
@ -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
|
@ -0,0 +1,34 @@
|
||||
import AgeIndice from "../Indices/AgeIndice";
|
||||
import ColorIndice from "../Indices/ColorIndice";
|
||||
import SportIndice from "../Indices/SportIndice";
|
||||
import Person from "../Person";
|
||||
import IndiceTester from "./IndiceTester";
|
||||
|
||||
class SportIndiceTester implements IndiceTester{
|
||||
|
||||
private sportIndice: SportIndice
|
||||
|
||||
constructor(sportIndice: SportIndice){
|
||||
this.sportIndice = sportIndice;
|
||||
}
|
||||
|
||||
Works(person: Person): boolean {
|
||||
for (const sport of person.getSports()){
|
||||
if (this.sportIndice.getSports().includes(sport)){
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
TestWorks(person: Person): boolean {
|
||||
for (const sport of person.getSports()){
|
||||
if (this.sportIndice.getSports().includes(sport)){
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export default SportIndiceTester
|
@ -0,0 +1,33 @@
|
||||
import { GetJsonFile } from "../EnumExtender";
|
||||
import Indice from "./Indice";
|
||||
|
||||
class AgeIndice extends Indice {
|
||||
private maximum: number;
|
||||
private minimum: number;
|
||||
|
||||
constructor(id: number, minimum: number, maximum: number) {
|
||||
super(id);
|
||||
this.minimum = minimum;
|
||||
this.maximum = maximum;
|
||||
}
|
||||
|
||||
// Implémentation de la méthode abstraite
|
||||
ToString(lang: string): string {
|
||||
let json = GetJsonFile(lang)
|
||||
if (this.maximum > 100){
|
||||
return `${json.age_indice_more_start} ${this.minimum} ${json.age_indice_end}`
|
||||
}
|
||||
return `${json.age_indice_start} ${this.minimum} ${json.and} ${this.maximum} ${json.age_indice_end}`
|
||||
}
|
||||
|
||||
|
||||
getMinimum(): number{
|
||||
return this.minimum
|
||||
}
|
||||
|
||||
getMaximum(): number{
|
||||
return this.maximum
|
||||
}
|
||||
}
|
||||
|
||||
export default AgeIndice
|
@ -0,0 +1,34 @@
|
||||
import Color from "../Color";
|
||||
import { ColorToString, GetJsonFile } from "../EnumExtender";
|
||||
import EdgesIndice from "./EdgesIndice";
|
||||
|
||||
class ColorEdgesIndice extends EdgesIndice {
|
||||
|
||||
private neighborsColors: Color[];
|
||||
|
||||
constructor(id: number, neighborsColors: Color[]) {
|
||||
super(id);
|
||||
this.neighborsColors = neighborsColors;
|
||||
}
|
||||
|
||||
public getColors(): Color[]{
|
||||
return this.neighborsColors
|
||||
}
|
||||
|
||||
// Implémentation de la méthode abstraite
|
||||
ToString(lang: string): string {
|
||||
let json = GetJsonFile(lang)
|
||||
let string = json.color_edges_start;
|
||||
for (let i = 0; i<this.neighborsColors.length; i++){
|
||||
if (i==this.neighborsColors.length - 1 || this.neighborsColors.length == 1){
|
||||
string = `${string} ${ColorToString(this.neighborsColors[i], lang)}`
|
||||
}
|
||||
else{
|
||||
string = `${string} ${ColorToString(this.neighborsColors[i], lang)} ${json.or}`
|
||||
}
|
||||
}
|
||||
return `${string} ${json.color_edges_end}`
|
||||
}
|
||||
}
|
||||
|
||||
export default ColorEdgesIndice
|
@ -0,0 +1,33 @@
|
||||
import Color from "../Color";
|
||||
import { ColorToString, GetJsonFile } from "../EnumExtender";
|
||||
import Indice from "./Indice";
|
||||
|
||||
class ColorIndice extends Indice {
|
||||
private colors: Color[]
|
||||
|
||||
constructor(id: number, colors: Color[]) {
|
||||
super(id);
|
||||
this.colors = colors
|
||||
}
|
||||
|
||||
// Implémentation de la méthode abstraite
|
||||
ToString(lang: string): string {
|
||||
let json = GetJsonFile(lang)
|
||||
let string = json.color_start;
|
||||
for (let i = 0; i<this.colors.length; i++){
|
||||
if (i==this.colors.length - 1 || this.colors.length == 1){
|
||||
string = `${string} ${ColorToString(this.colors[i], lang)}`
|
||||
}
|
||||
else{
|
||||
string = `${string} ${ColorToString(this.colors[i], lang)} ${json.or}`
|
||||
}
|
||||
}
|
||||
return `${string} ${json.color_end}`
|
||||
}
|
||||
|
||||
getColors(): Color[]{
|
||||
return this.colors
|
||||
}
|
||||
}
|
||||
|
||||
export default ColorIndice
|
@ -0,0 +1,6 @@
|
||||
import Indice from "./Indice";
|
||||
|
||||
abstract class EdgesIndice extends Indice {
|
||||
}
|
||||
|
||||
export default EdgesIndice
|
@ -0,0 +1,23 @@
|
||||
abstract class Indice {
|
||||
protected id: number;
|
||||
|
||||
constructor(id: number) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// Getter and setter for id
|
||||
getId(): number {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
setId(id: number): void {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// Méthode abstraite pour être implémentée par les classes dérivées
|
||||
abstract ToString(lang: string): string;
|
||||
|
||||
|
||||
}
|
||||
|
||||
export default Indice
|
@ -0,0 +1,23 @@
|
||||
import { GetJsonFile } from "../EnumExtender";
|
||||
import EdgesIndice from "./EdgesIndice";
|
||||
|
||||
class NbEdgesIndice extends EdgesIndice {
|
||||
private nbNeighbors: number;
|
||||
|
||||
constructor(id: number, nbNeighbors: number) {
|
||||
super(id);
|
||||
this.nbNeighbors = nbNeighbors;
|
||||
}
|
||||
|
||||
public getNbEdges(): number{
|
||||
return this.nbNeighbors
|
||||
}
|
||||
|
||||
// Implémentation de la méthode abstraite
|
||||
ToString(lang: string): string {
|
||||
let json = GetJsonFile(lang)
|
||||
return `${json.nb_friends_indice_start} ${this.nbNeighbors} ${json.nb_friends_indice_end}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default NbEdgesIndice
|
@ -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
|
@ -0,0 +1,34 @@
|
||||
import { GetJsonFile, SportToString } from "../EnumExtender";
|
||||
import Sport from "../Sport";
|
||||
import Indice from "./Indice";
|
||||
|
||||
class SportIndice extends Indice {
|
||||
private sports: Sport[]
|
||||
|
||||
constructor(id: number, sports: Sport[]) {
|
||||
super(id);
|
||||
this.sports = sports
|
||||
}
|
||||
|
||||
// Implémentation de la méthode abstraite
|
||||
ToString(lang: string): string {
|
||||
let json = GetJsonFile(lang)
|
||||
let string = json.sport_start;
|
||||
for (let i = 0; i<this.sports.length; i++){
|
||||
if (i==this.sports.length - 1 || this.sports.length == 1){
|
||||
string = `${string} ${SportToString(this.sports[i], lang)}`
|
||||
}
|
||||
else{
|
||||
string = `${string} ${SportToString(this.sports[i], lang)} ${json.or_sport}`
|
||||
}
|
||||
}
|
||||
return `${string} ${json.sport_end}`
|
||||
}
|
||||
|
||||
|
||||
getSports(): Sport[]{
|
||||
return this.sports
|
||||
}
|
||||
}
|
||||
|
||||
export default SportIndice
|
@ -0,0 +1,77 @@
|
||||
import Color from "./Color";
|
||||
import Person from "./Person";
|
||||
import PersonNetwork from "./PersonsNetwork";
|
||||
import Sport from "./Sport";
|
||||
|
||||
class NetworkGenerator{
|
||||
|
||||
static GenerateNetwork(nbPerson: number): PersonNetwork{
|
||||
let json = require("../res/names.json")
|
||||
const tabSports: Sport[] = [0, 1, 2, 3, 4, 5, 5, 5, 5]
|
||||
const tabColor: Color[] = [0, 1, 2, 3, 4]
|
||||
const tabJeune: number[] = []
|
||||
const tabAdo: number[] = []
|
||||
const tabAdulte: number[] = []
|
||||
const tabVieux: number[] = []
|
||||
|
||||
const tabPerson: Person[] = []
|
||||
|
||||
const tabNames = json.names
|
||||
|
||||
let id = 0
|
||||
for(let i = 0; i < nbPerson/4; i++){
|
||||
const nombreAleatoire = Math.floor(Math.random() * 14) + 1;
|
||||
tabJeune.push(nombreAleatoire)
|
||||
}
|
||||
for(let i = 0; i < nbPerson/4; i++){
|
||||
const nombreAleatoire = Math.floor(Math.random() * 5) + 15;
|
||||
tabAdo.push(nombreAleatoire)
|
||||
}
|
||||
for(let i = 0; i < nbPerson/4; i++){
|
||||
const nombreAleatoire = Math.floor(Math.random() * 10) + 20;
|
||||
tabAdulte.push(nombreAleatoire)
|
||||
}
|
||||
for(let i = 0; i < nbPerson/4; i++){
|
||||
const nombreAleatoire = Math.floor(Math.random() * 31) + 30;
|
||||
tabVieux.push(nombreAleatoire)
|
||||
}
|
||||
|
||||
const tabAge: number[][] = [tabJeune, tabAdo, tabAdulte, tabVieux]
|
||||
|
||||
let tmpTabSport=[...tabSports]
|
||||
let tmpTabColor = [...tabColor]
|
||||
for (let i = 0; i<nbPerson; i++){
|
||||
const randName = Math.floor(Math.random() * tabNames.length)
|
||||
const name = tabNames[randName]
|
||||
tabNames.splice(randName, 1)
|
||||
if (tmpTabColor.length == 0){
|
||||
tmpTabColor = [...tabColor]
|
||||
}
|
||||
let sports = []
|
||||
for (let j = 0; j < 3; j++){
|
||||
if (tmpTabSport.length == 0) tmpTabSport = [...tabSports]
|
||||
const rand = Math.floor(Math.random() * tmpTabSport.length)
|
||||
if (tmpTabSport[rand] != Sport.AUCUN){
|
||||
sports.push(tmpTabSport[rand])
|
||||
}
|
||||
tmpTabSport.splice(rand, 1)
|
||||
}
|
||||
const randCol = Math.floor(Math.random() * tmpTabColor.length)
|
||||
const color = tmpTabColor[randCol]
|
||||
tmpTabColor.splice(randCol, 1)
|
||||
|
||||
const randAge = Math.floor(Math.random() * tabAge.length)
|
||||
const randAge2 = Math.floor(Math.random() * tabAge[randAge].length)
|
||||
|
||||
const age = tabAge[randAge][randAge2]
|
||||
tabAge[randAge].splice(randAge2, 1)
|
||||
if (tabAge[randAge].length == 0){
|
||||
tabAge.splice(randAge, 1)
|
||||
}
|
||||
tabPerson.push(new Person(i, name, age, color, sports, []))
|
||||
}
|
||||
return new PersonNetwork(tabPerson)
|
||||
}
|
||||
}
|
||||
|
||||
export default NetworkGenerator
|
@ -0,0 +1,83 @@
|
||||
import Sport from "./Sport";
|
||||
import Color from "./Color";
|
||||
|
||||
class Person {
|
||||
private id: number;
|
||||
private name: string;
|
||||
private age: number;
|
||||
private color: Color;
|
||||
private sports: Sport[];
|
||||
private friends: Person[];
|
||||
|
||||
constructor(id: number, name: string, age: number, color: Color, sports: Sport[], friends: Person[]) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.color = color;
|
||||
this.sports = sports;
|
||||
this.friends = friends;
|
||||
}
|
||||
|
||||
getId(): number {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
setId(id: number): void {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
// Getter and setter for name
|
||||
getName(): string {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
setName(name: string): void {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
// Getter and setter for age
|
||||
getAge(): number {
|
||||
return this.age;
|
||||
}
|
||||
|
||||
setAge(age: number): void {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
// Getter and setter for color
|
||||
getColor(): Color {
|
||||
return this.color;
|
||||
}
|
||||
|
||||
setColor(color: Color): void {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
// Getter and setter for sports
|
||||
getSports(): Sport[] {
|
||||
return this.sports;
|
||||
}
|
||||
|
||||
addSport(sport: Sport): void {
|
||||
this.sports.push(sport)
|
||||
}
|
||||
|
||||
setSports(sports: Sport[]): void {
|
||||
this.sports = sports;
|
||||
}
|
||||
|
||||
// Getter and setter for friends
|
||||
getFriends(): Person[] {
|
||||
return this.friends;
|
||||
}
|
||||
|
||||
addFriend(friend: Person): void {
|
||||
this.friends.push(friend);
|
||||
}
|
||||
|
||||
setFriends(friends: Person[]): void {
|
||||
this.friends = friends;
|
||||
}
|
||||
}
|
||||
|
||||
export default Person
|
@ -0,0 +1,23 @@
|
||||
import Person from "./Person";
|
||||
|
||||
class PersonNetwork{
|
||||
private persons : Person[]
|
||||
|
||||
constructor(persons: Person[]){
|
||||
this.persons = persons;
|
||||
}
|
||||
|
||||
getPersons(): Person[]{
|
||||
return this.persons;
|
||||
}
|
||||
|
||||
setPersons(persons: Person[]){
|
||||
this.persons = persons
|
||||
}
|
||||
|
||||
addPerson(person: Person){
|
||||
this.persons.push(person)
|
||||
}
|
||||
}
|
||||
|
||||
export default PersonNetwork
|
@ -0,0 +1,11 @@
|
||||
enum Sport {
|
||||
FOOT,
|
||||
BASEBALL,
|
||||
BASKET,
|
||||
TENNIS,
|
||||
BOWLING,
|
||||
AUCUN
|
||||
}
|
||||
|
||||
export default Sport
|
||||
|
@ -0,0 +1,57 @@
|
||||
import Color from "./Color"
|
||||
import AgeIndice from "./Indices/AgeIndice"
|
||||
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"
|
||||
|
||||
class Stub{
|
||||
|
||||
static GenerateIndice(): Indice[]{
|
||||
let indice = new NbEdgesIndice(1, 3)
|
||||
let indice1 = new NbEdgesIndice(2, 4)
|
||||
let ageIndice = new AgeIndice(3, 0, 14)
|
||||
let ageIndice1 = new AgeIndice(4, 15, 19)
|
||||
let ageIndice2 = new AgeIndice(5, 20, 29)
|
||||
let ageIndice3 = new AgeIndice(6, 30, 100000)
|
||||
|
||||
let indices: Indice[] = [indice, indice1, ageIndice, ageIndice1, ageIndice2, ageIndice3]
|
||||
|
||||
let test = 7
|
||||
for (let i: Color=0; i<5; i++){
|
||||
for (let j: Color=0; j<5; j++){
|
||||
if (j==i){
|
||||
continue
|
||||
}
|
||||
indices.push(new ColorIndice(test, [i, j]))
|
||||
test++
|
||||
}
|
||||
}
|
||||
|
||||
for (let i: Sport=0; i<5; i++){
|
||||
for (let j: Sport=0; j<5; j++){
|
||||
if (j==i){
|
||||
continue
|
||||
}
|
||||
indices.push(new SportIndice(test, [i, j]))
|
||||
test++
|
||||
}
|
||||
}
|
||||
|
||||
for (let i: Color=0; i<5; i++){
|
||||
indices.push(new ColorEdgesIndice(test, [i]))
|
||||
test++
|
||||
}
|
||||
|
||||
for (let i=1; i<3; i++){
|
||||
indices.push(new NbSportIndice(test, i))
|
||||
test++
|
||||
}
|
||||
return indices
|
||||
}
|
||||
}
|
||||
|
||||
export default Stub
|
@ -1,14 +1,14 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"moduleResolution": "node",
|
||||
"target": "es5",
|
||||
"lib": ["dom", "es2015"],
|
||||
"jsx": "react",
|
||||
"strict": true,
|
||||
|
||||
},
|
||||
"compilerOptions": {
|
||||
// ...
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"moduleResolution": "node",
|
||||
"target": "es5",
|
||||
"lib": ["dom", "es2015"],
|
||||
"jsx": "react",
|
||||
"strict": true
|
||||
},
|
||||
// ...
|
||||
}
|
||||
// "noImplicitAny": false,
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue