Browse Source

added quarter interval type

pull/14253/head
IrynaMatveieva 11 months ago
parent
commit
11983660f7
  1. 1
      common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/AggInterval.java
  2. 1
      common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/AggIntervalType.java
  3. 12
      common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/BaseAggInterval.java
  4. 1
      common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/MonthInterval.java
  5. 30
      common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/QuarterInterval.java

1
common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/AggInterval.java

@ -31,6 +31,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonSubTypes.Type(value = WeekInterval.class, name = "WEEK"),
@JsonSubTypes.Type(value = WeekSunSatInterval.class, name = "WEEK_SUN_SAT"),
@JsonSubTypes.Type(value = MonthInterval.class, name = "MONTH"),
@JsonSubTypes.Type(value = QuarterInterval.class, name = "QUARTER"),
@JsonSubTypes.Type(value = YearInterval.class, name = "YEAR"),
@JsonSubTypes.Type(value = CustomInterval.class, name = "CUSTOM")
})

1
common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/AggIntervalType.java

@ -22,6 +22,7 @@ public enum AggIntervalType {
WEEK,
WEEK_SUN_SAT,
MONTH,
QUARTER,
YEAR,
CUSTOM

12
common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/BaseAggInterval.java

@ -47,6 +47,7 @@ public abstract class BaseAggInterval implements AggInterval {
case DAY -> Duration.ofDays(1).toMillis();
case WEEK, WEEK_SUN_SAT -> Duration.ofDays(7L).toMillis();
case MONTH -> Duration.ofDays(Math.round(30)).toMillis(); // average
case QUARTER -> Duration.ofDays(Math.round(91)).toMillis();
case YEAR -> Duration.ofDays(Math.round(365)).toMillis();
default -> throw new IllegalArgumentException("Unsupported type: " + getType());
};
@ -88,6 +89,7 @@ public abstract class BaseAggInterval implements AggInterval {
case WEEK -> alignByWeeks(reference, DayOfWeek.MONDAY, next);
case WEEK_SUN_SAT -> alignByWeeks(reference, DayOfWeek.SUNDAY, next);
case MONTH -> alignByMonths(reference, next);
case QUARTER -> alignByQuarters(reference, next);
case YEAR -> alignByYears(reference, next);
default -> throw new IllegalArgumentException("Unsupported interval type: " + getType());
};
@ -114,6 +116,16 @@ public abstract class BaseAggInterval implements AggInterval {
return next ? base.plusMonths(1) : base;
}
private ZonedDateTime alignByQuarters(ZonedDateTime now, boolean next) {
int month = now.getMonthValue();
int quarterStartMonth = ((month - 1) / 3) * 3 + 1; // 1, 4, 7, 10
ZonedDateTime base = ZonedDateTime.of(
LocalDate.of(now.getYear(), quarterStartMonth, 1),
LocalTime.MIDNIGHT,
now.getZone());
return next ? base.plusMonths(3) : base;
}
private ZonedDateTime alignByYears(ZonedDateTime now, boolean next) {
ZonedDateTime base = ZonedDateTime.of(
LocalDate.of(now.getYear(), 1, 1),

1
common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/MonthInterval.java

@ -27,5 +27,4 @@ public class MonthInterval extends BaseAggInterval {
return AggIntervalType.MONTH;
}
}

30
common/data/src/main/java/org/thingsboard/server/common/data/cf/configuration/aggregation/single/interval/QuarterInterval.java

@ -0,0 +1,30 @@
/**
* Copyright © 2016-2025 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.cf.configuration.aggregation.single.interval;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
public class QuarterInterval extends BaseAggInterval {
@Override
public AggIntervalType getType() {
return AggIntervalType.QUARTER;
}
}
Loading…
Cancel
Save