Skip to content

Commit

Permalink
Fix skipping of empty groups.
Browse files Browse the repository at this point in the history
Better messages about incorrect config.
  • Loading branch information
disturm committed Jun 18, 2021
1 parent b654878 commit e89ca95
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 48 deletions.
75 changes: 45 additions & 30 deletions src/managers/MarksManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import BrsApi, {
StudentFailure,
StudentMark,
} from "../apis/BrsApi";
import { compareNormalized, groupBy, parseAnyFloat } from "../helpers/tools";
import {
compareNormalized,
groupBy,
parseAnyFloat,
pluralize,
} from "../helpers/tools";
import * as fio from "../helpers/fio";
import { ActualStudent, SpreadsheetData } from "./SpreadsheetManager";
import { formatStudentFailure } from "../helpers/brsHelpers";
Expand Down Expand Up @@ -39,27 +44,31 @@ export default class MarksManager {
) {
const { actualStudents, disciplineConfig, controlActionConfigs } =
spreadsheetData;

try {
for (const discipline of disciplines) {
const students = actualStudents.filter((s) =>
compareNormalized(s.groupName, discipline.group)
);
if (students.length === 0) {
continue;
}

this.reportManager.newReport(discipline.group);

var isSuccessful = await this.putMarksForDisciplineAsync(
discipline,
actualStudents.filter((s) =>
compareNormalized(s.groupName, discipline.group)
),
students,
disciplineConfig.defaultStudentFailure,
controlActionConfigs
);

if (!isSuccessful) {
if (isSuccessful) {
this.reportManager.finishReport();
} else {
this.reportManager.cancelReport();
break;
}

this.reportManager.finishReport();

if (this.cancelPending) {
break;
}
Expand All @@ -77,8 +86,6 @@ export default class MarksManager {
defaultStudentFailure: StudentFailure,
controlActionConfigs: ControlActionConfig[]
) {
if (actualStudents.length === 0) return;

const controlActions = await this.brsApi.getAllControlActionsCachedAsync(
discipline
);
Expand Down Expand Up @@ -175,7 +182,9 @@ export default class MarksManager {
controlActions
);
if (!controlAction) {
throw new Error("Подходящее контрольное мероприятие не найдено");
throw new Error(
`Подходящее контрольное мероприятие для «${config.controlAction}» не найдено в БРС`
);
}

const brsMarkString = student.brs[controlAction.uuid] as string;
Expand Down Expand Up @@ -256,17 +265,17 @@ export default class MarksManager {
controlActions: ControlAction[]
) {
const suitableControlActions = controlActions.filter((a) =>
config.controlActions.some((b) => compareNormalized(a.controlAction, b))
compareNormalized(a.controlAction, config.controlAction)
);

const errorMessages = [];

if (suitableControlActions.length === 0) {
errorMessages.push(
`Все "${config.controlActions.join(", ")}" не найдены `
`Контрольное мероприятие «${config.controlAction}» не сопоставлено с БРС`
);
errorMessages.push(
`Найденные контрольные мероприятия: ${controlActions
`Найденные в БРС контрольные мероприятия: ${controlActions
.map((a) => a.controlAction)
.join(", ")}`
);
Expand All @@ -284,10 +293,18 @@ export default class MarksManager {
config.matchIndex >= config.matchCount
) {
errorMessages.push(
`Неверная конфигурация ${config.controlActions.join(", ")}`
`Неверная конфигурация контрольного мероприятия «${config.controlAction}»`
);
errorMessages.push(`Нет соответствий: ${config.matchIndex}/${config.matchCount}
и ${suitableControlActions.length}`);
if (suitableControlActions.length !== config.matchCount) {
errorMessages.push(
`В БРС найдено ${suitableControlActions.length} ${pluralize(
suitableControlActions.length,
"подходящее контрольное мероприятие",
"подходящих контрольных мероприятия",
"подходящих контрольных мероприятий"
)}, а в таблице указано ${config.matchCount}`
);
}

this.reportManager.onInvalidConfiguration(errorMessages);

Expand All @@ -298,9 +315,7 @@ export default class MarksManager {

if (suitableControlActions.length > 1) {
errorMessages.push(
`Несколько контрольных мероприятий найдены для ${config.controlActions.join(
", "
)}`
`Несколько контрольных мероприятий найдено для «${config.controlAction}»`
);
errorMessages.push(
`Найденные контрольные мероприятия: ${suitableControlActions
Expand Down Expand Up @@ -328,12 +343,12 @@ export default class MarksManager {
);

if (ratingResults.length > 0) {
const groupedResults = Object.entries(groupBy(ratingResults, "status")).map(
([groupKey, rawStudents]) => ({
title: formatMarkUpdateStatus(rawStudents[0]["status"]),
students: rawStudents.map((s) => s.infoString),
})
);
const groupedResults = Object.entries(
groupBy(ratingResults, "status")
).map(([groupKey, rawStudents]) => ({
title: formatMarkUpdateStatus(rawStudents[0]["status"]),
students: rawStudents.map((s) => s.infoString),
}));

this.reportManager.currentReport.skipped.push(...groupedResults);
}
Expand Down Expand Up @@ -369,9 +384,9 @@ export default class MarksManager {
const studentName = student.studentFio.substr(0, 30);
const description =
status !== MarkUpdateStatus.Skipped
? `выставлено «${formatStudentFailure(actualFailure)}», было «${formatStudentFailure(
brsFailureStatus
)}»`
? `выставлено «${formatStudentFailure(
actualFailure
)}», было «${formatStudentFailure(brsFailureStatus)}»`
: ${formatStudentFailure(actualFailure)}»`;

const infoString = `${studentName}, ${description}`;
Expand Down Expand Up @@ -464,7 +479,7 @@ function formatMarkUpdateStatus(status: MarkUpdateStatus) {
}

export interface ControlActionConfig {
controlActions: string[];
controlAction: string;
matchIndex?: number;
matchCount?: number;
propertyIndex: number;
Expand Down
30 changes: 12 additions & 18 deletions src/managers/SpreadsheetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,27 +191,19 @@ function buildControlActionConfig(header: string[], indices: Indices) {
continue;
}
controlActionConfigs.push({
controlActions: [header[index]],
controlAction: header[index],
propertyIndex: index - indices.left,
});
}

for (const config of controlActionConfigs) {
if (config.controlActions.length === 1) {
const sameColumns = controlActionConfigs.filter(
(c) =>
c.controlActions.length === 1 &&
compareNormalized(c.controlActions[0], config.controlActions[0])
);
if (sameColumns.length > 1) {
config.matchCount = sameColumns.length;
for (
let matchIndex = 0;
matchIndex < sameColumns.length;
matchIndex++
) {
sameColumns[matchIndex].matchIndex = matchIndex;
}
const sameColumns = controlActionConfigs.filter((c) =>
compareNormalized(c.controlAction, config.controlAction)
);
if (sameColumns.length > 1) {
config.matchCount = sameColumns.length;
for (let matchIndex = 0; matchIndex < sameColumns.length; matchIndex++) {
sameColumns[matchIndex].matchIndex = matchIndex;
}
}
}
Expand Down Expand Up @@ -248,8 +240,10 @@ function buildDisciplineConfig(rows: string[][], indices: Indices) {

const errorNames = filterNull(getKeys(errors).map((k) => errors[k]));
if (errorNames.length > 0) {
const errorNamesString = errorNames.map(n => ${n}»`).join(", ");
throw new Error(`Следующие параметры дисциплины не заданы: ${errorNamesString}`);
const errorNamesString = errorNames.map((n) => ${n}»`).join(", ");
throw new Error(
`Следующие параметры дисциплины не заданы: ${errorNamesString}`
);
}

return result;
Expand Down

0 comments on commit e89ca95

Please sign in to comment.