wp
This commit is contained in:
@@ -6,8 +6,8 @@ import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
diploma "gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/bin"
|
||||
bin "gordenko.dev/dima/bin/little"
|
||||
"gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/timeutil"
|
||||
)
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
type InstantPeriodsWriterOptions struct {
|
||||
Dst io.Writer
|
||||
GroupBy diploma.GroupBy
|
||||
GroupBy qb.GroupBy
|
||||
AggregateFuncs byte
|
||||
FirstHourOfDay int
|
||||
}
|
||||
@@ -24,7 +24,7 @@ type InstantPeriodsWriter struct {
|
||||
aggregateFuncs byte
|
||||
arr []byte
|
||||
responder *ChunkedResponder
|
||||
groupBy diploma.GroupBy
|
||||
groupBy qb.GroupBy
|
||||
firstHourOfDay int
|
||||
time2period func(uint32) time.Time
|
||||
currentPeriod time.Time
|
||||
@@ -45,13 +45,13 @@ func NewInstantPeriodsWriter(opt InstantPeriodsWriterOptions) (*InstantPeriodsWr
|
||||
}
|
||||
// Считаю q, чтобы заранее выделить массив для упаковки периодов
|
||||
var q int
|
||||
if (opt.AggregateFuncs & diploma.AggregateMin) == diploma.AggregateMin {
|
||||
if (opt.AggregateFuncs & qb.AggregateMin) == qb.AggregateMin {
|
||||
q++
|
||||
}
|
||||
if (opt.AggregateFuncs & diploma.AggregateMax) == diploma.AggregateMax {
|
||||
if (opt.AggregateFuncs & qb.AggregateMax) == qb.AggregateMax {
|
||||
q++
|
||||
}
|
||||
if (opt.AggregateFuncs & diploma.AggregateAvg) == diploma.AggregateAvg {
|
||||
if (opt.AggregateFuncs & qb.AggregateAvg) == qb.AggregateAvg {
|
||||
q++
|
||||
}
|
||||
|
||||
@@ -70,17 +70,17 @@ func NewInstantPeriodsWriter(opt InstantPeriodsWriterOptions) (*InstantPeriodsWr
|
||||
}
|
||||
|
||||
switch opt.GroupBy {
|
||||
case diploma.GroupByHour:
|
||||
case qb.GroupByHour:
|
||||
s.time2period = groupByHour
|
||||
|
||||
case diploma.GroupByDay:
|
||||
case qb.GroupByDay:
|
||||
if s.firstHourOfDay > 0 {
|
||||
s.time2period = s.groupByDayUsingFHD
|
||||
} else {
|
||||
s.time2period = groupByDay
|
||||
}
|
||||
|
||||
case diploma.GroupByMonth:
|
||||
case qb.GroupByMonth:
|
||||
if s.firstHourOfDay > 0 {
|
||||
s.time2period = s.groupByMonthUsingFHD
|
||||
} else {
|
||||
@@ -174,12 +174,12 @@ func (s *InstantPeriodsWriter) feed(timestamp uint32, value float64, isBuffer bo
|
||||
|
||||
func (s *InstantPeriodsWriter) decrementPeriod() {
|
||||
switch s.groupBy {
|
||||
case diploma.GroupByHour:
|
||||
case qb.GroupByHour:
|
||||
s.currentPeriod = s.currentPeriod.Add(-1 * time.Hour)
|
||||
//fmt.Println("decrement")
|
||||
case diploma.GroupByDay:
|
||||
case qb.GroupByDay:
|
||||
s.currentPeriod = s.currentPeriod.AddDate(0, 0, -1)
|
||||
case diploma.GroupByMonth:
|
||||
case qb.GroupByMonth:
|
||||
s.currentPeriod = s.currentPeriod.AddDate(0, -1, 0)
|
||||
}
|
||||
}
|
||||
@@ -210,15 +210,15 @@ func (s *InstantPeriodsWriter) packPeriod(timestamp uint32) {
|
||||
bin.PutUint32(s.arr[8:], s.endTimestamp)
|
||||
|
||||
pos := 12
|
||||
if (s.aggregateFuncs & diploma.AggregateMin) == diploma.AggregateMin {
|
||||
if (s.aggregateFuncs & qb.AggregateMin) == qb.AggregateMin {
|
||||
bin.PutFloat64(s.arr[pos:], s.min)
|
||||
pos += 8
|
||||
}
|
||||
if (s.aggregateFuncs & diploma.AggregateMax) == diploma.AggregateMax {
|
||||
if (s.aggregateFuncs & qb.AggregateMax) == qb.AggregateMax {
|
||||
bin.PutFloat64(s.arr[pos:], s.max)
|
||||
pos += 8
|
||||
}
|
||||
if (s.aggregateFuncs & diploma.AggregateAvg) == diploma.AggregateAvg {
|
||||
if (s.aggregateFuncs & qb.AggregateAvg) == qb.AggregateAvg {
|
||||
bin.PutFloat64(s.arr[pos:], s.total/float64(s.entries))
|
||||
}
|
||||
}
|
||||
@@ -236,7 +236,7 @@ type CumulativePeriodsWriter struct {
|
||||
responder *ChunkedResponder
|
||||
firstHourOfDay int
|
||||
currentPeriod time.Time
|
||||
groupBy diploma.GroupBy
|
||||
groupBy qb.GroupBy
|
||||
time2period func(uint32) time.Time
|
||||
endTimestamp uint32
|
||||
endValue float64
|
||||
@@ -246,7 +246,7 @@ type CumulativePeriodsWriter struct {
|
||||
|
||||
type CumulativePeriodsWriterOptions struct {
|
||||
Dst io.Writer
|
||||
GroupBy diploma.GroupBy
|
||||
GroupBy qb.GroupBy
|
||||
FirstHourOfDay int
|
||||
}
|
||||
|
||||
@@ -271,17 +271,17 @@ func NewCumulativePeriodsWriter(opt CumulativePeriodsWriterOptions) (*Cumulative
|
||||
}
|
||||
|
||||
switch opt.GroupBy {
|
||||
case diploma.GroupByHour:
|
||||
case qb.GroupByHour:
|
||||
s.time2period = groupByHour
|
||||
|
||||
case diploma.GroupByDay:
|
||||
case qb.GroupByDay:
|
||||
if s.firstHourOfDay > 0 {
|
||||
s.time2period = s.groupByDayUsingFHD
|
||||
} else {
|
||||
s.time2period = groupByDay
|
||||
}
|
||||
|
||||
case diploma.GroupByMonth:
|
||||
case qb.GroupByMonth:
|
||||
if s.firstHourOfDay > 0 {
|
||||
s.time2period = s.groupByMonthUsingFHD
|
||||
} else {
|
||||
@@ -360,12 +360,12 @@ func (s *CumulativePeriodsWriter) feed(timestamp uint32, value float64, isBuffer
|
||||
|
||||
func (s *CumulativePeriodsWriter) decrementPeriod() {
|
||||
switch s.groupBy {
|
||||
case diploma.GroupByHour:
|
||||
case qb.GroupByHour:
|
||||
s.currentPeriod = s.currentPeriod.Add(-1 * time.Hour)
|
||||
//fmt.Println("decrement")
|
||||
case diploma.GroupByDay:
|
||||
case qb.GroupByDay:
|
||||
s.currentPeriod = s.currentPeriod.AddDate(0, 0, -1)
|
||||
case diploma.GroupByMonth:
|
||||
case qb.GroupByMonth:
|
||||
s.currentPeriod = s.currentPeriod.AddDate(0, -1, 0)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user