function progress(t, latency, throughput, total) {
if (t < latency) return 0;
return Math.min(100, ((t - latency) * throughput / total) * 100);
}
// Reloj animado
time = {
let t0 = Date.now();
while (true) {
yield (Date.now() - t0) / 100; // en décimas de segundo
await Promises.tick(50);
}
}
// Tiempo máximo
maxTime = Math.max(latencyA + totalData/throughputA, latencyB + totalData/throughputB)
// Progresos
progA = progress(time % maxTime, latencyA, throughputA, totalData)
progB = progress(time % maxTime, latencyB, throughputB, totalData)
// Gráfico con Plot
Plot.plot({
y: {domain: [0, 100], label: "% completado"},
x: {label: "Tiempo (s)"},
color: {legend: true, domain: ["A", "B"], range: ["blue", "red"]},
marks: [
Plot.line(d3.range(0, maxTime, 0.1).map(t => ({t, y: progress(t, latencyA, throughputA, totalData), series: "A"})), {x: "t", y: "y", stroke: "series"}),
Plot.line(d3.range(0, maxTime, 0.1).map(t => ({t, y: progress(t, latencyB, throughputB, totalData), series: "B"})), {x: "t", y: "y", stroke: "series"}),
Plot.dot([{t: time % maxTime, y: progA, series: "A"}], {x: "t", y: "y", fill: "series", r: 5}),
Plot.dot([{t: time % maxTime, y: progB, series: "B"}], {x: "t", y: "y", fill: "series", r: 5})
]
})