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

Refactoring/612 refactor position #625

Merged
merged 26 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c3c0d15
Add MetaPosition Helpers
benn02 Jan 25, 2023
0ab923d
Remove position property
benn02 Jan 25, 2023
a3e2a9f
Merge branch 'dev' into refactoring/612-refactor-position
benn02 Jan 26, 2023
7f46247
Fix Lint
benn02 Jan 26, 2023
337d923
Unify access onto metaPosition
benn02 Jan 26, 2023
b51afac
Fix Frontend
benn02 Jan 26, 2023
74be906
Merge branch 'dev' into refactoring/612-refactor-position
benn02 Jan 26, 2023
d4d8499
Remove Position Class
benn02 Jan 26, 2023
9ff7ce5
Remove Position from Tests
benn02 Jan 26, 2023
161330c
Rename MetaPosition to Position
benn02 Jan 26, 2023
ce42c40
Add Migration (not for Add vehicle Action)
benn02 Jan 26, 2023
a4981b4
Merge branch 'dev' of https://github.com/hpi-sam/digital-fuesim-manv …
benn02 Jan 30, 2023
d32b1d7
complete the renaming
benn02 Jan 30, 2023
2877c08
Fix Tests
benn02 Jan 30, 2023
6dc9ade
Remove Transfer Property
benn02 Jan 30, 2023
cf8ac25
Add Migration for Add Vehicle Action
benn02 Jan 30, 2023
e587c7e
Fix Small Bug
benn02 Jan 30, 2023
277f74c
Use type properties instead of passed strings
benn02 Jan 30, 2023
64f2e0c
Add comments
benn02 Jan 30, 2023
2dfaf0b
Fix Test
benn02 Jan 30, 2023
86210e1
Fix Test
benn02 Jan 30, 2023
ffee6e1
Fix Transfer Overview
benn02 Jan 30, 2023
9a9019b
Refactor Helper Methods to avoid duplicate Code
benn02 Jan 31, 2023
991c6dc
Change Names of Helper Functions
benn02 Jan 31, 2023
86eb1cb
Added Comments to unused vars
benn02 Jan 31, 2023
1261445
Merge branch 'dev' into refactoring/612-refactor-position
benn02 Jan 31, 2023
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
3 changes: 2 additions & 1 deletion backend/src/exercise/patient-ticking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
PersonnelType,
} from 'digital-fuesim-manv-shared';
import {
isOnMap,
getElement,
healthPointsDefaults,
isAlive,
Expand All @@ -29,7 +30,7 @@ export function patientTick(
return (
Object.values(state.patients)
// Only look at patients that are alive and have a position, i.e. are not in a vehicle
.filter((patient) => isAlive(patient.health) && patient.position)
.filter((patient) => isAlive(patient.health) && isOnMap(patient))
.map((patient) => {
// update the time a patient is being treated, to check for pretriage later
const treatmentTime = Patient.isTreatedByPersonnel(patient)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ export class DragElementService {
this.exerciseService.proposeAction(
{
type: '[Patient] Add patient',
patient: {
...patient,
position,
},
patient,
},
true
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { Injectable } from '@angular/core';
import { Store } from '@ngrx/store';
import {
isNotInVehicle,
coordinatesOf,
isOnMap,
loopTroughTime,
uuid,
Viewport,
isNotInTransfer,
} from 'digital-fuesim-manv-shared';
import type {
Personnel,
Client,
ExerciseState,
Patient,
Vehicle,
} from 'digital-fuesim-manv-shared';
import {
loopTroughTime,
Personnel,
uuid,
Viewport,
} from 'digital-fuesim-manv-shared';
import { countBy } from 'lodash-es';
import { ReplaySubject } from 'rxjs';
import { ApiService } from 'src/app/core/api.service';
Expand Down Expand Up @@ -108,18 +112,27 @@ export class StatisticsService {
),
Object.values(draftState.patients).filter(
(patient) =>
patient.position &&
Viewport.isInViewport(viewport, patient.position)
isOnMap(patient) &&
Viewport.isInViewport(
viewport,
coordinatesOf(patient)
)
),
Object.values(draftState.vehicles).filter(
(vehicle) =>
vehicle.position &&
Viewport.isInViewport(viewport, vehicle.position)
isOnMap(vehicle) &&
Viewport.isInViewport(
viewport,
coordinatesOf(vehicle)
)
),
Object.values(draftState.personnel).filter(
(personnel) =>
personnel.position &&
Viewport.isInViewport(viewport, personnel.position)
isOnMap(personnel) &&
Viewport.isInViewport(
viewport,
coordinatesOf(personnel)
)
)
),
])
Expand Down Expand Up @@ -148,8 +161,8 @@ export class StatisticsService {
personnel: countBy(
personnel.filter(
(_personnel) =>
!Personnel.isInVehicle(_personnel) &&
_personnel.transfer === undefined
isNotInVehicle(_personnel) &&
isNotInTransfer(_personnel)
),
(_personnel) => _personnel.personnelType
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Component } from '@angular/core';
import { Store } from '@ngrx/store';
import type { AlarmGroup, UUID } from 'digital-fuesim-manv-shared';
import {
Position,
MapCoordinates,
AlarmGroupStartPoint,
createVehicleParameters,
TransferPoint,
Expand Down Expand Up @@ -97,10 +97,13 @@ export class SendAlarmGroupInterfaceComponent implements OnDestroy {
this.store
),
// TODO: This position is not correct but needs to be provided.
// Here one should use a MetaPosition with the Transfer.
// Here one should use a Position with the Transfer.
// But this is part of later Refactoring.
lukasrad02 marked this conversation as resolved.
Show resolved Hide resolved
// Also it is irrelevant, because the correctMetaPosition is set immediately after this is called.
Position.create(0, 0)
// We need the Transfer to be created before the Vehicle is created,
// else we need to provide a Position that is immediately overwritten by the Add to Transfer Action.
// This is done here
// Good Thing is, it is irrelevant, because the correctPosition is set immediately after this is called.
MapCoordinates.create(0, 0)
);

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import type VectorLayer from 'ol/layer/Vector';
import type OlMap from 'ol/Map';
import type VectorSource from 'ol/source/Vector';
import type { ExerciseService } from 'src/app/core/exercise.service';
import type { WithPosition } from '../../utility/types/with-position';
import { MaterialPopupComponent } from '../shared/material-popup/material-popup.component';
import { PointGeometryHelper } from '../utility/point-geometry-helper';
import { ImagePopupHelper } from '../utility/popup-helper';
import { ImageStyleHelper } from '../utility/style-helper/image-style-helper';
import { NameStyleHelper } from '../utility/style-helper/name-style-helper';
import { MoveableFeatureManager } from './moveable-feature-manager';

export class MaterialFeatureManager extends MoveableFeatureManager<
WithPosition<Material>
> {
export class MaterialFeatureManager extends MoveableFeatureManager<Material> {
private readonly imageStyleHelper = new ImageStyleHelper(
(feature) => (this.getElementFromFeature(feature) as Material).image
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ import type { ExerciseService } from 'src/app/core/exercise.service';
import type { AppState } from 'src/app/state/app.state';
import { selectConfiguration } from 'src/app/state/application/selectors/exercise.selectors';
import { selectStateSnapshot } from 'src/app/state/get-state-snapshot';
import type { WithPosition } from '../../utility/types/with-position';
import { PatientPopupComponent } from '../shared/patient-popup/patient-popup.component';
import { PointGeometryHelper } from '../utility/point-geometry-helper';
import { ImagePopupHelper } from '../utility/popup-helper';
import { CircleStyleHelper } from '../utility/style-helper/circle-style-helper';
import { ImageStyleHelper } from '../utility/style-helper/image-style-helper';
import { MoveableFeatureManager } from './moveable-feature-manager';

export class PatientFeatureManager extends MoveableFeatureManager<
WithPosition<Patient>
> {
export class PatientFeatureManager extends MoveableFeatureManager<Patient> {
private readonly popupHelper = new ImagePopupHelper(this.olMap, this.layer);

private readonly imageStyleHelper = new ImageStyleHelper((feature) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@ import type VectorLayer from 'ol/layer/Vector';
import type OlMap from 'ol/Map';
import type VectorSource from 'ol/source/Vector';
import type { ExerciseService } from 'src/app/core/exercise.service';
import type { WithPosition } from '../../utility/types/with-position';
import { PersonnelPopupComponent } from '../shared/personnel-popup/personnel-popup.component';
import { PointGeometryHelper } from '../utility/point-geometry-helper';
import { ImagePopupHelper } from '../utility/popup-helper';
import { ImageStyleHelper } from '../utility/style-helper/image-style-helper';
import { NameStyleHelper } from '../utility/style-helper/name-style-helper';
import { MoveableFeatureManager } from './moveable-feature-manager';

export class PersonnelFeatureManager extends MoveableFeatureManager<
WithPosition<Personnel>
> {
export class PersonnelFeatureManager extends MoveableFeatureManager<Personnel> {
private readonly imageStyleHelper = new ImageStyleHelper(
(feature) => (this.getElementFromFeature(feature) as Personnel).image
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Store } from '@ngrx/store';
import type { UUID, SimulatedRegion } from 'digital-fuesim-manv-shared';
import { Position, Size } from 'digital-fuesim-manv-shared';
import { MapCoordinates, Size } from 'digital-fuesim-manv-shared';
import type { Feature, MapBrowserEvent } from 'ol';
import type { Polygon } from 'ol/geom';
import type VectorLayer from 'ol/layer/Vector';
Expand Down Expand Up @@ -69,7 +69,7 @@ export class SimulatedRegionFeatureManager
{
type: '[SimulatedRegion] Resize simulated region',
simulatedRegionId: element.id,
targetPosition: Position.create(
targetPosition: MapCoordinates.create(
topLeftCoordinate[0]!,
topLeftCoordinate[1]!
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,14 @@ import type VectorLayer from 'ol/layer/Vector';
import type OlMap from 'ol/Map';
import type VectorSource from 'ol/source/Vector';
import type { ExerciseService } from 'src/app/core/exercise.service';
import type { WithPosition } from '../../utility/types/with-position';
import { VehiclePopupComponent } from '../shared/vehicle-popup/vehicle-popup.component';
import { PointGeometryHelper } from '../utility/point-geometry-helper';
import { ImagePopupHelper } from '../utility/popup-helper';
import { ImageStyleHelper } from '../utility/style-helper/image-style-helper';
import { NameStyleHelper } from '../utility/style-helper/name-style-helper';
import { MoveableFeatureManager } from './moveable-feature-manager';

export class VehicleFeatureManager extends MoveableFeatureManager<
WithPosition<Vehicle>
> {
export class VehicleFeatureManager extends MoveableFeatureManager<Vehicle> {
private readonly imageStyleHelper = new ImageStyleHelper(
(feature) => (this.getElementFromFeature(feature) as Vehicle).image
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Store } from '@ngrx/store';
import type { UUID } from 'digital-fuesim-manv-shared';
import { Position, Size, Viewport } from 'digital-fuesim-manv-shared';
import { MapCoordinates, Size, Viewport } from 'digital-fuesim-manv-shared';
import type { Feature, MapBrowserEvent } from 'ol';
import type { Coordinate } from 'ol/coordinate';
import type { Polygon } from 'ol/geom';
Expand Down Expand Up @@ -77,7 +77,7 @@ export class ViewportFeatureManager
{
type: '[Viewport] Resize viewport',
viewportId: element.id,
targetPosition: Position.create(
targetPosition: MapCoordinates.create(
topLeftCoordinate[0]!,
topLeftCoordinate[1]!
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { OnInit } from '@angular/core';
import { Component, EventEmitter, Output } from '@angular/core';
import { Store } from '@ngrx/store';
import type { UUID, Vehicle } from 'digital-fuesim-manv-shared';
import { Material, Patient, Personnel } from 'digital-fuesim-manv-shared';
import { isInVehicle } from 'digital-fuesim-manv-shared';
import type { Observable } from 'rxjs';
import { combineLatest, map, switchMap } from 'rxjs';
import { ExerciseService } from 'src/app/core/exercise.service';
Expand Down Expand Up @@ -45,23 +45,21 @@ export class VehiclePopupComponent implements PopupComponent, OnInit {
).map((materialId) =>
this.store
.select(createSelectMaterial(materialId))
.pipe(map((material) => Material.isInVehicle(material)))
.pipe(map((material) => isInVehicle(material)))
);
const personnelAreInVehicle$ = Object.keys(
_vehicle.personnelIds
).map((personnelId) =>
this.store
.select(createSelectPersonnel(personnelId))
.pipe(
map((personnel) => Personnel.isInVehicle(personnel))
)
.pipe(map((personnel) => isInVehicle(personnel)))
);
const patientsAreInVehicle$ = Object.keys(
_vehicle.patientIds
).map((patientId) =>
this.store
.select(createSelectPatient(patientId))
.pipe(map((patient) => Patient.isInVehicle(patient)))
.pipe(map((patient) => isInVehicle(patient)))
);
return combineLatest([
...materialsAreInVehicle$,
Expand All @@ -70,7 +68,7 @@ export class VehiclePopupComponent implements PopupComponent, OnInit {
]);
}),
map((areInVehicle) =>
areInVehicle.every((isInVehicle) => !isInVehicle)
areInVehicle.every((isInAVehicle) => !isInAVehicle)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import type { Position, Size, UUID } from 'digital-fuesim-manv-shared';
import type {
MapCoordinates,
Position,
Size,
UUID,
} from 'digital-fuesim-manv-shared';
import type { Feature } from 'ol';
import type { Coordinate } from 'ol/coordinate';
import type { Geometry } from 'ol/geom';
Expand Down Expand Up @@ -32,7 +37,7 @@ type ArrayElement<ArrayType> = ArrayType extends readonly (infer ElementType)[]
: never;

type SubstituteCoordinateForPoint<T> = T extends Coordinate
? Position
? MapCoordinates
: T extends Array<ArrayElement<T>>
? SubstituteCoordinateForPoint<ArrayElement<T>>[]
: never;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
MergeIntersection,
UUID,
} from 'digital-fuesim-manv-shared';
import { coordinatesOf } from 'digital-fuesim-manv-shared';
import type { Feature } from 'ol';
import { Overlay, View } from 'ol';
import type { Polygon } from 'ol/geom';
Expand Down Expand Up @@ -356,10 +357,10 @@ export class OlMapManager {
const center = view.getCenter()!;
const previousZoom = view.getZoom()!;
const targetExtent = [
viewport.position.x,
viewport.position.y - viewport.size.height,
viewport.position.x + viewport.size.width,
viewport.position.y,
coordinatesOf(viewport).x,
coordinatesOf(viewport).y - viewport.size.height,
coordinatesOf(viewport).x + viewport.size.width,
coordinatesOf(viewport).y,
];
view.fit(targetExtent);
const matchingZoom = view.getZoom()!;
Expand Down Expand Up @@ -528,20 +529,20 @@ export class OlMapManager {
return;
}
const minX = Math.min(
...viewports.map((viewport) => viewport.position.x)
...viewports.map((viewport) => coordinatesOf(viewport).x)
);
const minY = Math.min(
...viewports.map(
(viewport) => viewport.position.y - viewport.size.height
(viewport) => coordinatesOf(viewport).y - viewport.size.height
)
);
const maxX = Math.max(
...viewports.map(
(viewport) => viewport.position.x + viewport.size.width
(viewport) => coordinatesOf(viewport).x + viewport.size.width
)
);
const maxY = Math.max(
...viewports.map((viewport) => viewport.position.y)
...viewports.map((viewport) => coordinatesOf(viewport).y)
);
const padding = 25;
view.fit([minX, minY, maxX, maxY], {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Position } from 'digital-fuesim-manv-shared';
import type { WithPosition } from 'digital-fuesim-manv-shared';
import { MapCoordinates, coordinatesOf } from 'digital-fuesim-manv-shared';
import { Feature } from 'ol';
import { Point } from 'ol/geom';
import type { WithPosition } from '../../utility/types/with-position';
import type {
CoordinatePair,
Coordinates,
Expand All @@ -11,12 +11,13 @@ import type {
import { interpolate } from './geometry-helper';

export class PointGeometryHelper implements GeometryHelper<Point> {
create = (element: WithPosition<any>): Feature<Point> =>
create = (element: WithPosition): Feature<Point> =>
new Feature(new Point(this.getElementCoordinates(element)));

getElementCoordinates = (
element: WithPosition<any>
): Coordinates<Point> => [element.position.x, element.position.y];
getElementCoordinates = (element: WithPosition): Coordinates<Point> => [
coordinatesOf(element).x,
coordinatesOf(element).y,
];

getFeatureCoordinates = (feature: Feature<Point>): Coordinates<Point> =>
feature.getGeometry()!.getCoordinates();
Expand All @@ -28,7 +29,7 @@ export class PointGeometryHelper implements GeometryHelper<Point> {
interpolate(positions.startPosition, positions.endPosition, progress);

getFeaturePosition = (feature: Feature<Point>): Positions<Point> =>
Position.create(
MapCoordinates.create(
this.getFeatureCoordinates(feature)[0]!,
this.getFeatureCoordinates(feature)[1]!
);
Expand Down
Loading