regular routes journeys, persistent KV to store return states, ...

This commit is contained in:
2023-04-03 20:35:12 +02:00
parent 0ae5730e7f
commit 2f536dfb19
21 changed files with 1722 additions and 1070 deletions

View File

@@ -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
// }