Merge pull request #77 from yamori/issue72_fix_sorting

Issue72 fix sorting
master
Brandon Lee Camilleri 4 years ago committed by GitHub
commit e8aef035e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      layout.go
  2. 29
      sorter.go

@ -60,8 +60,8 @@ func NewLayout() *Layout {
{9, `Dividend`, `Dividend`, zero}, {9, `Dividend`, `Dividend`, zero},
{9, `Yield`, `Yield`, percent}, {9, `Yield`, `Yield`, percent},
{11, `MarketCap`, `MktCap`, currency}, {11, `MarketCap`, `MktCap`, currency},
{13, `PreOpen`, `PreMktChg%`, last}, {13, `PreOpen`, `PreMktChg%`, percent},
{13, `AfterHours`, `AfterMktChg%`, last}, {13, `AfterHours`, `AfterMktChg%`, percent},
} }
layout.regex = regexp.MustCompile(`(\.\d+)[BMK]?$`) layout.regex = regexp.MustCompile(`(\.\d+)[BMK]?$`)
layout.marketTemplate = buildMarketTemplate() layout.marketTemplate = buildMarketTemplate()

@ -37,6 +37,8 @@ type byPeRatioAsc struct{ sortable }
type byDividendAsc struct{ sortable } type byDividendAsc struct{ sortable }
type byYieldAsc struct{ sortable } type byYieldAsc struct{ sortable }
type byMarketCapAsc struct{ sortable } type byMarketCapAsc struct{ sortable }
type byPreOpenAsc struct{ sortable }
type byAfterHoursAsc struct{ sortable }
type byTickerDesc struct{ sortable } type byTickerDesc struct{ sortable }
type byLastTradeDesc struct{ sortable } type byLastTradeDesc struct{ sortable }
@ -53,6 +55,8 @@ type byPeRatioDesc struct{ sortable }
type byDividendDesc struct{ sortable } type byDividendDesc struct{ sortable }
type byYieldDesc struct{ sortable } type byYieldDesc struct{ sortable }
type byMarketCapDesc struct{ sortable } type byMarketCapDesc struct{ sortable }
type byPreOpenDesc struct{ sortable }
type byAfterHoursDesc struct{ sortable }
func (list byTickerAsc) Less(i, j int) bool { func (list byTickerAsc) Less(i, j int) bool {
return list.sortable[i].Ticker < list.sortable[j].Ticker return list.sortable[i].Ticker < list.sortable[j].Ticker
@ -69,7 +73,9 @@ func (list byChangePctAsc) Less(i, j int) bool {
func (list byOpenAsc) Less(i, j int) bool { func (list byOpenAsc) Less(i, j int) bool {
return list.sortable[i].Open < list.sortable[j].Open return list.sortable[i].Open < list.sortable[j].Open
} }
func (list byLowAsc) Less(i, j int) bool { return list.sortable[i].Low < list.sortable[j].Low } func (list byLowAsc) Less(i, j int) bool {
return list.sortable[i].Low < list.sortable[j].Low
}
func (list byHighAsc) Less(i, j int) bool { func (list byHighAsc) Less(i, j int) bool {
return list.sortable[i].High < list.sortable[j].High return list.sortable[i].High < list.sortable[j].High
} }
@ -97,6 +103,13 @@ func (list byYieldAsc) Less(i, j int) bool {
func (list byMarketCapAsc) Less(i, j int) bool { func (list byMarketCapAsc) Less(i, j int) bool {
return m(list.sortable[i].MarketCap) < m(list.sortable[j].MarketCap) return m(list.sortable[i].MarketCap) < m(list.sortable[j].MarketCap)
} }
func (list byPreOpenAsc) Less(i, j int) bool {
return c(list.sortable[i].PreOpen) < c(list.sortable[j].PreOpen)
}
func (list byAfterHoursAsc) Less(i, j int) bool {
return c(list.sortable[i].AfterHours) < c(list.sortable[j].AfterHours)
}
func (list byTickerDesc) Less(i, j int) bool { func (list byTickerDesc) Less(i, j int) bool {
return list.sortable[j].Ticker < list.sortable[i].Ticker return list.sortable[j].Ticker < list.sortable[i].Ticker
@ -113,7 +126,9 @@ func (list byChangePctDesc) Less(i, j int) bool {
func (list byOpenDesc) Less(i, j int) bool { func (list byOpenDesc) Less(i, j int) bool {
return list.sortable[j].Open < list.sortable[i].Open return list.sortable[j].Open < list.sortable[i].Open
} }
func (list byLowDesc) Less(i, j int) bool { return list.sortable[j].Low < list.sortable[i].Low } func (list byLowDesc) Less(i, j int) bool {
return list.sortable[j].Low < list.sortable[i].Low
}
func (list byHighDesc) Less(i, j int) bool { func (list byHighDesc) Less(i, j int) bool {
return list.sortable[j].High < list.sortable[i].High return list.sortable[j].High < list.sortable[i].High
} }
@ -141,6 +156,12 @@ func (list byYieldDesc) Less(i, j int) bool {
func (list byMarketCapDesc) Less(i, j int) bool { func (list byMarketCapDesc) Less(i, j int) bool {
return m(list.sortable[j].MarketCap) < m(list.sortable[i].MarketCap) return m(list.sortable[j].MarketCap) < m(list.sortable[i].MarketCap)
} }
func (list byPreOpenDesc) Less(i, j int) bool {
return c(list.sortable[j].PreOpen) < c(list.sortable[i].PreOpen)
}
func (list byAfterHoursDesc) Less(i, j int) bool {
return c(list.sortable[j].AfterHours) < c(list.sortable[i].AfterHours)
}
// Returns new Sorter struct. // Returns new Sorter struct.
func NewSorter(profile *Profile) *Sorter { func NewSorter(profile *Profile) *Sorter {
@ -171,6 +192,8 @@ func (sorter *Sorter) SortByCurrentColumn(stocks []Stock) *Sorter {
byDividendAsc{stocks}, byDividendAsc{stocks},
byYieldAsc{stocks}, byYieldAsc{stocks},
byMarketCapAsc{stocks}, byMarketCapAsc{stocks},
byPreOpenAsc{stocks},
byAfterHoursAsc{stocks},
} }
} else { } else {
interfaces = []sort.Interface{ interfaces = []sort.Interface{
@ -189,6 +212,8 @@ func (sorter *Sorter) SortByCurrentColumn(stocks []Stock) *Sorter {
byDividendDesc{stocks}, byDividendDesc{stocks},
byYieldDesc{stocks}, byYieldDesc{stocks},
byMarketCapDesc{stocks}, byMarketCapDesc{stocks},
byPreOpenDesc{stocks},
byAfterHoursDesc{stocks},
} }
} }

Loading…
Cancel
Save