refactor: statistics dialog

- use `%aN+%aE` instead of `%aN` to get commit author
- show user avatar in statistics dialog

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo 2025-04-07 21:20:59 +08:00
parent 1555abd027
commit 7cda7211f1
No known key found for this signature in database
3 changed files with 20 additions and 14 deletions

View file

@ -8,7 +8,7 @@ namespace SourceGit.Commands
{
WorkingDirectory = repo;
Context = repo;
Args = $"log --date-order --branches --remotes -{max} --format=%ct$%aN";
Args = $"log --date-order --branches --remotes -{max} --format=%ct$%aN±%aE";
}
public Models.Statistics Result()

View file

@ -18,9 +18,9 @@ namespace SourceGit.Models
ThisWeek,
}
public class StaticsticsAuthor(string name, int count)
public class StaticsticsAuthor(User user, int count)
{
public string Name { get; set; } = name;
public User User { get; set; } = user;
public int Count { get; set; } = count;
}
@ -73,7 +73,7 @@ namespace SourceGit.Models
}
}
public void AddCommit(DateTime time, string author)
public void AddCommit(DateTime time, User author)
{
Total++;
@ -126,7 +126,7 @@ namespace SourceGit.Models
}
private StaticsticsMode _mode = StaticsticsMode.All;
private Dictionary<string, int> _mapUsers = new Dictionary<string, int>();
private Dictionary<User, int> _mapUsers = new Dictionary<User, int>();
private Dictionary<DateTime, int> _mapSamples = new Dictionary<DateTime, int>();
}
@ -150,14 +150,16 @@ namespace SourceGit.Models
public void AddCommit(string author, double timestamp)
{
var user = User.FindOrAdd(author);
var time = DateTime.UnixEpoch.AddSeconds(timestamp).ToLocalTime();
if (time >= _thisWeekStart)
Week.AddCommit(time, author);
Week.AddCommit(time, user);
if (time >= _thisMonthStart)
Month.AddCommit(time, author);
Month.AddCommit(time, user);
All.AddCommit(time, author);
All.AddCommit(time, user);
}
public void Complete()

View file

@ -136,7 +136,7 @@
<DataTemplate DataType="m:StatisticsReport">
<Grid ColumnDefinitions="256,*">
<Grid Grid.Column="0" RowDefinitions="*,16">
<!-- Table By Committer -->
<!-- Table By Autor -->
<ListBox Grid.Column="0"
ItemsSource="{Binding Authors}"
SelectionMode="Single"
@ -162,11 +162,15 @@
<ListBox.ItemTemplate>
<DataTemplate DataType="m:StaticsticsAuthor">
<Border BorderThickness="0,0,0,1" BorderBrush="{DynamicResource Brush.Border2}">
<Grid ColumnDefinitions="*,100">
<Border Grid.Column="0" Padding="8,0" ClipToBounds="True">
<TextBlock Text="{Binding Name}" HorizontalAlignment="Left"/>
<Grid ColumnDefinitions="26,*,100">
<v:Avatar Grid.Column="0"
Width="16" Height="16"
HorizontalAlignment="Center" VerticalAlignment="Center"
User="{Binding User}"/>
<Border Grid.Column="1" Padding="4,0,8,0" ClipToBounds="True">
<TextBlock Text="{Binding User.Name}" HorizontalAlignment="Left"/>
</Border>
<Border Grid.Column="1" Padding="8,0" ClipToBounds="True">
<Border Grid.Column="2" Padding="8,0" ClipToBounds="True">
<TextBlock Text="{Binding Count}" HorizontalAlignment="Right"/>
</Border>
</Grid>
@ -177,7 +181,7 @@
<!-- Summary -->
<Grid Grid.Row="1" ColumnDefinitions="*,*">
<!-- Total Committers -->
<!-- Total Authors -->
<StackPanel Grid.Column="0" Orientation="Horizontal" VerticalAlignment="Bottom">
<TextBlock Classes="primary" Text="{DynamicResource Text.Statistics.TotalAuthors}" FontSize="11" Foreground="{DynamicResource Brush.FG2}"/>
<TextBlock Classes="primary" Text="{Binding Authors.Count}" FontSize="11" Margin="4,0,0,0"/>