-
Notifications
You must be signed in to change notification settings - Fork 9
/
state.ts
186 lines (175 loc) · 6.42 KB
/
state.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { Type } from 'class-transformer';
import {
Equals,
IsArray,
IsInt,
IsObject,
IsString,
IsUUID,
Min,
ValidateNested,
} from 'class-validator';
import { defaultMaterialTemplates } from './data/default-state/material-templates';
import { defaultPersonnelTemplates } from './data/default-state/personnel-templates';
import {
AlarmGroup,
Client,
EocLogEntry,
Hospital,
HospitalPatient,
MapImage,
MapImageTemplate,
Material,
Patient,
PatientCategory,
Personnel,
SimulatedRegion,
TransferPoint,
Vehicle,
VehicleTemplate,
Viewport,
} from './models';
import { ExerciseConfiguration } from './models/exercise-configuration';
import type { MaterialTemplate } from './models/material-template';
import type { PersonnelTemplate } from './models/personnel-template';
import type { ExerciseRadiogram } from './models/radiogram/exercise-radiogram';
import { getRadiogramConstructor } from './models/radiogram/exercise-radiogram';
import type { PersonnelType } from './models/utils';
import {
ExerciseStatus,
exerciseStatusAllowedValues,
getCreate,
SpatialTree,
} from './models/utils';
import type { MaterialType } from './models/utils/material-type';
import { RandomState, seededRandomState } from './simulation/utils/randomness';
import type { SpatialElementPlural } from './store/action-reducers/utils/spatial-elements';
import type { UUID } from './utils';
import { uuid, uuidValidationOptions } from './utils';
import { IsIdMap, IsLiteralUnion, IsMultiTypedIdMap } from './utils/validators';
import {
createCatchAllHospital,
catchAllHospitalId,
} from './data/default-state/catch-all-hospital';
import { defaultPatientCategories } from './data/default-state/patient-templates';
import { defaultVehicleTemplates } from './data/default-state/vehicle-templates';
import { defaultMapImagesTemplates } from './data/default-state/map-images-templates';
import type { LogEntry } from './models/log-entry';
import { TreatmentAssignment } from './store/action-reducers/exercise';
export class ExerciseState {
@IsUUID(4, uuidValidationOptions)
public readonly id = uuid();
/**
* The number of ms since the start of the exercise.
* This time is updated each `tick` by a constant value, is guaranteed to be (a bit) slower than the real time
* (depending on the server load and overhead of the tick).
*
* It is guaranteed that the `ExerciseTickAction` is the only action that modifies this value.
*/
@IsInt()
@Min(0)
public readonly currentTime: number = 0;
@IsLiteralUnion(exerciseStatusAllowedValues)
public readonly currentStatus: ExerciseStatus = 'notStarted';
@Type(() => RandomState)
@ValidateNested()
public readonly randomState: RandomState = seededRandomState();
@IsIdMap(Viewport)
public readonly viewports: { readonly [key: UUID]: Viewport } = {};
@IsIdMap(SimulatedRegion)
public readonly simulatedRegions: {
readonly [key: UUID]: SimulatedRegion;
} = {};
@IsIdMap(Vehicle)
public readonly vehicles: { readonly [key: UUID]: Vehicle } = {};
@IsIdMap(Personnel)
public readonly personnel: { readonly [key: UUID]: Personnel } = {};
@IsIdMap(Patient)
public readonly patients: { readonly [key: UUID]: Patient } = {};
@IsIdMap(Material)
public readonly materials: { readonly [key: UUID]: Material } = {};
@IsIdMap(MapImage)
public readonly mapImages: { readonly [key: UUID]: MapImage } = {};
@IsIdMap(TransferPoint)
public readonly transferPoints: { readonly [key: UUID]: TransferPoint } =
{};
@IsIdMap(Hospital)
public readonly hospitals: { readonly [key: UUID]: Hospital } = {
[catchAllHospitalId]: createCatchAllHospital(),
};
@IsIdMap(HospitalPatient, (hospitalPatient) => hospitalPatient.patientId)
public readonly hospitalPatients: {
readonly [key: UUID]: HospitalPatient;
} = {};
@IsIdMap(AlarmGroup)
public readonly alarmGroups: { readonly [key: UUID]: AlarmGroup } = {};
@IsIdMap(Client)
public readonly clients: { readonly [key: UUID]: Client } = {};
@IsMultiTypedIdMap(getRadiogramConstructor)
@ValidateNested()
public readonly radiograms: { readonly [key: UUID]: ExerciseRadiogram } =
{};
@IsArray()
@ValidateNested()
@Type(() => PatientCategory)
public readonly patientCategories = defaultPatientCategories;
@IsArray()
@ValidateNested()
@Type(() => VehicleTemplate)
public readonly vehicleTemplates = defaultVehicleTemplates;
@IsObject()
public readonly materialTemplates: {
[Key in MaterialType]: MaterialTemplate;
} = defaultMaterialTemplates;
@IsObject()
public readonly personnelTemplates: {
[Key in PersonnelType]: PersonnelTemplate;
} = defaultPersonnelTemplates;
@IsArray()
@ValidateNested()
@Type(() => MapImageTemplate)
public readonly mapImageTemplates = defaultMapImagesTemplates;
@IsArray()
@ValidateNested()
@Type(() => EocLogEntry)
public readonly eocLog: readonly EocLogEntry[] = [];
@IsString()
public readonly participantId: string;
// Mutable<ExerciseState>` could still have immutable objects in spatialTree
@IsObject()
public readonly spatialTrees: {
[type in SpatialElementPlural]: SpatialTree;
} = {
materials: SpatialTree.create(),
patients: SpatialTree.create(),
personnel: SpatialTree.create(),
};
@ValidateNested()
@Type(() => ExerciseConfiguration)
public readonly configuration = ExerciseConfiguration.create();
@IsInt()
@Min(0)
public readonly patientCounter: number = 0;
/**
* The log entries generated for the statistics.
* This must not be defined on a normal state,
* unless the statistics are currently being generated.
*/
@Equals(undefined)
public logEntries?: LogEntry[];
@Equals(undefined)
public previousTreatmentAssignment?: TreatmentAssignment;
/**
* @deprecated Use {@link create} instead.
*/
constructor(participantId: string) {
this.participantId = participantId;
}
static readonly create = getCreate(this);
/**
* **Important**
*
* This number MUST be increased every time a change to any object (that is part of the state or the state itself) is made in a way that there may be states valid before that are no longer valid.
*/
static readonly currentStateVersion = 37;
}