Skip to content

Commit

Permalink
feat: Support fractional timeliness days (#18597)
Browse files Browse the repository at this point in the history
* Support fractional timeliness days
  • Loading branch information
jason-p-pickering authored Sep 25, 2024
1 parent df865c5 commit ffaaa0c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public class DataSet extends BaseDimensionalItemObject
private int expiryDays;

/** Days after period end to qualify for timely data submission */
private int timelyDays;
private double timelyDays;

/** User group which will receive notifications when data set is marked complete, can be null. */
private UserGroup notificationRecipients;
Expand Down Expand Up @@ -631,11 +631,11 @@ public void setExpiryDays(int expiryDays) {

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
public int getTimelyDays() {
public double getTimelyDays() {
return timelyDays;
}

public void setTimelyDays(int timelyDays) {
public void setTimelyDays(double timelyDays) {
this.timelyDays = timelyDays;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public class DateUtils {

private static final long MS_PER_S = 1000;

public static final long SECONDS_PER_DAY = 86400;

private static final Pattern DURATION_PATTERN = Pattern.compile("^(\\d+)(d|h|m|s)$");

private static final Map<String, ChronoUnit> TEMPORAL_MAP =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
import static org.hisp.dhis.commons.util.TextUtils.replace;
import static org.hisp.dhis.db.model.DataType.BOOLEAN;
import static org.hisp.dhis.db.model.DataType.CHARACTER_11;
import static org.hisp.dhis.db.model.DataType.DATE;
import static org.hisp.dhis.db.model.DataType.INTEGER;
import static org.hisp.dhis.db.model.DataType.TEXT;
import static org.hisp.dhis.db.model.DataType.TIMESTAMP;
import static org.hisp.dhis.db.model.constraint.Nullable.NOT_NULL;
import static org.hisp.dhis.util.DateUtils.toLongDate;

Expand Down Expand Up @@ -256,7 +256,8 @@ private String getPartitionClause(AnalyticsTablePartition partition) {

private List<AnalyticsTableColumn> getColumns() {
String idColAlias = "concat(ds.uid,'-',ps.iso,'-',ous.organisationunituid,'-',ao.uid) as id ";
String timelyDateDiff = "cast(cdr.date as date) - ps.enddate";
String timelyDateDiff =
"extract(epoch from (cdr.date - ps.enddate)) / ( " + DateUtils.SECONDS_PER_DAY + " )";
String timelyAlias = "((" + timelyDateDiff + ") <= ds.timelydays) as timely";

List<AnalyticsTableColumn> columns = new ArrayList<>();
Expand All @@ -281,7 +282,7 @@ private List<AnalyticsTableColumn> getColumns() {
columns.add(
AnalyticsTableColumn.builder()
.name("value")
.dataType(DATE)
.dataType(TIMESTAMP)
.valueType(FACT)
.selectExpression("cdr.date as value")
.build());
Expand All @@ -304,7 +305,7 @@ select distinct(extract(year from pe.startdate)) \
sql +=
replace(
"and pe.startdate >= '${fromDate}'",
Map.of("fromDate", DateUtils.toMediumDate(params.getFromDate())));
Map.of("fromDate", DateUtils.toLongDate(params.getFromDate())));
}

return jdbcTemplate.queryForList(sql, Integer.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE dataset ALTER COLUMN timelydays TYPE DOUBLE PRECISION USING timelydays::DOUBLE PRECISION;

0 comments on commit ffaaa0c

Please sign in to comment.