switched to new csv format
This commit is contained in:
parent
b7dd4e221f
commit
0eea70ebe4
23
cake.go
23
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)
|
||||
}
|
||||
}
|
||||
|
2
main.go
2
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)
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user