utxo-prague/utils/events.js

62 řádky
1.8 KiB
JavaScript
Surový Normální zobrazení Historie

2022-01-27 08:56:34 +01:00
import { Table } from "https://deno.land/x/cliffy@v0.20.1/table/mod.ts";
import { UTXOEngine } from "./engine.js";
const utxo = new UTXOEngine({ silent: true });
await utxo.init();
const entryId = "22";
const entry = utxo.entries[entryId];
2022-01-28 16:23:49 +01:00
const speakers = entry.specs.speakers;
2022-01-27 12:05:36 +01:00
2022-01-27 08:56:34 +01:00
const setup = [
{ col: "type", title: "Type" },
{ col: "id", title: "ID" },
{ col: "track", title: "Track" },
{ col: "name", title: "Name" },
{ col: "duration", title: "Len" },
{
col: "speakers",
title: "Speakers", //process: (e) => e.speakers.map((s) => entry.specs.speakers.find((sp) => sp.id === s).name).join(", ")
},
];
const arr = [setup.map((s) => s.title)];
//const types = [...new Set(entry.specs.events.map(e => e.type))]
2022-01-27 09:53:37 +01:00
const totals = {
items: 0,
duration: 0,
speakers: {},
};
2022-01-27 08:56:34 +01:00
for (const item of entry.specs.events) {
const out = [];
for (const sc of setup) {
out.push(sc.process ? sc.process(item) : item[sc.col]);
}
arr.push(out);
2022-01-27 09:53:37 +01:00
totals.items++;
2022-05-19 13:32:51 +02:00
if (item.type !== "lightning-series") {
totals.duration += item.duration || 0;
}
2022-01-27 09:53:37 +01:00
//console.log(JSON.stringify(item.speakers))
for (const sid of item.speakers) {
if (!totals.speakers[sid]) {
totals.speakers[sid] = { duration: 0 };
}
2022-04-25 14:53:32 +02:00
totals.speakers[sid].duration += item.duration || 0;
2022-01-27 09:53:37 +01:00
}
2022-01-27 08:56:34 +01:00
}
2022-01-27 10:04:23 +01:00
const totalSpeakers = Object.keys(totals.speakers).length;
const minutesPerSpeaker = totals.duration / totalSpeakers;
2022-01-28 16:23:49 +01:00
const durationPrediction = speakers.length / (totals.duration / 100) *
speakers.length;
2022-01-27 10:04:23 +01:00
2022-01-27 08:56:34 +01:00
console.log(Table.from(arr).border(true).toString());
2022-01-27 09:53:37 +01:00
console.log(
2022-01-27 12:05:36 +01:00
`Events: ${totals.items}, Speakers: ${totalSpeakers}/${speakers.length}, duration: ${totals.duration} minutes (${
2022-01-27 09:53:37 +01:00
(totals.duration / 60).toFixed(2)
2022-01-27 12:05:36 +01:00
} hours, estimated full: ${durationPrediction.toFixed(2)} hours), ` +
2022-01-27 09:53:37 +01:00
`minutes per speaker: ${minutesPerSpeaker.toFixed(2)} min`,
);