Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

front: fix stdcm consist length and mass minimum values #10418

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const StdcmConsist = ({ isDebugMode, consistErrors = {}, disabled = false }: Std
status: 'error',
tooltip: 'left',
message: t(consistErrors.totalMass, {
low: Math.floor(
low: Math.ceil(
kgToT((rollingStock?.mass ?? 0) + (towedRollingStock?.mass ?? 0))
),
high: CONSIST_TOTAL_MASS_MAX,
Expand All @@ -168,7 +168,7 @@ const StdcmConsist = ({ isDebugMode, consistErrors = {}, disabled = false }: Std
status: 'error',
tooltip: 'left',
message: t(consistErrors.totalLength, {
low: Math.floor((rollingStock?.length ?? 0) + (towedRollingStock?.length ?? 0)),
low: Math.ceil((rollingStock?.length ?? 0) + (towedRollingStock?.length ?? 0)),
high: CONSIST_TOTAL_LENGTH_MAX,
}),
}
Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/stdcm/hooks/useStdcmConsist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ const useStdcmConsist = () => {
maxSpeedTag?: string | null
) => {
if (!totalMassChanged) {
const consistMass = Math.floor(kgToT((rollingStock?.mass ?? 0) + (towed?.mass ?? 0)));
const consistMass = Math.ceil(kgToT((rollingStock?.mass ?? 0) + (towed?.mass ?? 0)));
dispatch(updateTotalMass(consistMass > 0 ? consistMass : undefined));
}

if (!totalLengthChanged) {
const consistLength = Math.floor((rollingStock?.length ?? 0) + (towed?.length ?? 0));
const consistLength = Math.ceil((rollingStock?.length ?? 0) + (towed?.length ?? 0));
dispatch(updateTotalLength(consistLength > 0 ? consistLength : undefined));
}

Expand Down
4 changes: 2 additions & 2 deletions front/src/applications/stdcm/utils/consistValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const validateTotalMass = ({
}

const tractionMassInTons = kgToT(tractionEngineMass);
const consistMassInTons = Math.floor(kgToT(tractionEngineMass + towedMass));
const consistMassInTons = Math.ceil(kgToT(tractionEngineMass + towedMass));
const massLimit = towedMass ? consistMassInTons : tractionMassInTons;

if (totalMass < massLimit || totalMass > CONSIST_TOTAL_MASS_MAX) {
Expand All @@ -49,7 +49,7 @@ export const validateTotalLength = ({
return 'consist.errors.totalLength.negative';
}

const consistLength = Math.floor(tractionEngineLength + towedLength);
const consistLength = Math.ceil(tractionEngineLength + towedLength);

if (totalLength < consistLength || totalLength > CONSIST_TOTAL_LENGTH_MAX) {
return 'consist.errors.totalLength.range';
Expand Down
2 changes: 1 addition & 1 deletion front/tests/006-stdcm.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test.describe('Verify train schedule elements and filters', () => {
};
const fastRollingStockPrefilledValues = {
tonnage: '190',
length: '45',
length: '46',
maxSpeed: '220',
};
const towedRollingStockPrefilledValues = {
Expand Down
Loading