This commit is contained in:
+33
-7
@@ -2,6 +2,7 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
@@ -152,7 +153,7 @@ func (db *DB) SetPause(chatID int64, duration time.Duration) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (db *DB) GetStatAfter(chatID int64, t time.Time) (map[string]float64, error) {
|
||||
func (db *DB) GetStatBetween(chatID int64, startTime time.Time, endTime time.Time) (map[string]float64, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
if err := db.AddChat(chatID); err != nil {
|
||||
@@ -164,9 +165,17 @@ func (db *DB) GetStatAfter(chatID int64, t time.Time) (map[string]float64, error
|
||||
cursor, err := db.workoutsColection.Find(
|
||||
ctx,
|
||||
bson.M{
|
||||
"chat_id": chatID,
|
||||
"created_at": bson.M{"$gt": t},
|
||||
"chat_id": chatID,
|
||||
"created_at": bson.M{
|
||||
"$gte": startTime,
|
||||
"$lt": endTime,
|
||||
},
|
||||
},
|
||||
options.Find().SetSort(
|
||||
bson.M{
|
||||
"created_at": 1,
|
||||
},
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -176,6 +185,7 @@ func (db *DB) GetStatAfter(chatID int64, t time.Time) (map[string]float64, error
|
||||
if err := cursor.Decode(&result); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(result)
|
||||
res[result.Name] += float64(result.Count)
|
||||
}
|
||||
if err := cursor.Err(); err != nil {
|
||||
@@ -185,9 +195,17 @@ func (db *DB) GetStatAfter(chatID int64, t time.Time) (map[string]float64, error
|
||||
caloriesCursor, err := db.caloriesColection.Find(
|
||||
ctx,
|
||||
bson.M{
|
||||
"chat_id": chatID,
|
||||
"created_at": bson.M{"$gt": t},
|
||||
"chat_id": chatID,
|
||||
"created_at": bson.M{
|
||||
"$gte": startTime,
|
||||
"$lt": endTime,
|
||||
},
|
||||
},
|
||||
options.Find().SetSort(
|
||||
bson.M{
|
||||
"created_at": 1,
|
||||
},
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -206,9 +224,17 @@ func (db *DB) GetStatAfter(chatID int64, t time.Time) (map[string]float64, error
|
||||
weightCursor, err := db.weightColection.Find(
|
||||
ctx,
|
||||
bson.M{
|
||||
"chat_id": chatID,
|
||||
"created_at": bson.M{"$gt": t},
|
||||
"chat_id": chatID,
|
||||
"created_at": bson.M{
|
||||
"$gte": startTime,
|
||||
"$lt": endTime,
|
||||
},
|
||||
},
|
||||
options.Find().SetSort(
|
||||
bson.M{
|
||||
"created_at": 1,
|
||||
},
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user