tmp
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
type InstantAggregator struct {
|
||||
firstHourOfDay int
|
||||
lastDayOfMonth int
|
||||
time2period func(uint32) uint32
|
||||
currentPeriod uint32
|
||||
since uint32
|
||||
@@ -26,13 +25,11 @@ type InstantAggregator struct {
|
||||
type InstantAggregatorOptions struct {
|
||||
GroupBy diploma.GroupBy
|
||||
FirstHourOfDay int
|
||||
LastDayOfMonth int
|
||||
}
|
||||
|
||||
func NewInstantAggregator(opt InstantAggregatorOptions) (*InstantAggregator, error) {
|
||||
s := &InstantAggregator{
|
||||
firstHourOfDay: opt.FirstHourOfDay,
|
||||
lastDayOfMonth: opt.LastDayOfMonth,
|
||||
}
|
||||
|
||||
switch opt.GroupBy {
|
||||
@@ -48,17 +45,9 @@ func NewInstantAggregator(opt InstantAggregatorOptions) (*InstantAggregator, err
|
||||
|
||||
case diploma.GroupByMonth:
|
||||
if s.firstHourOfDay > 0 {
|
||||
if s.lastDayOfMonth > 0 {
|
||||
s.time2period = s.groupByMonthUsingFHDAndLDM
|
||||
} else {
|
||||
s.time2period = s.groupByMonthUsingFHD
|
||||
}
|
||||
s.time2period = s.groupByMonthUsingFHD
|
||||
} else {
|
||||
if s.lastDayOfMonth > 0 {
|
||||
s.time2period = s.groupByMonthUsingLDM
|
||||
} else {
|
||||
s.time2period = groupByMonth
|
||||
}
|
||||
s.time2period = groupByMonth
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -145,32 +134,10 @@ func (s *InstantAggregator) groupByMonthUsingFHD(timestamp uint32) uint32 {
|
||||
return uint32(tm.Unix())
|
||||
}
|
||||
|
||||
func (s *InstantAggregator) groupByMonthUsingLDM(timestamp uint32) uint32 {
|
||||
tm := timeutil.FirstSecondInPeriod(time.Unix(int64(timestamp), 0), "m")
|
||||
if tm.Day() > s.lastDayOfMonth {
|
||||
tm = tm.AddDate(0, 1, 0)
|
||||
}
|
||||
return uint32(tm.Unix())
|
||||
}
|
||||
|
||||
func (s *InstantAggregator) groupByMonthUsingFHDAndLDM(timestamp uint32) uint32 {
|
||||
// ВАЖНО!
|
||||
// Сперва проверяю время.
|
||||
tm := timeutil.FirstSecondInPeriod(time.Unix(int64(timestamp), 0), "m")
|
||||
if tm.Hour() < s.firstHourOfDay {
|
||||
tm = tm.AddDate(0, 0, -1)
|
||||
}
|
||||
if tm.Day() > s.lastDayOfMonth {
|
||||
tm = tm.AddDate(0, 1, 0)
|
||||
}
|
||||
return uint32(tm.Unix())
|
||||
}
|
||||
|
||||
// CUMULATIVE
|
||||
|
||||
type CumulativeAggregator struct {
|
||||
firstHourOfDay int
|
||||
lastDayOfMonth int
|
||||
time2period func(uint32) uint32
|
||||
currentPeriod uint32
|
||||
since uint32
|
||||
@@ -183,13 +150,11 @@ type CumulativeAggregator struct {
|
||||
type CumulativeAggregatorOptions struct {
|
||||
GroupBy diploma.GroupBy
|
||||
FirstHourOfDay int
|
||||
LastDayOfMonth int
|
||||
}
|
||||
|
||||
func NewCumulativeAggregator(opt CumulativeAggregatorOptions) (*CumulativeAggregator, error) {
|
||||
s := &CumulativeAggregator{
|
||||
firstHourOfDay: opt.FirstHourOfDay,
|
||||
lastDayOfMonth: opt.LastDayOfMonth,
|
||||
}
|
||||
|
||||
switch opt.GroupBy {
|
||||
@@ -205,17 +170,9 @@ func NewCumulativeAggregator(opt CumulativeAggregatorOptions) (*CumulativeAggreg
|
||||
|
||||
case diploma.GroupByMonth:
|
||||
if s.firstHourOfDay > 0 {
|
||||
if s.lastDayOfMonth > 0 {
|
||||
s.time2period = s.groupByMonthUsingFHDAndLDM
|
||||
} else {
|
||||
s.time2period = s.groupByMonthUsingFHD
|
||||
}
|
||||
s.time2period = s.groupByMonthUsingFHD
|
||||
} else {
|
||||
if s.lastDayOfMonth > 0 {
|
||||
s.time2period = s.groupByMonthUsingLDM
|
||||
} else {
|
||||
s.time2period = groupByMonth
|
||||
}
|
||||
s.time2period = groupByMonth
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -291,27 +248,6 @@ func (s *CumulativeAggregator) groupByMonthUsingFHD(timestamp uint32) uint32 {
|
||||
return uint32(tm.Unix())
|
||||
}
|
||||
|
||||
func (s *CumulativeAggregator) groupByMonthUsingLDM(timestamp uint32) uint32 {
|
||||
tm := timeutil.FirstSecondInPeriod(time.Unix(int64(timestamp), 0), "m")
|
||||
if tm.Day() > s.lastDayOfMonth {
|
||||
tm = tm.AddDate(0, 1, 0)
|
||||
}
|
||||
return uint32(tm.Unix())
|
||||
}
|
||||
|
||||
func (s *CumulativeAggregator) groupByMonthUsingFHDAndLDM(timestamp uint32) uint32 {
|
||||
// ВАЖНО!
|
||||
// Сперва проверяю время.
|
||||
tm := timeutil.FirstSecondInPeriod(time.Unix(int64(timestamp), 0), "m")
|
||||
if tm.Hour() < s.firstHourOfDay {
|
||||
tm = tm.AddDate(0, 0, -1)
|
||||
}
|
||||
if tm.Day() > s.lastDayOfMonth {
|
||||
tm = tm.AddDate(0, 1, 0)
|
||||
}
|
||||
return uint32(tm.Unix())
|
||||
}
|
||||
|
||||
func groupByHour(timestamp uint32) uint32 {
|
||||
return uint32(timeutil.FirstSecondInPeriod(time.Unix(int64(timestamp), 0), "h").Unix())
|
||||
}
|
||||
|
||||
@@ -430,7 +430,6 @@ type FindInstantPeriodsReq struct {
|
||||
Until uint32
|
||||
GroupBy octopus.GroupBy
|
||||
FirstHourOfDay int
|
||||
LastDayOfMonth int
|
||||
}
|
||||
|
||||
func (s *Atree) FindInstantPeriods(req FindInstantPeriodsReq) error {
|
||||
@@ -442,7 +441,6 @@ func (s *Atree) FindInstantPeriods(req FindInstantPeriodsReq) error {
|
||||
aggregator, err := NewInstantAggregator(InstantAggregatorOptions{
|
||||
GroupBy: req.GroupBy,
|
||||
FirstHourOfDay: req.FirstHourOfDay,
|
||||
LastDayOfMonth: req.LastDayOfMonth,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -499,7 +497,6 @@ type FindCumulativePeriodsReq struct {
|
||||
Until uint32
|
||||
GroupBy octopus.GroupBy
|
||||
FirstHourOfDay int
|
||||
LastDayOfMonth int
|
||||
}
|
||||
|
||||
func (s *Atree) FindCumulativePeriods(req FindCumulativePeriodsReq) error {
|
||||
@@ -511,7 +508,6 @@ func (s *Atree) FindCumulativePeriods(req FindCumulativePeriodsReq) error {
|
||||
aggregator, err := NewCumulativeAggregator(CumulativeAggregatorOptions{
|
||||
GroupBy: req.GroupBy,
|
||||
FirstHourOfDay: req.FirstHourOfDay,
|
||||
LastDayOfMonth: req.LastDayOfMonth,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user