-
Notifications
You must be signed in to change notification settings - Fork 2
/
ConsoleStats.cs
64 lines (55 loc) · 2.04 KB
/
ConsoleStats.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
using BetterConsoleTables;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace SqliteToCsv
{
public class ConsoleStats : IDisposable
{
private Timer timer;
private ParallelProcessor processor;
private DateTime startTime;
public ConsoleStats(ParallelProcessor processor)
{
startTime = DateTime.Now;
this.processor = processor;
timer = new Timer(UpdateConsole, null, 250, Timeout.Infinite);
}
private void UpdateConsole(object state)
{
Console.SetCursorPosition(0, 0);
ConsoleTables tables = new ConsoleTables();
tables.AddTable(GetCurrentStats());
tables.AddTable(GetTableStats());
string output = tables.ToString();
Console.Write(output);
timer.Change(250, Timeout.Infinite);
}
private Table GetCurrentStats()
{
Table table = new Table(Config.Markdown(), "Time Elapsed", "Processing Queue", "Writing Queue");
table.AddRow(DateTime.Now.Subtract(startTime),processor.ProcessingQueue.Count, processor.WritingQueue.Count);
return table;
}
private Table GetTableStats()
{
Table table = new Table(Config.Markdown(), "Table", "Extracted", "Processed", "Written", "Processing Speed");
foreach(SqliteToCsv.Models.Table sTable in processor.Tables)
{
string countPerSec = $"{String.Format("{0:n0}", sTable.Processed.AverageCountPerSecond) }/s";
table.AddRow(
String.Format("{0:n0}", sTable.Name),
String.Format("{0:n0}", sTable.Extracted.Count),
String.Format("{0:n0}", sTable.Processed.Count),
String.Format("{0:n0}", sTable.Written.Count),
countPerSec);
}
return table;
}
public void Dispose()
{
timer.Dispose();
}
}
}