diff --git a/cake.go b/cake.go index af379d8..c6d4ed6 100644 --- a/cake.go +++ b/cake.go @@ -18,8 +18,10 @@ import ( type line struct { Date time.Time Operation string - Cryptocurrency string Amount float64 + Cryptocurrency string + FiatValue string + FiatCurrency string TransactionID string WithdrawalAddress string Reference string @@ -33,6 +35,7 @@ type rewards struct { Referral map[time.Month]string Airdrop map[time.Month]string Swapped map[time.Month]string + Deposits map[time.Month]string } func getCumulative(r rewards, precision int) map[time.Month]string { @@ -49,6 +52,7 @@ func getCumulative(r rewards, precision int) map[time.Month]string { referral, err := strconv.ParseFloat(r.Referral[month], 64) staking, err := strconv.ParseFloat(r.Staking[month], 64) swapped, err := strconv.ParseFloat(r.Swapped[month], 64) + // deposits, err := strconv.ParseFloat(r.Deposits[month], 64) // add all fields up and format result as string res[month] = strconv.FormatFloat(airdrop+confectionery+lapis+lapisDFI+referral+staking+swapped, 'g', precision, 64) @@ -149,6 +153,7 @@ func monthlyRewardOverview(lines []line) rewards { referral := make(map[time.Month]float64) airdrop := make(map[time.Month]float64) swapped := make(map[time.Month]float64) + deposits := make(map[time.Month]float64) // coinValue, err := GetCoinValue("bitcoin", "eur") // if err == nil { // loop through all lines @@ -169,8 +174,9 @@ func monthlyRewardOverview(lines []line) rewards { airdrop[lines[i].Date.Month()] += lines[i].Amount case "Swapped in": swapped[lines[i].Date.Month()] += lines[i].Amount + case "Deposit": + deposits[lines[i].Date.Month()] += lines[i].Amount } - // } } // get precision for specific coin @@ -184,6 +190,7 @@ func monthlyRewardOverview(lines []line) rewards { Referral: fillSums(referral, precision), Airdrop: fillSums(airdrop, precision), Swapped: fillSums(swapped, precision), + Deposits: fillSums(deposits, precision), } return r } @@ -238,11 +245,13 @@ func readUploadedFile(fileContents []byte) ([]line, error) { return nil, err } l.Operation = csvArgs[1] - l.Cryptocurrency = csvArgs[2] - l.Amount, _ = strconv.ParseFloat(csvArgs[3], 64) - l.TransactionID = csvArgs[4] - l.WithdrawalAddress = csvArgs[5] - l.Reference = csvArgs[6] + l.Amount, _ = strconv.ParseFloat(csvArgs[2], 64) + l.Cryptocurrency = csvArgs[3] + l.FiatValue = csvArgs[4] + l.FiatCurrency = csvArgs[5] + l.TransactionID = csvArgs[6] + l.WithdrawalAddress = csvArgs[7] + l.Reference = csvArgs[8] lines = append(lines, l) } } diff --git a/main.go b/main.go index d6b339d..2bb58de 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "html/template" "net/http" ) @@ -12,6 +13,7 @@ func main() { http.HandleFunc("/", Home) http.HandleFunc("/rewards", Rewards) http.HandleFunc("/kraken", Rewards) + fmt.Println("Starting server on http://localhost:8080") http.ListenAndServe(":8080", nil) } diff --git a/rewards.go b/rewards.go index 7915cd2..0c9b943 100644 --- a/rewards.go +++ b/rewards.go @@ -20,7 +20,7 @@ func Rewards(w http.ResponseWriter, r *http.Request) { } // set common attributes - d := data{} + var d data // set title according to site that called this function switch r.URL.Path { @@ -69,6 +69,7 @@ func Rewards(w http.ResponseWriter, r *http.Request) { d.Rewards.Referral = rewards.Referral d.Rewards.Airdrop = rewards.Airdrop d.Rewards.Swapped = rewards.Swapped + d.Rewards.Deposits = rewards.Deposits d.Colors = getOtherColors(color, 8) d.Currency = currency } diff --git a/templates/includes.html b/templates/includes.html index 5c6be64..a2eb28f 100644 --- a/templates/includes.html +++ b/templates/includes.html @@ -75,6 +75,9 @@ {"name":"Cumulative","type":"bar","stack":"stackB","waveAnimation":false,"data":[ {{ range $month, $amount := .CumulativeRewards}}{"value": "{{ $amount }}" },{{ end }} ]}, +{"name":"Deposits","type":"bar","stack":"stackC","waveAnimation":false,"data":[ +{{ range $month, $amount := .Rewards.Deposits}}{"value": "{{ $amount }}" },{{ end }} +]}, {{else}} // Stakeable coins {"name":"Staking Rewards","type":"bar","stack":"stackA","waveAnimation":false,"data":[ @@ -92,6 +95,9 @@ {"name":"Cumulative","type":"bar","stack":"stackB","waveAnimation":false,"data":[ {{ range $month, $amount := .CumulativeRewards}}{"value": "{{ $amount }}" },{{ end }} ]}, +{"name":"Deposits","type":"bar","stack":"stackC","waveAnimation":false,"data":[ +{{ range $month, $amount := .Rewards.Deposits}}{"value": "{{ $amount }}" },{{ end }} +]}, {{end}} {{end}}