Published
Edited
Mar 7, 2020
1 star
Insert cell
md`# Статы по написанию тестов`
Insert cell
viewof jsonFile = file()
Insert cell
html`
<table border="1">
<caption>Сделанные толокерами кейсы</caption>
<tr>
<th>WorkerId</th>
<th>Testcase</th>
<th>Submit time</th>
<th>Duration</th>
</tr>
${perUserStat.map(rowView)}
</table>
`
Insert cell
rowView = ({ assignments, workerId }) => {
const formatDay = day => new Date(day).toISOString().split('.')[0];

const formatDuration = duration => moment.duration(duration, 'ms').humanize();

let cell = value => `<td>${value}</td>`;
let durationCell = value => {
let color = 'green';
if (value < 900000) {
color = 'red';
} else if (value < 1200000) {
color = '#CCCC00';
}
return `<td style="color: ${color}">${formatDuration(value)}</td>`;
};

let row = (assignment, workerId, assignmentsCount) => `<tr>
${workerId ? `<td rowspan="${assignmentsCount}">${workerId}</td>` : ''}
${cell(assignment.id)}
${cell(formatDay(assignment.ts))}
${durationCell(assignment.duration)}
</td></tr>`;

let rows = `${row(assignments[0], workerId, assignments.length)}`;

for (let assignment of assignments.slice(1)) {
rows += `${row(assignment)}`;
}
return rows;
}
Insert cell
perUserStat = {
const assignmentsPerUser = {};

for (const datum of data.filter(d => d.status === 'ACCEPTED')) {
const { workerId } = datum;
assignmentsPerUser[workerId] = (assignmentsPerUser[workerId] || []).concat(
datum
);
}

for (const [k, v] of Object.entries(assignmentsPerUser)) {
assignmentsPerUser[k] = v.reduce(
(acc, item) => {
return {
...acc,
assignmentsCount: acc.assignmentsCount + 1,
assignments: [
...acc.assignments,
{
id: item.inputValues.testcase_id,
ts: item.submitTs,
duration: item.acceptTs - item.createTs
}
],
workerId: item.workerId
};
},
{
assignments: [],
assignmentsCount: 0
}
);
}

const res = Object.values(assignmentsPerUser).sort(
(a, b) => b.assignments.length - a.assignments.length
);

res.forEach(r => {
r.assignments.sort((a, b) => a.ts - b.ts);
});

return res;
}
Insert cell
Insert cell
data.filter(d => d.inputValues.testcase_id === 'TOLOKA-4')
Insert cell
moment = require("moment")
Insert cell
import {file} from "@jashkenas/inputs"
Insert cell
d3 = require("d3@5")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more