Compare commits

..

No commits in common. "1c6d5e9917e49a52bba331d7dee8275d8b0e1b1c" and "36b6504a38241b242b73a10e074bf8ef73323efe" have entirely different histories.

2 changed files with 32 additions and 44 deletions

View File

@ -2,7 +2,6 @@ package moon
import ( import (
"context" "context"
"fmt"
"math" "math"
"time" "time"
@ -15,7 +14,6 @@ type Math struct {
CurrentPrice coindesk.Price CurrentPrice coindesk.Price
Columns []Column Columns []Column
Goals []Goal Goals []Goal
Labels []string
} }
func NewMath(asset coindesk.Asset, goals []Goal, bases []Base) (m Math) { func NewMath(asset coindesk.Asset, goals []Goal, bases []Base) (m Math) {
@ -24,14 +22,10 @@ func NewMath(asset coindesk.Asset, goals []Goal, bases []Base) (m Math) {
} }
m.Asset = asset m.Asset = asset
m.Goals = goals m.Goals = goals
m.Labels = []string{"Starting", "CDPR"}
m.Columns = make([]Column, len(bases)) m.Columns = make([]Column, len(bases))
for i := range bases { for i := range bases {
m.Columns[i].Base = bases[i] m.Columns[i].Base = bases[i]
} }
for i := range goals {
m.Labels = append(m.Labels, goals[i].Name)
}
return return
} }
@ -112,25 +106,6 @@ type Column struct {
Projections Projection 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{ var DefaultGoals = []Goal{
{"$100k", 100000}, {"$100k", 100000},
{"$150k", 150000}, {"$150k", 150000},

View File

@ -49,9 +49,19 @@ func New(cfg config.Data) Model {
Width: 10, Width: 10,
}) })
} }
projectionRows := make([]table.Row, len(math.Goals)+2)
for i := range projectionRows {
projectionRows[i] = make(table.Row, len(projectionCols))
}
projectionRows[0][0] = "Starting"
projectionRows[1][0] = "CDPR"
for i := range math.Goals {
projectionRows[i+2][0] = fmt.Sprintf("$%.0f", math.Goals[i].Value)
}
projections := table.New( projections := table.New(
table.WithColumns(projectionCols), table.WithColumns(projectionCols),
table.WithHeight(len(math.Labels)), table.WithRows(projectionRows),
table.WithHeight(len(math.Goals)+2),
table.WithStyles(tableStyle), table.WithStyles(tableStyle),
) )
@ -96,27 +106,30 @@ func refillPrice(m *Model) {
} }
func refillProjections(m *Model) { func refillProjections(m *Model) {
rows := []table.Row{m.math.Labels} rows := m.projections.Rows()
for i := range m.math.Columns {
rows = append(rows, m.math.Columns[i].Column())
}
rows = transpose(rows)
m.projections.SetRows(rows)
}
func transpose(slice []table.Row) []table.Row { for col := range m.math.Columns {
xl := len(slice[0]) _ = col
yl := len(slice) never := false
result := make([]table.Row, xl) if m.math.Columns[col].CDPR <= 1 {
for i := range result { never = true
result[i] = make(table.Row, yl)
} }
for i := 0; i < xl; i++ {
for j := 0; j < yl; j++ { rows[0][col+1] = fmt.Sprintf("$%.2f", m.math.Columns[col].StartingPrice)
result[i][j] = slice[j][i] rows[1][col+1] = fmt.Sprintf("%.2f%%", (m.math.Columns[col].CDPR-1)*100)
for row := 0; row < len(m.math.Goals); row++ {
var cell string
if never {
cell = "NEVER!!!!!"
} else {
cell = m.math.Columns[col].
Projections.Dates[row].
Format("2006-01-02")
}
rows[row+2][col+1] = cell
} }
} }
return result m.projections.SetRows(rows)
} }
func (m Model) View() string { func (m Model) View() string {