fix and conversions

This commit is contained in:
Arnaud Delcasse 2023-04-05 20:57:27 +02:00
parent 2f536dfb19
commit d8346a20be
14 changed files with 1212 additions and 958 deletions

View File

@ -27,7 +27,6 @@ func DistanceFromLineString(point orb.Point, lineString orb.LineString) (distanc
Float64("min distance", minDistance).
Int("index", closest).
Any("point", point).
Any("linestring", lineString).
Msg("minimum distance to polyline")
return minDistance, closest
}

2
go.mod
View File

@ -2,7 +2,7 @@ module git.coopgo.io/coopgo-platform/carpool-service
go 1.18
// replace git.coopgo.io/coopgo-platform/routing-service => ../../coopgo-platform/routing-service/
replace git.coopgo.io/coopgo-platform/routing-service => ../../coopgo-platform/routing-service/
replace git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss => ./interoperability/ocss/

View File

@ -111,3 +111,13 @@ func (h *CarpoolServiceHandler) GetUserPlanning(userid string, minDepartureDate
return results, nil
}
func (h *CarpoolServiceHandler) GetPlannedTrip(id string) (*internal.PlannedRouteSchedule, error) {
planned_trip, err := h.Storage.GetRouteSchedule(id)
if err != nil {
log.Error().Str("planned trip id", id).Err(err).Msg("could not retrieve planned schedule")
return nil, err
}
return planned_trip, nil
}

View File

@ -62,9 +62,9 @@ func (h *CarpoolServiceHandler) GetDriverJourneys(departure orb.Point, arrival o
distanceFromDeparture, indexDeparture := geoutils.DistanceFromLineString(departure, ls)
distanceFromArrival, indexArrival := geoutils.DistanceFromLineString(arrival, ls)
if indexArrival >= indexDeparture && distanceFromDeparture <= drad && distanceFromArrival < arad {
if indexArrival >= indexDeparture && distanceFromDeparture <= drad && distanceFromArrival <= arad {
//routePoints := []orb.Point{r.Route.Features[0].Point(), departure, arrival, r.Route.Features[1].Point()}
routePoints := []orb.Point{departure, arrival}
routePoints := []orb.Point{r.Route.Features[0].Point(), departure, arrival, r.Route.Features[1].Point()}
log.Debug().Any("route points", routePoints).Msg("calculate multipoint route")
itinerary, err := h.Routing.Route(routePoints)
if err != nil {
@ -161,8 +161,8 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
distanceFromArrival, indexArrival := geoutils.DistanceFromLineString(r.Route.Features[1].Point(), ls)
if indexArrival >= indexDeparture && distanceFromDeparture <= drad && distanceFromArrival < arad {
routePoints := []orb.Point{r.Route.Features[0].Point(), departure, arrival, r.Route.Features[0].Point()}
itinerary, err := h.Routing.Route(routePoints)
routePoints := []orb.Point{r.Route.Features[0].Point(), departure, arrival, r.Route.Features[1].Point()}
way, err := h.Routing.Route(routePoints)
if err != nil {
log.Error().Err(err).Msg("error getting route with viapoints")
continue
@ -171,7 +171,7 @@ func (h *CarpoolServiceHandler) GetPassengerJourneys(departure orb.Point, arriva
ID: r.ID,
Route: r.Route,
DepartureDate: r.DepartureDate,
Itinerary: itinerary,
Itinerary: way,
})
counted = counted + 1
if counted == *count {

File diff suppressed because it is too large Load Diff

View File

@ -77,7 +77,7 @@ message CarpoolServicePassengerJourney {
}
message CarpoolServiceDriverRegularTrip {
string id = 1;
optional string id = 1;
string operator = 2;
double passenger_pickup_lat = 3;
double passenger_pickup_lng = 4;
@ -85,30 +85,26 @@ message CarpoolServiceDriverRegularTrip {
double passenger_drop_lng = 6;
optional string passenger_pickup_address = 7;
optional string passenger_drop_address = 8;
int64 distance = 9;
double driver_departure_lat = 10;
double driver_departure_lng = 11;
double driver_arrival_lat = 12;
double driver_arrival_lng = 13;
string driver_departure_address = 14;
string driver_arrival_address = 15;
optional int64 distance = 9;
optional double driver_departure_lat = 10;
optional double driver_departure_lng = 11;
optional double driver_arrival_lat = 12;
optional double driver_arrival_lng = 13;
optional string driver_departure_address = 14;
optional string driver_arrival_address = 15;
int64 duration = 16;
string journey_polyline = 17;
string web_url = 18;
optional string journey_polyline = 17;
optional string web_url = 18;
CarpoolServiceUser driver = 19;
int64 departure_to_pickup_walking_distance = 20;
int64 departure_to_pickup_walking_duration = 21;
string departure_to_pickup_walking_polyline = 22;
int64 dropoff_to_arrival_walking_distance = 23;
int64 dropoff_to_arrival_walking_duration = 24;
string dropoff_to_arrival_walking_polyline = 25;
CarpoolServiceCar car = 26;
google.protobuf.Timestamp passenger_pickup_date = 27;
google.protobuf.Timestamp driver_departure_date = 28;
CarpoolServiceJourneyType type = 29;
int64 requested_seats = 30;
CarpoolServicePreferences preferences = 32;
repeated CarpoolServiceJourneySchedule schedules = 33;
optional int64 departure_to_pickup_walking_distance = 20;
optional int64 departure_to_pickup_walking_duration = 21;
optional string departure_to_pickup_walking_polyline = 22;
optional int64 dropoff_to_arrival_walking_distance = 23;
optional int64 dropoff_to_arrival_walking_duration = 24;
optional string dropoff_to_arrival_walking_polyline = 25;
optional CarpoolServiceCar car = 26;
optional CarpoolServicePreferences preferences = 32;
repeated CarpoolServiceSchedule schedules = 33;
}
message CarpoolServicePassengerRegularTrip {
@ -118,21 +114,21 @@ message CarpoolServicePassengerRegularTrip {
double passenger_pickup_lng = 4;
double passenger_drop_lat = 5;
double passenger_drop_lng = 6;
string passenger_pickup_address = 7;
string passenger_drop_address = 8;
int64 distance = 9;
double driver_departure_lat = 10;
double driver_departure_lng = 11;
double driver_arrival_lat = 12;
double driver_arrival_lng = 13;
string driver_departure_address = 14;
string driver_arrival_address = 15;
optional string passenger_pickup_address = 7;
optional string passenger_drop_address = 8;
optional int64 distance = 9;
optional double driver_departure_lat = 10;
optional double driver_departure_lng = 11;
optional double driver_arrival_lat = 12;
optional double driver_arrival_lng = 13;
optional string driver_departure_address = 14;
optional string driver_arrival_address = 15;
int64 duration = 16;
string journey_polyline = 17;
string web_url = 18;
optional string journey_polyline = 17;
optional string web_url = 18;
CarpoolServiceUser passenger = 19;
CarpoolServicePreferences preferences = 32;
repeated CarpoolServiceJourneySchedule schedules = 33;
optional CarpoolServicePreferences preferences = 32;
repeated CarpoolServiceSchedule schedules = 33;
}
message CarpoolServiceBooking {
@ -144,15 +140,16 @@ message CarpoolServiceBooking {
double passenger_pickup_lng = 6;
double passenger_drop_lat = 7;
double passenger_drop_lng = 8;
string passenger_pickup_address = 9;
string passenger_drop_address = 10;
optional string passenger_pickup_address = 9;
optional string passenger_drop_address = 10;
CarpoolServiceBookingStatus status = 11;
int64 duration = 12;
string web_url = 13;
CarpoolServicePrice price = 14;
CarpoolServiceCar car = 15;
string driver_journey_id = 16;
string passenger_journey_id = 17;
optional int64 distance = 12;
optional int64 duration = 13;
optional string web_url = 14;
CarpoolServicePrice price = 15;
optional CarpoolServiceCar car = 16;
string driver_journey_id = 17;
string passenger_journey_id = 18;
}
message CarpoolServicePreferences {
@ -195,7 +192,7 @@ message CarpoolServiceSchedule {
message CarpoolServiceJourneySchedule {
string id = 1;
google.protobuf.Timestamp passenger_pickup_date = 2;
google.protobuf.Timestamp driver_departure_date = 3;
optional google.protobuf.Timestamp driver_departure_date = 3;
optional string web_url = 4;
CarpoolServiceJourneyType type = 5;
}

File diff suppressed because it is too large Load Diff

View File

@ -12,6 +12,7 @@ service CarpoolService {
rpc DeleteRegularRoutes(DeleteRegularRoutesRequest) returns (DeleteRegularRoutesResponse) {}
rpc GetUserPlanning(GetUserPlanningRequest) returns (GetUserPlanningResponse) {}
rpc GetPlannedTrip(GetPlannedTripRequest) returns (GetPlannedTripResponse) {}
// OCSS-like interaction
rpc DriverJourneys(DriverJourneysRequest) returns (DriverJourneysResponse) {}
@ -46,6 +47,14 @@ message GetUserPlanningResponse {
map<string, CarpoolRoutesCollection> routes_by_dates = 1;
}
message GetPlannedTripRequest {
string id = 1;
}
message GetPlannedTripResponse {
CarpoolFeatureCollection planned_trip = 1;
}
// OCSS-like interaction messages

View File

@ -27,6 +27,7 @@ type CarpoolServiceClient interface {
CreateRegularRoutes(ctx context.Context, in *CreateRegularRoutesRequest, opts ...grpc.CallOption) (*CreateRegularRoutesResponse, error)
DeleteRegularRoutes(ctx context.Context, in *DeleteRegularRoutesRequest, opts ...grpc.CallOption) (*DeleteRegularRoutesResponse, error)
GetUserPlanning(ctx context.Context, in *GetUserPlanningRequest, opts ...grpc.CallOption) (*GetUserPlanningResponse, error)
GetPlannedTrip(ctx context.Context, in *GetPlannedTripRequest, opts ...grpc.CallOption) (*GetPlannedTripResponse, error)
// OCSS-like interaction
DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error)
PassengerJourneys(ctx context.Context, in *PassengerJourneysRequest, opts ...grpc.CallOption) (*PassengerJourneysResponse, error)
@ -72,6 +73,15 @@ func (c *carpoolServiceClient) GetUserPlanning(ctx context.Context, in *GetUserP
return out, nil
}
func (c *carpoolServiceClient) GetPlannedTrip(ctx context.Context, in *GetPlannedTripRequest, opts ...grpc.CallOption) (*GetPlannedTripResponse, error) {
out := new(GetPlannedTripResponse)
err := c.cc.Invoke(ctx, "/CarpoolService/GetPlannedTrip", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *carpoolServiceClient) DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error) {
out := new(DriverJourneysResponse)
err := c.cc.Invoke(ctx, "/CarpoolService/DriverJourneys", in, out, opts...)
@ -144,6 +154,7 @@ type CarpoolServiceServer interface {
CreateRegularRoutes(context.Context, *CreateRegularRoutesRequest) (*CreateRegularRoutesResponse, error)
DeleteRegularRoutes(context.Context, *DeleteRegularRoutesRequest) (*DeleteRegularRoutesResponse, error)
GetUserPlanning(context.Context, *GetUserPlanningRequest) (*GetUserPlanningResponse, error)
GetPlannedTrip(context.Context, *GetPlannedTripRequest) (*GetPlannedTripResponse, error)
// OCSS-like interaction
DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error)
PassengerJourneys(context.Context, *PassengerJourneysRequest) (*PassengerJourneysResponse, error)
@ -168,6 +179,9 @@ func (UnimplementedCarpoolServiceServer) DeleteRegularRoutes(context.Context, *D
func (UnimplementedCarpoolServiceServer) GetUserPlanning(context.Context, *GetUserPlanningRequest) (*GetUserPlanningResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetUserPlanning not implemented")
}
func (UnimplementedCarpoolServiceServer) GetPlannedTrip(context.Context, *GetPlannedTripRequest) (*GetPlannedTripResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetPlannedTrip not implemented")
}
func (UnimplementedCarpoolServiceServer) DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DriverJourneys not implemented")
}
@ -256,6 +270,24 @@ func _CarpoolService_GetUserPlanning_Handler(srv interface{}, ctx context.Contex
return interceptor(ctx, in, info, handler)
}
func _CarpoolService_GetPlannedTrip_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetPlannedTripRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(CarpoolServiceServer).GetPlannedTrip(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/CarpoolService/GetPlannedTrip",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(CarpoolServiceServer).GetPlannedTrip(ctx, req.(*GetPlannedTripRequest))
}
return interceptor(ctx, in, info, handler)
}
func _CarpoolService_DriverJourneys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(DriverJourneysRequest)
if err := dec(in); err != nil {
@ -401,6 +433,10 @@ var CarpoolService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetUserPlanning",
Handler: _CarpoolService_GetUserPlanning_Handler,
},
{
MethodName: "GetPlannedTrip",
Handler: _CarpoolService_GetPlannedTrip_Handler,
},
{
MethodName: "DriverJourneys",
Handler: _CarpoolService_DriverJourneys_Handler,

View File

@ -98,7 +98,7 @@ func (j *CarpoolServiceDriverJourney) ToOCSS() ocss.DriverJourney {
Duration: time.Duration(j.Duration),
Distance: j.Distance,
DriverDepartureLat: j.DriverDepartureLat,
DriverDepartureLng: j.DriverArrivalLng,
DriverDepartureLng: j.DriverDepartureLng,
DriverArrivalLat: j.DriverArrivalLat,
DriverArrivalLng: j.DriverArrivalLng,
DriverDepartureAddress: j.DriverDepartureAddress,
@ -161,7 +161,7 @@ func (j *CarpoolServicePassengerJourney) ToOCSS() ocss.PassengerJourney {
Duration: time.Duration(j.Duration),
Distance: j.Distance,
DriverDepartureLat: j.DriverDepartureLat,
DriverDepartureLng: j.DriverArrivalLng,
DriverDepartureLng: j.DriverDepartureLng,
DriverArrivalLat: j.DriverArrivalLat,
DriverArrivalLng: j.DriverArrivalLng,
DriverDepartureAddress: j.DriverDepartureAddress,

View File

@ -66,3 +66,24 @@ func (s *CarpoolServiceServerImpl) GetUserPlanning(ctx context.Context, req *pro
RoutesByDates: results,
}, nil
}
func (s *CarpoolServiceServerImpl) GetPlannedTrip(ctx context.Context, req *proto.GetPlannedTripRequest) (*proto.GetPlannedTripResponse, error) {
planned_trip, err := s.Handler.GetPlannedTrip(req.Id)
if err != nil {
return nil, status.Errorf(codes.Internal, "could not retrieve planned trip - %s", err.Error())
}
planned_trip.Route.ExtraMembers["departure_date"] = planned_trip.DepartureDate
serialized, err := planned_trip.Route.FeatureCollection().MarshalJSON()
if err != nil {
log.Error().Err(err).Msg("grpc GetPlannedTrip - could not serialize feature collection")
return nil, status.Errorf(codes.Internal, "could not serialize feature collection")
}
return &proto.GetPlannedTripResponse{
PlannedTrip: &proto.CarpoolFeatureCollection{
Serialized: string(serialized),
},
}, nil
}

View File

@ -53,6 +53,14 @@ func (s *CarpoolServiceServerImpl) DriverJourneys(ctx context.Context, req *prot
driverDepartureLng := j.Route.Features[0].Point().Lon()
driverArrivalLat := j.Route.Features[1].Point().Lat()
driverArrivalLng := j.Route.Features[1].Point().Lon()
var driverDepartureAddress *string
if dda := j.Route.Features[0].Properties.MustString("label", ""); dda != "" {
driverDepartureAddress = &dda
}
var driverArrivalAddress *string
if daa := j.Route.Features[1].Properties.MustString("label", ""); daa != "" {
driverArrivalAddress = &daa
}
duration := time.Duration(0)
var distance *int64
if len(j.Itinerary.Legs) > 2 {
@ -67,21 +75,24 @@ func (s *CarpoolServiceServerImpl) DriverJourneys(ctx context.Context, req *prot
Operator: usermap["operator"].(string),
Alias: usermap["alias"].(string),
},
Operator: "ridygo.fr",
PassengerPickupLat: req.DepartureLat,
PassengerPickupLng: req.DepartureLng,
PassengerDropLat: req.ArrivalLat,
PassengerDropLng: req.ArrivalLng,
DriverDepartureLat: &driverDepartureLat,
DriverDepartureLng: &driverDepartureLng,
DriverArrivalLat: &driverArrivalLat,
DriverArrivalLng: &driverArrivalLng,
Duration: int64(duration),
Distance: distance,
Id: journeyId,
PassengerPickupDate: timestamppb.New(j.DepartureDate.Add(j.Itinerary.Legs[0].Duration)),
DriverDepartureDate: timestamppb.New(j.DepartureDate),
Type: proto.CarpoolServiceJourneyType_PLANNED,
Operator: "ridygo.fr",
PassengerPickupLat: req.DepartureLat,
PassengerPickupLng: req.DepartureLng,
PassengerDropLat: req.ArrivalLat,
PassengerDropLng: req.ArrivalLng,
DriverDepartureLat: &driverDepartureLat,
DriverDepartureLng: &driverDepartureLng,
DriverArrivalLat: &driverArrivalLat,
DriverArrivalLng: &driverArrivalLng,
DriverDepartureAddress: driverDepartureAddress,
DriverArrivalAddress: driverArrivalAddress,
Duration: int64(duration),
Distance: distance,
Id: journeyId,
PassengerPickupDate: timestamppb.New(j.DepartureDate.Add(j.Itinerary.Legs[0].Duration)),
DriverDepartureDate: timestamppb.New(j.DepartureDate),
Type: proto.CarpoolServiceJourneyType_PLANNED,
JourneyPolyline: &j.Itinerary.Summary.Polyline,
})
}
@ -121,10 +132,17 @@ func (s *CarpoolServiceServerImpl) PassengerJourneys(ctx context.Context, req *p
passengerArrivalLat := j.Route.Features[1].Point().Lat()
passengerArrivalLng := j.Route.Features[1].Point().Lon()
passengerDepartureDate := timestamppb.New(j.DepartureDate)
var passengerPickupAddress *string
if ppa := j.Route.Features[0].Properties.MustString("label", ""); ppa != "" {
passengerPickupAddress = &ppa
}
var passengerDropAddress *string
if pda := j.Route.Features[0].Properties.MustString("label", ""); pda != "" {
passengerDropAddress = &pda
}
driverDepartureDate := timestamppb.New(j.DepartureDate.Add(-j.Itinerary.Legs[0].Duration))
duration := time.Duration(0)
var distance *int64
log.Debug().Any("itinerary", j.Itinerary).Msg("debug itinerary")
if len(j.Itinerary.Legs) > 2 {
duration = j.Itinerary.Legs[1].Duration / time.Second
dist := int64(j.Itinerary.Legs[1].Distance)
@ -137,21 +155,24 @@ func (s *CarpoolServiceServerImpl) PassengerJourneys(ctx context.Context, req *p
Operator: usermap["operator"].(string),
Alias: usermap["alias"].(string),
},
Operator: "ridygo.fr",
PassengerPickupLat: passengerDepartureLat,
PassengerPickupLng: passengerDepartureLng,
PassengerDropLat: passengerArrivalLat,
PassengerDropLng: passengerArrivalLng,
DriverDepartureLat: &req.DepartureLat,
DriverDepartureLng: &req.DepartureLng,
DriverArrivalLat: &req.ArrivalLat,
DriverArrivalLng: &req.ArrivalLng,
Duration: int64(duration),
Distance: distance,
Id: journeyId,
PassengerPickupDate: passengerDepartureDate,
DriverDepartureDate: driverDepartureDate,
Type: proto.CarpoolServiceJourneyType_PLANNED,
Operator: "ridygo.fr",
PassengerPickupLat: passengerDepartureLat,
PassengerPickupLng: passengerDepartureLng,
PassengerDropLat: passengerArrivalLat,
PassengerDropLng: passengerArrivalLng,
PassengerPickupAddress: passengerPickupAddress,
PassengerDropAddress: passengerDropAddress,
DriverDepartureLat: &req.DepartureLat,
DriverDepartureLng: &req.DepartureLng,
DriverArrivalLat: &req.ArrivalLat,
DriverArrivalLng: &req.ArrivalLng,
Duration: int64(duration),
Distance: distance,
Id: journeyId,
PassengerPickupDate: passengerDepartureDate,
DriverDepartureDate: driverDepartureDate,
Type: proto.CarpoolServiceJourneyType_PLANNED,
JourneyPolyline: &j.Itinerary.Summary.Polyline,
})
}

View File

@ -274,7 +274,7 @@ func (s MongoDBStorage) StoreRouteSchedules(js []internal.PlannedRouteSchedule)
return s.PersistedKVPut(documents)
}
func (s MongoDBStorage) GetRouteSchedules(id string) (*internal.PlannedRouteSchedule, error) {
func (s MongoDBStorage) GetRouteSchedule(id string) (*internal.PlannedRouteSchedule, error) {
var result internal.PlannedRouteSchedule
err := s.PersistedKVGet(id, &result)

View File

@ -23,7 +23,7 @@ type Storage interface {
StoreSearchResults([]internal.SearchResult) error
GetSearchResult(id string) (*internal.SearchResult, error)
StoreRouteSchedules([]internal.PlannedRouteSchedule) error
GetRouteSchedules(id string) (*internal.PlannedRouteSchedule, error)
GetRouteSchedule(id string) (*internal.PlannedRouteSchedule, error)
}
func NewStorage(cfg *viper.Viper) (Storage, error) {