Simplify projection table generation.
All checks were successful
Build & Test / Main (push) Successful in 1m28s
All checks were successful
Build & Test / Main (push) Successful in 1m28s
Instead of pre-allocating the grid and using tricky indexing to fill in the cells, just fully regenerate it. But do it columnwise first, and then transpose it.
This commit is contained in:
25
moon/moon.go
25
moon/moon.go
@@ -2,6 +2,7 @@ package moon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
@@ -14,6 +15,7 @@ type Math struct {
|
||||
CurrentPrice coindesk.Price
|
||||
Columns []Column
|
||||
Goals []Goal
|
||||
Labels []string
|
||||
}
|
||||
|
||||
func NewMath(asset coindesk.Asset, goals []Goal, bases []Base) (m Math) {
|
||||
@@ -22,10 +24,14 @@ func NewMath(asset coindesk.Asset, goals []Goal, bases []Base) (m Math) {
|
||||
}
|
||||
m.Asset = asset
|
||||
m.Goals = goals
|
||||
m.Labels = []string{"Starting", "CDPR"}
|
||||
m.Columns = make([]Column, len(bases))
|
||||
for i := range bases {
|
||||
m.Columns[i].Base = bases[i]
|
||||
}
|
||||
for i := range goals {
|
||||
m.Labels = append(m.Labels, goals[i].Name)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -106,6 +112,25 @@ type Column struct {
|
||||
Projections Projection
|
||||
}
|
||||
|
||||
func (c *Column) Column() (entries []string) {
|
||||
entries = append(entries, fmt.Sprintf("$%.2f", c.StartingPrice))
|
||||
entries = append(entries, fmt.Sprintf("%.2f%%", (c.CDPR-1)*100))
|
||||
never := c.CDPR <= 1
|
||||
for i := range c.Projections.Dates {
|
||||
var cell string
|
||||
if never {
|
||||
cell = "NEVER!!!!!"
|
||||
} else {
|
||||
cell = c.
|
||||
Projections.
|
||||
Dates[i].
|
||||
Format("2006-01-02")
|
||||
}
|
||||
entries = append(entries, cell)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var DefaultGoals = []Goal{
|
||||
{"$100k", 100000},
|
||||
{"$150k", 150000},
|
||||
|
Reference in New Issue
Block a user