Implemented grouping by advanced/declined

master
Michael Dvorkin 11 years ago
parent 233e5122d6
commit 3ca08c6522
  1. 35
      lib/format.go
  2. 8
      lib/profile.go
  3. 3
      mop.go

@ -68,7 +68,7 @@ func (self *Formatter) format_market(m *Market) string {
}
//-----------------------------------------------------------------------------
func (self *Formatter) format_quotes(q *Quotes) string {
func (self *Formatter) format_quotes(quotes *Quotes) string {
vars := struct {
Now string
Header string
@ -76,7 +76,7 @@ func (self *Formatter) format_quotes(q *Quotes) string {
}{
time.Now().Format(`3:04:05pm PST`),
header(),
prettify(q.stocks),
prettify(quotes),
}
markup := `<right><white>{{.Now}}</white></right>
@ -86,7 +86,7 @@ func (self *Formatter) format_quotes(q *Quotes) string {
{{.Header}}
{{range .Stocks}}{{.Color}}{{.Ticker}} {{.LastTrade}} {{.Change}} {{.ChangePercent}} {{.Open}} {{.Low}} {{.High}} {{.Low52}} {{.High52}} {{.Volume}} {{.AvgVolume}} {{.PeRatio}} {{.Dividend}} {{.Yield}} {{.MarketCap}}
{{end}}`
//markup += fmt.Sprintf("[%v]", quotes.profile.Grouped)
template, err := template.New(`quotes`).Parse(markup)
if err != nil {
panic(err)
@ -123,9 +123,9 @@ func header() string {
}
//-----------------------------------------------------------------------------
func prettify(stocks []Stock) []Stock {
pretty := make([]Stock, len(stocks))
for i, q := range stocks {
func prettify(quotes *Quotes) []Stock {
pretty := make([]Stock, len(quotes.stocks))
for i, q := range group(quotes) {
pretty[i].Ticker = pad(q.Ticker, -7)
pretty[i].LastTrade = pad(with_currency(q.LastTrade), 9)
pretty[i].Change = pad(with_currency(q.Change), 9)
@ -145,6 +145,29 @@ func prettify(stocks []Stock) []Stock {
return pretty
}
//-----------------------------------------------------------------------------
func group(quotes *Quotes) []Stock {
if !quotes.profile.Grouped {
return quotes.stocks
} else {
grouped := make([]Stock, len(quotes.stocks))
current := 0
for _,stock := range quotes.stocks {
if strings.Index(stock.Change, "-") == -1 {
grouped[current] = stock
current++
}
}
for _,stock := range quotes.stocks {
if strings.Index(stock.Change, "-") != -1 {
grouped[current] = stock
current++
}
}
return grouped
}
}
//-----------------------------------------------------------------------------
func nullify(str string) string {
if len(str) == 3 && str[0:3] == `N/A` {

@ -15,6 +15,7 @@ const moprc = `/.moprc`
type Profile struct {
MarketRefresh int
QuotesRefresh int
Grouped bool
Tickers []string
SortBy string
SortOrder string
@ -27,6 +28,7 @@ func (self *Profile) Initialize() *Profile {
// Set default values.
self.MarketRefresh = 12
self.QuotesRefresh = 5
self.Grouped = false
self.Tickers = []string{`AAPL`, `C`, `GOOG`, `IBM`, `KO`, `ORCL`, `V`}
self.SortBy = `Ticker`
self.SortOrder = `Desc`
@ -51,6 +53,12 @@ func (self *Profile) ListOfTickers() string {
return strings.Join(self.Tickers, `+`)
}
//-----------------------------------------------------------------------------
func (self *Profile) Regroup() error {
self.Grouped = !self.Grouped
return self.Save()
}
//-----------------------------------------------------------------------------
func (self *Profile) AddTickers(tickers []string) (added int, err error) {
added = 0

@ -38,6 +38,9 @@ loop:
} else if event.Ch == '+' || event.Ch == '-' {
line_editor = new(mop.LineEditor).Initialize(screen, quotes)
line_editor.Prompt(event.Ch)
} else if event.Ch == 'g' {
profile.Regroup()
screen.Draw(quotes)
}
} else {
done := line_editor.Handle(event)

Loading…
Cancel
Save