lot of new functionalities

This commit is contained in:
Arnaud Delcasse
2025-10-14 18:11:13 +02:00
parent a6f70a6e85
commit d992a7984f
164 changed files with 15113 additions and 9442 deletions

View File

@@ -0,0 +1,13 @@
package sorting
import (
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
)
type BeneficiariesByName []mobilityaccountsstorage.Account
func (e BeneficiariesByName) Len() int { return len(e) }
func (e BeneficiariesByName) Less(i, j int) bool {
return e[i].Data["first_name"].(string) < e[j].Data["first_name"].(string)
}
func (e BeneficiariesByName) Swap(i, j int) { e[i], e[j] = e[j], e[i] }

11
core/utils/sorting/events.go Executable file
View File

@@ -0,0 +1,11 @@
package sorting
import (
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
)
type EventsByStartdate []agendastorage.Event
func (e EventsByStartdate) Len() int { return len(e) }
func (e EventsByStartdate) Less(i, j int) bool { return e[i].Startdate.Before(e[j].Startdate) }
func (e EventsByStartdate) Swap(i, j int) { e[i], e[j] = e[j], e[i] }

73
core/utils/sorting/fleets.go Executable file
View File

@@ -0,0 +1,73 @@
package sorting
import (
"cmp"
"encoding/json"
"strings"
"git.coopgo.io/coopgo-platform/fleets/storage"
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
"github.com/paulmach/orb/geo"
"github.com/paulmach/orb/geojson"
"github.com/rs/zerolog/log"
)
type VehiclesByLicencePlate []fleetsstorage.Vehicle
func (a VehiclesByLicencePlate) Len() int { return len(a) }
func (a VehiclesByLicencePlate) Less(i, j int) bool {
return strings.Compare(a[i].Data["licence_plate"].(string), a[j].Data["licence_plate"].(string)) < 0
}
func (a VehiclesByLicencePlate) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type BookingsByStartdate []fleetsstorage.Booking
func (a BookingsByStartdate) Len() int { return len(a) }
func (a BookingsByStartdate) Less(i, j int) bool {
return a[i].Startdate.Before(a[j].Startdate)
}
func (a BookingsByStartdate) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// Functions
func VehiclesByDistanceFrom(from geojson.Feature) func(vehicle1, vehicle2 storage.Vehicle) int {
return func(vehicle1, vehicle2 storage.Vehicle) int {
vehicle1Address, ok := vehicle1.Data["address"]
if !ok {
return 1
}
vehicle1Json, err := json.Marshal(vehicle1Address)
if err != nil {
log.Error().Err(err).Msg("failed marshalling vehicle 1 json")
return 1
}
vehicle1Geojson, err := geojson.UnmarshalFeature(vehicle1Json)
if err != nil {
log.Error().Err(err).Msg("failed unmarshalling vehicle 1 geojson")
return 1
}
vehicle2Address, ok := vehicle2.Data["address"]
if !ok {
log.Debug().Msg("Vehicle 2 does not have an address")
return -1
}
vehicle2Json, err := json.Marshal(vehicle2Address)
if err != nil {
log.Error().Err(err).Msg("failed marshalling vehicle 2 json")
return -1
}
vehicle2Geojson, err := geojson.UnmarshalFeature(vehicle2Json)
if err != nil {
log.Error().Err(err).Msg("failed unmarshalling vehicle 2 geojson")
return -1
}
distance1 := geo.Distance(from.Point(), vehicle1Geojson.Point())
distance2 := geo.Distance(from.Point(), vehicle2Geojson.Point())
return cmp.Compare(distance1, distance2)
}
}

15
core/utils/sorting/groups.go Executable file
View File

@@ -0,0 +1,15 @@
package sorting
import (
"strings"
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
)
type GroupsByName []groupstorage.Group
func (a GroupsByName) Len() int { return len(a) }
func (a GroupsByName) Less(i, j int) bool {
return strings.Compare(a[i].Data["name"].(string), a[j].Data["name"].(string)) < 0
}
func (a GroupsByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }

View File

@@ -0,0 +1,32 @@
package sorting
import (
"strings"
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
)
type SolidarityDriversByName []mobilityaccountsstorage.Account
func (e SolidarityDriversByName) Len() int { return len(e) }
func (e SolidarityDriversByName) Less(i, j int) bool {
return e[i].Data["first_name"].(string) < e[j].Data["first_name"].(string)
}
func (e SolidarityDriversByName) Swap(i, j int) { e[i], e[j] = e[j], e[i] }
type SolidarityAvailabilitiesByDay []*gen.DriverRegularAvailability
func (e SolidarityAvailabilitiesByDay) Len() int { return len(e) }
func (e SolidarityAvailabilitiesByDay) Less(i, j int) bool {
if e[i].Day == e[j].Day {
return strings.Compare(e[i].StartTime, e[j].StartTime) < 0
}
if e[i].Day == 0 {
return false
}
return e[i].Day < e[j].Day
}
func (e SolidarityAvailabilitiesByDay) Swap(i, j int) { e[i], e[j] = e[j], e[i] }

1
core/utils/sorting/sorting.go Executable file
View File

@@ -0,0 +1 @@
package sorting