regular routes journeys, persistent KV to store return states, ...
This commit is contained in:
@@ -14,7 +14,7 @@ func (h *CarpoolServiceHandler) Book(booking ocss.Booking) (*internal.Booking, e
|
||||
futureBooking.Roles = []string{}
|
||||
if booking.Driver.Operator == "ridygo.fr" {
|
||||
futureBooking.Roles = append(futureBooking.Roles, "driver")
|
||||
previous_search_result, err := h.Storage.GetSearchResult("driver", booking.DriverJourneyID)
|
||||
previous_search_result, err := h.Storage.GetSearchResult(booking.DriverJourneyID)
|
||||
if err == nil {
|
||||
futureBooking.DriverJourney = &internal.PlannedJourney{
|
||||
Route: internal.RegularRoute(*previous_search_result.Route),
|
||||
@@ -25,7 +25,7 @@ func (h *CarpoolServiceHandler) Book(booking ocss.Booking) (*internal.Booking, e
|
||||
|
||||
if booking.Passenger.Operator == "ridygo.fr" {
|
||||
futureBooking.Roles = append(futureBooking.Roles, "passenger")
|
||||
previous_search_result, err := h.Storage.GetSearchResult("passenger", booking.PassengerJourneyID)
|
||||
previous_search_result, err := h.Storage.GetSearchResult(booking.PassengerJourneyID)
|
||||
if err == nil {
|
||||
futureBooking.PassengerJourney = &internal.PlannedJourney{
|
||||
Route: internal.RegularRoute(*previous_search_result.Route),
|
||||
|
||||
@@ -78,6 +78,8 @@ func (h *CarpoolServiceHandler) GetUserPlanning(userid string, minDepartureDate
|
||||
return nil, err
|
||||
}
|
||||
|
||||
all_schedules := []internal.PlannedRouteSchedule{}
|
||||
|
||||
for _, r := range routes {
|
||||
rr := internal.RegularRoute(*r)
|
||||
schedules, err := rr.PlannedJourneySchedules(minDepartureDate, maxDepartureDate)
|
||||
@@ -86,6 +88,8 @@ func (h *CarpoolServiceHandler) GetUserPlanning(userid string, minDepartureDate
|
||||
return nil, err
|
||||
}
|
||||
|
||||
all_schedules = append(all_schedules, schedules...)
|
||||
|
||||
for _, s := range schedules {
|
||||
log.Debug().
|
||||
Str("route id", s.Route.ExtraMembers.MustString("id")).
|
||||
@@ -97,5 +101,13 @@ func (h *CarpoolServiceHandler) GetUserPlanning(userid string, minDepartureDate
|
||||
}
|
||||
}
|
||||
|
||||
if len(all_schedules) > 0 {
|
||||
err = h.Storage.StoreRouteSchedules(all_schedules)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("could not store route schedules")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
@@ -49,8 +49,6 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug().Any("tileset", tileset).Msg("got tileset")
|
||||
|
||||
candidate_routes := tileset.GetTiledRoutes()
|
||||
|
||||
journeys := []internal.SearchResult{}
|
||||
@@ -86,10 +84,12 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
|
||||
}
|
||||
}
|
||||
|
||||
err = h.Storage.StoreSearchResults("driver", journeys)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error saving search results")
|
||||
return nil, err
|
||||
if len(journeys) > 0 {
|
||||
err = h.Storage.StoreSearchResults(journeys)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error saving search results")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return journeys, nil
|
||||
@@ -149,8 +149,6 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Debug().Any("tileset", tileset).Msg("got tileset")
|
||||
|
||||
candidate_routes := tileset.GetTiledRoutes()
|
||||
|
||||
journeys := []internal.SearchResult{}
|
||||
@@ -159,8 +157,6 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
|
||||
for _, r := range candidate_routes {
|
||||
ls := decodedPolyline
|
||||
|
||||
// distanceFromDeparture, indexDeparture := planar.DistanceFromWithIndex(ls, r.Route.Features[0].Point())
|
||||
// distanceFromArrival, indexArrival := planar.DistanceFromWithIndex(ls, r.Route.Features[1].Point())
|
||||
distanceFromDeparture, indexDeparture := geoutils.DistanceFromLineString(r.Route.Features[0].Point(), ls)
|
||||
distanceFromArrival, indexArrival := geoutils.DistanceFromLineString(r.Route.Features[1].Point(), ls)
|
||||
|
||||
@@ -184,36 +180,13 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
|
||||
}
|
||||
}
|
||||
|
||||
err = h.Storage.StoreSearchResults("passenger", journeys)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error saving search results")
|
||||
return nil, err
|
||||
if len(journeys) > 0 {
|
||||
err = h.Storage.StoreSearchResults(journeys)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Error saving search results")
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return journeys, nil
|
||||
}
|
||||
|
||||
// //distance to Linestring computes the distance from point to the given linestring anf returns this minimum distance and the segment number
|
||||
// func distanceToLineSTring(point orb.Point, lineString orb.LineString) (distance float64, closest_segment_index int) {
|
||||
// minDistance := math.Inf(1)
|
||||
// closest := -1
|
||||
|
||||
// for i := 0; i < len(lineString)-1; i++ {
|
||||
// segment1 := lineString[i]
|
||||
// segment2 := lineString[i+1]
|
||||
// dist := distanceToSegment(point, segment1, segment2)
|
||||
// if dist < minDistance {
|
||||
// minDistance = dist
|
||||
// closest = i
|
||||
// }
|
||||
// }
|
||||
// return minDistance, closest
|
||||
// }
|
||||
|
||||
// //distanceToSegment computes the distance to the segment defined with a starting and a ending point
|
||||
// func distanceToSegment(point orb.Point, start orb.Point, end orb.Point) float64 {
|
||||
// len := (end.Lon()-start.Lon())*(end.Lon()-start.Lon()) + (end.Lat()-start.Lat())*(end.Lat()-start.Lat())
|
||||
// s := ((start.Lat()-point.Lat())*(end.Lon()-start.Lon()) - (start.Lon()-point.Lon())*(end.Lat()-start.Lat())) / len
|
||||
// distance := math.Abs(s) * math.Sqrt(len)
|
||||
// return distance
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user