Skip to content
Snippets Groups Projects
Commit ce3926c4 authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #be plot device behaviour

parent 2d252f63
No related branches found
No related tags found
No related merge requests found
...@@ -104,3 +104,57 @@ new Chart( ...@@ -104,3 +104,57 @@ new Chart(
document.getElementById("shotsByDurationChart"), document.getElementById("shotsByDurationChart"),
shotsByDurationConfig, shotsByDurationConfig,
); );
//=[ Devices behaviour ]========================================================
const devicesBehaviourData = JSON.parse(
document.getElementById("devicesBehaviourData").textContent,
)
.filter((item) => item.device_id)
.map((item) => [
item.ended_count,
item.interrupted_count,
parseFloat((item.time_spent / 100000).toFixed(2)),
]);
console.log(devicesBehaviourData);
const devicesBehaviourConfig = {
type: "bubble",
data: {
datasets: [
{
data: devicesBehaviourData,
backgroundColor: "blue",
},
],
},
options: {
// maintainAspectRatio: true,
// aspectRatio: 1,
scales: {
x: {
type: "logarithmic",
title: {
display: true,
text: "Finished games",
},
},
y: {
type: "logarithmic",
title: {
display: true,
text: "Interrupted games",
},
},
},
plugins: {
legend: { display: false },
},
},
};
new Chart(
document.getElementById("devicesBehaviourChart"),
devicesBehaviourConfig,
);
...@@ -64,6 +64,25 @@ server.get("/", async (request, reply) => { ...@@ -64,6 +64,25 @@ server.get("/", async (request, reply) => {
const cluesCount = (await connection.table("clues").count())[0].count; const cluesCount = (await connection.table("clues").count())[0].count;
const shotsCount = (await connection.table("shots").count())[0].count; const shotsCount = (await connection.table("shots").count())[0].count;
const normalizedGames = connection
.table("games")
.select(
connection.raw(
"games.id, games.device_id, games.began_at_gmtm, games.ended_at_gmtm, max(shots.ended_at_gmtm) as last_shot_ended_at_gmtm",
),
)
.fullOuterJoin("shots", "games.id", "shots.game_id")
.groupBy("games.id");
const devicesBehaviour = await connection
.select(
connection.raw(
"sum(coalesce (ended_at_gmtm, last_shot_ended_at_gmtm) - began_at_gmtm) as time_spent, count(case when ended_at_gmtm is not null then 1 end) as ended_count, count(case when ended_at_gmtm is null then 1 end) as interrupted_count, device_id",
),
)
.from(normalizedGames.as("g"))
.groupBy("device_id");
const devicesByDate = await connection const devicesByDate = await connection
.table("games") .table("games")
.select(connection.raw("COUNT(DISTINCT device_id), DATE(began_at)")) .select(connection.raw("COUNT(DISTINCT device_id), DATE(began_at)"))
...@@ -96,13 +115,13 @@ server.get("/", async (request, reply) => { ...@@ -96,13 +115,13 @@ server.get("/", async (request, reply) => {
devicesByDate, devicesByDate,
gamesByDate, gamesByDate,
shotsByDuration, shotsByDuration,
devicesBehaviour,
}); });
}); });
// TODO: this is an horrible kludge // TODO: this is an horrible kludge
import fastifyStatic from "fastify-static"; import fastifyStatic from "fastify-static";
import path from "path"; import path from "path";
import { connect } from "http2";
server.register(fastifyStatic, { server.register(fastifyStatic, {
root: path.join(__dirname, "../public"), root: path.join(__dirname, "../public"),
prefix: "/public/", prefix: "/public/",
......
...@@ -88,6 +88,11 @@ ...@@ -88,6 +88,11 @@
<h1>Shot count by duration [ms]</h1> <h1>Shot count by duration [ms]</h1>
<script id="shotsByDurationData" type="application/json"><%- JSON.stringify(shotsByDuration) %></script> <script id="shotsByDurationData" type="application/json"><%- JSON.stringify(shotsByDuration) %></script>
<canvas id="shotsByDurationChart"></canvas> <canvas id="shotsByDurationChart"></canvas>
<h1>Total gametime per device [m]</h1>
<script id="devicesBehaviourData"
type="application/json"><%- JSON.stringify(devicesBehaviour) %></script>
<canvas id="devicesBehaviourChart"></canvas>
</main> </main>
</div> </div>
</div> </div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment