switched to new csv format

This commit is contained in:
Nils Stinnesbeck 2021-01-16 15:13:12 +01:00
parent b7dd4e221f
commit 0eea70ebe4
4 changed files with 26 additions and 8 deletions

23
cake.go
View File

@ -18,8 +18,10 @@ import (
type line struct { type line struct {
Date time.Time Date time.Time
Operation string Operation string
Cryptocurrency string
Amount float64 Amount float64
Cryptocurrency string
FiatValue string
FiatCurrency string
TransactionID string TransactionID string
WithdrawalAddress string WithdrawalAddress string
Reference string Reference string
@ -33,6 +35,7 @@ type rewards struct {
Referral map[time.Month]string Referral map[time.Month]string
Airdrop map[time.Month]string Airdrop map[time.Month]string
Swapped map[time.Month]string Swapped map[time.Month]string
Deposits map[time.Month]string
} }
func getCumulative(r rewards, precision int) 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) referral, err := strconv.ParseFloat(r.Referral[month], 64)
staking, err := strconv.ParseFloat(r.Staking[month], 64) staking, err := strconv.ParseFloat(r.Staking[month], 64)
swapped, err := strconv.ParseFloat(r.Swapped[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 // add all fields up and format result as string
res[month] = strconv.FormatFloat(airdrop+confectionery+lapis+lapisDFI+referral+staking+swapped, 'g', precision, 64) 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) referral := make(map[time.Month]float64)
airdrop := make(map[time.Month]float64) airdrop := make(map[time.Month]float64)
swapped := make(map[time.Month]float64) swapped := make(map[time.Month]float64)
deposits := make(map[time.Month]float64)
// coinValue, err := GetCoinValue("bitcoin", "eur") // coinValue, err := GetCoinValue("bitcoin", "eur")
// if err == nil { // if err == nil {
// loop through all lines // loop through all lines
@ -169,8 +174,9 @@ func monthlyRewardOverview(lines []line) rewards {
airdrop[lines[i].Date.Month()] += lines[i].Amount airdrop[lines[i].Date.Month()] += lines[i].Amount
case "Swapped in": case "Swapped in":
swapped[lines[i].Date.Month()] += lines[i].Amount swapped[lines[i].Date.Month()] += lines[i].Amount
case "Deposit":
deposits[lines[i].Date.Month()] += lines[i].Amount
} }
// }
} }
// get precision for specific coin // get precision for specific coin
@ -184,6 +190,7 @@ func monthlyRewardOverview(lines []line) rewards {
Referral: fillSums(referral, precision), Referral: fillSums(referral, precision),
Airdrop: fillSums(airdrop, precision), Airdrop: fillSums(airdrop, precision),
Swapped: fillSums(swapped, precision), Swapped: fillSums(swapped, precision),
Deposits: fillSums(deposits, precision),
} }
return r return r
} }
@ -238,11 +245,13 @@ func readUploadedFile(fileContents []byte) ([]line, error) {
return nil, err return nil, err
} }
l.Operation = csvArgs[1] l.Operation = csvArgs[1]
l.Cryptocurrency = csvArgs[2] l.Amount, _ = strconv.ParseFloat(csvArgs[2], 64)
l.Amount, _ = strconv.ParseFloat(csvArgs[3], 64) l.Cryptocurrency = csvArgs[3]
l.TransactionID = csvArgs[4] l.FiatValue = csvArgs[4]
l.WithdrawalAddress = csvArgs[5] l.FiatCurrency = csvArgs[5]
l.Reference = csvArgs[6] l.TransactionID = csvArgs[6]
l.WithdrawalAddress = csvArgs[7]
l.Reference = csvArgs[8]
lines = append(lines, l) lines = append(lines, l)
} }
} }

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"html/template" "html/template"
"net/http" "net/http"
) )
@ -12,6 +13,7 @@ func main() {
http.HandleFunc("/", Home) http.HandleFunc("/", Home)
http.HandleFunc("/rewards", Rewards) http.HandleFunc("/rewards", Rewards)
http.HandleFunc("/kraken", Rewards) http.HandleFunc("/kraken", Rewards)
fmt.Println("Starting server on http://localhost:8080")
http.ListenAndServe(":8080", nil) http.ListenAndServe(":8080", nil)
} }

View File

@ -20,7 +20,7 @@ func Rewards(w http.ResponseWriter, r *http.Request) {
} }
// set common attributes // set common attributes
d := data{} var d data
// set title according to site that called this function // set title according to site that called this function
switch r.URL.Path { switch r.URL.Path {
@ -69,6 +69,7 @@ func Rewards(w http.ResponseWriter, r *http.Request) {
d.Rewards.Referral = rewards.Referral d.Rewards.Referral = rewards.Referral
d.Rewards.Airdrop = rewards.Airdrop d.Rewards.Airdrop = rewards.Airdrop
d.Rewards.Swapped = rewards.Swapped d.Rewards.Swapped = rewards.Swapped
d.Rewards.Deposits = rewards.Deposits
d.Colors = getOtherColors(color, 8) d.Colors = getOtherColors(color, 8)
d.Currency = currency d.Currency = currency
} }

View File

@ -75,6 +75,9 @@
{"name":"Cumulative","type":"bar","stack":"stackB","waveAnimation":false,"data":[ {"name":"Cumulative","type":"bar","stack":"stackB","waveAnimation":false,"data":[
{{ range $month, $amount := .CumulativeRewards}}{"value": "{{ $amount }}" },{{ end }} {{ 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}} {{else}}
// Stakeable coins // Stakeable coins
{"name":"Staking Rewards","type":"bar","stack":"stackA","waveAnimation":false,"data":[ {"name":"Staking Rewards","type":"bar","stack":"stackA","waveAnimation":false,"data":[
@ -92,6 +95,9 @@
{"name":"Cumulative","type":"bar","stack":"stackB","waveAnimation":false,"data":[ {"name":"Cumulative","type":"bar","stack":"stackB","waveAnimation":false,"data":[
{{ range $month, $amount := .CumulativeRewards}}{"value": "{{ $amount }}" },{{ end }} {{ 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}}
{{end}} {{end}}