Files
CTFd/assets/js/utils/graphs/vega/userscore.js
Kevin Chung a64e7d51ef Squashed 'CTFd/themes/core-beta/' changes from 9126d77d..5ce3003b
5ce3003b Merge pull request #47 from aCursedComrade/patch-1
c9887cb1 Fix team template

git-subtree-dir: CTFd/themes/core-beta
git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
2023-06-11 15:56:28 -04:00

61 lines
1.3 KiB
JavaScript

import { cumulativeSum } from "../math";
export function getSpec(description, values) {
return {
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
description: description,
data: {
values: values,
},
width: "container",
mark: {
type: "area",
line: true,
point: true,
// interpolate: "step-after",
tooltip: { content: "data", nearest: true },
},
encoding: {
x: { field: "time", type: "temporal" },
y: { field: "score", type: "quantitative" },
},
};
}
export function getValues(solves, awards) {
const times = [];
let scores = [];
const solvesData2 = solves.data;
const awardsData = awards.data;
const total = solvesData2.concat(awardsData);
total.sort((a, b) => {
return new Date(a.date) - new Date(b.date);
});
for (let i = 0; i < total.length; i++) {
// const date = dayjs(total[i].date);
// times.push(date.toDate());
const date = total[i].date;
times.push(date);
try {
scores.push(total[i].challenge.value);
} catch (e) {
scores.push(total[i].value);
}
}
scores = cumulativeSum(scores);
let values = [];
times.forEach((time, index) => {
// option.xAxis[0].data.push(time);
values.push({
time: time,
score: scores[index],
});
});
return values;
}