2022-01-11 04:18:35 -08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2022-01-12 02:38:03 -08:00
|
|
|
|
using System.Linq;
|
2022-01-11 04:18:35 -08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace SourceGit.Views {
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 提交统计
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class Statistics : Controls.Window {
|
|
|
|
|
private string repo = null;
|
|
|
|
|
|
|
|
|
|
public Statistics(string repo) {
|
|
|
|
|
this.repo = repo;
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Task.Run(Refresh);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Quit(object sender, RoutedEventArgs e) {
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Refresh() {
|
|
|
|
|
var mapsWeek = new Dictionary<int, Models.StatisticSample>();
|
|
|
|
|
for (int i = 0; i < 7; i++) {
|
|
|
|
|
mapsWeek.Add(i, new Models.StatisticSample {
|
2022-01-11 04:35:17 -08:00
|
|
|
|
Name = App.Text($"Weekday.{i}"),
|
2022-01-12 02:38:03 -08:00
|
|
|
|
Index = i,
|
2022-01-11 04:18:35 -08:00
|
|
|
|
Count = 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mapsMonth = new Dictionary<int, Models.StatisticSample>();
|
|
|
|
|
var today = DateTime.Now;
|
|
|
|
|
var maxDays = DateTime.DaysInMonth(today.Year, today.Month);
|
|
|
|
|
for (int i = 1; i <= maxDays; i++) {
|
|
|
|
|
mapsMonth.Add(i, new Models.StatisticSample {
|
|
|
|
|
Name = $"{i}",
|
2022-01-12 02:38:03 -08:00
|
|
|
|
Index = i,
|
|
|
|
|
Count = 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mapsYear = new Dictionary<int, Models.StatisticSample>();
|
|
|
|
|
for (int i = 1; i <= 12; i++) {
|
|
|
|
|
mapsYear.Add(i, new Models.StatisticSample {
|
|
|
|
|
Name = App.Text($"Month.{i}"),
|
|
|
|
|
Index = i,
|
2022-01-11 04:18:35 -08:00
|
|
|
|
Count = 0,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var mapCommitterWeek = new Dictionary<string, Models.StatisticSample>();
|
|
|
|
|
var mapCommitterMonth = new Dictionary<string, Models.StatisticSample>();
|
2022-01-12 02:38:03 -08:00
|
|
|
|
var mapCommitterYear = new Dictionary<string, Models.StatisticSample>();
|
|
|
|
|
|
2022-01-12 01:28:46 -08:00
|
|
|
|
var weekStart = today.AddSeconds(-(int)today.DayOfWeek * 3600 * 24 - today.Hour * 3600 - today.Minute * 60 - today.Second);
|
2022-01-12 01:26:30 -08:00
|
|
|
|
var weekEnd = weekStart.AddDays(7);
|
2022-01-12 02:38:03 -08:00
|
|
|
|
var month = today.Month;
|
2022-01-11 04:18:35 -08:00
|
|
|
|
|
2022-01-12 02:38:03 -08:00
|
|
|
|
var limits = $"--branches --remotes --since=\"{today.ToString("yyyy-01-01 00:00:00")}\"";
|
2022-01-11 04:18:35 -08:00
|
|
|
|
var commits = new Commands.Commits(repo, limits).Result();
|
|
|
|
|
var totalCommitsWeek = 0;
|
2022-01-12 02:38:03 -08:00
|
|
|
|
var totalCommitsMonth = 0;
|
|
|
|
|
var totalCommitsYear = commits.Count;
|
2022-01-11 04:18:35 -08:00
|
|
|
|
foreach (var c in commits) {
|
|
|
|
|
var commitTime = DateTime.Parse(c.Committer.Time);
|
2022-01-12 01:26:30 -08:00
|
|
|
|
if (commitTime.CompareTo(weekStart) >= 0 && commitTime.CompareTo(weekEnd) < 0) {
|
2022-01-11 04:18:35 -08:00
|
|
|
|
mapsWeek[(int)commitTime.DayOfWeek].Count++;
|
2022-01-12 02:38:03 -08:00
|
|
|
|
totalCommitsWeek++;
|
|
|
|
|
|
2022-01-11 04:18:35 -08:00
|
|
|
|
if (mapCommitterWeek.ContainsKey(c.Committer.Name)) {
|
|
|
|
|
mapCommitterWeek[c.Committer.Name].Count++;
|
|
|
|
|
} else {
|
|
|
|
|
mapCommitterWeek[c.Committer.Name] = new Models.StatisticSample {
|
|
|
|
|
Name = c.Committer.Name,
|
|
|
|
|
Count = 1,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 02:38:03 -08:00
|
|
|
|
if (commitTime.Month == month) {
|
|
|
|
|
mapsMonth[commitTime.Day].Count++;
|
|
|
|
|
totalCommitsMonth++;
|
2022-01-11 04:18:35 -08:00
|
|
|
|
|
2022-01-12 02:38:03 -08:00
|
|
|
|
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++;
|
2022-01-11 04:18:35 -08:00
|
|
|
|
} else {
|
2022-01-12 02:38:03 -08:00
|
|
|
|
mapCommitterYear[c.Committer.Name] = new Models.StatisticSample {
|
2022-01-11 04:18:35 -08:00
|
|
|
|
Name = c.Committer.Name,
|
|
|
|
|
Count = 1,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-12 02:38:03 -08:00
|
|
|
|
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);
|
|
|
|
|
|
2022-01-11 04:18:35 -08:00
|
|
|
|
mapsMonth.Clear();
|
|
|
|
|
mapsWeek.Clear();
|
2022-01-12 02:38:03 -08:00
|
|
|
|
mapsYear.Clear();
|
2022-01-11 04:18:35 -08:00
|
|
|
|
mapCommitterMonth.Clear();
|
|
|
|
|
mapCommitterWeek.Clear();
|
2022-01-12 02:38:03 -08:00
|
|
|
|
mapCommitterYear.Clear();
|
2022-01-11 04:18:35 -08:00
|
|
|
|
commits.Clear();
|
|
|
|
|
|
|
|
|
|
Dispatcher.Invoke(() => {
|
|
|
|
|
loading.IsAnimating = false;
|
|
|
|
|
loading.Visibility = Visibility.Collapsed;
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-01-12 02:38:03 -08:00
|
|
|
|
|
|
|
|
|
private void SetPage(Widgets.StatisticsPage page, List<Models.StatisticSample> committers, List<Models.StatisticSample> commits, int total) {
|
|
|
|
|
committers.Sort((x, y) => y.Count - x.Count);
|
|
|
|
|
commits.Sort((x, y) => x.Index - y.Index);
|
|
|
|
|
page.SetData(committers, commits, total);
|
|
|
|
|
}
|
2022-01-11 04:18:35 -08:00
|
|
|
|
}
|
|
|
|
|
}
|