removing example
This commit is contained in:
parent
a7ff82d63f
commit
872b97b99f
5 changed files with 34 additions and 103 deletions
|
@ -1,46 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/wcharczuk/go-chart"
|
||||
"github.com/wcharczuk/go-chart/seq"
|
||||
"github.com/wcharczuk/go-chart/util"
|
||||
)
|
||||
|
||||
func drawChart(res http.ResponseWriter, req *http.Request) {
|
||||
start := util.Date.Date(2016, 7, 01, util.Date.Eastern())
|
||||
end := util.Date.Date(2016, 07, 21, util.Date.Eastern())
|
||||
xv := seq.Time.MarketHours(start, end, util.NYSEOpen(), util.NYSEClose(), util.Date.IsNYSEHoliday)
|
||||
yv := seq.New(seq.NewRandom().WithLen(len(xv)).WithAverage(200).WithScale(10)).Array()
|
||||
|
||||
graph := chart.Chart{
|
||||
XAxis: chart.XAxis{
|
||||
Style: chart.StyleShow(),
|
||||
TickPosition: chart.TickPositionBetweenTicks,
|
||||
ValueFormatter: chart.TimeHourValueFormatter,
|
||||
Range: &chart.MarketHoursRange{
|
||||
MarketOpen: util.NYSEOpen(),
|
||||
MarketClose: util.NYSEClose(),
|
||||
HolidayProvider: util.Date.IsNYSEHoliday,
|
||||
},
|
||||
},
|
||||
YAxis: chart.YAxis{
|
||||
Style: chart.StyleShow(),
|
||||
},
|
||||
Series: []chart.Series{
|
||||
chart.TimeSeries{
|
||||
XValues: xv,
|
||||
YValues: yv,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
res.Header().Set("Content-Type", "image/png")
|
||||
graph.Render(chart.PNG, res)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", drawChart)
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 67 KiB |
22
util/math.go
22
util/math.go
|
@ -2,7 +2,6 @@ package util
|
|||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -58,27 +57,6 @@ func (m mathUtil) MinAndMax(values ...float64) (min float64, max float64) {
|
|||
return
|
||||
}
|
||||
|
||||
// MinAndMaxOfTime returns the min and max of a given set of times
|
||||
// in one pass.
|
||||
func (m mathUtil) MinAndMaxOfTime(values ...time.Time) (min time.Time, max time.Time) {
|
||||
if len(values) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
min = values[0]
|
||||
max = values[0]
|
||||
|
||||
for _, v := range values[1:] {
|
||||
if max.Before(v) {
|
||||
max = v
|
||||
}
|
||||
if min.After(v) {
|
||||
min = v
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetRoundToForDelta returns a `roundTo` value for a given delta.
|
||||
func (m mathUtil) GetRoundToForDelta(delta float64) float64 {
|
||||
startingDeltaBound := math.Pow(10.0, 10.0)
|
||||
|
|
|
@ -2,7 +2,6 @@ package util
|
|||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/blend/go-sdk/assert"
|
||||
)
|
||||
|
@ -31,40 +30,6 @@ func TestMinAndMaxEmpty(t *testing.T) {
|
|||
assert.Equal(0.0, max)
|
||||
}
|
||||
|
||||
func TestMinAndMaxOfTime(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
values := []time.Time{
|
||||
time.Now().AddDate(0, 0, -1),
|
||||
time.Now().AddDate(0, 0, -2),
|
||||
time.Now().AddDate(0, 0, -3),
|
||||
time.Now().AddDate(0, 0, -4),
|
||||
}
|
||||
min, max := Math.MinAndMaxOfTime(values...)
|
||||
assert.Equal(values[3], min)
|
||||
assert.Equal(values[0], max)
|
||||
}
|
||||
|
||||
func TestMinAndMaxOfTimeReversed(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
values := []time.Time{
|
||||
time.Now().AddDate(0, 0, -4),
|
||||
time.Now().AddDate(0, 0, -2),
|
||||
time.Now().AddDate(0, 0, -3),
|
||||
time.Now().AddDate(0, 0, -1),
|
||||
}
|
||||
min, max := Math.MinAndMaxOfTime(values...)
|
||||
assert.Equal(values[0], min)
|
||||
assert.Equal(values[3], max)
|
||||
}
|
||||
|
||||
func TestMinAndMaxOfTimeEmpty(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
values := []time.Time{}
|
||||
min, max := Math.MinAndMaxOfTime(values...)
|
||||
assert.Equal(time.Time{}, min)
|
||||
assert.Equal(time.Time{}, max)
|
||||
}
|
||||
|
||||
func TestGetRoundToForDelta(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
|
@ -28,3 +28,37 @@ func TestTimeDiffHours(t *testing.T) {
|
|||
assert.Equal(68, Time.DiffHours(t2, t1))
|
||||
assert.Equal(24, Time.DiffHours(t1, t3))
|
||||
}
|
||||
|
||||
func TestTimeStartAndEnd(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
values := []time.Time{
|
||||
time.Now().AddDate(0, 0, -1),
|
||||
time.Now().AddDate(0, 0, -2),
|
||||
time.Now().AddDate(0, 0, -3),
|
||||
time.Now().AddDate(0, 0, -4),
|
||||
}
|
||||
min, max := Time.StartAndEnd(values...)
|
||||
assert.Equal(values[3], min)
|
||||
assert.Equal(values[0], max)
|
||||
}
|
||||
|
||||
func TestTimeStartAndEndReversed(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
values := []time.Time{
|
||||
time.Now().AddDate(0, 0, -4),
|
||||
time.Now().AddDate(0, 0, -2),
|
||||
time.Now().AddDate(0, 0, -3),
|
||||
time.Now().AddDate(0, 0, -1),
|
||||
}
|
||||
min, max := Time.StartAndEnd(values...)
|
||||
assert.Equal(values[0], min)
|
||||
assert.Equal(values[3], max)
|
||||
}
|
||||
|
||||
func TestTimeStartAndEndEmpty(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
values := []time.Time{}
|
||||
min, max := Time.StartAndEnd(values...)
|
||||
assert.Equal(time.Time{}, min)
|
||||
assert.Equal(time.Time{}, max)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue