print out a nice summary at the end =u=
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
9a1272c085
commit
2f6818aa5d
4 changed files with 31 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ bin/
|
|||
obj/
|
||||
test.csv
|
||||
rules.csv
|
||||
.~lock*
|
||||
|
|
21
Program.cs
21
Program.cs
|
@ -68,7 +68,7 @@ namespace BunyMuny {
|
|||
while (csv.Read()) {
|
||||
switch (bank) {
|
||||
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"));
|
||||
|
||||
statements.Add(new Statement() {
|
||||
|
@ -95,11 +95,28 @@ namespace BunyMuny {
|
|||
}
|
||||
|
||||
foreach (var statement in statements.
|
||||
// Where(s => s.Category != null).
|
||||
// Where(s => s.Category == null).
|
||||
OrderBy(s => s.Date)) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
15
Rule.cs
15
Rule.cs
|
@ -15,18 +15,23 @@ namespace BunyMuny {
|
|||
/// <param name="input">The string to check against the rule's Value.</param>
|
||||
/// <returns></returns>
|
||||
public bool Check(string input) {
|
||||
var value = Value;
|
||||
if (!CaseSensitive) {
|
||||
input = input.ToLower();
|
||||
value = value.ToLower();
|
||||
}
|
||||
switch (Match) {
|
||||
case RuleMatch.Exact:
|
||||
return input == Value;
|
||||
return input == value;
|
||||
case RuleMatch.Start:
|
||||
return input.StartsWith(Value);
|
||||
return input.StartsWith(value);
|
||||
case RuleMatch.End:
|
||||
return input.EndsWith(Value);
|
||||
return input.EndsWith(value);
|
||||
case RuleMatch.Regex:
|
||||
var re = new Regex(Value);
|
||||
var re = new Regex(value);
|
||||
return re.IsMatch(input);
|
||||
case RuleMatch.Contains:
|
||||
return input.Contains(input);
|
||||
return input.Contains(value);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace BunyMuny {
|
|||
}
|
||||
|
||||
public string OriginalDescription;
|
||||
public double Value;
|
||||
public decimal Value;
|
||||
public string Category;
|
||||
|
||||
public override string ToString() {
|
||||
|
|
Loading…
Reference in a new issue