diff --git a/README.md b/README.md index 92be3da..2c88daa 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ INSERT INTO aliases (`type`, `user_id`, `key`, `value`) VALUES (0, 'your_usernam * Language ~ type **1** * Editor ~ type **2** * OS ~ type **3** +* Machine ~ type **4** **NOTE:** In order for the aliases to take effect for non-live statistics, you would either have to wait 24 hours for the cache to be invalidated or restart Wakapi. diff --git a/models/summary.go b/models/summary.go index b862451..4fed09b 100644 --- a/models/summary.go +++ b/models/summary.go @@ -5,11 +5,12 @@ import ( ) const ( - NSummaryTypes uint8 = 4 + NSummaryTypes uint8 = 99 SummaryProject uint8 = 0 SummaryLanguage uint8 = 1 SummaryEditor uint8 = 2 SummaryOS uint8 = 3 + SummaryMachine uint8 = 4 ) type Summary struct { @@ -21,6 +22,7 @@ type Summary struct { Languages []*SummaryItem `json:"languages"` Editors []*SummaryItem `json:"editors"` OperatingSystems []*SummaryItem `json:"operating_systems"` + Machines []*SummaryItem `json:"machines"` } type SummaryItem struct { diff --git a/services/summary.go b/services/summary.go index 4553b6c..a029f6e 100644 --- a/services/summary.go +++ b/services/summary.go @@ -65,12 +65,13 @@ func (srv *SummaryService) Construct(from, to time.Time, user *models.User, reco heartbeats = append(heartbeats, hb...) } - types := []uint8{models.SummaryProject, models.SummaryLanguage, models.SummaryEditor, models.SummaryOS} + types := []uint8{models.SummaryProject, models.SummaryLanguage, models.SummaryEditor, models.SummaryOS, models.SummaryMachine} var projectItems []*models.SummaryItem var languageItems []*models.SummaryItem var editorItems []*models.SummaryItem var osItems []*models.SummaryItem + var machineItems []*models.SummaryItem if err := srv.AliasService.LoadUserAliases(user.ID); err != nil { return nil, err @@ -92,6 +93,8 @@ func (srv *SummaryService) Construct(from, to time.Time, user *models.User, reco editorItems = item.Items case models.SummaryOS: osItems = item.Items + case models.SummaryMachine: + machineItems = item.Items } } close(c) @@ -119,6 +122,7 @@ func (srv *SummaryService) Construct(from, to time.Time, user *models.User, reco Languages: languageItems, Editors: editorItems, OperatingSystems: osItems, + Machines: machineItems, } allSummaries := []*models.Summary{aggregatedSummary} @@ -154,6 +158,7 @@ func (srv *SummaryService) GetByUserWithin(user *models.User, from, to time.Time Preload("Languages", "type = ?", models.SummaryLanguage). Preload("Editors", "type = ?", models.SummaryEditor). Preload("OperatingSystems", "type = ?", models.SummaryOS). + Preload("Machines", "type = ?", models.SummaryMachine). Find(&summaries).Error; err != nil { return nil, err } @@ -187,6 +192,8 @@ func (srv *SummaryService) aggregateBy(heartbeats []*models.Heartbeat, summaryTy key = h.Language case models.SummaryOS: key = h.OperatingSystem + case models.SummaryMachine: + key = h.Machine } if key == "" { @@ -276,6 +283,7 @@ func mergeSummaries(summaries []*models.Summary) (*models.Summary, error) { Languages: make([]*models.SummaryItem, 0), Editors: make([]*models.SummaryItem, 0), OperatingSystems: make([]*models.SummaryItem, 0), + Machines: make([]*models.SummaryItem, 0), } for _, s := range summaries { @@ -295,6 +303,7 @@ func mergeSummaries(summaries []*models.Summary) (*models.Summary, error) { finalSummary.Languages = mergeSummaryItems(finalSummary.Languages, s.Languages) finalSummary.Editors = mergeSummaryItems(finalSummary.Editors, s.Editors) finalSummary.OperatingSystems = mergeSummaryItems(finalSummary.OperatingSystems, s.OperatingSystems) + finalSummary.Machines = mergeSummaryItems(finalSummary.Machines, s.Machines) } finalSummary.FromTime = minTime diff --git a/static/assets/app.js b/static/assets/app.js index 8f10f95..e587b83 100644 --- a/static/assets/app.js +++ b/static/assets/app.js @@ -5,6 +5,7 @@ const projectsCanvas = document.getElementById('chart-projects') const osCanvas = document.getElementById('chart-os') const editorsCanvas = document.getElementById('chart-editor') const languagesCanvas = document.getElementById('chart-language') +const machinesCanvas = document.getElementById('chart-machine') let charts = [] let resizeCount = 0 @@ -135,10 +136,31 @@ function draw() { } }) + let machineChart = new Chart(machinesCanvas.getContext('2d'), { + type: 'pie', + data: { + datasets: [{ + data: wakapiData.machines + .slice(0, Math.min(SHOW_TOP_N, wakapiData.machines.length)) + .map(p => parseInt(p.total)), + backgroundColor: wakapiData.machines.map(p => getRandomColor(p.key)) + }], + labels: wakapiData.machines + .slice(0, Math.min(SHOW_TOP_N, wakapiData.machines.length)) + .map(p => p.key) + }, + options: { + title: Object.assign(titleOptions, {text: `Machines (top ${SHOW_TOP_N})`}), + tooltips: getTooltipOptions('machines', 'pie'), + maintainAspectRatio: false, + onResize: onChartResize + } + }) + getTotal(wakapiData.operatingSystems) document.getElementById('grid-container').style.visibility = 'visible' - charts = [projectChart, osChart, editorChart, languageChart] + charts = [projectChart, osChart, editorChart, languageChart, machineChart] charts.forEach(c => c.options.onResize(c.chart)) equalizeHeights() diff --git a/version.txt b/version.txt index d263485..afa2b35 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.7.6 \ No newline at end of file +1.8.0 \ No newline at end of file diff --git a/views/foot.tpl.html b/views/foot.tpl.html index e0f451e..906ab16 100644 --- a/views/foot.tpl.html +++ b/views/foot.tpl.html @@ -2,11 +2,13 @@ \ No newline at end of file diff --git a/views/summary.tpl.html b/views/summary.tpl.html index 3512935..3ef2340 100644 --- a/views/summary.tpl.html +++ b/views/summary.tpl.html @@ -78,6 +78,11 @@ +