mirror of
https://github.com/aljazceru/CTFd.git
synced 2026-02-19 05:04:20 +01:00
5ce3003b Merge pull request #47 from aCursedComrade/patch-1 c9887cb1 Fix team template git-subtree-dir: CTFd/themes/core-beta git-subtree-split: 5ce3003b4d68352e629ee2d390bc999e7d6b071e
107 lines
2.2 KiB
JavaScript
107 lines
2.2 KiB
JavaScript
import { colorHash } from "@ctfdio/ctfd-js/ui";
|
|
import dayjs from "dayjs";
|
|
|
|
export function cumulativeSum(arr) {
|
|
let result = arr.concat();
|
|
for (let i = 0; i < arr.length; i++) {
|
|
result[i] = arr.slice(0, i + 1).reduce(function (p, i) {
|
|
return p + i;
|
|
});
|
|
}
|
|
return result;
|
|
}
|
|
|
|
export function getOption(mode, places) {
|
|
let option = {
|
|
title: {
|
|
left: "center",
|
|
text: "Top 10 " + (mode === "teams" ? "Teams" : "Users"),
|
|
},
|
|
tooltip: {
|
|
trigger: "axis",
|
|
axisPointer: {
|
|
type: "cross",
|
|
},
|
|
},
|
|
legend: {
|
|
type: "scroll",
|
|
orient: "horizontal",
|
|
align: "left",
|
|
bottom: 35,
|
|
data: [],
|
|
},
|
|
toolbox: {
|
|
feature: {
|
|
dataZoom: {
|
|
yAxisIndex: "none",
|
|
},
|
|
saveAsImage: {},
|
|
},
|
|
},
|
|
grid: {
|
|
containLabel: true,
|
|
},
|
|
xAxis: [
|
|
{
|
|
type: "time",
|
|
boundaryGap: false,
|
|
data: [],
|
|
},
|
|
],
|
|
yAxis: [
|
|
{
|
|
type: "value",
|
|
},
|
|
],
|
|
dataZoom: [
|
|
{
|
|
id: "dataZoomX",
|
|
type: "slider",
|
|
xAxisIndex: [0],
|
|
filterMode: "filter",
|
|
height: 20,
|
|
top: 35,
|
|
fillerColor: "rgba(233, 236, 241, 0.4)",
|
|
},
|
|
],
|
|
series: [],
|
|
};
|
|
|
|
const teams = Object.keys(places);
|
|
for (let i = 0; i < teams.length; i++) {
|
|
const team_score = [];
|
|
const times = [];
|
|
for (let j = 0; j < places[teams[i]]["solves"].length; j++) {
|
|
team_score.push(places[teams[i]]["solves"][j].value);
|
|
const date = dayjs(places[teams[i]]["solves"][j].date);
|
|
times.push(date.toDate());
|
|
}
|
|
|
|
const total_scores = cumulativeSum(team_score);
|
|
let scores = times.map(function (e, i) {
|
|
return [e, total_scores[i]];
|
|
});
|
|
|
|
option.legend.data.push(places[teams[i]]["name"]);
|
|
|
|
const data = {
|
|
name: places[teams[i]]["name"],
|
|
type: "line",
|
|
label: {
|
|
normal: {
|
|
position: "top",
|
|
},
|
|
},
|
|
itemStyle: {
|
|
normal: {
|
|
color: colorHash(places[teams[i]]["name"] + places[teams[i]]["id"]),
|
|
},
|
|
},
|
|
data: scores,
|
|
};
|
|
option.series.push(data);
|
|
}
|
|
|
|
return option;
|
|
}
|