created a basic home page #97
This commit is contained in:
44
logic/stats/PublicStats.go
Normal file
44
logic/stats/PublicStats.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package stats
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils"
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
||||
)
|
||||
|
||||
func HandlePublicStats(handle *Handle) {
|
||||
handle.Post("/stats/public/main", func(c *Context) *Error {
|
||||
if handle.DataMap["PublicMainLastUpdate"] != nil && handle.DataMap["PublicMainLastUpdate"].(int64) > time.Now().UnixMilli() {
|
||||
c.ShowMessage = false
|
||||
return c.SendJSON(handle.DataMap["PublicMain"])
|
||||
}
|
||||
number_of_models, err := GetDbVar[int](c, "count(*)", "models")
|
||||
if err != nil {
|
||||
return c.E500M("Could not get statistics", err)
|
||||
}
|
||||
number_of_classfications, err := GetDbVar[int](c, "count(*)", "tasks where task_type=$1", TASK_TYPE_CLASSIFICATION)
|
||||
if err != nil {
|
||||
return c.E500M("Could not get statistics", err)
|
||||
}
|
||||
number_of_images_processed, err := GetDbVar[int](c, "count(*)", "model_data_point")
|
||||
if err != nil {
|
||||
return c.E500M("Could not get statistics", err)
|
||||
}
|
||||
|
||||
handle.DataMap["PublicMainLastUpdate"] = time.Now().UnixNano() + 60*60*1000*1000
|
||||
handle.DataMap["PublicMain"] = struct {
|
||||
NumberOfModels int `json:"number_of_models"`
|
||||
NumberOfClassfications int `json:"number_of_classfications"`
|
||||
NumberOfImagesProcessed int `json:"number_of_images_processed"`
|
||||
}{
|
||||
*number_of_models,
|
||||
*number_of_classfications,
|
||||
*number_of_images_processed,
|
||||
}
|
||||
|
||||
c.ShowMessage = false
|
||||
return c.SendJSON(handle.DataMap["PublicMain"])
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user