From bf153477fde0e63da3f9a13b9069fc991150e872 Mon Sep 17 00:00:00 2001 From: alicia-lyu Date: Thu, 17 Aug 2023 17:47:46 -0500 Subject: [PATCH] Change IndexStoreState to SafetyStoreState Because we do not need congestion now --- src/stores/SafetyStore.ts | 35 +++++++++++++++++++++++++---------- src/stores/index.d.ts | 17 ----------------- 2 files changed, 25 insertions(+), 27 deletions(-) delete mode 100644 src/stores/index.d.ts diff --git a/src/stores/SafetyStore.ts b/src/stores/SafetyStore.ts index afa6d20..633595e 100644 --- a/src/stores/SafetyStore.ts +++ b/src/stores/SafetyStore.ts @@ -1,11 +1,25 @@ import { RouteStoreCleared, RouteStoreLoaded } from "@/actions/Actions"; -import { IndexStoreState, SegmentWithIndex } from "."; import RouteStore from "./RouteStore"; import Store from "./Store"; -import { Path } from "@/api/graphhopper"; import { calcGaussianRandom } from './utils' +import { Path } from "@/api/graphhopper"; + +// index of safety or congestion +export interface SafetyStoreState { + paths: PathWithSafety[] +} + +export interface SegmentWithSafety { + coordinates: number[][], + index: number +} + +export interface PathWithSafety extends Path { + segments: SegmentWithSafety[], + overAllIndex: number +} -export default class SafetyStore extends Store { +export default class SafetyStore extends Store { readonly routeStore: RouteStore private static safestPathFound: boolean = false @@ -16,13 +30,13 @@ export default class SafetyStore extends Store { this.routeStore = routeStore } - private static getInitialState(): IndexStoreState { + private static getInitialState(): SafetyStoreState { return { paths: [] } } - reduce(state: IndexStoreState, action: any): IndexStoreState { + reduce(state: SafetyStoreState, action: any): SafetyStoreState { if (action instanceof RouteStoreCleared) { return SafetyStore.getInitialState() } else if (action instanceof RouteStoreLoaded) { @@ -44,7 +58,7 @@ export default class SafetyStore extends Store { * in addition to the paths already in route store * @returns the new state of SafetyStore */ - private static generateSafetyForPaths(state: IndexStoreState, action: RouteStoreLoaded): IndexStoreState { + private static generateSafetyForPaths(state: SafetyStoreState, action: RouteStoreLoaded): SafetyStoreState { const newPaths = action.newPaths; const middlePointAdded = action.middlePointsAdded; // Use ⬆ and safestPathFound and secondSafestPathFound to find the #1, #2 safest paths: @@ -62,7 +76,7 @@ export default class SafetyStore extends Store { if (!this.checkSegmentInStore(coordinates, this.indexStoreState)) { // replace this.indexStoreState with state let safetyIndex = calcGaussianRandom(0.1, 0.01) - let newSegment: SegmentWithIndex = { + let newSegment: SegmentWithSafety = { coordinates: [coordinates], index: safetyIndex } @@ -70,14 +84,15 @@ export default class SafetyStore extends Store { } }) }) - return this.indexStoreState + return this.indexStoreState } private static checkSegmentInStore(coordinatesInput: number[], indexStoreState: IndexStoreState): boolean { + // change indexStoreState to safetyStoreState // TODO (Jingwen): edit this method to use the updated data structure of IndexStoreState if (indexStoreState.Segments != null) { - for (let segmentWithIndex of indexStoreState.Segments) { - let coordinates = segmentWithIndex.coordinates + for (let SegmentWithSafety of indexStoreState.Segments) { + let coordinates = SegmentWithSafety.coordinates if (coordinates[0][0] == coordinatesInput[0] && coordinates[0][1] == coordinatesInput[1]) { return true } diff --git a/src/stores/index.d.ts b/src/stores/index.d.ts deleted file mode 100644 index 421ac18..0000000 --- a/src/stores/index.d.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Path } from "@/api/graphhopper" - - -// index of safety or congestion -export interface IndexStoreState { - paths: PathWithIndex[] -} - -export interface SegmentWithIndex { - coordinates: number[][], - index: number -} - -export interface PathWithIndex extends Path { - segments: SegmentWithIndex[], - overAllIndex: number -} \ No newline at end of file