-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
94 lines (78 loc) · 2.62 KB
/
Program.cs
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Text.Json;
class Core
{
static void Main(string[] args)
{
var logFile = File.ReadAllText(args[0]);
logFile = logFile.Replace("\r\n", "\n"); // idk man
var splits = logFile.Split($"\ncommit ");
List<Commit> commits = new();
foreach (var split in splits)
{
var commit = new Commit(split.Split("\n"));
commits.Add(commit);
}
var updates = commits.SelectMany(x => x.Updates);
var includedMods = updates.Select(x => x.Repo).Distinct();
List<Entry> entries = new();
foreach (var mod in includedMods)
{
List<DownloadCountUpdate> countUpdates = new();
foreach (var update in updates)
{
var isMod = update.Repo == mod;
if (Offsets.oldRepos.ContainsKey(mod))
{
isMod = isMod || Offsets.oldRepos[mod].Contains(update.Repo);
}
if (isMod)
{
countUpdates.Add(new DownloadCountUpdate(((DateTimeOffset)update.Time).ToUnixTimeSeconds(), update.DownloadCount));
}
}
if (Offsets.offsetBetween.ContainsKey(mod))
{
List<Offsets.Between> offsetBetween = Offsets.offsetBetween[mod];
foreach (DownloadCountUpdate update in countUpdates)
{
long unixTimestamp = update.UnixTimestamp;
foreach (var between in offsetBetween)
{
if (unixTimestamp > between.AfterUnixTimestamp && unixTimestamp <= between.BeforeUnixTimestamp)
{
update.DownloadCount += between.DownloadCount;
}
}
}
}
if (Offsets.offsets.ContainsKey(mod))
{
countUpdates.AddRange(Offsets.offsets[mod]);
}
var entry = new Entry()
{
Repo = mod,
Updates = countUpdates.ToArray()
};
entries.Add(entry);
}
var json = JsonSerializer.Serialize(entries);
Console.WriteLine(json);
}
public static int GetNthIndex(string s, char t, int n)
{
var count = 0;
for (var i = 0; i < s.Length; i++)
{
if (s[i] == t)
{
count++;
if (count == n)
{
return i;
}
}
}
return -1;
}
}