1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

Unstable. Further work on aggregations.

This commit is contained in:
Ferdinand Mütsch
2019-05-17 02:05:38 +02:00
parent de65ab1814
commit adb5abd4d2
5 changed files with 158 additions and 15 deletions

View File

@ -1,31 +1,45 @@
package models
import (
"database/sql/driver"
"time"
"github.com/jinzhu/gorm"
)
const (
AggregationProject int = 0
AggregationLanguage int = 1
AggregationEditor int = 2
AggregationOS int = 3
NAggregationTypes uint8 = 4
AggregationProject uint8 = 0
AggregationLanguage uint8 = 1
AggregationEditor uint8 = 2
AggregationOS uint8 = 3
)
type Aggregation struct {
gorm.Model
User *User `gorm:"not null; association_foreignkey:ID"`
UserID string `gorm:"not null; index:idx_user,idx_type_time_user"`
From time.Time `gorm:"not null; index:idx_from,idx_type_time_user; default:now()"`
To time.Time `gorm:"not null; index:idx_to,idx_type_time_user; default:now()"`
FromTime *time.Time `gorm:"not null; index:idx_from,idx_type_time_user; default:now()"`
ToTime *time.Time `gorm:"not null; index:idx_to,idx_type_time_user; default:now()"`
Duration time.Duration `gorm:"-"`
Type uint8 `gorm:"not null; index:idx_type,idx_type_time_user"`
Items []AggregationItem
}
type AggregationItem struct {
ID uint `gorm:"primary_key; auto_increment"`
AggregationID uint `gorm:"not null; association_foreignkey:ID"`
Key string `gorm:"not null"`
Total time.Duration
Total ScannableDuration
}
type ScannableDuration time.Duration
func (d *ScannableDuration) Scan(value interface{}) error {
*d = ScannableDuration(*d) * ScannableDuration(time.Second)
return nil
}
func (d ScannableDuration) Value() (driver.Value, error) {
return int64(time.Duration(d) / time.Second), nil
}

View File

@ -45,7 +45,6 @@ func (j *HeartbeatReqTime) UnmarshalJSON(b []byte) error {
}
func (j *HeartbeatReqTime) Scan(value interface{}) error {
fmt.Printf("%T", value)
switch value.(type) {
case int64:
*j = HeartbeatReqTime(time.Unix(123456, 0))
@ -67,3 +66,7 @@ func (j HeartbeatReqTime) String() string {
t := time.Time(j)
return t.Format("2006-01-02 15:04:05")
}
func (j HeartbeatReqTime) Time() time.Time {
return time.Time(j)
}