-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Blacklisting API Enables fast checking of some necessary conditions for new the viability of new Tours. * wip * wip * Change constat MAX_PASSENGER_WAITING_TIME * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add tests for blacklisting API * Remove unnecessary tests * wip * wip * Format * wip * Run unit tests when db is set up * wip * wip * Format * wip * wip * Remove unused import * Split blacklist Query into multiple functions * Move sql for checking if a zone covers a point into its' own function * Add variables for readability in blacklisting API * Format * wip * wip * Rename variable * wip --------- Co-authored-by: nils_penzel <penzel.nils @web.de>
- Loading branch information
1 parent
90785a6
commit 4ef43f3
Showing
13 changed files
with
812 additions
and
15 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,83 @@ | ||
import type { BusStop } from './busStop'; | ||
import type { Capacities } from './capacities'; | ||
import type { Coordinates } from './location'; | ||
|
||
export type BookingRequestParameters = { | ||
userChosen: Coordinates; | ||
busStops: BusStop[]; | ||
startFixed: boolean; | ||
capacities: Capacities; | ||
}; | ||
|
||
export const schema = { | ||
$schema: 'http://json-schema.org/draft-07/schema#', | ||
type: 'object', | ||
definitions: { | ||
coordinates: { | ||
type: 'object', | ||
properties: { | ||
lat: { | ||
type: 'number', | ||
minimum: -90, | ||
maximum: 90 | ||
}, | ||
lng: { | ||
type: 'number', | ||
minimum: -180, | ||
maximum: 180 | ||
} | ||
}, | ||
required: ['lat', 'lng'] | ||
} | ||
}, | ||
properties: { | ||
userChosen: { | ||
$ref: '#/definitions/coordinates' | ||
}, | ||
busStops: { | ||
type: 'array', | ||
items: { | ||
type: 'object', | ||
properties: { | ||
coordinates: { | ||
$ref: '#/definitions/coordinates' | ||
}, | ||
times: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
format: 'date-time' | ||
} | ||
} | ||
}, | ||
required: ['coordinates', 'times'] | ||
} | ||
}, | ||
startFixed: { | ||
type: 'boolean' | ||
}, | ||
capacities: { | ||
type: 'object', | ||
properties: { | ||
passengers: { | ||
type: 'integer', | ||
minimum: 0 | ||
}, | ||
wheelchairs: { | ||
type: 'integer', | ||
minimum: 0 | ||
}, | ||
bikes: { | ||
type: 'integer', | ||
minimum: 0 | ||
}, | ||
luggage: { | ||
type: 'integer', | ||
minimum: 0 | ||
} | ||
}, | ||
required: ['passengers', 'wheelchairs', 'bikes', 'luggage'] | ||
} | ||
}, | ||
required: ['userChosen', 'busStops', 'startFixed', 'capacities'] | ||
}; |
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,6 @@ | ||
import type { Coordinates } from './location'; | ||
|
||
export type BusStop = { | ||
coordinates: Coordinates; | ||
times: Date[]; | ||
}; |
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,5 +1,8 @@ | ||
import { hoursToMs } from './time_utils'; | ||
import { hoursToMs, minutesToMs } from './time_utils'; | ||
|
||
export const TZ = 'Europe/Berlin'; | ||
export const MIN_PREP_MINUTES = 30; | ||
export const MAX_TRAVEL_DURATION = hoursToMs(1); | ||
export const MAX_PASSENGER_WAITING_TIME_PICKUP = minutesToMs(10); | ||
export const MAX_PASSENGER_WAITING_TIME_DROPOFF = minutesToMs(10); | ||
export const SRID = 4326; |
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 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,59 @@ | ||
import type { Capacities } from './capacities'; | ||
import { db } from './database'; | ||
|
||
let plate = 1; | ||
|
||
export enum Zone { | ||
ALTKREIS_BAUTZEN = 1, | ||
WEIßWASSER = 2, | ||
NIESKY = 3, | ||
GÖRLITZ = 4, | ||
LÖBAU = 5, | ||
ZITTAU = 6 | ||
} | ||
|
||
export const addCompany = async (zone: Zone): Promise<number> => { | ||
return ( | ||
await db.insertInto('company').values({ zone: zone }).returning('id').executeTakeFirstOrThrow() | ||
).id; | ||
}; | ||
|
||
export const addTaxi = async (company: number, capacities: Capacities): Promise<number> => { | ||
++plate; | ||
return ( | ||
await db | ||
.insertInto('vehicle') | ||
.values({ | ||
license_plate: String(plate), | ||
company, | ||
seats: capacities.passengers, | ||
wheelchair_capacity: capacities.wheelchairs, | ||
bike_capacity: capacities.bikes, | ||
storage_space: capacities.luggage | ||
}) | ||
.returning('id') | ||
.executeTakeFirstOrThrow() | ||
).id; | ||
}; | ||
|
||
export const setAvailability = async (vehicle: number, start_time: Date, end_time: Date) => { | ||
await db.insertInto('availability').values({ vehicle, start_time, end_time }).execute(); | ||
}; | ||
|
||
export const setTour = async (vehicle: number, departure: Date, arrival: Date) => { | ||
await db.insertInto('tour').values({ vehicle, arrival, departure }).execute(); | ||
}; | ||
|
||
export const clearDatabase = async () => { | ||
await Promise.all([ | ||
db.deleteFrom('address').execute(), | ||
db.deleteFrom('availability').execute(), | ||
db.deleteFrom('event').execute(), | ||
db.deleteFrom('request').execute(), | ||
db.deleteFrom('tour').execute(), | ||
db.deleteFrom('vehicle').execute(), | ||
db.deleteFrom('user_session').execute(), | ||
db.deleteFrom('auth_user').execute(), | ||
db.deleteFrom('company').execute() | ||
]); | ||
}; |
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 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,27 @@ | ||
import { Validator } from 'jsonschema'; | ||
import { getViableBusStops } from './viableBusStops'; | ||
import type { RequestEvent } from './$types'; | ||
import { json } from '@sveltejs/kit'; | ||
import { schema } from '$lib/bookingApiParameters'; | ||
|
||
export const POST = async (event: RequestEvent) => { | ||
const parameters = await event.request.json(); | ||
const validator = new Validator(); | ||
const result = validator.validate(parameters, schema); | ||
if (!result.valid) { | ||
return json( | ||
{ | ||
message: result.errors | ||
}, | ||
{ status: 400 } | ||
); | ||
} | ||
return json( | ||
getViableBusStops( | ||
parameters.userChosen, | ||
parameters.busStops, | ||
parameters.startFixed, | ||
parameters.capacities | ||
) | ||
); | ||
}; |
Oops, something went wrong.