2024-02-13 04:11:30 +08:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
2024-03-28 22:26:56 +08:00
|
|
|
"sync"
|
2024-02-13 04:11:30 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var uniqueID string
|
|
|
|
|
|
|
|
func InitUniqueID() {
|
|
|
|
uniqueID = uuid.New().String()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetUniqueID() string {
|
|
|
|
return uniqueID
|
|
|
|
}
|
2024-03-28 22:26:56 +08:00
|
|
|
|
2024-03-29 04:17:13 +08:00
|
|
|
type ActivitiesOverviewObj struct {
|
|
|
|
Started int64
|
|
|
|
Completed int64
|
|
|
|
}
|
|
|
|
|
|
|
|
var activitiesOverview = make(map[string]ActivitiesOverviewObj)
|
2024-03-28 22:26:56 +08:00
|
|
|
var activitiesOverviewMux = sync.Mutex{}
|
|
|
|
|
2024-03-29 04:17:13 +08:00
|
|
|
func ActivitiesOverviewStarted(index string) {
|
2024-03-28 22:26:56 +08:00
|
|
|
activitiesOverviewMux.Lock()
|
|
|
|
defer activitiesOverviewMux.Unlock()
|
|
|
|
|
|
|
|
if _, exists := activitiesOverview[index]; !exists {
|
2024-03-29 04:17:13 +08:00
|
|
|
activitiesOverview[index] = ActivitiesOverviewObj{
|
|
|
|
Started: 0,
|
|
|
|
Completed: 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
updatedValues := activitiesOverview[index]
|
|
|
|
updatedValues.Started++
|
|
|
|
|
|
|
|
activitiesOverview[index] = updatedValues
|
|
|
|
}
|
|
|
|
|
|
|
|
func ActivitiesOverviewCompleted(index string) {
|
|
|
|
activitiesOverviewMux.Lock()
|
|
|
|
defer activitiesOverviewMux.Unlock()
|
|
|
|
|
|
|
|
if updatedValues, exists := activitiesOverview[index]; exists {
|
|
|
|
updatedValues.Completed++
|
|
|
|
|
|
|
|
activitiesOverview[index] = updatedValues
|
2024-03-28 22:26:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-03-29 04:17:13 +08:00
|
|
|
func GetActivitiesOverview() map[string]ActivitiesOverviewObj {
|
2024-03-28 22:26:56 +08:00
|
|
|
activitiesOverviewMux.Lock()
|
|
|
|
defer activitiesOverviewMux.Unlock()
|
|
|
|
|
|
|
|
return activitiesOverview
|
|
|
|
}
|