From 7ac97273855e5e68d9e4b10e96d5466201fb8871 Mon Sep 17 00:00:00 2001 From: Florian Orben Date: Sat, 28 Nov 2015 14:56:30 +0100 Subject: PLT-1035: Remove last data point in graphs on #statistics page --- store/sql_post_store.go | 17 +++++++++++++---- store/sql_post_store_test.go | 5 +++-- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'store') diff --git a/store/sql_post_store.go b/store/sql_post_store.go index cc596074f..1831eb23c 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -807,6 +807,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan WHERE Posts.ChannelId = Channels.Id AND Channels.TeamId = :TeamId + AND Posts.CreateAt <= :EndTime ORDER BY Name DESC) AS t1 GROUP BY Name ORDER BY Name DESC @@ -825,17 +826,20 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan WHERE Posts.ChannelId = Channels.Id AND Channels.TeamId = :TeamId + AND Posts.CreateAt <= :EndTime ORDER BY Name DESC) AS t1 GROUP BY Name ORDER BY Name DESC LIMIT 30` } + end := utils.MillisFromTime(utils.EndOfDay(utils.Yesterday())) + var rows model.AnalyticsRows _, err := s.GetReplica().Select( &rows, query, - map[string]interface{}{"TeamId": teamId, "Time": model.GetMillis() - 1000*60*60*24*31}) + map[string]interface{}{"TeamId": teamId, "EndTime": end}) if err != nil { result.Err = model.NewAppError("SqlPostStore.AnalyticsUserCountsWithPostsByDay", "We couldn't get user counts with posts", err.Error()) } else { @@ -867,7 +871,8 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel { WHERE Posts.ChannelId = Channels.Id AND Channels.TeamId = :TeamId - AND Posts.CreateAt >:Time) AS t1 + AND Posts.CreateAt <= :EndTime + AND Posts.CreateAt >= :StartTime) AS t1 GROUP BY Name ORDER BY Name DESC LIMIT 30` @@ -885,17 +890,21 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel { WHERE Posts.ChannelId = Channels.Id AND Channels.TeamId = :TeamId - AND Posts.CreateAt > :Time) AS t1 + AND Posts.CreateAt <= :EndTime + AND Posts.CreateAt >= :StartTime) AS t1 GROUP BY Name ORDER BY Name DESC LIMIT 30` } + end := utils.MillisFromTime(utils.EndOfDay(utils.Yesterday())) + start := utils.MillisFromTime(utils.StartOfDay(utils.Yesterday().AddDate(0, 0, -31))) + var rows model.AnalyticsRows _, err := s.GetReplica().Select( &rows, query, - map[string]interface{}{"TeamId": teamId, "Time": model.GetMillis() - 1000*60*60*24*31}) + map[string]interface{}{"TeamId": teamId, "StartTime": start, "EndTime": end}) if err != nil { result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCountsByDay", "We couldn't get post counts by day", err.Error()) } else { diff --git a/store/sql_post_store_test.go b/store/sql_post_store_test.go index d9b087ea7..12b50cad3 100644 --- a/store/sql_post_store_test.go +++ b/store/sql_post_store_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/mattermost/platform/model" + "github.com/mattermost/platform/utils" ) func TestPostStoreSave(t *testing.T) { @@ -776,7 +777,7 @@ func TestUserCountsWithPostsByDay(t *testing.T) { o1 := &model.Post{} o1.ChannelId = c1.Id o1.UserId = model.NewId() - o1.CreateAt = model.GetMillis() + o1.CreateAt = utils.MillisFromTime(utils.Yesterday()) o1.Message = "a" + model.NewId() + "b" o1 = Must(store.Post().Save(o1)).(*model.Post) @@ -836,7 +837,7 @@ func TestPostCountsByDay(t *testing.T) { o1 := &model.Post{} o1.ChannelId = c1.Id o1.UserId = model.NewId() - o1.CreateAt = model.GetMillis() + o1.CreateAt = utils.MillisFromTime(utils.Yesterday()) o1.Message = "a" + model.NewId() + "b" o1 = Must(store.Post().Save(o1)).(*model.Post) -- cgit v1.2.3-1-g7c22