Permalink
Browse files

CandleStickの更新Timingを変更

  • Loading branch information...
nomeaning777 committed Oct 20, 2018
1 parent 7d342c5 commit 9251d4f1f563e1e50d76dccb4489a112fa32010f
Showing with 6 additions and 1 deletion.
  1. +1 −0 src/isucon8/isucoin/controller/handler.go
  2. +5 −1 src/isucon8/isucoin/model/trade.go
@@ -69,6 +69,7 @@ func (h *Handler) Initialize(w http.ResponseWriter, r *http.Request, _ httproute
}
return nil
})
model.UpdateCandleStickData(h.db)
if err != nil {
h.handleError(w, err, 500)
} else {
@@ -77,6 +77,8 @@ func appendCandleStick(data *[]*CandlestickData, ts uint64, price int64, id int6
}

func UpdateCandleStickData(d QueryExecutor) error {
candleStickMutex.Lock()
defer candleStickMutex.Unlock()
query := `
SELECT
UNIX_TIMESTAMP(STR_TO_DATE(DATE_FORMAT(created_at, '%Y-%m-%d %H:%i:%s'), '%Y-%m-%d %H:%i:%s')) as t,
@@ -107,6 +109,8 @@ func UpdateCandleStickData(d QueryExecutor) error {
}

func getCandleStick(data []*CandlestickData, ts uint64) []*CandlestickData {
candleStickMutex.RLock()
defer candleStickMutex.RUnlock()
low := 0
high := len(data)
// data.TimeSec >= tsのデータを取得する
@@ -118,7 +122,7 @@ func getCandleStick(data []*CandlestickData, ts uint64) []*CandlestickData {
high = mid
}
}
return data[low:]
return append(make([]*CandlestickData, 0), data[low:]...)
}

func GetCandlestick1Sec(mt time.Time) []*CandlestickData {

0 comments on commit 9251d4f

Please sign in to comment.