mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
feat: implement file statistics (resolve #80)
This commit is contained in:
@ -51,6 +51,9 @@ func (srv *DurationService) Get(from, to time.Time, user *models.User, filters *
|
||||
}
|
||||
|
||||
d1 := models.NewDurationFromHeartbeat(h)
|
||||
if !filters.IsProjectDetails() {
|
||||
d1 = d1.WithEntityIgnored() // only for efficiency
|
||||
}
|
||||
|
||||
if list, ok := mapping[d1.GroupHash]; !ok || len(list) < 1 {
|
||||
mapping[d1.GroupHash] = []*models.Duration{d1}
|
||||
|
@ -26,6 +26,8 @@ const (
|
||||
TestOsWin = "Windows"
|
||||
TestMachine1 = "muety-desktop"
|
||||
TestMachine2 = "muety-work"
|
||||
TestEntity1 = "/home/bob/dev/wakapi.go"
|
||||
TestEntity2 = "/home/bob/dev/SomethingElse.java"
|
||||
TestBranchMaster = "master"
|
||||
TestBranchDev = "dev"
|
||||
MinUnixTime1 = 1601510400000 * 1e6
|
||||
|
@ -238,6 +238,7 @@ func (srv *HeartbeatService) updateEntityUserCacheByHeartbeat(hb *models.Heartbe
|
||||
go srv.updateEntityUserCache(models.SummaryOS, hb.OperatingSystem, hb.User)
|
||||
go srv.updateEntityUserCache(models.SummaryMachine, hb.Machine, hb.User)
|
||||
go srv.updateEntityUserCache(models.SummaryBranch, hb.Branch, hb.User)
|
||||
go srv.updateEntityUserCache(models.SummaryEntity, hb.Entity, hb.User)
|
||||
}
|
||||
|
||||
func (srv *HeartbeatService) notifyBatch(heartbeats []*models.Heartbeat) {
|
||||
|
@ -84,8 +84,9 @@ func (srv *SummaryService) Aliased(from, to time.Time, user *models.User, f type
|
||||
summary.FillBy(models.SummaryProject, models.SummaryLabel) // first fill up labels from projects
|
||||
summary.FillMissing() // then, full up types which are entirely missing
|
||||
|
||||
if withBranches := filters != nil && filters.Project != nil && filters.Project.Exists(); !withBranches {
|
||||
if withDetails := filters != nil && filters.IsProjectDetails(); !withDetails {
|
||||
summary.Branches = nil
|
||||
summary.Entities = nil
|
||||
}
|
||||
|
||||
srv.cache.SetDefault(cacheKey, summary)
|
||||
@ -139,8 +140,9 @@ func (srv *SummaryService) Summarize(from, to time.Time, user *models.User, filt
|
||||
}
|
||||
|
||||
types := models.PersistedSummaryTypes()
|
||||
if filters != nil && filters.Project != nil && filters.Project.Exists() {
|
||||
if filters != nil && filters.IsProjectDetails() {
|
||||
types = append(types, models.SummaryBranch)
|
||||
types = append(types, models.SummaryEntity)
|
||||
}
|
||||
|
||||
typedAggregations := make(chan models.SummaryItemContainer)
|
||||
@ -156,6 +158,7 @@ func (srv *SummaryService) Summarize(from, to time.Time, user *models.User, filt
|
||||
var osItems []*models.SummaryItem
|
||||
var machineItems []*models.SummaryItem
|
||||
var branchItems []*models.SummaryItem
|
||||
var entityItems []*models.SummaryItem
|
||||
|
||||
for i := 0; i < len(types); i++ {
|
||||
item := <-typedAggregations
|
||||
@ -172,6 +175,8 @@ func (srv *SummaryService) Summarize(from, to time.Time, user *models.User, filt
|
||||
machineItems = item.Items
|
||||
case models.SummaryBranch:
|
||||
branchItems = item.Items
|
||||
case models.SummaryEntity:
|
||||
entityItems = item.Items
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,6 +195,7 @@ func (srv *SummaryService) Summarize(from, to time.Time, user *models.User, filt
|
||||
OperatingSystems: osItems,
|
||||
Machines: machineItems,
|
||||
Branches: branchItems,
|
||||
Entities: entityItems,
|
||||
NumHeartbeats: durations.TotalNumHeartbeats(),
|
||||
}
|
||||
|
||||
@ -302,6 +308,7 @@ func (srv *SummaryService) mergeSummaries(summaries []*models.Summary) (*models.
|
||||
Machines: make([]*models.SummaryItem, 0),
|
||||
Labels: make([]*models.SummaryItem, 0),
|
||||
Branches: make([]*models.SummaryItem, 0),
|
||||
Entities: make([]*models.SummaryItem, 0),
|
||||
}
|
||||
|
||||
var processed = map[time.Time]bool{}
|
||||
@ -332,6 +339,7 @@ func (srv *SummaryService) mergeSummaries(summaries []*models.Summary) (*models.
|
||||
finalSummary.Machines = srv.mergeSummaryItems(finalSummary.Machines, s.Machines)
|
||||
finalSummary.Labels = srv.mergeSummaryItems(finalSummary.Labels, s.Labels)
|
||||
finalSummary.Branches = srv.mergeSummaryItems(finalSummary.Branches, s.Branches)
|
||||
finalSummary.Entities = srv.mergeSummaryItems(finalSummary.Entities, s.Entities)
|
||||
finalSummary.NumHeartbeats += s.NumHeartbeats
|
||||
|
||||
processed[hash] = true
|
||||
|
@ -43,6 +43,7 @@ func (suite *SummaryServiceTestSuite) SetupSuite() {
|
||||
OperatingSystem: TestOsLinux,
|
||||
Machine: TestMachine1,
|
||||
Branch: TestBranchMaster,
|
||||
Entity: TestEntity1,
|
||||
Time: models.CustomTime(suite.TestStartTime),
|
||||
Duration: 150 * time.Second,
|
||||
NumHeartbeats: 2,
|
||||
@ -55,6 +56,7 @@ func (suite *SummaryServiceTestSuite) SetupSuite() {
|
||||
OperatingSystem: TestOsLinux,
|
||||
Machine: TestMachine1,
|
||||
Branch: TestBranchMaster,
|
||||
Entity: TestEntity1,
|
||||
Time: models.CustomTime(suite.TestStartTime.Add((30 + 130) * time.Second)),
|
||||
Duration: 20 * time.Second,
|
||||
NumHeartbeats: 1,
|
||||
@ -67,6 +69,7 @@ func (suite *SummaryServiceTestSuite) SetupSuite() {
|
||||
OperatingSystem: TestOsLinux,
|
||||
Machine: TestMachine1,
|
||||
Branch: TestBranchDev,
|
||||
Entity: TestEntity1,
|
||||
Time: models.CustomTime(suite.TestStartTime.Add(3 * time.Minute)),
|
||||
Duration: 15 * time.Second,
|
||||
NumHeartbeats: 3,
|
||||
@ -154,6 +157,7 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Summarize() {
|
||||
assert.Equal(suite.T(), 185*time.Second, result.TotalTimeBy(models.SummaryLanguage))
|
||||
assert.Equal(suite.T(), 185*time.Second, result.TotalTimeBy(models.SummaryEditor))
|
||||
assert.Zero(suite.T(), result.TotalTimeBy(models.SummaryBranch)) // no filters -> no branches contained
|
||||
assert.Zero(suite.T(), result.TotalTimeBy(models.SummaryEntity)) // no filters -> no entities contained
|
||||
assert.Zero(suite.T(), result.TotalTimeBy(models.SummaryLabel))
|
||||
assert.Equal(suite.T(), 170*time.Second, result.TotalTimeByKey(models.SummaryEditor, TestEditorGoland))
|
||||
assert.Equal(suite.T(), 15*time.Second, result.TotalTimeByKey(models.SummaryEditor, TestEditorVscode))
|
||||
@ -477,6 +481,7 @@ func (suite *SummaryServiceTestSuite) TestSummaryService_Filters() {
|
||||
|
||||
result, _ := sut.Aliased(from, to, suite.TestUser, sut.Summarize, filters, false)
|
||||
assert.NotNil(suite.T(), result.Branches) // project filters were applied -> include branches
|
||||
assert.NotNil(suite.T(), result.Entities) // project filters were applied -> include entities
|
||||
|
||||
effectiveFilters := suite.DurationService.Calls[0].Arguments[3].(*models.Filters)
|
||||
assert.Contains(suite.T(), effectiveFilters.Project, TestProject1) // because actually requested
|
||||
|
Reference in New Issue
Block a user