feat: add average pieces per box
This commit is contained in:
parent
16e6b04e66
commit
e4cb8c3300
@ -16,9 +16,7 @@ async function getPiecesFromBox(id_box: number): Promise<Array<Pair<Piece, numbe
|
|||||||
const res = await client.query(`SELECT * FROM contenir WHERE id_boite = $1;`, [ id_box ]);
|
const res = await client.query(`SELECT * FROM contenir WHERE id_boite = $1;`, [ id_box ]);
|
||||||
const arr: Array<Pair<Piece, number>> = new Array();
|
const arr: Array<Pair<Piece, number>> = new Array();
|
||||||
for (let i = 0; i < res.rows.length; ++i) {
|
for (let i = 0; i < res.rows.length; ++i) {
|
||||||
console.log(res.rows[i]['id_piece']);
|
|
||||||
const piece: Either<Piece, string> = await getPiece(res.rows[i]['id_piece']);
|
const piece: Either<Piece, string> = await getPiece(res.rows[i]['id_piece']);
|
||||||
console.log(piece);
|
|
||||||
if (piece.hasRight)
|
if (piece.hasRight)
|
||||||
continue;
|
continue;
|
||||||
arr.push(createPair(piece.left, res.rows[i]['quantite_contenir'] as number));
|
arr.push(createPair(piece.left, res.rows[i]['quantite_contenir'] as number));
|
||||||
|
@ -91,7 +91,6 @@ async function getPiece(id: number): Promise<Either<Piece, string>> {
|
|||||||
if (!res.rows[0]) {
|
if (!res.rows[0]) {
|
||||||
return eitherRight<Piece, string>("Nothing found");
|
return eitherRight<Piece, string>("Nothing found");
|
||||||
}
|
}
|
||||||
console.log(`Get entity ${Object.keys(res.rows[0])}`);
|
|
||||||
const result: Piece = { id_piece: res.rows[0]['id_piece'], colour: toColour(res.rows[0]), pattern: toPattern(res.rows[0]), shape: toShape(res.rows[0]) };
|
const result: Piece = { id_piece: res.rows[0]['id_piece'], colour: toColour(res.rows[0]), pattern: toPattern(res.rows[0]), shape: toShape(res.rows[0]) };
|
||||||
return eitherLeft<Piece, string>(result);
|
return eitherLeft<Piece, string>(result);
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
id : <%= box.id %>
|
id : <%= box.id %>
|
||||||
date : <%= box.date %>
|
date : <%= box.date %>
|
||||||
pièces :
|
pièces :
|
||||||
<% box.pieces.forEach(function(pair) { console.log(pair);%>
|
<% box.pieces.forEach(function(pair) { %>
|
||||||
<li>
|
<li>
|
||||||
<a href="/pieces/<%=pair.first.id_piece%>">
|
<a href="/pieces/<%=pair.first.id_piece%>">
|
||||||
<%=pair.first.id_piece%> @ <%=pair.second%>
|
<%=pair.first.id_piece%> @ <%=pair.second%>
|
||||||
|
@ -20,6 +20,12 @@
|
|||||||
<label for="fromDate">À partir de : </label>
|
<label for="fromDate">À partir de : </label>
|
||||||
<input type="date" name="fromDate" id="fromDate">
|
<input type="date" name="fromDate" id="fromDate">
|
||||||
<input type="submit" value="Filtrer" onclick="window.location.pathname = '/boxes/from/' + document.getElementById('fromDate').value;">
|
<input type="submit" value="Filtrer" onclick="window.location.pathname = '/boxes/from/' + document.getElementById('fromDate').value;">
|
||||||
|
<span>Nombre moyen de pièces : <%-
|
||||||
|
boxes.map(
|
||||||
|
(b) => b.pieces.reduce(
|
||||||
|
(p, q) => p + q.second, 0
|
||||||
|
)
|
||||||
|
).reduce((i, j) => i + j, 0) / boxes.length%></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user