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

Thesis of @anonym-HPI #458

Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
aae014d
add patients datastructure (not complete)
anonym-HPI Jun 19, 2022
3464fed
dataStructure prototype
anonym-HPI Jun 30, 2022
fcbc5b1
change how many patients personnel + material can treat
anonym-HPI Jun 30, 2022
fd9f459
notarzt aura prototype (missing that personnel + material can have ow…
anonym-HPI Jul 1, 2022
e3d6f47
material template + material and personnel having own thresholds
anonym-HPI Jul 1, 2022
7c7254f
fix: findAllElementsInCircle with radius 0
anonym-HPI Jul 1, 2022
845874c
aura radius dynamically about the size of maximum threshold of personnel
anonym-HPI Jul 1, 2022
81b6353
material can also have auraMode + material now being in and mode
anonym-HPI Jul 1, 2022
4456f83
created big material (not used right now) with auraMode = true
anonym-HPI Jul 1, 2022
0640359
fix maximum threshold calculation in calculate-treatments.ts
anonym-HPI Jul 2, 2022
2624d8c
scale in material and personnel feature manager + commenting fill Cir…
anonym-HPI Jul 2, 2022
efc7e83
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 2, 2022
0eab670
removed redundant PatientTickResult - replaced with PatientUpdate
anonym-HPI Jul 3, 2022
30e5c84
remove console.logs
anonym-HPI Jul 3, 2022
ebbbad2
making refreshTreatments more efficient (only for patients there visi…
anonym-HPI Jul 3, 2022
8b75a5e
fix: remove maxNumberOfPatients
anonym-HPI Jul 13, 2022
716f2aa
fix: cumulative calculation
anonym-HPI Jul 14, 2022
d5088dd
make threshold radii bigger
anonym-HPI Jul 14, 2022
ce95c81
comments + new lines
anonym-HPI Jul 14, 2022
472d2f4
removing startingPosition form calculateTreatment (not needed)
anonym-HPI Jul 14, 2022
27a71db
TODO comment
anonym-HPI Jul 14, 2022
45c1901
fix: vehicle-template importing material validation
anonym-HPI Jul 16, 2022
6d609fb
datastructure cleanup, comments and first remove then add (moveElement)
anonym-HPI Jul 18, 2022
91b6415
Merge branch 'hpi-sam:dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 18, 2022
4c8dee0
only get dataStructures from JSON in exerciseTick when refreshTreatme…
anonym-HPI Jul 20, 2022
a1ecff5
dataStructure remove comments and add findAllElementsInRectangle func…
anonym-HPI Jul 28, 2022
fc7ebc3
MyRBush renamed to dataStructure and DataStructure to DataStructureIn…
anonym-HPI Jul 28, 2022
f3c4183
maxGlobalThreshold
anonym-HPI Jul 28, 2022
dc95147
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 28, 2022
22f0159
renaming
anonym-HPI Jul 28, 2022
4083bdf
spatialTree now reading and writing itself into and from state + rena…
anonym-HPI Jul 28, 2022
8a4b916
fixed obvious in calculate-treatments.spec.ts
anonym-HPI Jul 28, 2022
1fa2250
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 29, 2022
9f17fcb
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 30, 2022
88581f1
after first feedback round
anonym-HPI Jul 31, 2022
a8b8ecc
Merge branch 'experimental/bachelors-thesis-marvin' of https://github…
anonym-HPI Jul 31, 2022
fe050b0
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 31, 2022
68f469d
Merge branch 'hpi-sam:dev' into experimental/bachelors-thesis-marvin
anonym-HPI Jul 31, 2022
9ebc6c4
fix remarks missing in the constructor in patient.ts
anonym-HPI Jul 31, 2022
c4263ea
fix/... cateringLines
anonym-HPI Aug 1, 2022
599ecd8
Merge remote-tracking branch 'origin/dev' into experimental/bachelors…
anonym-HPI Aug 13, 2022
43221ff
Remove aura mode and smaller fixes
Dassderdie Aug 19, 2022
83e6323
Refactor getElementFromFeature
Dassderdie Aug 19, 2022
1dacf9c
getImmutableElement + used in patient-ticking.ts
anonym-HPI Aug 19, 2022
05aa5d7
Improve code by integrating getImmutableElement into getElement
Dassderdie Aug 19, 2022
b772ece
cloneDeepImmutable fixes (removed unecessary and added necessary) + e…
anonym-HPI Aug 19, 2022
2877a55
Merge branch 'experimental/bachelors-thesis-marvin' of https://github…
anonym-HPI Aug 19, 2022
2b799f3
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Aug 20, 2022
d2d17aa
Make smaller code improvements in the frontend
Dassderdie Aug 20, 2022
8ead5a1
Do some refactoring in shared
Dassderdie Aug 20, 2022
6a27f9a
Refactor shared
Dassderdie Aug 22, 2022
3c56bf4
Fix treatments
Dassderdie Aug 22, 2022
b608fdc
Remove unnecessary `patient.needsNewCalculateTreatments`
Dassderdie Aug 22, 2022
56336f9
Apply suggestions from code review
anonym-HPI Aug 25, 2022
944875b
Merge branch 'dev' into experimental/bachelors-thesis-marvin
anonym-HPI Aug 25, 2022
123fd5a
Apply some more feedback
Dassderdie Aug 25, 2022
0f430aa
Apply more feedback
Dassderdie Sep 13, 2022
c960ecc
Fix refreshTreatments ignoring 19 out of 20 status changes
Dassderdie Sep 13, 2022
4edaa7d
Fix tests (and small bug with `isBeingTreated`)
Dassderdie Sep 14, 2022
fde8ca5
Remove unnecessary comment
Dassderdie Sep 14, 2022
567fd0c
Fix couldCaterFor for "or"
Dassderdie Sep 15, 2022
fe07465
Add migrations
Dassderdie Sep 15, 2022
0b56e37
Update allowedCommonJsDependencies for angular
Dassderdie Sep 16, 2022
851a47e
Merge branch 'dev' into experimental/bachelors-thesis-marvin
Dassderdie Sep 16, 2022
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
6 changes: 6 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion backend/src/exercise/exercise-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ export class ExerciseWrapper extends NormalType<
type: '[Exercise] Tick',
patientUpdates,
/**
* refresh every {@link refreshTreatmentInterval} * {@link tickInterval} ms seconds
* Refresh every {@link refreshTreatmentInterval} * {@link tickInterval} ms seconds
*/
// TODO: Refactor this: do this in the reducer instead of sending it in the action
Dassderdie marked this conversation as resolved.
Show resolved Hide resolved
refreshTreatments:
this.tickCounter % this.refreshTreatmentInterval === 0,
tickInterval: this.tickInterval,
Expand Down
92 changes: 30 additions & 62 deletions backend/src/exercise/patient-ticking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,30 @@ import type {
ExerciseState,
HealthPoints,
Patient,
PatientUpdate,
PersonnelType,
UUID,
} from 'digital-fuesim-manv-shared';
import { healthPointsDefaults, isAlive } from 'digital-fuesim-manv-shared';
import {
getElement,
healthPointsDefaults,
isAlive,
} from 'digital-fuesim-manv-shared';

/**
* The count of assigned personnel and material that cater for a {@link Patient}.
*/
type Catering = { [key in PersonnelType | 'material']: number };

interface PatientTickResult {
/**
* The id of the patient
*/
id: UUID;
/**
* The new {@link HealthPoints} the patient should have
*/
nextHealthPoints: HealthPoints;
/**
* The next {@link PatientHealthState} the patient should be in
*/
nextStateId: UUID;
/**
* The new state time of the patient
*/
nextStateTime: number;
/**
* The time a patient was treated overall
*/
treatmentTime: number;
}

anonym-HPI marked this conversation as resolved.
Show resolved Hide resolved
/**
* Apply the patient tick to the {@link state}
* @param state The {@link ExerciseState} the patient tick should be applied on later
* @param patientTickInterval The interval in ms between calls to this function
* @returns An array of {@link PatientTickResult}s to apply to the {@link state} in a reducer
* @returns An array of {@link PatientUpdate}s to apply to the {@link state} in a reducer
*/
export function patientTick(
state: ExerciseState,
patientTickInterval: number
): PatientTickResult[] {
): PatientUpdate[] {
return (
Object.values(state.patients)
// Only look at patients that are alive and have a position, i.e. are not in a vehicle
Expand Down Expand Up @@ -86,43 +67,30 @@ function getDedicatedResources(
state: ExerciseState,
patient: Patient
): Catering {
const cateringTypes: Catering = {
notarzt: 0,
notSan: 0,
rettSan: 0,
san: 0,
gf: 0,
material: 0,
};

if (!patient.isBeingTreated) {
return {
gf: 0,
material: 0,
notarzt: 0,
notSan: 0,
rettSan: 0,
san: 0,
};
return cateringTypes;
}
const material = Object.values(state.materials).filter((thisMaterial) =>
Object.keys(thisMaterial.assignedPatientIds).includes(patient.id)
).length;
const treatingPersonnel = Object.values(state.personnel).filter(
(thisPersonnel) =>
Object.keys(thisPersonnel.assignedPatientIds).includes(patient.id)

cateringTypes.material = Object.keys(patient.assignedMaterialIds).length;

// Get the number of every personnel
Object.keys(patient.assignedPersonnelIds).forEach(
(personnelId) =>
cateringTypes[
getElement(state, 'personnel', personnelId).personnelType
]++
);
const notarzt = treatingPersonnel.filter(
(thisPersonnel) => thisPersonnel.personnelType === 'notarzt'
).length;
const notSan = treatingPersonnel.filter(
(thisPersonnel) => thisPersonnel.personnelType === 'notSan'
).length;
const rettSan = treatingPersonnel.filter(
(thisPersonnel) => thisPersonnel.personnelType === 'rettSan'
).length;
const san = treatingPersonnel.filter(
(thisPersonnel) => thisPersonnel.personnelType === 'san'
).length;
return {
gf: 0,
material,
notarzt,
notSan,
rettSan,
san,
};

return cateringTypes;
}

/**
Expand All @@ -143,7 +111,7 @@ function getNextPatientHealthPoints(
const notarzt = treatedBy.notarzt;
const notSan = treatedBy.notSan;
const rettSan = treatedBy.rettSan;
// TODO: Sans should be able to treat patients too
// TODO: Sans should be able to treat patients too.
const functionParameters =
patient.healthStates[patient.currentHealthStateId]!.functionParameters;
// To do anything the personnel needs material
Expand Down
6 changes: 6 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import LineString from 'ol/geom/LineString';
import type { TranslateEvent } from 'ol/interaction/Translate';
import type VectorLayer from 'ol/layer/Vector';
import type VectorSource from 'ol/source/Vector';
import { rgbColorPalette } from 'src/app/shared/functions/colors';
import type { CateringLine } from 'src/app/shared/types/catering-line';
import type { FeatureManager } from '../utility/feature-manager';
import { LineStyleHelper } from '../utility/style-helper/line-style-helper';
Expand All @@ -18,14 +19,20 @@ export class CateringLinesFeatureManager
>
implements FeatureManager<Feature<LineString>>
{
readonly type = 'cateringLines';
readonly unsupportedChangeProperties = new Set(['id'] as const);

private readonly lineStyleHelper = new LineStyleHelper(0.1, '#0dcaf0');
private readonly lineStyleHelper = new LineStyleHelper(
(feature) => ({
color: rgbColorPalette.cyan,
}),
0.05
);

constructor(public readonly layer: VectorLayer<VectorSource<LineString>>) {
super();
layer.setStyle((thisFeature, currentZoom) =>
this.lineStyleHelper.getStyle(thisFeature as Feature, currentZoom)
layer.setStyle((feature, currentZoom) =>
this.lineStyleHelper.getStyle(feature as Feature, currentZoom)
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
import type { UUID, Position, Size } from 'digital-fuesim-manv-shared';
import type {
ExerciseState,
Position,
Size,
UUID,
} from 'digital-fuesim-manv-shared';
import { isArray } from 'lodash-es';
import type { MapBrowserEvent } from 'ol';
import { Feature } from 'ol';
import type { Coordinate } from 'ol/coordinate';
import { LineString } from 'ol/geom';
import Point from 'ol/geom/Point';
import type { TranslateEvent } from 'ol/interaction/Translate';
import type VectorLayer from 'ol/layer/Vector';
import type VectorSource from 'ol/source/Vector';
import type OlMap from 'ol/Map';
import type { AppState } from 'src/app/state/app.state';
import type { Store } from '@ngrx/store';
import { getStateSnapshot } from 'src/app/state/get-state-snapshot';
import type { TranslateEvent } from 'ol/interaction/Translate';
import { LineString } from 'ol/geom';
import { isArray } from 'lodash-es';
import type { Coordinate } from 'ol/coordinate';
import type VectorSource from 'ol/source/Vector';
import { Subject } from 'rxjs';
import type { WithPosition } from '../../utility/types/with-position';
import type { FeatureManager } from '../utility/feature-manager';
import type { Coordinates } from '../utility/movement-animator';
import { MovementAnimator } from '../utility/movement-animator';
import { TranslateHelper } from '../utility/translate-helper';
import type { FeatureManager } from '../utility/feature-manager';
import type { WithPosition } from '../../utility/types/with-position';
import type { OpenPopupOptions } from '../utility/popup-manager';
import { TranslateHelper } from '../utility/translate-helper';
import { ElementManager } from './element-manager';

export interface PositionableElement {
Expand Down Expand Up @@ -81,6 +83,7 @@ export abstract class ElementFeatureManager<
>
implements FeatureManager<ElementFeature>
{
abstract override readonly type: keyof ExerciseState;
public readonly togglePopup$ = new Subject<OpenPopupOptions<any>>();
protected readonly movementAnimator = new MovementAnimator<FeatureType>(
this.olMap,
Expand All @@ -89,7 +92,6 @@ export abstract class ElementFeatureManager<
protected readonly translateHelper = new TranslateHelper<FeatureType>();

constructor(
protected readonly store: Store<AppState>,
protected readonly olMap: OlMap,
public readonly layer: VectorLayer<VectorSource<FeatureType>>,
private readonly proposeMovementAction: (
Expand Down Expand Up @@ -154,55 +156,6 @@ export abstract class ElementFeatureManager<
);
}

protected getElementFromFeature(feature: Feature<any>) {
const id = feature.getId() as UUID;
const exerciseState = getStateSnapshot(this.store).exercise;
// We expect the id to be globally unique
if (exerciseState.materials[id]) {
return {
type: 'material',
value: exerciseState.materials[id] as unknown as Element,
} as const;
}
if (exerciseState.patients[id]) {
return {
type: 'patient',
value: exerciseState.patients[id] as unknown as Element,
} as const;
}
if (exerciseState.vehicles[id]) {
return {
type: 'vehicle',
value: exerciseState.vehicles[id] as unknown as Element,
} as const;
}
if (exerciseState.personnel[id]) {
return {
type: 'personnel',
value: exerciseState.personnel[id] as unknown as Element,
} as const;
}
if (exerciseState.mapImages[id]) {
return {
type: 'image',
value: exerciseState.mapImages[id] as unknown as Element,
} as const;
}
if (exerciseState.viewports[id]) {
return {
type: 'viewport',
value: exerciseState.viewports[id] as unknown as Element,
} as const;
}
if (exerciseState.transferPoints[id]) {
return {
type: 'transferPoint',
value: exerciseState.transferPoints[id] as unknown as Element,
} as const;
}
return undefined;
}

public getCenter(feature: ElementFeature): Coordinate {
const coordinates = feature.getGeometry()!.getCoordinates();
if (!isCoordinateArray(coordinates)) {
Expand Down
Loading