mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-05-21 04:04:59 +00:00
style: add .editorconfig for code formatting. see issu #25
This commit is contained in:
parent
a8eeea4f78
commit
18aaa0a143
225 changed files with 7781 additions and 3911 deletions
|
@ -1,44 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SourceGit.Models {
|
||||
public class StatisticsSample {
|
||||
namespace SourceGit.Models
|
||||
{
|
||||
public class StatisticsSample
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
|
||||
public class StatisticsReport {
|
||||
public class StatisticsReport
|
||||
{
|
||||
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 void AddCommit(int index, string committer) {
|
||||
public void AddCommit(int index, string committer)
|
||||
{
|
||||
Total++;
|
||||
Samples[index].Count++;
|
||||
|
||||
if (_mapByCommitter.ContainsKey(committer)) {
|
||||
if (_mapByCommitter.ContainsKey(committer))
|
||||
{
|
||||
_mapByCommitter[committer].Count++;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
var sample = new StatisticsSample() { Name = committer, Count = 1 };
|
||||
_mapByCommitter.Add(committer, sample);
|
||||
ByCommitter.Add(sample);
|
||||
}
|
||||
}
|
||||
|
||||
public void Complete() {
|
||||
public void Complete()
|
||||
{
|
||||
ByCommitter.Sort((l, r) => r.Count - l.Count);
|
||||
_mapByCommitter.Clear();
|
||||
}
|
||||
|
||||
private Dictionary<string, StatisticsSample> _mapByCommitter = new Dictionary<string, StatisticsSample>();
|
||||
private readonly Dictionary<string, StatisticsSample> _mapByCommitter = new Dictionary<string, StatisticsSample>();
|
||||
}
|
||||
|
||||
public class Statistics {
|
||||
public class Statistics
|
||||
{
|
||||
public StatisticsReport Year { get; set; } = new StatisticsReport();
|
||||
public StatisticsReport Month { get; set; } = new StatisticsReport();
|
||||
public StatisticsReport Week { get; set; } = new StatisticsReport();
|
||||
|
||||
public Statistics() {
|
||||
public Statistics()
|
||||
{
|
||||
_utcStart = DateTime.UnixEpoch;
|
||||
_today = DateTime.Today;
|
||||
_thisWeekStart = _today.AddSeconds(-(int)_today.DayOfWeek * 3600 * 24 - _today.Hour * 3600 - _today.Minute * 60 - _today.Second);
|
||||
|
@ -59,16 +69,20 @@ namespace SourceGit.Models {
|
|||
"Dec",
|
||||
];
|
||||
|
||||
for (int i = 0; i < monthNames.Length; i++) {
|
||||
Year.Samples.Add(new StatisticsSample {
|
||||
for (int i = 0; i < monthNames.Length; i++)
|
||||
{
|
||||
Year.Samples.Add(new StatisticsSample
|
||||
{
|
||||
Name = monthNames[i],
|
||||
Count = 0,
|
||||
});
|
||||
}
|
||||
|
||||
var monthDays = DateTime.DaysInMonth(_today.Year, _today.Month);
|
||||
for (int i = 0; i < monthDays; i++) {
|
||||
Month.Samples.Add(new StatisticsSample {
|
||||
for (int i = 0; i < monthDays; i++)
|
||||
{
|
||||
Month.Samples.Add(new StatisticsSample
|
||||
{
|
||||
Name = $"{i + 1}",
|
||||
Count = 0,
|
||||
});
|
||||
|
@ -84,40 +98,47 @@ namespace SourceGit.Models {
|
|||
"SAT",
|
||||
];
|
||||
|
||||
for (int i = 0; i < weekDayNames.Length; i++) {
|
||||
Week.Samples.Add(new StatisticsSample {
|
||||
for (int i = 0; i < weekDayNames.Length; i++)
|
||||
{
|
||||
Week.Samples.Add(new StatisticsSample
|
||||
{
|
||||
Name = weekDayNames[i],
|
||||
Count = 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public string Since() {
|
||||
public string Since()
|
||||
{
|
||||
return _today.ToString("yyyy-01-01 00:00:00");
|
||||
}
|
||||
|
||||
public void AddCommit(string committer, double timestamp) {
|
||||
public void AddCommit(string committer, double timestamp)
|
||||
{
|
||||
var time = _utcStart.AddSeconds(timestamp).ToLocalTime();
|
||||
if (time.CompareTo(_thisWeekStart) >= 0 && time.CompareTo(_thisWeekEnd) < 0) {
|
||||
if (time.CompareTo(_thisWeekStart) >= 0 && time.CompareTo(_thisWeekEnd) < 0)
|
||||
{
|
||||
Week.AddCommit((int)time.DayOfWeek, committer);
|
||||
}
|
||||
|
||||
if (time.Month == _today.Month) {
|
||||
if (time.Month == _today.Month)
|
||||
{
|
||||
Month.AddCommit(time.Day - 1, committer);
|
||||
}
|
||||
|
||||
Year.AddCommit(time.Month - 1, committer);
|
||||
Year.AddCommit(time.Month - 1, committer);
|
||||
}
|
||||
|
||||
public void Complete() {
|
||||
public void Complete()
|
||||
{
|
||||
Year.Complete();
|
||||
Month.Complete();
|
||||
Week.Complete();
|
||||
}
|
||||
|
||||
private DateTime _utcStart;
|
||||
private DateTime _today;
|
||||
private DateTime _thisWeekStart;
|
||||
private DateTime _thisWeekEnd;
|
||||
private readonly DateTime _utcStart;
|
||||
private readonly DateTime _today;
|
||||
private readonly DateTime _thisWeekStart;
|
||||
private readonly DateTime _thisWeekEnd;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue