-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
154 lines (136 loc) · 4.88 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
using System.Globalization;
using MMStatsWatcher;
using Newtonsoft.Json;
const string url = "https://nnp.nnchan.ru/mahomaps/log.txt";
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Show from date (MM.DD.YYYY): ");
var dateFrom = DateTime.Parse(Console.ReadLine()!, CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal);
var dateTo = DateTime.Now;
var days = Math.Ceiling((dateTo - dateFrom).TotalDays);
if (dateFrom >= dateTo)
{
Console.WriteLine("Invalid date!");
return;
}
using HttpClient hc = new HttpClient();
Console.WriteLine();
Console.WriteLine($"GET: {url}");
var rawLines = hc.GetStringAsync(url).Result.Split('\n');
Console.WriteLine("GET: OK");
var lines = rawLines
.Select(JsonConvert.DeserializeObject<TempEntry>)
.Where(x => x != null && !x.IsBroken())
.Select(x => new Entry(x!))
.Where(x => x.device != "сиськи" && x.device != "asd")
.Where(x => x.date > dateFrom).ToArray();
// totals
{
PrintUtils.PrintHeader("Total stats");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Launch count: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"{lines.Length}");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Days passed: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"{(int) days}");
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Launches per day: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine($"~{lines.Length / days:F2}");
}
// version/device
{
var allVers = lines.Select(x => x.v).Distinct().Order().ToArray();
var maxlen = lines.Select(x => x.device.Length).Max();
PrintUtils.PrintHeader("Versions usage");
PrintLine("Versions:", "All", allVers, maxlen);
Console.WriteLine();
var bydev = lines.GroupBy(x => x.device).OrderByDescending(x => x.Count());
foreach (var dev in bydev)
{
string name = dev.Key;
string total = dev.Count().ToString();
var byVers = allVers.Select(x => dev.Count(y => y.v == x).ToString());
PrintLine(name, total, byVers, maxlen);
}
}
// per-day
{
PrintUtils.PrintHeader("Usage by day");
var byday = lines.GroupBy(x => x.date.Date).OrderBy(x => x.Key).ToArray();
var maxLaunches = byday.Select(x => x.Count()).Max();
foreach (var day in byday)
{
var count = day.Count();
Console.ForegroundColor = ConsoleColor.Green;
Console.Write($"{day.Key.Day:00}.{day.Key.Month:00} ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(count.ToString().PadLeft(3));
Console.ForegroundColor = ConsoleColor.White;
Console.Write(' ');
Console.Write(new string('#', count));
Console.Write(new string(' ', maxLaunches - count));
if (count != 0)
{
var mostUsed = day.GroupBy(x => x.device).OrderByDescending(x => x.Count()).First();
Console.Write(" Most used: ");
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(mostUsed.Key);
Console.ForegroundColor = ConsoleColor.White;
Console.Write($" ({mostUsed.Count()})");
}
Console.WriteLine();
}
}
// geopoint
{
PrintUtils.PrintHeader("Geopoint look choice stats");
PrintUtils.PrintGeoTypeStat(lines, 1, "Я");
PrintUtils.PrintGeoTypeStat(lines, 2, "Ы");
PrintUtils.PrintGeoTypeStat(lines, 3, "Ъ");
}
// telemetry
{
PrintUtils.PrintHeader("Functions usage");
var funcNames = Enum.GetNames<UsageFlags>();
var maxLen = funcNames.Select(x => x.Length).Max();
var funcs = Enum.GetValues<UsageFlags>().Select(x => lines.Where(y => y.usage.HasFlag(x)));
var zip = funcNames.Zip(funcs);
foreach (var func in zip)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(func.First.PadRight(maxLen + 1));
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Total: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(func.Second.Count());
Console.ForegroundColor = ConsoleColor.White;
Console.Write(", per-day: ");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write($"~{func.Second.Count() / days:F2}");
Console.WriteLine();
}
}
// end
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
Console.WriteLine();
}
static void PrintLine(string a, string b, IEnumerable<string> c, int maxALen)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Write(a.PadRight(maxALen + 1));
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write(b.PadRight(9));
foreach (var n in c)
{
if (n.Equals("0"))
Console.ForegroundColor = ConsoleColor.Gray;
else
Console.ForegroundColor = ConsoleColor.White;
Console.Write(n.PadRight(9));
}
Console.WriteLine();
}