print out a nice summary at the end =u=
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Lynne Megido 2020-09-27 13:59:58 +10:00
parent 9a1272c085
commit 2f6818aa5d
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
4 changed files with 31 additions and 8 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ bin/
obj/ obj/
test.csv test.csv
rules.csv rules.csv
.~lock*

View file

@ -68,7 +68,7 @@ namespace BunyMuny {
while (csv.Read()) { while (csv.Read()) {
switch (bank) { switch (bank) {
case Bank.ME: case Bank.ME:
var value = double.Parse(csv.GetField("Debits and credits").TrimStart().Replace("$", "")); var value = decimal.Parse(csv.GetField("Debits and credits").TrimStart().Replace("$", ""));
var (category, description) = MatchAgainstRules(rules, csv.GetField("Description")); var (category, description) = MatchAgainstRules(rules, csv.GetField("Description"));
statements.Add(new Statement() { statements.Add(new Statement() {
@ -95,11 +95,28 @@ namespace BunyMuny {
} }
foreach (var statement in statements. foreach (var statement in statements.
// Where(s => s.Category != null). // Where(s => s.Category == null).
OrderBy(s => s.Date)) { OrderBy(s => s.Date)) {
Console.WriteLine(statement); Console.WriteLine(statement);
} }
Console.WriteLine("Summary:");
Console.WriteLine("==================");
var summaries = statements.
GroupBy(s => s.Category). // group statements by category
Select(summary => new { // and then select:
Name = summary.First().Category?? "Other", // the name of the category...
Total = summary.Sum(s => s.Value).ToString() // ...and the sum of all the statement's values in that category
});
var longestCategoryName = summaries.
ToList().
Max(summary => summary.Name.Length);
foreach (var summary in summaries) {
Console.WriteLine("{0}: {1}", summary.Name.PadLeft(longestCategoryName), summary.Total);
}
return 0; return 0;
} }

15
Rule.cs
View file

@ -15,18 +15,23 @@ namespace BunyMuny {
/// <param name="input">The string to check against the rule's Value.</param> /// <param name="input">The string to check against the rule's Value.</param>
/// <returns></returns> /// <returns></returns>
public bool Check(string input) { public bool Check(string input) {
var value = Value;
if (!CaseSensitive) {
input = input.ToLower();
value = value.ToLower();
}
switch (Match) { switch (Match) {
case RuleMatch.Exact: case RuleMatch.Exact:
return input == Value; return input == value;
case RuleMatch.Start: case RuleMatch.Start:
return input.StartsWith(Value); return input.StartsWith(value);
case RuleMatch.End: case RuleMatch.End:
return input.EndsWith(Value); return input.EndsWith(value);
case RuleMatch.Regex: case RuleMatch.Regex:
var re = new Regex(Value); var re = new Regex(value);
return re.IsMatch(input); return re.IsMatch(input);
case RuleMatch.Contains: case RuleMatch.Contains:
return input.Contains(input); return input.Contains(value);
default: default:
return false; return false;
} }

View file

@ -11,7 +11,7 @@ namespace BunyMuny {
} }
public string OriginalDescription; public string OriginalDescription;
public double Value; public decimal Value;
public string Category; public string Category;
public override string ToString() { public override string ToString() {