refactor: show statistics data by authors intead of committers

This commit is contained in:
leo 2024-08-28 18:38:29 +08:00
parent 83b802e357
commit 3d57398d15
No known key found for this signature in database
10 changed files with 30 additions and 32 deletions

View file

@ -10,7 +10,7 @@ namespace SourceGit.Commands
WorkingDirectory = repo;
Context = repo;
Args = $"log --date-order --branches --remotes --since=\"{_statistics.Since()}\" --pretty=format:\"%ct$%cn\"";
Args = $"log --date-order --branches --remotes --since=\"{_statistics.Since()}\" --pretty=format:\"%ct$%an\"";
}
public Models.Statistics Result()

View file

@ -13,34 +13,34 @@ namespace SourceGit.Models
{
public int Total { get; set; } = 0;
public List<StatisticsSample> Samples { get; set; } = new List<StatisticsSample>();
public List<StatisticsSample> ByCommitter { get; set; } = new List<StatisticsSample>();
public List<StatisticsSample> ByAuthor { get; set; } = new List<StatisticsSample>();
public void AddCommit(int index, string committer)
public void AddCommit(int index, string author)
{
Total++;
Samples[index].Count++;
if (_mapByCommitter.TryGetValue(committer, out var value))
if (_mapUsers.TryGetValue(author, out var value))
{
value.Count++;
}
else
{
var sample = new StatisticsSample(committer);
var sample = new StatisticsSample(author);
sample.Count++;
_mapByCommitter.Add(committer, sample);
ByCommitter.Add(sample);
_mapUsers.Add(author, sample);
ByAuthor.Add(sample);
}
}
public void Complete()
{
ByCommitter.Sort((l, r) => r.Count - l.Count);
_mapByCommitter.Clear();
ByAuthor.Sort((l, r) => r.Count - l.Count);
_mapUsers.Clear();
}
private readonly Dictionary<string, StatisticsSample> _mapByCommitter = new Dictionary<string, StatisticsSample>();
private readonly Dictionary<string, StatisticsSample> _mapUsers = new Dictionary<string, StatisticsSample>();
}
public class Statistics
@ -72,16 +72,16 @@ namespace SourceGit.Models
return _today.AddMonths(-11).ToString("yyyy-MM-01 00:00:00");
}
public void AddCommit(string committer, double timestamp)
public void AddCommit(string author, double timestamp)
{
var time = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime();
if (time.CompareTo(_thisWeekStart) >= 0 && time.CompareTo(_thisWeekEnd) < 0)
Week.AddCommit((int)time.DayOfWeek, committer);
Week.AddCommit((int)time.DayOfWeek, author);
if (time.Month == _today.Month)
Month.AddCommit(time.Day - 1, committer);
Month.AddCommit(time.Day - 1, author);
Year.AddCommit(time.Month - 1, committer);
Year.AddCommit(time.Month - 1, author);
}
public void Complete()

View file

@ -555,9 +555,9 @@
<x:String x:Key="Text.Statistics.Committer" xml:space="preserve">COMMITTER</x:String>
<x:String x:Key="Text.Statistics.ThisMonth" xml:space="preserve">MONAT</x:String>
<x:String x:Key="Text.Statistics.ThisWeek" xml:space="preserve">WOCHE</x:String>
<x:String x:Key="Text.Statistics.ThisYear" xml:space="preserve">JAHR</x:String>
<x:String x:Key="Text.Statistics.MostRecentYear" xml:space="preserve">JAHR</x:String>
<x:String x:Key="Text.Statistics.TotalCommits" xml:space="preserve">COMMITS: </x:String>
<x:String x:Key="Text.Statistics.TotalCommitters" xml:space="preserve">COMMITTERS: </x:String>
<x:String x:Key="Text.Statistics.TotalAuthors" xml:space="preserve">AUTOREN: </x:String>
<x:String x:Key="Text.Submodule" xml:space="preserve">SUBMODULE</x:String>
<x:String x:Key="Text.Submodule.Add" xml:space="preserve">Submodul hinzufügen</x:String>
<x:String x:Key="Text.Submodule.CopyPath" xml:space="preserve">Relativen Pfad kopieren</x:String>

View file

@ -555,9 +555,9 @@
<x:String x:Key="Text.Statistics.Committer" xml:space="preserve">COMMITTER</x:String>
<x:String x:Key="Text.Statistics.ThisMonth" xml:space="preserve">MONTH</x:String>
<x:String x:Key="Text.Statistics.ThisWeek" xml:space="preserve">WEEK</x:String>
<x:String x:Key="Text.Statistics.ThisYear" xml:space="preserve">YEAR</x:String>
<x:String x:Key="Text.Statistics.MostRecentYear" xml:space="preserve">YEAR</x:String>
<x:String x:Key="Text.Statistics.TotalCommits" xml:space="preserve">COMMITS: </x:String>
<x:String x:Key="Text.Statistics.TotalCommitters" xml:space="preserve">COMMITTERS: </x:String>
<x:String x:Key="Text.Statistics.TotalAuthors" xml:space="preserve">AUTHORS: </x:String>
<x:String x:Key="Text.Submodule" xml:space="preserve">SUBMODULES</x:String>
<x:String x:Key="Text.Submodule.Add" xml:space="preserve">Add Submodule</x:String>
<x:String x:Key="Text.Submodule.CopyPath" xml:space="preserve">Copy Relative Path</x:String>

View file

@ -554,9 +554,9 @@
<x:String x:Key="Text.Statistics.Committer" xml:space="preserve">COMMITTER</x:String>
<x:String x:Key="Text.Statistics.ThisMonth" xml:space="preserve">MONTH</x:String>
<x:String x:Key="Text.Statistics.ThisWeek" xml:space="preserve">WEEK</x:String>
<x:String x:Key="Text.Statistics.ThisYear" xml:space="preserve">YEAR</x:String>
<x:String x:Key="Text.Statistics.MostRecentYear" xml:space="preserve">YEAR</x:String>
<x:String x:Key="Text.Statistics.TotalCommits" xml:space="preserve">COMMITS: </x:String>
<x:String x:Key="Text.Statistics.TotalCommitters" xml:space="preserve">COMMITTERS: </x:String>
<x:String x:Key="Text.Statistics.TotalAuthors" xml:space="preserve">AUTHORS: </x:String>
<x:String x:Key="Text.Submodule" xml:space="preserve">SUBMODULES</x:String>
<x:String x:Key="Text.Submodule.Add" xml:space="preserve">Add Submodule</x:String>
<x:String x:Key="Text.Submodule.CopyPath" xml:space="preserve">Copy Relative Path</x:String>

View file

@ -547,9 +547,9 @@
<x:String x:Key="Text.Statistics.Committer" xml:space="preserve">COMMITTER</x:String>
<x:String x:Key="Text.Statistics.ThisMonth" xml:space="preserve">MÊS</x:String>
<x:String x:Key="Text.Statistics.ThisWeek" xml:space="preserve">SEMANA</x:String>
<x:String x:Key="Text.Statistics.ThisYear" xml:space="preserve">ANO</x:String>
<x:String x:Key="Text.Statistics.MostRecentYear" xml:space="preserve">ANO</x:String>
<x:String x:Key="Text.Statistics.TotalCommits" xml:space="preserve">COMMITS: </x:String>
<x:String x:Key="Text.Statistics.TotalCommitters" xml:space="preserve">COMMITTERS: </x:String>
<x:String x:Key="Text.Statistics.TotalAuthors" xml:space="preserve">AUTORES: </x:String>
<x:String x:Key="Text.Submodule" xml:space="preserve">SUBMÓDULOS</x:String>
<x:String x:Key="Text.Submodule.Add" xml:space="preserve">Adicionar Submódulo</x:String>
<x:String x:Key="Text.Submodule.CopyPath" xml:space="preserve">Copiar Caminho Relativo</x:String>

View file

@ -557,9 +557,9 @@
<x:String x:Key="Text.Statistics.Committer" xml:space="preserve">提交者</x:String>
<x:String x:Key="Text.Statistics.ThisMonth" xml:space="preserve">本月</x:String>
<x:String x:Key="Text.Statistics.ThisWeek" xml:space="preserve">本周</x:String>
<x:String x:Key="Text.Statistics.ThisYear" xml:space="preserve">最近一年</x:String>
<x:String x:Key="Text.Statistics.MostRecentYear" xml:space="preserve">最近一年</x:String>
<x:String x:Key="Text.Statistics.TotalCommits" xml:space="preserve">提交次数: </x:String>
<x:String x:Key="Text.Statistics.TotalCommitters" xml:space="preserve">提交者: </x:String>
<x:String x:Key="Text.Statistics.TotalAuthors" xml:space="preserve">贡献者人数: </x:String>
<x:String x:Key="Text.Submodule" xml:space="preserve">子模块</x:String>
<x:String x:Key="Text.Submodule.Add" xml:space="preserve">添加子模块</x:String>
<x:String x:Key="Text.Submodule.CopyPath" xml:space="preserve">复制路径</x:String>

View file

@ -558,9 +558,9 @@
<x:String x:Key="Text.Statistics.Committer" xml:space="preserve">提交者</x:String>
<x:String x:Key="Text.Statistics.ThisMonth" xml:space="preserve">本月</x:String>
<x:String x:Key="Text.Statistics.ThisWeek" xml:space="preserve">本週</x:String>
<x:String x:Key="Text.Statistics.ThisYear" xml:space="preserve">最近一年</x:String>
<x:String x:Key="Text.Statistics.MostRecentYear" xml:space="preserve">最近一年</x:String>
<x:String x:Key="Text.Statistics.TotalCommits" xml:space="preserve">提交次數:</x:String>
<x:String x:Key="Text.Statistics.TotalCommitters" xml:space="preserve">提交者:</x:String>
<x:String x:Key="Text.Statistics.TotalAuthors" xml:space="preserve">貢獻者人數:</x:String>
<x:String x:Key="Text.Submodule" xml:space="preserve">子模組</x:String>
<x:String x:Key="Text.Submodule.Add" xml:space="preserve">新增子模組</x:String>
<x:String x:Key="Text.Submodule.CopyPath" xml:space="preserve">複製路徑</x:String>

View file

@ -1,7 +1,5 @@
using System.Threading.Tasks;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels

View file

@ -110,7 +110,7 @@
<ListBoxItem>
<Border Classes="switcher_bg">
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.ThisYear}"/>
<TextBlock Classes="view_mode_switcher" Text="{DynamicResource Text.Statistics.MostRecentYear}"/>
</Border>
</ListBoxItem>
@ -135,7 +135,7 @@
<Grid Grid.Column="0" RowDefinitions="*,16">
<!-- Table By Committer -->
<ListBox Grid.Column="0"
ItemsSource="{Binding ByCommitter}"
ItemsSource="{Binding ByAuthor}"
SelectionMode="Single"
BorderThickness="1"
BorderBrush="{DynamicResource Brush.Border2}"
@ -176,8 +176,8 @@
<Grid Grid.Row="1" ColumnDefinitions="*,*">
<!-- Total Committers -->
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBlock Classes="primary" Text="{DynamicResource Text.Statistics.TotalCommitters}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Classes="primary" Text="{Binding ByCommitter.Count}" FontSize="11" Margin="4,0,0,0"/>
<TextBlock Classes="primary" Text="{DynamicResource Text.Statistics.TotalAuthors}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Classes="primary" Text="{Binding ByAuthor.Count}" FontSize="11" Margin="4,0,0,0"/>
</StackPanel>
<!-- Total Commits -->