-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTdlFile.cs
More file actions
57 lines (45 loc) · 1.9 KB
/
Copy pathTdlFile.cs
File metadata and controls
57 lines (45 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
namespace ExistSpoon
{
public class TdlFile
{
private readonly string _path;
public TdlFile(string path)
{
_path = path;
}
private static readonly Regex DoneRegex = new Regex(
@"DONEDATESTRING=""(?<date>\d\d\d\d-\d\d-\d\d|\d\d?/\d\d?/\d\d\d\d)",
RegexOptions.Compiled);
public List<DateCompletionCount> PerseCompletions()
{
string tdlText = File.ReadAllText(_path);
string archiveTdlText = File.ReadAllText(_path.Replace(".tdl", ".done.tdl"));
var mainMatches = DoneRegex.Matches(tdlText).Cast<Match>();
var archiveMatches = DoneRegex.Matches(archiveTdlText).Cast<Match>();
var matchGroups = mainMatches.Union(archiveMatches).GroupBy(match =>
{
string dateString = match.Groups["date"].Value;
DateTime doneDate;
DateTime.TryParseExact(
dateString,
new[] { "yyyy-MM-dd", "M/d/yyyy" },
new CultureInfo("en-US"),
DateTimeStyles.None,
out doneDate);
return doneDate;
});
var completions = matchGroups.Where(aGroup => DateTime.Today.Subtract(aGroup.Key).Days < 7)
.Select(aGroup => new DateCompletionCount(aGroup.Key, aGroup.Count()))
.ToList();
foreach (var completion in completions)
ProgressAggregator.Publish($"Found {completion.CompletedCount} complete on {completion.Date}.");
return completions;
}
}
}