Skip to content
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
29 changes: 27 additions & 2 deletions backend/context-service/resources/ATM/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,35 @@

from api.schemas import MetadataSchema
from apiflask.fields import Dict, String, Float, List, Integer
class MetadataSchemaATM(MetadataSchema):
from apiflask import Schema, fields
from marshmallow import pre_load
class PlaneMetadataSchemaATM(MetadataSchema):
id_plane = String()
ApDest = Dict()
Current_airspeed = Float()
Latitude = Float()
Longitude = Float()
wpList = List(Dict())
id_plane = Integer()

class MetadataSchemaATM(MetadataSchema):
airplanes = List(fields.Nested(PlaneMetadataSchemaATM), required=True)

# Backward compatibility: optional fields for the single airplane case
ApDest = Dict(required=False)
Current_airspeed = Float(required=False)
Latitude = Float(required=False)
Longitude = Float(required=False)
wpList = List(Dict(), required=False)

@pre_load
def handle_backward_compatibility(self, data, **kwargs):
# If the new 'airplanes' field is not provided, assume the old format.
if 'airplanes' not in data:
airplane = {}
for field in ['ApDest', 'Current_airspeed', 'Latitude', 'Longitude', 'wpList']:
if field in data:
airplane[field] = data[field]
# Provide a default id_plane if not present.
airplane.setdefault('id_plane', "X")
data['airplanes'] = [airplane]
return data
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# backend/recommendation-service/resources/RTE/manager.py
# backend/recommendation-service/resources/Railway/manager.py

from api.manager.base_manager import BaseRecommendationManager

Expand Down
17 changes: 13 additions & 4 deletions frontend/src/components/organisms/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ import { useMapStore } from '@/stores/components/map'
import type { Waypoint } from '@/types/components/map'
import { criticalityToColor, maxCriticality } from '@/utils/utils'

withDefaults(
const props = withDefaults(
defineProps<{
tileLayers?: string[]
contextClick?: (waypoint: Waypoint) => void
waypointClick?: (waypoint: Waypoint) => void
autoFit?: boolean
}>(),
{
tileLayers: () => ['http://{s}.tile.osm.org/{z}/{x}/{y}.png'],
Expand All @@ -103,9 +104,17 @@ const lockView = ref(true)
const zoom = ref(6)
const map = ref()

watch(mapStore.contextWaypoints, () => {
toggleLockView()
})
watch(
() => mapStore.contextWaypoints,
() => {
if (props.autoFit) {
toggleLockView()
}

}
)


watch(appStore.panels, () => {
map.value.leafletObject.invalidateSize()
})
Expand Down
115 changes: 80 additions & 35 deletions frontend/src/entities/ATM/CAB/Context.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
<Map v-if="appStore.tab.context === 0" />
</Context>
</template>

<script setup lang="ts">
import { onBeforeMount, onUnmounted, ref, watch } from 'vue'
import { onBeforeMount, onUnmounted, ref } from 'vue'
import { useI18n } from 'vue-i18n'

import Context from '@/components/organisms/CAB/Context.vue'
import Map from '@/components/organisms/Map.vue'
import type { System } from '@/entities/ATM/types'
import type { AirplaneContext, LegacyContext, ContextType } from '@/entities/ATM/types'
import { useAppStore } from '@/stores/app'
import { useMapStore } from '@/stores/components/map'
import { useServicesStore } from '@/stores/services'


const { t, locale } = useI18n()
const servicesStore = useServicesStore()
const mapStore = useMapStore()
Expand All @@ -23,40 +22,86 @@ const appStore = useAppStore()
const contextPID = ref(0)
const faulty = ref(false)


onBeforeMount(async () => {
locale.value = `en-ATM`
contextPID.value = await servicesStore.getContext('ATM', (context) => {
mapStore.addContextWaypoint({
lat: context.data.Latitude,
lng: context.data.Longitude,
id: t('map.context')
})
const waypoints = [
...(context.data.wpList
? context.data.wpList.map(({ wplat, wplon, wpid }) => ({
id: wpid,
lat: wplat,
lng: wplon
}))
: []),
...(context.data.ApDest
? [
{
id: context.data.ApDest.apid,
lat: context.data.ApDest.aplat,
lng: context.data.ApDest.aplon,
permanentTooltip: true
}
]
: [])
]
mapStore.addPolyline({
id: 'current_route',
waypoints
})
contextPID.value = await servicesStore.getContext('ATM', (context: { data: ContextType }) => {
// New context data: iterate over the airplanes array
// 1- Clear last tick's markers and ROUTE waypoints
mapStore.removeCategoryWaypoint('ROUTE')
for (const waypoint of waypoints) mapStore.addWaypoint({ ...waypoint, category: 'ROUTE' })
// 2- add new markers and ROUTE waypoints
if ('airplanes' in context.data) {
context.data.airplanes.forEach((airplane: AirplaneContext) => {
mapStore.addContextWaypoint({
lat: airplane.Latitude,
lng: airplane.Longitude,
id: `plane-${airplane.id_plane}`
})
// build the route waypoints
const waypoints = [
...(airplane.wpList
? airplane.wpList.map(({ wplat, wplon, wpid }) => ({
id: wpid,
lat: wplat,
lng: wplon
}))
: []),
...(airplane.ApDest
? [
{
id: airplane.ApDest.apid,
lat: airplane.ApDest.aplat,
lng: airplane.ApDest.aplon,
permanentTooltip: true
}
]
: [])
]
// draw polyline for the plane
mapStore.addPolyline({
id: `current_route_plane-${airplane.id_plane}`,
waypoints
})
// add each wp a ROUTE waypoint
for (const waypoint of waypoints) {
mapStore.addWaypoint({ ...waypoint, category: 'ROUTE' })
}
})
} else {
// Legacy context data handling
const legacy = context.data as LegacyContext
mapStore.addContextWaypoint({
lat: legacy.Latitude,
lng: legacy.Longitude,
id: t('map.context')
})
const waypoints = [
...(legacy.wpList
? legacy.wpList.map(({ wplat, wplon, wpid }) => ({
id: wpid,
lat: wplat,
lng: wplon
}))
: []),
...(legacy.ApDest
? [
{
id: legacy.ApDest.apid,
lat: legacy.ApDest.aplat,
lng: legacy.ApDest.aplon,
permanentTooltip: true
}
]
: [])
]
mapStore.addPolyline({
id: 'current_route',
waypoints
})
//mapStore.removeCategoryWaypoint('ROUTE')
for (const waypoint of waypoints) {
mapStore.addWaypoint({ ...waypoint, category: 'ROUTE' })
}
}
})
})

Expand Down
95 changes: 60 additions & 35 deletions frontend/src/entities/ATM/types.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,68 @@
export type AirplaneContext = {
id_plane: number;
Current_airspeed: number;
Latitude: number;
Longitude: number;
ApDest?: {
apcity: string;
apid: Uppercase<string>;
aplat: number;
aplon: number;
apname: string;
};
wpList?: {
wpid: Uppercase<string>;
wpidx: number;
wplat: number;
wplon: number;
}[];
};

export type LegacyContext = {
Current_airspeed: number;
Latitude: number;
Longitude: number;
ApDest?: {
apcity: string;
apid: Uppercase<string>;
aplat: number;
aplon: number;
apname: string;
};
wpList?: {
wpid: Uppercase<string>;
wpidx: number;
wplat: number;
wplon: number;
}[];
};

export type ContextType = { airplanes: AirplaneContext[] } | LegacyContext;

export type ATM = {
Context: {
'Current airspeed': number
Latitude: number
Longitude: number
ApDest?: {
apcity: string
apid: Uppercase<string>
aplat: number
aplon: number
apname: string
}
wpList?: {
wpid: Uppercase<string>
wpidx: number
wplat: number
wplon: number
}[]
}
Metadata: { event_type: string; system: string }
Context: ContextType;
Metadata: { event_type: string; system: string };
Action: {
airport_destination: {
apcity: string
apid: Uppercase<string>
apname: Uppercase<string>
latitude: number
longitude: number
}
apcity: string;
apid: Uppercase<string>;
apname: Uppercase<string>;
latitude: number;
longitude: number;
};
waypoints: {
wplat: number
wplon: number
wpidx: number
wpid: Uppercase<string>
}[]
}
}
wplat: number;
wplon: number;
wpidx: number;
wpid: Uppercase<string>;
}[];
};
};


export const SYSTEMS = [
'ENGINE',
'ELECTRIC',
] as const
Object.freeze(SYSTEMS)
export type System = (typeof SYSTEMS)[number]
] as const;
Object.freeze(SYSTEMS);
export type System = (typeof SYSTEMS)[number];
2 changes: 1 addition & 1 deletion frontend/src/entities/Railway/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"card.event_type.INFRASTRUCTURE": "Infrastructure",
"card.event_type.PASSENGER": "Passenger",
"card.event_type.RAIL": "Rail",
"event.button.primary": "Recalculate transport plans",
"event.button.primary": "Get recommendation from maze",
"event.button.primary.passenger": "Show procedure",
"event.button.secondary": "Continue the procedure follow-up",
"event.button.secondary.passenger": "Put on hold",
Expand Down