forked from motis-project/motis
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: query api for plan details (#23)
* feat: implement plan itinerary depiction * feat: minor adjustments, conversion to shadcn * feat: plan parsing, depiction of computed plans * feat: QueryBatchOverview changed to buttons for switching plans * chore: remove unused demo file * fix: minor naming fixes
- Loading branch information
Showing
13 changed files
with
311 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
visual-debugger/src/data-processing/parsing-types/planParsingTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Plan type used for parsing plan responses | ||
*/ | ||
export interface Plan{ | ||
requestParameters:string; | ||
debugOutput: number[]; | ||
from:Place; | ||
to: Place; | ||
direct: Itinerary[]; | ||
itineraries: Itinerary[]; | ||
previousPageCursor: string; | ||
nextPageCursor: string; | ||
} | ||
|
||
/** | ||
* Place type used for parsing plan responses | ||
*/ | ||
export interface Place{ | ||
name:string; | ||
stopId:string; | ||
lat:number; | ||
lon:number; | ||
level: number; | ||
arrival: string; | ||
departure:string; | ||
scheduledArrival: string; | ||
scheduledDeparture: string; | ||
scheduledTrack:string; | ||
track:string; | ||
vertexType:string; | ||
} | ||
|
||
/** | ||
* Itinerary type used for parsing plan responses | ||
*/ | ||
export interface Itinerary { | ||
duration:number; | ||
startTime:string; | ||
endTime:string; | ||
transfers:number; | ||
legs:Leg[]; | ||
} | ||
|
||
/** | ||
* Leg type used for parsing plan responses | ||
*/ | ||
export interface Leg { | ||
mode:string; | ||
from:Place; | ||
to:Place; | ||
duration:number; | ||
startTime:string; | ||
endTime:string; | ||
scheduledStartTime:string; | ||
scheduledEndTime:string; | ||
realTime:boolean; | ||
legGeometry:EncodedPolyline; | ||
} | ||
|
||
/** | ||
* EncodedPolyline type used for parsing plan responses | ||
*/ | ||
export interface EncodedPolyline { | ||
points:string; | ||
length:number; | ||
} |
44 changes: 44 additions & 0 deletions
44
visual-debugger/src/data-processing/parsing-types/queryInterpolationTypes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* location type used for storing stop information | ||
*/ | ||
export interface Location { | ||
type: string; | ||
tokens: number[][]; | ||
name: string; | ||
id: string; | ||
lat: number; | ||
lon: number; | ||
level: number; | ||
zip: string; | ||
areas: Area[]; | ||
score: number; | ||
} | ||
|
||
/** | ||
* area type used for storing information about the area of a stop | ||
*/ | ||
export interface Area { | ||
name: string; | ||
adminLevel: number; | ||
matched: boolean; | ||
default: boolean; | ||
} | ||
|
||
/** | ||
* Query type used for storing information about a single query | ||
*/ | ||
export interface Query { | ||
index: number; | ||
from:string; | ||
fromStopID:string; | ||
to: string; | ||
toStopID: string; | ||
class:string; | ||
} | ||
|
||
/** | ||
* Type used for storing all queries in a Batch | ||
*/ | ||
export interface Batch { | ||
queries: Query[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {interpolatedQueryStore, computedPlanStore, currentPlanStore} from "../sveltestore.ts"; | ||
import type {Query} from "./parsing-types/queryInterpolationTypes.ts"; | ||
import type {Plan} from "./parsing-types/planParsingTypes.ts" | ||
import axios from "axios"; | ||
|
||
/** | ||
* Base URL of the MOTIS API | ||
*/ | ||
const motisApiUrlBase = 'http://localhost:8080/api/v1/' | ||
|
||
/** | ||
* data of the interpolated queries | ||
*/ | ||
let queries: Query[] | ||
|
||
/** | ||
* Interaction function that is accessed by the frontend to get the plan for all queries | ||
*/ | ||
export async function computePlan(){ | ||
//get read file content from storage | ||
interpolatedQueryStore.subscribe(file_data => { | ||
queries = file_data; | ||
}) | ||
|
||
// if store is empty abort data processing | ||
if(queries == undefined){return} | ||
|
||
let plans: Plan[] = []; | ||
let index =0; | ||
|
||
// compute the plan for each query | ||
for(const query of queries){ | ||
plans[index] = await computePlanForQuery(query) | ||
index++; | ||
} | ||
|
||
// put computed plans into storage and set first plan as active | ||
computedPlanStore.set(plans) | ||
currentPlanStore.set(plans[0]) | ||
} | ||
|
||
/** | ||
* Calls the MOTIS API for a specific query and returns the plan for it | ||
* @param query the query to get the plan for | ||
*/ | ||
export async function computePlanForQuery(query:Query){ | ||
const response = await axios | ||
.get( | ||
//configuration for api call parameters | ||
`${motisApiUrlBase}plan/?fromPlace=${query.fromStopID}&toPlace=${query.toStopID}` | ||
) | ||
let plan: Plan = response.data | ||
return plan | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,31 @@ | ||
<script lang="ts"> | ||
import {queryJsonStringStore} from "../../../sveltestore"; | ||
let file: File | null = null; // Use TypeScript's File type | ||
const handleFileChange = (event: Event): void => { | ||
const input = event.target as HTMLInputElement; | ||
file = input.files ? input.files[0] : null; | ||
console.log(file?.name); // Logs the file name | ||
import {computeQueryAttributes} from "../../../data-processing/queryBuild.ts"; | ||
let file: File | null = null; | ||
// put content of read file as string into storage | ||
file?.text().then((file_content_string) => { | ||
queryJsonStringStore.set(file_content_string); | ||
} | ||
) | ||
// When file was first uploaded, parse and interpolate the queries | ||
$: if(!($queryJsonStringStore=="DEFAULT")){computeQueryAttributes()} | ||
}; | ||
</script> | ||
|
||
<div> | ||
<input type="file" on:change={handleFileChange} /> | ||
{#if file} | ||
<p>Selected file: {file.name}</p> | ||
{/if} | ||
</div> | ||
/** | ||
* Gets the uploaded file and puts its content into the svelte store | ||
* @param event event that the file was uploaded | ||
*/ | ||
const putFileIntoStorage = (event: Event): void => { | ||
const input = event.target as HTMLInputElement; | ||
file = input.files ? input.files[0] : null; | ||
// put content of read file as string into storage | ||
file?.text().then((file_content_string) => { | ||
queryJsonStringStore.set(file_content_string); | ||
} | ||
) | ||
}; | ||
</script> | ||
|
||
<div> | ||
<input type="file" on:change={putFileIntoStorage} /> | ||
{#if file} | ||
<p>Selected file: {file.name}</p> | ||
{/if} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<script lang="ts"> | ||
import {currentPlanStore} from "../../../sveltestore.ts"; | ||
import type {Itinerary, Plan} from "../../../data-processing/parsing-types/planParsingTypes.ts"; | ||
import PlanEntry from "$lib/components/ui/subcomponents/PlanEntry.svelte"; | ||
let itineraries: Itinerary[] | ||
// let queries be up-to-date with the store | ||
currentPlanStore.subscribe((data) => { | ||
if (data == undefined) { | ||
itineraries = [] | ||
}else{ | ||
itineraries = data.itineraries; | ||
} | ||
} | ||
) | ||
</script> | ||
|
||
<h2>Plan of Query(Routing results)</h2> | ||
<div class="rounded-border"> | ||
{#each itineraries as itinerary} | ||
<PlanEntry startTime="{itinerary.startTime}" endTime="{itinerary.endTime}" | ||
duration="{itinerary.duration.toString()}" transfers="{itinerary.transfers.toString()}"/> | ||
{/each} | ||
</div> | ||
|
||
|
||
<style> | ||
.rounded-border { | ||
border: 1px solid black; | ||
border-radius: 8px; | ||
padding: 10px; | ||
} | ||
</style> |
10 changes: 0 additions & 10 deletions
10
visual-debugger/src/lib/components/ui/QueryBatchEntry.svelte
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.