update db and added weight
continuous-integration/drone/push Build is passing

This commit is contained in:
2023-04-16 17:08:40 +07:00
parent 3f9447f0b8
commit 09fe5f2324
7 changed files with 86 additions and 25 deletions
+33 -7
View File
@@ -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