Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

160 add timestamp #172

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
3 changes: 2 additions & 1 deletion Server/src/models/api.app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const UpdateRequestApp = z.object({
vehicleId: z.number().int().nonnegative(), // vehicle id of user
pos: Position.optional(), // the current position of user
speed: z.number().optional(), // Speed in km/h
heading: z.number().optional() // Heading of the vehicle between 0 and 359
heading: z.number().optional(), // Heading of the vehicle between 0 and 359
timestamp: z.number().optional() // Timestamp of GPS measurement in milliseconds since epoch
})

//================ new
Expand Down
6 changes: 4 additions & 2 deletions Server/src/routes/vehicle.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ export class VehicleRoute {
if (
vehiclePayload.pos !== undefined &&
vehiclePayload.heading !== undefined &&
vehiclePayload.speed !== undefined
vehiclePayload.speed !== undefined &&
vehiclePayload.timestamp !== undefined
) {
await VehicleService.appendLog(userVehicle.uid, vehiclePayload.pos, vehiclePayload.heading, vehiclePayload.speed)
await VehicleService.appendLog(userVehicle.uid, vehiclePayload.pos, vehiclePayload.heading, vehiclePayload.speed,
new Date(vehiclePayload.timestamp))
}

const userVehicleData = await VehicleService.getVehicleData(userVehicle)
Expand Down
31 changes: 16 additions & 15 deletions Server/src/services/vehicle.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ export type VehicleData = {

/** Service for vehicle management. */
export default class VehicleService {
public static async appendLog(
vehicleId: number,
position: z.infer<typeof Position>,
heading: number,
speed: number
): Promise<Log> {
return await database.logs.save({
timestamp: new Date(),
vehicleId,
position: [position.lng, position.lat],
heading,
speed
})
}

/**
* Search for vehicles on a track
* @param track `Track` to search on for vehicles
Expand All @@ -67,6 +52,22 @@ export default class VehicleService {
return filteredVehicles
}

public static async appendLog(
vehicleId: number,
position: z.infer<typeof Position>,
heading: number,
speed: number,
timestamp: Date
): Promise<Log> {
return await database.logs.save({
timestamp,
vehicleId,
position: [position.lng, position.lat],
heading,
speed
})
}

/**
* Compute all data (e.g. position, speed and heading) for a given vehicle
* @param vehicle `Vehicle` to compute data for
Expand Down
Loading