add functions to display statistiques
This commit is contained in:
parent
c9b326c49a
commit
1b2902c632
|
@ -10,19 +10,20 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/identification"
|
||||||
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
"git.coopgo.io/coopgo-apps/parcoursmob/utils/sorting"
|
||||||
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
agenda "git.coopgo.io/coopgo-platform/agenda/grpcapi"
|
||||||
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
agendastorage "git.coopgo.io/coopgo-platform/agenda/storage"
|
||||||
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
fleets "git.coopgo.io/coopgo-platform/fleets/grpcapi"
|
||||||
"git.coopgo.io/coopgo-platform/fleets/storage"
|
fleetsstorage "git.coopgo.io/coopgo-platform/fleets/storage"
|
||||||
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
groupsmanagement "git.coopgo.io/coopgo-platform/groups-management/grpcapi"
|
||||||
|
"git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
groupstorage "git.coopgo.io/coopgo-platform/groups-management/storage"
|
||||||
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
accounts "git.coopgo.io/coopgo-platform/mobility-accounts/grpcapi"
|
||||||
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
mobilityaccountsstorage "git.coopgo.io/coopgo-platform/mobility-accounts/storage"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"google.golang.org/protobuf/types/known/structpb"
|
"google.golang.org/protobuf/types/known/structpb"
|
||||||
"google.golang.org/protobuf/types/known/timestamppb"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
|
func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -70,7 +71,6 @@ func (h *ApplicationHandler) Administration(w http.ResponseWriter, r *http.Reque
|
||||||
////////////////////////////////////add event////////////////////////////////////////////
|
////////////////////////////////////add event////////////////////////////////////////////
|
||||||
rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
rresp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
Namespaces: []string{"parcoursmob_dispositifs"},
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
Mindate: timestamppb.New(time.Now().Add(-24 * time.Hour)),
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -368,30 +368,125 @@ func (h *ApplicationHandler) AdministrationGroupInviteMember(w http.ResponseWrit
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filteVehicle(r *http.Request, v *fleets.Vehicle) bool {
|
||||||
|
g := r.Context().Value(identification.GroupKey)
|
||||||
|
if g == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
group := g.(storage.Group)
|
||||||
|
|
||||||
|
for _, n := range v.Administrators {
|
||||||
|
if n == group.ID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
|
func (h ApplicationHandler) AdminStatVehicles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
request := &fleets.GetBookingsRequest{}
|
// request := &fleets.GetVehiclesRequest{
|
||||||
resp, err := h.services.GRPC.Fleets.GetBookings(context.TODO(), request)
|
// Namespaces: []string{"parcoursmob"},
|
||||||
|
// }
|
||||||
|
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
// }
|
||||||
|
|
||||||
|
//vehicles := []fleetsstorage.Vehicle{}
|
||||||
|
bookings := []fleetsstorage.Booking{}
|
||||||
|
//vehicles_map := map[string]fleetsstorage.Vehicle{}
|
||||||
|
|
||||||
|
// for _, vehicle := range resp.Vehicles {
|
||||||
|
// if filteVehicle(r, vehicle) {
|
||||||
|
// v := vehicle.ToStorageType()
|
||||||
|
// vehicles = append(vehicles, v)
|
||||||
|
// vehicles_map[v.ID] = v
|
||||||
|
// for _, b := range v.Bookings {
|
||||||
|
// if b.Status() != fleetsstorage.StatusOld {
|
||||||
|
// bookings = append(bookings, b)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
administrators := []string{}
|
||||||
|
reequest := &fleets.GetVehiclesRequest{
|
||||||
|
Namespaces: []string{"parcoursmob"},
|
||||||
|
}
|
||||||
|
reesp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), reequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
w.WriteHeader(http.StatusNotFound)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
}
|
||||||
|
|
||||||
|
vehicles := []fleetsstorage.Vehicle{}
|
||||||
|
for _, vehiicle := range reesp.Vehicles {
|
||||||
|
|
||||||
|
v := vehiicle.ToStorageType()
|
||||||
|
adminfound := false
|
||||||
|
for _, a := range administrators {
|
||||||
|
if a == v.Administrators[0] {
|
||||||
|
adminfound = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !adminfound {
|
||||||
|
administrators = append(administrators, v.Administrators[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
vehicles = append(vehicles, v)
|
||||||
|
|
||||||
|
}
|
||||||
|
groups := map[string]any{}
|
||||||
|
|
||||||
|
if len(administrators) > 0 {
|
||||||
|
admingroups, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: administrators,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
bookings := []storage.Booking{}
|
for _, g := range admingroups.Groups {
|
||||||
|
groups[g.Id] = g.ToStorageType()
|
||||||
for _, b := range resp.Bookings {
|
|
||||||
booking := b.ToStorageType()
|
|
||||||
bookings = append(bookings, booking)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sort.Sort(sorting.BookingsByStartdate(bookings))
|
}
|
||||||
|
//fmt.Println(groups)
|
||||||
vehicles, _ := h.services.GetVehiclesMap()
|
//fmt.Println("****************************************************************")
|
||||||
groups, _ := h.services.GetGroupsMap()
|
|
||||||
// fmt.Println(vehicles)
|
// fmt.Println(vehicles)
|
||||||
// fmt.Println("////////////////////////////////////////:")
|
// fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
|
||||||
h.Renderer.VehicleBookingsList(w, r, bookings, vehicles, groups)
|
// id := ""
|
||||||
|
// for _, v := range vehicles {
|
||||||
|
// id = v.ID
|
||||||
|
// for _, vv := range v.Bookings {
|
||||||
|
|
||||||
|
// i := 1
|
||||||
|
// // fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
|
||||||
|
// // fmt.Println(vv.Vehicleid)
|
||||||
|
// // fmt.Println("*********************************************************")
|
||||||
|
// if id == vv.Vehicleid {
|
||||||
|
// i++
|
||||||
|
// fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
|
||||||
|
// fmt.Println(vv.Vehicleid)
|
||||||
|
// fmt.Println("*********************************************************")
|
||||||
|
// }
|
||||||
|
// fmt.Println(i)
|
||||||
|
|
||||||
|
// }
|
||||||
|
// fmt.Println(v.Status)
|
||||||
|
// fmt.Println("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
|
||||||
|
//}
|
||||||
|
// fmt.Println(bookings)
|
||||||
|
sort.Sort(sorting.VehiclesByLicencePlate(vehicles))
|
||||||
|
sort.Sort(sorting.BookingsByStartdate(bookings))
|
||||||
|
h.Renderer.AdminStatVehicles(w, r, vehicles, bookings, groups)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
func (h *ApplicationHandler) members() ([]*accounts.Account, error) {
|
||||||
|
@ -431,3 +526,75 @@ func (h *ApplicationHandler) groupmembers(groupid string) (groupmembers []mobili
|
||||||
|
|
||||||
return groupmembers, admins, err
|
return groupmembers, admins, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////available ////////////////////////////////////
|
||||||
|
// func (h ApplicationHandler) AdminStatAvailableVehicles(w http.ResponseWriter, r *http.Request) {
|
||||||
|
// request := &fleets.GetVehiclesRequest{
|
||||||
|
// Namespaces: []string{"parcoursmob"},
|
||||||
|
// }
|
||||||
|
// resp, err := h.services.GRPC.Fleets.GetVehicles(context.TODO(), request)
|
||||||
|
// if err != nil {
|
||||||
|
// fmt.Println(err)
|
||||||
|
// w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// vehicles := []fleetsstorage.Vehicle{}
|
||||||
|
// for i, vehiicle := range resp.Vehicles {
|
||||||
|
// if len(resp.Vehicles[i].Bookings) == 0 {
|
||||||
|
// v := vehiicle.ToStorageType()
|
||||||
|
// vehicles = append(vehicles, v)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// fmt.Println(vehicles)
|
||||||
|
// fmt.Println("////////////////////////////////////////:")
|
||||||
|
// h.Renderer.UnbookingVehicles(w, r, vehicles)
|
||||||
|
// }
|
||||||
|
|
||||||
|
//////////////////////////////beneificiare list///////////
|
||||||
|
func (h ApplicationHandler) AdminStatBeneficaires(w http.ResponseWriter, r *http.Request) {
|
||||||
|
beneficiaries, err := h.services.GetBeneficiaries()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cacheid := uuid.NewString()
|
||||||
|
h.cache.PutWithTTL(cacheid, beneficiaries, 1*time.Hour)
|
||||||
|
fmt.Println(beneficiaries)
|
||||||
|
h.Renderer.AdminStatBeneficaires(w, r, beneficiaries, cacheid)
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////event list///////////
|
||||||
|
func (h ApplicationHandler) AdminStatEvents(w http.ResponseWriter, r *http.Request) {
|
||||||
|
resp, err := h.services.GRPC.Agenda.GetEvents(context.TODO(), &agenda.GetEventsRequest{
|
||||||
|
Namespaces: []string{"parcoursmob_dispositifs"},
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
responses := []agendastorage.Event{}
|
||||||
|
|
||||||
|
groupids := []string{}
|
||||||
|
for _, e := range resp.Events {
|
||||||
|
groupids = append(groupids, e.Owners...)
|
||||||
|
responses = append(responses, e.ToStorageType())
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Sort(sorting.EventsByStartdate(responses))
|
||||||
|
|
||||||
|
groupsresp, err := h.services.GRPC.GroupsManagement.GetGroupsBatch(context.TODO(), &groupsmanagement.GetGroupsBatchRequest{
|
||||||
|
Groupids: groupids,
|
||||||
|
})
|
||||||
|
groups := map[string]any{}
|
||||||
|
|
||||||
|
if err == nil {
|
||||||
|
for _, g := range groupsresp.Groups {
|
||||||
|
groups[g.Id] = g.ToStorageType()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
h.Renderer.AdminStatEvents(w, r, responses, groups)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue