refactored code a bit

This commit is contained in:
Nils Stinnesbeck 2021-05-05 08:51:29 +02:00
parent 9b4db62b83
commit 25ca20c487
Signed by: nils
GPG Key ID: 86D4882C6C6CA48B

43
main.go
View File

@ -46,33 +46,36 @@ func main() {
} }
} }
// daily // print out all rewards
listRewards("2006-01-02", rewards) printRewards(rewards)
// monthly
listRewards("2006-01", rewards)
// yearly
listRewards("2006", rewards)
} }
func listRewards(format string, entries []lineEntry) { func printRewards(rewards []lineEntry) {
var str string // daily
switch format { daily := listRewards("2006-01-02", rewards)
case "2006-01-02":
str = "daily" // monthly
case "2006-01": monthly := listRewards("2006-01", rewards)
str = "monthly"
case "2006": // yearly
str = "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) rewards := make(map[string]float64)
log.Printf("listing %s Rewards", str)
for i := range entries { for i := range entries {
rewardsString := entries[i].Time.Format(format) rewardsString := entries[i].Time.Format(format)
rewards[rewardsString] += entries[i].Amounts["DFI"] rewards[rewardsString] += entries[i].Amounts["DFI"]
} }
prettify.Print(rewards) return rewards
} }
func readCSV(filename string) ([]byte, error) { func readCSV(filename string) ([]byte, error) {