From 25ca20c48723e602c0f4c13e90f8e936b44bbfb4 Mon Sep 17 00:00:00 2001 From: Nils Jakobi Date: Wed, 5 May 2021 08:51:29 +0200 Subject: [PATCH] refactored code a bit --- main.go | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/main.go b/main.go index 6414e67..4496e91 100644 --- a/main.go +++ b/main.go @@ -46,33 +46,36 @@ func main() { } } - // daily - listRewards("2006-01-02", rewards) - - // monthly - listRewards("2006-01", rewards) - - // yearly - listRewards("2006", rewards) + // print out all rewards + printRewards(rewards) } -func listRewards(format string, entries []lineEntry) { - var str string - switch format { - case "2006-01-02": - str = "daily" - case "2006-01": - str = "monthly" - case "2006": - str = "yearly" - } +func printRewards(rewards []lineEntry) { + // daily + daily := listRewards("2006-01-02", rewards) + + // monthly + monthly := listRewards("2006-01", rewards) + + // yearly + yearly := listRewards("2006", rewards) + + // print rewards + log.Println("listing daily Rewards") + prettify.Print(daily) + log.Println("listing monthly Rewards") + prettify.Print(monthly) + log.Println("listing yearly Rewards") + prettify.Print(yearly) +} + +func listRewards(format string, entries []lineEntry) map[string]float64 { rewards := make(map[string]float64) - log.Printf("listing %s Rewards", str) for i := range entries { rewardsString := entries[i].Time.Format(format) rewards[rewardsString] += entries[i].Amounts["DFI"] } - prettify.Print(rewards) + return rewards } func readCSV(filename string) ([]byte, error) {