Skip to content
Snippets Groups Projects
Commit 615177d8 authored by Timothé Bailly-Barthez's avatar Timothé Bailly-Barthez
Browse files

Merge branch 'feature-several-promotions' into 'master'

Feature several promotions

See merge request 2018barthezt/graphe-des-assos!2
parents fecf753e 490f6cd7
Branches
No related tags found
No related merge requests found
......@@ -83,7 +83,21 @@ async function request_promotion(access_token, promotion, offset) {
}
async function fetch_data(access_token, promotion) {
async function fetch_data(access_token, promotion_min, promotion_max) {
let total_users = []
let changed = false;
for (let i = promotion_min; i <= promotion_max; i++) {
let result = await fetch_data_promotion(access_token, i)
total_users = total_users.concat(result.users)
changed = changed || result.changed
}
return {users: total_users, changed: changed};
}
async function fetch_data_promotion(access_token, promotion) {
// const token = await get_token()
let offset = 0;
......@@ -167,10 +181,11 @@ function create_graph(users) {
/* GET the fetched data. */
router.post('/', function(req, res, next) {
const promotion = req.body.promotion || 2021;
fetch_data(req.session.access_token, promotion)
const promotion_min = req.body.promotion_min || 2021;
const promotion_max = req.body.promotion_max || 2021;
fetch_data(req.session.access_token, promotion_min, promotion_max)
.then(result => {
let key = "__express__graph_" + promotion;
let key = "__express__graph_" + promotion_min + "_" + promotion_max;
let cached_graph = myCache.get(key);
let all_edges;
let all_nodes;
......
......@@ -29,10 +29,12 @@
const [allNodes, setAllNodes] = React.useState([]);
const [allEdges, setAllEdges] = React.useState([]);
const [promotionMin, setPromotionMin] = React.useState(2021);
const [promotionMax, setPromotionMax] = React.useState(2021);
const [nodeMin, setNodeMin] = React.useState(10);
const [edgeMin, setEdgeMin] = React.useState(5);
const [promotion, setPromotion] = React.useState(2021);
const [submitted, setSubmitted] = React.useState(true);
const [ready, setReady] = React.useState(false);
......@@ -44,14 +46,17 @@
React.useEffect(() => {
setReady(false);
setError(false);
axios.post('/', {promotion: promotion})
axios.post('/', {
promotion_min: promotionMin,
promotion_max: promotionMax
})
.then(result => {
setAllEdges(result.data.all_edges);
setAllNodes(result.data.all_nodes);
setReady(true);
})
.catch(err => setError(true))
}, [promotion])
}, [promotionMin, promotionMax])
function handleSubmit (event) {
......@@ -85,8 +90,12 @@
return (
<form onSubmit={handleSubmit}>
<div>
<label htmlFor="promotion">Promotion : </label>
<input type="number" id="promotion" value={promotion} onChange={e => setPromotion(e.target.value)} />
<label htmlFor="promotionMin">Promotion minimale : </label>
<input type="number" id="promotionMin" value={promotionMin} onChange={e => setPromotionMin(e.target.value)} />
</div>
<div>
<label htmlFor="promotionMax">Promotion maximale : </label>
<input type="number" id="promotionMax" value={promotionMax} onChange={e => setPromotionMax(e.target.value)} />
</div>
<div>
<label htmlFor="nodeMin">Taille minimale :</label>
......@@ -96,6 +105,7 @@
<label htmlFor="edgeMin">Consanguinité :</label>
<input type="number" id="edgeMin" value={edgeMin} onChange={e => setEdgeMin(e.target.value)} />
</div>
<button type="submit">Générer</button>
{error
? <p style={{color: "red"}}>Erreur</p>
......@@ -109,39 +119,6 @@
ReactDOM.render(React.createElement(FormComponent), document.getElementById('form'));
function draw() {
var container = document.getElementById('mynetwork');
axios.post('/', {promotion: 2022})
.then(result => {
all_nodes = result.data.all_nodes;
all_edges = result.data.all_edges;
let nodes = [];
all_nodes.forEach(node => {
if (node.value >= 5) {
nodes.push(node);
}
})
let edges = [];
all_edges.forEach(edge => {
if (edge.value >= 3) {
edges.push(edge);
}
})
var data = {
nodes: nodes,
edges: edges
};
var options = {
nodes: {
shape: 'dot',
}
};
let network = new vis.Network(container, data, options);
})
.catch(err => console.log(err))
}
</script>
</head>
......@@ -149,10 +126,11 @@
<h1><%= title %></h1>
<p>
<b>Comment ça marche ?</b><br>
Lorsqu'on arrive sur le site ou que l'on change la promotion, le site charge les données liées à la promotion.<br>
Quand le champ de texte sous le menu des promotions indique prêt, vous pouvez générer le graphe en cliquant sur le bouton Générer ci-dessous.<br>
Vous pouvez modifier la taille des assos ainsi que la consanguinité minimales, puis générer le graphe à nouveau.</br>
Tu peux déplacer le graphe ou zoomer dessus pour voir les détails.
Lorsqu'on arrive sur le site ou que l'on change l'une des promotions, le site charge les données liées aux promotions.<br>
Quand le champ de texte sous le menu indique prêt, vous pouvez générer le graphe en cliquant sur le bouton Générer ci-dessous.<br>
Les promotions prises en compte seront les promotions situées entre la promotion minimale et la promotion maximale (inclusion large)<br>
Vous pouvez modifier la taille des assos ainsi que la consanguinité minimales, puis générer le graphe à nouveau.<br>
Vous pouvez déplacer le graphe ou zoomer dessus pour voir les détails.
</p>
<div id="form"></div>
<div id="mynetwork"></div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment