diff --git a/src/Models/StatisticSample.cs b/src/Models/StatisticSample.cs
index 1e59371b..1fa7283b 100644
--- a/src/Models/StatisticSample.cs
+++ b/src/Models/StatisticSample.cs
@@ -3,6 +3,10 @@
/// 统计图表样品
///
public class StatisticSample {
+ ///
+ /// 在图表中的顺序
+ ///
+ public int Index { get; set; }
///
/// 样品名
///
diff --git a/src/Resources/Locales/en_US.xaml b/src/Resources/Locales/en_US.xaml
index 09a0e93a..62686a51 100644
--- a/src/Resources/Locales/en_US.xaml
+++ b/src/Resources/Locales/en_US.xaml
@@ -491,6 +491,7 @@
Statistics
WEEK
MONTH
+ YEAR
Total Committers: {0}
Total Commits:{0}
COMMITTER
@@ -504,6 +505,19 @@
FRI
SAT
+ Jan
+ Feb
+ Mar
+ Apr
+ May
+ Jun
+ Jul
+ Aug
+ Sep
+ Oct
+ Nov
+ Dec
+
Git has NOT been configured. Please to go [Preference] and configure it first.
Path[{0}] not exists!
Can NOT locate bash.exe. Make sure bash.exe exists under the same folder with git.exe
diff --git a/src/Resources/Locales/zh_CN.xaml b/src/Resources/Locales/zh_CN.xaml
index 0fd48163..60521cd5 100644
--- a/src/Resources/Locales/zh_CN.xaml
+++ b/src/Resources/Locales/zh_CN.xaml
@@ -490,6 +490,7 @@
提交统计
本周
本月
+ 本年
提交者人数:{0}
总计提交次数:{0}
提交者
@@ -503,6 +504,19 @@
星期五
星期六
+ 1月
+ 2月
+ 3月
+ 4月
+ 5月
+ 6月
+ 7月
+ 8月
+ 9月
+ 10月
+ 11月
+ 12月
+
GIT尚未配置。请打开【偏好设置】配置GIT路径。
路径({0})不存在或不可读取!
无法找到bash.exe,请确保其在git.exe同目录中!
diff --git a/src/Views/Statistics.xaml b/src/Views/Statistics.xaml
index 68ab4b15..c9431ab1 100644
--- a/src/Views/Statistics.xaml
+++ b/src/Views/Statistics.xaml
@@ -6,6 +6,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="clr-namespace:SourceGit.Views.Controls"
+ xmlns:widgets="clr-namespace:SourceGit.Views.Widgets"
mc:Ignorable="d"
Title="Statistics"
Height="450" Width="600"
@@ -50,142 +51,13 @@
Margin="8"
Style="{DynamicResource Style.TabControl.MiddleSwitch}">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
diff --git a/src/Views/Statistics.xaml.cs b/src/Views/Statistics.xaml.cs
index 58734af0..ad480931 100644
--- a/src/Views/Statistics.xaml.cs
+++ b/src/Views/Statistics.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Threading.Tasks;
using System.Windows;
@@ -25,6 +26,7 @@ namespace SourceGit.Views {
for (int i = 0; i < 7; i++) {
mapsWeek.Add(i, new Models.StatisticSample {
Name = App.Text($"Weekday.{i}"),
+ Index = i,
Count = 0,
});
}
@@ -35,23 +37,39 @@ namespace SourceGit.Views {
for (int i = 1; i <= maxDays; i++) {
mapsMonth.Add(i, new Models.StatisticSample {
Name = $"{i}",
+ Index = i,
+ Count = 0,
+ });
+ }
+
+ var mapsYear = new Dictionary();
+ for (int i = 1; i <= 12; i++) {
+ mapsYear.Add(i, new Models.StatisticSample {
+ Name = App.Text($"Month.{i}"),
+ Index = i,
Count = 0,
});
}
var mapCommitterWeek = new Dictionary();
var mapCommitterMonth = new Dictionary();
+ var mapCommitterYear = new Dictionary();
+
var weekStart = today.AddSeconds(-(int)today.DayOfWeek * 3600 * 24 - today.Hour * 3600 - today.Minute * 60 - today.Second);
var weekEnd = weekStart.AddDays(7);
+ var month = today.Month;
- var limits = $"--branches --remotes --since=\"{today.ToString("yyyy-MM-01 00:00:00")}\"";
+ var limits = $"--branches --remotes --since=\"{today.ToString("yyyy-01-01 00:00:00")}\"";
var commits = new Commands.Commits(repo, limits).Result();
- var totalCommitsMonth = commits.Count;
var totalCommitsWeek = 0;
+ var totalCommitsMonth = 0;
+ var totalCommitsYear = commits.Count;
foreach (var c in commits) {
var commitTime = DateTime.Parse(c.Committer.Time);
if (commitTime.CompareTo(weekStart) >= 0 && commitTime.CompareTo(weekEnd) < 0) {
mapsWeek[(int)commitTime.DayOfWeek].Count++;
+ totalCommitsWeek++;
+
if (mapCommitterWeek.ContainsKey(c.Committer.Name)) {
mapCommitterWeek[c.Committer.Name].Count++;
} else {
@@ -60,53 +78,55 @@ namespace SourceGit.Views {
Count = 1,
};
}
-
- totalCommitsWeek++;
}
- mapsMonth[commitTime.Day].Count++;
+ if (commitTime.Month == month) {
+ mapsMonth[commitTime.Day].Count++;
+ totalCommitsMonth++;
- if (mapCommitterMonth.ContainsKey(c.Committer.Name)) {
- mapCommitterMonth[c.Committer.Name].Count++;
+ if (mapCommitterMonth.ContainsKey(c.Committer.Name)) {
+ mapCommitterMonth[c.Committer.Name].Count++;
+ } else {
+ mapCommitterMonth[c.Committer.Name] = new Models.StatisticSample {
+ Name = c.Committer.Name,
+ Count = 1,
+ };
+ }
+ }
+
+ mapsYear[commitTime.Month].Count++;
+ if (mapCommitterYear.ContainsKey(c.Committer.Name)) {
+ mapCommitterYear[c.Committer.Name].Count++;
} else {
- mapCommitterMonth[c.Committer.Name] = new Models.StatisticSample {
+ mapCommitterYear[c.Committer.Name] = new Models.StatisticSample {
Name = c.Committer.Name,
Count = 1,
};
}
}
- var samplesChartWeek = new List();
- var samplesChartMonth = new List();
- var samplesCommittersWeek = new List();
- var samplesCommittersMonth = new List();
- for (int i = 0; i < 7; i++) samplesChartWeek.Add(mapsWeek[i]);
- for (int i = 1; i <= maxDays; i++) samplesChartMonth.Add(mapsMonth[i]);
- foreach (var kv in mapCommitterWeek) samplesCommittersWeek.Add(kv.Value);
- foreach (var kv in mapCommitterMonth) samplesCommittersMonth.Add(kv.Value);
+ SetPage(pageWeek, mapCommitterWeek.Values.ToList(), mapsWeek.Values.ToList(), totalCommitsWeek);
+ SetPage(pageMonth, mapCommitterMonth.Values.ToList(), mapsMonth.Values.ToList(), totalCommitsMonth);
+ SetPage(pageYear, mapCommitterYear.Values.ToList(), mapsYear.Values.ToList(), totalCommitsYear);
+
mapsMonth.Clear();
mapsWeek.Clear();
+ mapsYear.Clear();
mapCommitterMonth.Clear();
mapCommitterWeek.Clear();
+ mapCommitterYear.Clear();
commits.Clear();
- samplesCommittersWeek.Sort((x, y) => y.Count - x.Count);
- samplesCommittersMonth.Sort((x, y) => y.Count - x.Count);
Dispatcher.Invoke(() => {
loading.IsAnimating = false;
loading.Visibility = Visibility.Collapsed;
-
- chartWeek.SetData(samplesChartWeek);
- chartMonth.SetData(samplesChartMonth);
-
- lstCommitterWeek.ItemsSource = samplesCommittersWeek;
- lstCommitterMonth.ItemsSource = samplesCommittersMonth;
-
- txtMemberCountWeek.Text = App.Text("Statistics.TotalCommitterCount", samplesCommittersWeek.Count);
- txtMemberCountMonth.Text = App.Text("Statistics.TotalCommitterCount", samplesCommittersMonth.Count);
- txtCommitCountWeek.Text = App.Text("Statistics.TotalCommitsCount", totalCommitsWeek);
- txtCommitCountMonth.Text = App.Text("Statistics.TotalCommitsCount", totalCommitsMonth);
});
}
+
+ private void SetPage(Widgets.StatisticsPage page, List committers, List commits, int total) {
+ committers.Sort((x, y) => y.Count - x.Count);
+ commits.Sort((x, y) => x.Index - y.Index);
+ page.SetData(committers, commits, total);
+ }
}
}
diff --git a/src/Views/Widgets/StatisticsPage.xaml b/src/Views/Widgets/StatisticsPage.xaml
new file mode 100644
index 00000000..23559ae9
--- /dev/null
+++ b/src/Views/Widgets/StatisticsPage.xaml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Views/Widgets/StatisticsPage.xaml.cs b/src/Views/Widgets/StatisticsPage.xaml.cs
new file mode 100644
index 00000000..5790a4f6
--- /dev/null
+++ b/src/Views/Widgets/StatisticsPage.xaml.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+using System.Windows.Controls;
+
+namespace SourceGit.Views.Widgets {
+ ///
+ /// 统计内容
+ ///
+ public partial class StatisticsPage : UserControl {
+
+ public StatisticsPage() {
+ InitializeComponent();
+ }
+
+ public void SetData(List committers, List commits, int totalCommits) {
+ Dispatcher.Invoke(() => {
+ txtMemberCount.Text = App.Text("Statistics.TotalCommitterCount", committers.Count);
+ txtCommitCount.Text = App.Text("Statistics.TotalCommitsCount", totalCommits);
+
+ lstCommitters.ItemsSource = committers;
+ chartCommits.SetData(commits);
+ });
+ }
+ }
+}