Include complete API and frontend sources for unified deployment
This commit is contained in:
1 parent
627b0ae60e
commit
d8fcae32b0
93 files changed
+53270
-3
No files matched your search
@@ -0,0 +1,97 @@
|
||||
import 'dotenv/config';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { resolve } from 'node:path';
|
||||
import { initializeDbModels } from '../utils/db.js';
|
||||
import { sequelize } from '../models/index.js';
|
||||
import Mark from '../models/mark.js';
|
||||
import Case from '../models/case.js';
|
||||
import Team from '../models/team.js';
|
||||
import User from '../models/user.js';
|
||||
import Sequelize from 'sequelize';
|
||||
|
||||
const { Op } = Sequelize;
|
||||
|
||||
export async function calculatePositions() {
|
||||
const [marksDB, casesDB, teams] = await Promise.all([
|
||||
Mark.findAll({
|
||||
where: { mark: { [Op.ne]: null } },
|
||||
include: [
|
||||
{ model: Case, as: 'case' },
|
||||
{ model: Team, as: 'team' },
|
||||
{ model: User, as: 'user' },
|
||||
],
|
||||
}),
|
||||
Case.findAll({
|
||||
include: [
|
||||
{ model: User, as: 'users', attributes: ['id'], through: { attributes: [] } },
|
||||
{ model: Team, as: 'teams', attributes: ['id'], through: { attributes: [] } },
|
||||
],
|
||||
}),
|
||||
Team.findAll(),
|
||||
]);
|
||||
|
||||
const marks = marksDB.map(mark => mark.toJSON());
|
||||
const placesByUser = {};
|
||||
for (const m of marks) {
|
||||
if (!m.user || !m.case || !m.team || m.user.role === 'technical') continue;
|
||||
const task = casesDB.find(c => c.id === m.caseId);
|
||||
if (!task?.users.some(u => u.id === m.userId) || !task.teams.some(t => t.id === m.teamId)) continue;
|
||||
if (!placesByUser[m.user.id]) placesByUser[m.user.id] = {};
|
||||
if (!placesByUser[m.user.id][m.case.id]) placesByUser[m.user.id][m.case.id] = {};
|
||||
if (!placesByUser[m.user.id][m.case.id][m.team.id]) placesByUser[m.user.id][m.case.id][m.team.id] = 0;
|
||||
placesByUser[m.user.id][m.case.id][m.team.id] += m.mark;
|
||||
}
|
||||
|
||||
const cases = {};
|
||||
for (const userId of Object.keys(placesByUser)) {
|
||||
for (const caseId of Object.keys(placesByUser[userId])) {
|
||||
let place = 0;
|
||||
|
||||
placesByUser[userId][caseId] = Object.fromEntries(
|
||||
Object.entries(placesByUser[userId][caseId])
|
||||
.sort(([, a], [, b]) => b - a)
|
||||
.map((v, i, arr) => [v[0], v[1] !== arr[i - 1]?.[1] ? ++place : place])
|
||||
);
|
||||
if (!cases[caseId]) cases[caseId] = {};
|
||||
for (const team of Object.entries(placesByUser[userId][caseId])) {
|
||||
if (!cases[caseId][team[0]]) cases[caseId][team[0]] = 0;
|
||||
cases[caseId][team[0]] += team[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const positions = {};
|
||||
for (const [caseId, scores] of Object.entries(cases)) {
|
||||
let place = 0;
|
||||
positions[caseId] = Object.fromEntries(
|
||||
Object.entries(scores)
|
||||
.sort(([, a], [, b]) => a - b)
|
||||
.map(([id, score], index, rows) => [id, score !== rows[index - 1]?.[1] ? ++place : place])
|
||||
);
|
||||
}
|
||||
return {
|
||||
positions,
|
||||
cases: Object.fromEntries(casesDB.map(c => [c.id, c.name])),
|
||||
teams: Object.fromEntries(teams.map(t => [t.id, t.name])),
|
||||
};
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await initializeDbModels();
|
||||
const result = await calculatePositions();
|
||||
for (const [caseId, positions] of Object.entries(result.positions)) {
|
||||
console.log('\n' + result.cases[caseId]);
|
||||
console.table(Object.fromEntries(Object.entries(positions).map(([id, place]) => [result.teams[id], place])));
|
||||
}
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
||||
main().catch(error => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config();
|
||||
import { initializeDbModels } from '../utils/db.js';
|
||||
import { sequelize } from '../models/index.js';
|
||||
import creds from '../config/google-credentials.js';
|
||||
import { GoogleSpreadsheet } from 'google-spreadsheet';
|
||||
import Case from '../models/case.js';
|
||||
import Team from '../models/team.js';
|
||||
import Mark from '../models/mark.js';
|
||||
import User from '../models/user.js';
|
||||
import markTypesNames from '../config/markTypesNames.js';
|
||||
|
||||
const doc = new GoogleSpreadsheet('1ofOGiYrDv_Pp-rJlgjKDJR2HY0IEHnSNmI1jwCIb7JU');
|
||||
|
||||
async function start() {
|
||||
await initializeDbModels();
|
||||
await doc.useServiceAccountAuth(creds);
|
||||
await doc.loadInfo();
|
||||
|
||||
const cases = await Case.findAll({
|
||||
attributes: ['id', 'name'],
|
||||
include: [
|
||||
{ model: Team, as: 'teams', order: 'name', attributes: ['id', 'name'], through: { attributes: [] } },
|
||||
{
|
||||
model: User,
|
||||
as: 'users',
|
||||
attributes: ['id', 'firstName', 'lastName'],
|
||||
through: { attributes: [] },
|
||||
include: { model: Mark, as: 'marks' },
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
let xOffset = 0;
|
||||
let yOffset = 0;
|
||||
for (const c of cases) {
|
||||
const sheet = await doc.addSheet({ title: c.name });
|
||||
await sheet.loadCells();
|
||||
for (const user of c.users) {
|
||||
const userName = sheet.getCell(xOffset, yOffset);
|
||||
userName.value = user.firstName + ' ' + user.lastName;
|
||||
xOffset += 2;
|
||||
for (const team of c.teams) {
|
||||
const teamName = sheet.getCell(xOffset, yOffset);
|
||||
teamName.value = team.name;
|
||||
xOffset++;
|
||||
|
||||
for (const [typeMark, nameTypeMark] of Object.entries(markTypesNames)) {
|
||||
const markType = sheet.getCell(xOffset, yOffset);
|
||||
const mark = sheet.getCell(xOffset, yOffset + 1);
|
||||
markType.value = nameTypeMark;
|
||||
const markValue = user.marks.find(m => m.teamId === team.id && m.markType === +typeMark)?.mark;
|
||||
mark.value = markValue;
|
||||
if (!markValue || markValue === 0)
|
||||
mark.backgroundColor = {
|
||||
red: 1,
|
||||
green: 0,
|
||||
blue: 0,
|
||||
};
|
||||
xOffset++;
|
||||
}
|
||||
|
||||
xOffset++;
|
||||
}
|
||||
yOffset += 3;
|
||||
xOffset = 0;
|
||||
}
|
||||
yOffset = 0;
|
||||
await sheet.saveUpdatedCells();
|
||||
}
|
||||
|
||||
await sequelize.close();
|
||||
}
|
||||
|
||||
start();
|
||||
@@ -0,0 +1,92 @@
|
||||
import 'dotenv/config';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { resolve } from 'node:path';
|
||||
import { initializeDbModels } from '../utils/db.js';
|
||||
import { sequelize } from '../models/index.js';
|
||||
import Mark from '../models/mark.js';
|
||||
import Case from '../models/case.js';
|
||||
import Team from '../models/team.js';
|
||||
import User from '../models/user.js';
|
||||
|
||||
import { editableMarkTypes } from '../utils/expert-roles.js';
|
||||
|
||||
export async function getMissingMarks() {
|
||||
const cases = await Case.findAll({
|
||||
attributes: ['id', 'name'],
|
||||
include: [
|
||||
{
|
||||
model: Team,
|
||||
as: 'teams',
|
||||
order: 'name',
|
||||
attributes: ['id', 'name'],
|
||||
through: { attributes: [] },
|
||||
include: { model: Mark, as: 'marks' },
|
||||
},
|
||||
{ model: User, as: 'users', attributes: ['id', 'firstName', 'lastName', 'role'], through: { attributes: [] } },
|
||||
],
|
||||
});
|
||||
|
||||
const noMarks = {};
|
||||
for (const c of cases) {
|
||||
for (const team of c.teams) {
|
||||
for (const user of c.users) {
|
||||
const userMark = team.marks.filter(m => m.userId === user.id && m.caseId === c.id && m.mark !== null);
|
||||
if (!editableMarkTypes(user.role).every(type => userMark.some(mark => mark.markType === type))) {
|
||||
if (!noMarks[user.firstName + ' ' + user.lastName]) noMarks[user.firstName + ' ' + user.lastName] = {};
|
||||
if (!noMarks[user.firstName + ' ' + user.lastName][c.name])
|
||||
noMarks[user.firstName + ' ' + user.lastName][c.name] = [];
|
||||
noMarks[user.firstName + ' ' + user.lastName][c.name].push(team.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const zeroMarks = {};
|
||||
for (const c of cases) {
|
||||
for (const team of c.teams) {
|
||||
for (const user of c.users) {
|
||||
const userMark = team.marks.filter(
|
||||
m =>
|
||||
m.userId === user.id &&
|
||||
m.caseId === c.id &&
|
||||
m.mark === 0 &&
|
||||
(user.role !== 'technical' || editableMarkTypes(user.role).includes(m.markType))
|
||||
);
|
||||
if (userMark.length) {
|
||||
if (!zeroMarks[user.firstName + ' ' + user.lastName]) zeroMarks[user.firstName + ' ' + user.lastName] = {};
|
||||
if (!zeroMarks[user.firstName + ' ' + user.lastName][c.name])
|
||||
zeroMarks[user.firstName + ' ' + user.lastName][c.name] = [];
|
||||
zeroMarks[user.firstName + ' ' + user.lastName][c.name].push(team.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { noMarks, zeroMarks };
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await initializeDbModels();
|
||||
const { noMarks, zeroMarks } = await getMissingMarks();
|
||||
for (const [user, cases] of Object.entries(noMarks)) {
|
||||
console.log('\n' + user);
|
||||
console.table(cases);
|
||||
}
|
||||
console.log('\nZERO MARKS');
|
||||
for (const [user, cases] of Object.entries(zeroMarks)) {
|
||||
console.log('\n' + user);
|
||||
console.table(cases);
|
||||
}
|
||||
if (Object.keys(noMarks).length) process.exitCode = 1;
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
||||
main().catch(error => {
|
||||
console.error(error);
|
||||
process.exitCode = 1;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import { initializeDbModels } from '../utils/db.js';
|
||||
import { models, sequelize } from '../models/index.js';
|
||||
|
||||
if (process.env.DB_HOST !== 'db' || process.env.WEB_SERVICE !== 'cg-grade-local') {
|
||||
throw new Error('Demo seed is only intended for the local Compose database');
|
||||
}
|
||||
|
||||
try {
|
||||
await initializeDbModels();
|
||||
const [judge] = await models.User.findOrCreate({
|
||||
where: { login: 'demo-judge' },
|
||||
defaults: {
|
||||
firstName: 'Демо', lastName: 'Эксперт',
|
||||
password: 'DemoJudge2026!', passwordForAdmin: 'DemoJudge2026!',
|
||||
},
|
||||
});
|
||||
const [task] = await models.Case.findOrCreate({
|
||||
where: { name: 'Демонстрационный кейс' },
|
||||
defaults: { description: 'Локальные данные для проверки системы оценивания.' },
|
||||
});
|
||||
await task.addUser(judge);
|
||||
for (const name of ['Демо: Альфа', 'Демо: Бета']) {
|
||||
const [team] = await models.Team.findOrCreate({
|
||||
where: { name }, defaults: { description: 'Тестовая команда.' },
|
||||
});
|
||||
await task.addTeam(team);
|
||||
}
|
||||
console.log('Demo ready: one judge, one case, two teams.');
|
||||
} finally {
|
||||
await sequelize.close();
|
||||
}
|
||||
Reference in new issue
Block a user