@@ -14,6 +14,7 @@ import (
1414 "github.com/chaitin/MonkeyCode/backend/db/user"
1515 "github.com/chaitin/MonkeyCode/backend/domain"
1616 "github.com/chaitin/MonkeyCode/backend/pkg/cvt"
17+ "github.com/chaitin/MonkeyCode/backend/pkg/entx"
1718)
1819
1920type DashboardRepo struct {
@@ -26,6 +27,7 @@ func NewDashboardRepo(db *db.Client) domain.DashboardRepo {
2627
2728// CategoryStat implements domain.DashboardRepo.
2829func (d * DashboardRepo ) CategoryStat (ctx context.Context , req domain.StatisticsFilter ) (* domain.CategoryStat , error ) {
30+ ctx = entx .SkipSoftDelete (ctx )
2931 var cs []domain.CategoryPoint
3032 if err := d .db .Task .Query ().
3133 Where (task .CreatedAtGTE (req .StartTime ())).
@@ -89,6 +91,17 @@ type DateValue struct {
8991
9092// TimeStat implements domain.DashboardRepo.
9193func (d * DashboardRepo ) TimeStat (ctx context.Context , req domain.StatisticsFilter ) (* domain.TimeStat , error ) {
94+ udv := make ([]DateValue , 0 )
95+ if err := d .db .Task .Query ().
96+ Where (task .CreatedAtGTE (req .StartTime ())).
97+ Aggregate (func (s * sql.Selector ) string {
98+ return sql .As ("COUNT(DISTINCT user_id)" , "count" )
99+ }).
100+ Scan (ctx , & udv ); err != nil {
101+ return nil , err
102+ }
103+
104+ ctx = entx .SkipSoftDelete (ctx )
92105 ds := make ([]DateValue , 0 )
93106 if err := d .db .Task .Query ().
94107 Where (task .CreatedAtGTE (req .StartTime ())).
@@ -130,6 +143,10 @@ func (d *DashboardRepo) TimeStat(ctx context.Context, req domain.StatisticsFilte
130143 AcceptedPer : []domain.TimePoint [float64 ]{},
131144 }
132145
146+ if len (udv ) > 0 {
147+ ts .TotalUsers = udv [0 ].Count
148+ }
149+
133150 for _ , v := range dsOneHour {
134151 ts .RealTimeTokens = append (ts .RealTimeTokens , domain.TimePoint [int64 ]{
135152 Timestamp : v .Date .Unix (),
@@ -138,7 +155,6 @@ func (d *DashboardRepo) TimeStat(ctx context.Context, req domain.StatisticsFilte
138155 }
139156
140157 for _ , v := range ds {
141- ts .TotalUsers += v .UserCount
142158 ts .TotalChats += v .LlmCount
143159 ts .TotalCompletions += v .CodeCount
144160 ts .TotalLinesOfCode += v .CodeLines
@@ -176,6 +192,7 @@ type UserCodeRank struct {
176192
177193// UserCodeRank implements domain.DashboardRepo.
178194func (d * DashboardRepo ) UserCodeRank (ctx context.Context , req domain.StatisticsFilter ) ([]* domain.UserCodeRank , error ) {
195+ ctx = entx .SkipSoftDelete (ctx )
179196 var rs []UserCodeRank
180197 if err := d .db .Task .Query ().
181198 Where (task .CreatedAtGTE (req .StartTime ())).
@@ -213,6 +230,7 @@ func (d *DashboardRepo) UserCodeRank(ctx context.Context, req domain.StatisticsF
213230
214231// UserEvents implements domain.DashboardRepo.
215232func (d * DashboardRepo ) UserEvents (ctx context.Context , req domain.StatisticsFilter ) ([]* domain.UserEvent , error ) {
233+ ctx = entx .SkipSoftDelete (ctx )
216234 id , err := uuid .Parse (req .UserID )
217235 if err != nil {
218236 return nil , err
@@ -247,6 +265,7 @@ func (d *DashboardRepo) UserEvents(ctx context.Context, req domain.StatisticsFil
247265
248266// UserStat implements domain.DashboardRepo.
249267func (d * DashboardRepo ) UserStat (ctx context.Context , req domain.StatisticsFilter ) (* domain.UserStat , error ) {
268+ ctx = entx .SkipSoftDelete (ctx )
250269 id , err := uuid .Parse (req .UserID )
251270 if err != nil {
252271 return nil , err
@@ -343,6 +362,7 @@ func (d *DashboardRepo) UserStat(ctx context.Context, req domain.StatisticsFilte
343362}
344363
345364func (d * DashboardRepo ) UserHeatmap (ctx context.Context , userID string ) ([]* domain.UserHeatmap , error ) {
365+ ctx = entx .SkipSoftDelete (ctx )
346366 id , err := uuid .Parse (userID )
347367 if err != nil {
348368 return nil , err
0 commit comments