-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathsimulationSheet.ts
94 lines (90 loc) · 2.69 KB
/
simulationSheet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import fs from 'fs';
import path from 'path';
export interface Simulation {
header: {
toolDescription: string;
documentTitle: string;
creationDetails: {
number: string;
date: string;
time: string;
};
};
responsiblePerson: {
role: string;
name: string;
phone: string;
email: string;
};
applicationDate: string;
referenceTrack: string;
trainDetails: {
compositionCode: string;
towedMaterial: string | null;
maxSpeed: string;
maxTonnage: string;
referenceEngine: string | null;
maxLength: string;
};
requestedRoute: Array<{
stopNumber: number;
station: string;
type: string;
arrivalTime?: string;
departureTime?: string;
reason?: string;
}>;
simulationDetails: {
referenceTrackNumber: string;
viewSimulationLink: string;
totalDistance: string;
simulationPath: Array<{
stopNumber: number;
station: string;
type: string;
arrivalTime?: string;
passageTime?: string;
departureTime?: string;
tonnage?: string;
referenceEngine?: string | null;
signal?: string | null;
crossedTrain?: string | null;
}>;
disclaimer: string;
};
}
export function findFirstPdf(directory: string): string | null {
try {
const files = fs.readdirSync(directory);
const pdfFile = files.find((file) => file.endsWith('.pdf'));
return pdfFile ? path.resolve(directory, pdfFile) : null;
} catch (error) {
console.error(`Error reading directory ${directory}:`, error);
return null;
}
}
/**
* Verifies the PDF content against the expected simulation.
* @param pdfText The text extracted from the PDF.
* @param expectedSimulation The expected simulation data.
* @returns Whether the content matches the expected simulation.
*/
export function verifySimulationContent(pdfText: string, expectedSimulation: Simulation): boolean {
const textChecks = [
expectedSimulation.header.toolDescription,
expectedSimulation.header.documentTitle,
expectedSimulation.header.creationDetails.number,
expectedSimulation.header.creationDetails.date,
expectedSimulation.header.creationDetails.time,
expectedSimulation.applicationDate,
expectedSimulation.referenceTrack,
expectedSimulation.trainDetails.compositionCode,
expectedSimulation.trainDetails.maxSpeed,
expectedSimulation.trainDetails.maxTonnage,
expectedSimulation.trainDetails.maxLength,
...expectedSimulation.requestedRoute.map((route) => route.station),
...expectedSimulation.simulationDetails.simulationPath.map((p) => p.station),
expectedSimulation.simulationDetails.disclaimer,
];
return textChecks.every((check) => pdfText.includes(check));
}