-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathusage.go
More file actions
28 lines (23 loc) · 781 Bytes
/
usage.go
File metadata and controls
28 lines (23 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package models
import (
"time"
"go.mongodb.org/mongo-driver/v2/bson"
)
// Usage tracks cost per user, per project, per model, per hour.
// Each document represents one hour bucket of usage.
type Usage struct {
ID bson.ObjectID `bson:"_id"`
UserID bson.ObjectID `bson:"user_id"`
ProjectID string `bson:"project_id"`
ModelSlug string `bson:"model_slug"`
HourBucket bson.DateTime `bson:"hour_bucket"` // Timestamp truncated to the hour
Cost float64 `bson:"cost"` // Cost in USD
UpdatedAt bson.DateTime `bson:"updated_at"`
}
func (u Usage) CollectionName() string {
return "usages"
}
// TruncateToHour truncates a time to the start of its hour.
func TruncateToHour(t time.Time) time.Time {
return t.Truncate(time.Hour)
}