A few tweaks

This commit is contained in:
cdricms
2024-04-30 00:48:02 +02:00
parent 6c5c1d594c
commit abb1a148ff
8 changed files with 208 additions and 37 deletions

31
app.go
View File

@@ -2,8 +2,6 @@ package main
import (
"context"
"fmt"
"os"
"git.cems.dev/cdricms/bdooc/proto"
"github.com/wailsapp/wails/v2/pkg/runtime"
@@ -52,13 +50,6 @@ func (a *App) GetEmployees(path string, limit, page uint, column, query *string)
return a.employees.Employees[page*limit : page*limit+limit], nil
}
func (a *App) SaveData(data []uint8, filename string) {
err := proto.SaveToFile(data, filename)
if err != nil {
panic(err)
}
}
func (a *App) GetProtoPath() string {
return a.OpenPath([]runtime.FileFilter{{
DisplayName: "Proto binary file",
@@ -78,8 +69,22 @@ func (a *App) OpenPath(filters []runtime.FileFilter) string {
return path
}
func (a *App) IsPathValid(path string) bool {
_, err := os.Stat(path)
fmt.Println(path)
return !os.IsNotExist(err)
type FunctionAgg string
const (
AVG = FunctionAgg("AVG")
SUM = FunctionAgg("SUM")
)
func (a *App) AggregateByColumn(groupBy proto.EmployeeField, on proto.EmployeeField, function FunctionAgg) map[string]float64 {
return proto.AggregateByColumn(a.employees, proto.EmployeeField(proto.SnakeCaseToPascalCase(string(groupBy))), func(ep proto.EmployeePList) float64 {
switch function {
case AVG:
return proto.Average(ep, proto.EmployeeField(proto.SnakeCaseToPascalCase(string(on))))
case SUM:
return proto.Sum(ep, proto.EmployeeField(proto.SnakeCaseToPascalCase(string(on))))
}
return 0.0
})
}