Fix messages and percentages in Data Insight reports (#14731)

This commit is contained in:
Mohit Yadav 2024-01-17 16:11:43 +05:30 committed by GitHub
parent 6620389ad1
commit bfbd953b53
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 50 additions and 66 deletions

View File

@ -247,26 +247,22 @@ public class DataInsightsReportApp extends AbstractNativeApplication {
double currentCompletedDescription = getCompletedDescriptionCount(last); double currentCompletedDescription = getCompletedDescriptionCount(last);
double currentTotalCount = getTotalEntityFromDescriptionList(last); double currentTotalCount = getTotalEntityFromDescriptionList(last);
// Calculate Percent Change // Previous Percent
double previousDiff = previousTotalCount - previousCompletedDescription; double previousPercentCompleted = 0D;
double currentDiff = currentTotalCount - currentCompletedDescription; if (previousTotalCount != 0) {
previousPercentCompleted = (previousCompletedDescription / previousTotalCount) * 100;
// Change
double percentChange = 0D;
if (previousDiff != 0) {
percentChange = ((currentDiff - previousDiff) / previousDiff) * 100;
} }
// Completion // Current Percent
double percentCompleted = 0; double currentPercentCompleted = 0;
if (currentTotalCount != 0) { if (currentTotalCount != 0) {
percentCompleted = (currentCompletedDescription / currentTotalCount) * 100; currentPercentCompleted = (currentCompletedDescription / currentTotalCount) * 100;
} }
return getTemplate( return getTemplate(
DataInsightDescriptionAndOwnerTemplate.MetricType.DESCRIPTION, DataInsightDescriptionAndOwnerTemplate.MetricType.DESCRIPTION,
PERCENTAGE_OF_ENTITIES_WITH_DESCRIPTION_BY_TYPE, PERCENTAGE_OF_ENTITIES_WITH_DESCRIPTION_BY_TYPE,
percentCompleted, currentPercentCompleted,
percentChange, currentPercentCompleted - previousPercentCompleted,
numberOfDaysChange); numberOfDaysChange);
} }
@ -300,27 +296,22 @@ public class DataInsightsReportApp extends AbstractNativeApplication {
double currentHasOwner = getCompletedOwnershipCount(last); double currentHasOwner = getCompletedOwnershipCount(last);
double currentTotalCount = getTotalEntityFromOwnerList(last); double currentTotalCount = getTotalEntityFromOwnerList(last);
// Calculate Change // Previous Percent
double previousDiff = previousTotalCount - previousHasOwner; double previousPercentCompleted = 0D;
double currentDiff = currentTotalCount - currentHasOwner; if (previousTotalCount != 0) {
previousPercentCompleted = (previousHasOwner / previousTotalCount) * 100;
// Change Percent
double percentChange = 0D;
if (previousDiff != 0) {
percentChange = ((currentDiff - previousDiff) / previousDiff) * 100;
} }
// Current Percent
// Completion double currentPercentCompleted = 0;
double percentCompleted = 0;
if (currentTotalCount != 0) { if (currentTotalCount != 0) {
percentCompleted = (currentHasOwner / currentTotalCount) * 100; currentPercentCompleted = (currentHasOwner / currentTotalCount) * 100;
} }
return getTemplate( return getTemplate(
DataInsightDescriptionAndOwnerTemplate.MetricType.OWNER, DataInsightDescriptionAndOwnerTemplate.MetricType.OWNER,
PERCENTAGE_OF_ENTITIES_WITH_OWNER_BY_TYPE, PERCENTAGE_OF_ENTITIES_WITH_OWNER_BY_TYPE,
percentCompleted, currentPercentCompleted,
percentChange, currentPercentCompleted - previousPercentCompleted,
numberOfDaysChange); numberOfDaysChange);
} }
@ -479,28 +470,23 @@ public class DataInsightsReportApp extends AbstractNativeApplication {
private long getTimeFromSchedule( private long getTimeFromSchedule(
AppSchedule appSchedule, JobExecutionContext jobExecutionContext) { AppSchedule appSchedule, JobExecutionContext jobExecutionContext) {
AppSchedule.ScheduleTimeline timeline = appSchedule.getScheduleType(); AppSchedule.ScheduleTimeline timeline = appSchedule.getScheduleType();
switch (timeline) { return switch (timeline) {
case HOURLY: case HOURLY -> 3600000L;
return 3600000L; case DAILY -> 86400000L;
case DAILY: case WEEKLY -> 604800000L;
return 86400000L; case MONTHLY -> 2592000000L;
case WEEKLY: case CUSTOM -> {
return 604800000L;
case MONTHLY:
return 2592000000L;
case CUSTOM:
if (jobExecutionContext.getTrigger() != null) { if (jobExecutionContext.getTrigger() != null) {
Trigger triggerQrz = jobExecutionContext.getTrigger(); Trigger triggerQrz = jobExecutionContext.getTrigger();
Date previousFire = Date previousFire =
triggerQrz.getPreviousFireTime() == null triggerQrz.getPreviousFireTime() == null
? triggerQrz.getStartTime() ? triggerQrz.getStartTime()
: triggerQrz.getPreviousFireTime(); : triggerQrz.getPreviousFireTime();
return previousFire.toInstant().toEpochMilli(); yield previousFire.toInstant().toEpochMilli();
} }
return 86400000L; yield 86400000L;
default: }
throw new IllegalArgumentException("Invalid Trigger Type."); };
}
} }
public static int getNumberOfDays(AppSchedule appSchedule) { public static int getNumberOfDays(AppSchedule appSchedule) {

View File

@ -28,9 +28,9 @@ public class DataInsightDescriptionAndOwnerTemplate {
NOT_MET NOT_MET
} }
private final Double percentCompleted; private final String percentCompleted;
private boolean kpiAvailable; private boolean kpiAvailable;
private Double percentChange; private String percentChange;
private String targetKpi; private String targetKpi;
private String numberOfDaysLeft; private String numberOfDaysLeft;
private String completeMessage; private String completeMessage;
@ -47,9 +47,9 @@ public class DataInsightDescriptionAndOwnerTemplate {
String numberOfDaysLeft, String numberOfDaysLeft,
int numberOfDaysChange, int numberOfDaysChange,
Map<String, Double> tierMap) { Map<String, Double> tierMap) {
this.percentCompleted = percentCompleted; this.percentCompleted = String.format("%.2f", percentCompleted);
this.targetKpi = targetKpi; this.targetKpi = targetKpi;
this.percentChange = percentChange; this.percentChange = String.format("%.2f", percentChange);
this.kpiAvailable = isKpiAvailable; this.kpiAvailable = isKpiAvailable;
this.numberOfDaysLeft = numberOfDaysLeft; this.numberOfDaysLeft = numberOfDaysLeft;
this.tierMap = tierMap; this.tierMap = tierMap;
@ -60,10 +60,10 @@ public class DataInsightDescriptionAndOwnerTemplate {
} }
this.completeMessage = this.completeMessage =
String.format( String.format(
"The %s changed by <strong style=\"color: %s;\">%.2f%%</strong> per cent in the last week. %s", "The %s changed by <strong style=\"color: %s;\">%s</strong>%% in the last week. %s",
getMetricTypeMessage(metricType), getMetricTypeMessage(metricType),
color, color,
percentChange, this.percentChange,
getKpiCriteriaMessage(metricType, criteria)); getKpiCriteriaMessage(metricType, criteria));
} }
@ -81,8 +81,8 @@ public class DataInsightDescriptionAndOwnerTemplate {
return switch (criteria) { return switch (criteria) {
case MET -> "Great the Target Set for KPIs has been achieved. It's time to restructure your goals, set new KPIs and progress faster."; case MET -> "Great the Target Set for KPIs has been achieved. It's time to restructure your goals, set new KPIs and progress faster.";
case IN_PROGRESS -> String.format( case IN_PROGRESS -> String.format(
"To meet the KPIs you will need a minimum of %s per cent completed description in the next %s days.", "To meet the KPIs you will need a minimum of %s%% %s in the next %s days.",
targetKpi, numberOfDaysLeft); targetKpi, getMetricTypeMessage(metricType).toLowerCase(), numberOfDaysLeft);
case NOT_MET -> "The Target set for KPIs was not met its time to restructure your goals and progress faster."; case NOT_MET -> "The Target set for KPIs was not met its time to restructure your goals and progress faster.";
}; };
} }
@ -91,7 +91,7 @@ public class DataInsightDescriptionAndOwnerTemplate {
return ""; return "";
} }
public Double getPercentCompleted() { public String getPercentCompleted() {
return percentCompleted; return percentCompleted;
} }
@ -103,12 +103,12 @@ public class DataInsightDescriptionAndOwnerTemplate {
this.targetKpi = targetKpi; this.targetKpi = targetKpi;
} }
public Double getPercentChange() { public String getPercentChange() {
return percentChange; return percentChange;
} }
public void setPercentChange(Double percentChange) { public void setPercentChange(Double percentChange) {
this.percentChange = percentChange; this.percentChange = String.format("%.2f", percentChange);
} }
public boolean isKpiAvailable() { public boolean isKpiAvailable() {

View File

@ -14,16 +14,15 @@
package org.openmetadata.service.events.scheduled.template; package org.openmetadata.service.events.scheduled.template;
public class DataInsightTotalAssetTemplate { public class DataInsightTotalAssetTemplate {
private Double totalDataAssets; private String totalDataAssets;
private Double percentChangeTotalAssets; private String percentChangeTotalAssets;
private String completeMessage; private String completeMessage;
private int numberOfDaysChange; private int numberOfDaysChange;
public DataInsightTotalAssetTemplate( public DataInsightTotalAssetTemplate(
Double totalDataAssets, Double percentChangeTotalAssets, int numberOfDaysChange) { Double totalDataAssets, Double percentChangeTotalAssets, int numberOfDaysChange) {
this.totalDataAssets = totalDataAssets; this.totalDataAssets = String.format("%.2f", totalDataAssets);
this.percentChangeTotalAssets = percentChangeTotalAssets; this.percentChangeTotalAssets = String.format("%.2f", percentChangeTotalAssets);
this.numberOfDaysChange = numberOfDaysChange; this.numberOfDaysChange = numberOfDaysChange;
String color = "#BF0000"; String color = "#BF0000";
if (percentChangeTotalAssets > 0) { if (percentChangeTotalAssets > 0) {
@ -31,24 +30,24 @@ public class DataInsightTotalAssetTemplate {
} }
completeMessage = completeMessage =
String.format( String.format(
"In the past week, the Total Data Assets changed by a total of <span style=\"color: %s; font-weight: bold;\">%.2f%%</span>", "In the past week, the Total Data Assets changed by <span style=\"color: %s; font-weight: bold;\">%s</span>%%.",
color, percentChangeTotalAssets); color, this.percentChangeTotalAssets);
} }
public Double getTotalDataAssets() { public String getTotalDataAssets() {
return totalDataAssets; return totalDataAssets;
} }
public void setTotalDataAssets(Double totalDataAssets) { public void setTotalDataAssets(Double totalDataAssets) {
this.totalDataAssets = totalDataAssets; this.totalDataAssets = String.format("%.2f", totalDataAssets);
} }
public Double getPercentChangeTotalAssets() { public String getPercentChangeTotalAssets() {
return percentChangeTotalAssets; return percentChangeTotalAssets;
} }
public void setPercentChangeTotalAssets(Double percentChangeTotalAssets) { public void setPercentChangeTotalAssets(Double percentChangeTotalAssets) {
this.percentChangeTotalAssets = percentChangeTotalAssets; this.percentChangeTotalAssets = String.format("%.2f", percentChangeTotalAssets);
} }
public String getCompleteMessage() { public String getCompleteMessage() {

View File

@ -6,7 +6,6 @@
"sendToTeams": true "sendToTeams": true
}, },
"appSchedule": { "appSchedule": {
"scheduleType": "Custom", "scheduleType": "Weekly"
"cronExpression": "0 59 23 ? * 1"
} }
} }