refactor to only filter transactions based on dates, not the entries
This commit is contained in:
parent
a3b54b1326
commit
8d3d48d846
@ -65,11 +65,33 @@ public partial class MainWindow : Window {
|
||||
GenerateLog();
|
||||
}
|
||||
|
||||
private void HandleEntries(List<Entry> entries) {
|
||||
private void Report_OnLog(string message) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.Append(DateTime.Now.ToString());
|
||||
builder.Append(": ");
|
||||
builder.Append(message);
|
||||
builder.Append("\n");
|
||||
|
||||
log.AppendText(builder.ToString());
|
||||
}
|
||||
|
||||
private void Log(string message) {
|
||||
Report_OnLog(message);
|
||||
}
|
||||
|
||||
private void HandleEntries(List<Entry> entries, DateTime start, DateTime end) {
|
||||
try {
|
||||
TransactionParser parser = new TransactionParser();
|
||||
List<Transaction> transactions = parser.Parse(entries);
|
||||
|
||||
// Filter the transactions down to the given time frame
|
||||
DateTime actualend = end.AddDays(1);
|
||||
transactions = transactions
|
||||
.Where(t => t.CompletedAtDateTime >= start && t.CompletedAtDateTime <= actualend)
|
||||
.ToList()
|
||||
;
|
||||
|
||||
List<IncompleteTransaction> incompletes = transactions.OfType<IncompleteTransaction>().ToList();
|
||||
// Log incomplete and remove them from the results.
|
||||
foreach (var incomplete in incompletes) {
|
||||
@ -86,25 +108,14 @@ public partial class MainWindow : Window {
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleEntries(List<Entry> entries) {
|
||||
HandleEntries(entries, DateTime.Now, DateTime.Now);
|
||||
}
|
||||
|
||||
private void Loadentries_EntriesLoaded(List<Entry> lines) {
|
||||
HandleEntries(lines);
|
||||
}
|
||||
|
||||
private void Report_OnLog(string message) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
builder.Append(DateTime.Now.ToString());
|
||||
builder.Append(": ");
|
||||
builder.Append(message);
|
||||
builder.Append("\n");
|
||||
|
||||
log.AppendText(builder.ToString());
|
||||
}
|
||||
|
||||
private void Log(string message) {
|
||||
Report_OnLog(message);
|
||||
}
|
||||
|
||||
private void ParseJournal_Click(object sender, RoutedEventArgs e) {
|
||||
try {
|
||||
TransactionParser parser = new TransactionParser();
|
||||
@ -121,21 +132,14 @@ public partial class MainWindow : Window {
|
||||
// files have to be read in their entirety to check this). So we assume that you can't play
|
||||
// three days straight, and keep the code fast.
|
||||
DateTime actualstart = start.AddDays(-3);
|
||||
DateTime actualend = end.AddDays(1);
|
||||
List<Entry> entries = journal.Files
|
||||
.Where(f => f.NormalisedDateTime >= actualstart && f.NormalisedDateTime <= end)
|
||||
.Where(f => f.NormalisedDateTime >= actualstart && f.NormalisedDateTime <= actualend)
|
||||
.SelectMany(e => e.Entries)
|
||||
.ToList()
|
||||
;
|
||||
// Now further sort the list down to entries that are actually within the given datetime
|
||||
// Note that entry datetimes are not normalised, so we have to sort until end + 1 day
|
||||
DateTime actualend = end.AddDays(1);
|
||||
|
||||
entries = entries
|
||||
.Where(e => e.Timestamp >= start && e.Timestamp < actualend)
|
||||
.ToList()
|
||||
;
|
||||
|
||||
HandleEntries(entries);
|
||||
HandleEntries(entries, start, end);
|
||||
GenerateLog();
|
||||
} catch (Exception exception) {
|
||||
Log("Something went terribly wrong while parsing the E:D player journal.");
|
||||
|
Loading…
Reference in New Issue
Block a user