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

33
main.go
View File

@ -46,33 +46,36 @@ func main() {
} }
} }
// print out all rewards
printRewards(rewards)
}
func printRewards(rewards []lineEntry) {
// daily // daily
listRewards("2006-01-02", rewards) daily := listRewards("2006-01-02", rewards)
// monthly // monthly
listRewards("2006-01", rewards) monthly := listRewards("2006-01", rewards)
// yearly // yearly
listRewards("2006", rewards) 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) { func listRewards(format string, entries []lineEntry) map[string]float64 {
var str string
switch format {
case "2006-01-02":
str = "daily"
case "2006-01":
str = "monthly"
case "2006":
str = "yearly"
}
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) {