Skip to content

Commit

Permalink
chore: prevent parsing errors (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosvv authored Jan 16, 2025
1 parent bd5f60a commit e347af0
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions visual-debugger/src/data-processing/queryBuild.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import axios from "axios";
import {queryJsonStringStore, interpolatedQueryStore} from "../sveltestore";
import type { Location, Batch } from "./parsing-types/queryInterpolationTypes.ts"
import type {Location, Batch} from "./parsing-types/queryInterpolationTypes.ts"


/**
* Base URL of the MOTIS API
Expand All @@ -17,9 +18,17 @@ let queryFileContent: string
* @param query_batch path to the query batch JSON file
* @return the query batch dataset with stop id's
*/
export async function buildQueryDataset(query_batch:string) {
export async function buildQueryDataset(query_batch: string) {
// parse query batch file into readable queries
let batch: Batch = JSON.parse(query_batch)
let batch: Batch;
try {
batch = JSON.parse(query_batch)
} catch (e) {
alert("An error occurred while parsing query data.");
throw new Error(`Failed to build query data: ${e}`)
}


let queries = batch.queries

// call MOTIS API to search for the nearest stations to the start and end point of the query
Expand All @@ -37,7 +46,7 @@ export async function buildQueryDataset(query_batch:string) {
* @param locationName location the most similar stop id is needed of
* @return the id of the most similar location to the input string
*/
async function computeLocationId (locationName:string){
async function computeLocationId(locationName: string) {
const response = await axios
.get(
//configuration for api call parameters
Expand All @@ -50,16 +59,22 @@ async function computeLocationId (locationName:string){
/**
* Interaction method for printing queries to page
*/
export function computeQueryAttributes(){
export function computeQueryAttributes() {

//get read file content from storage
queryJsonStringStore.subscribe(file_data => {
queryFileContent = file_data;
})

// if store is empty abort data processing
if(queryFileContent.length==0){return}
if (queryFileContent.length == 0) {
return
}

//interpolate data
buildQueryDataset(queryFileContent)
try {
//interpolate data
buildQueryDataset(queryFileContent)
} catch (err) {
console.log(err)
}
}

0 comments on commit e347af0

Please sign in to comment.