[Monitor Service | master]: Stakeholder.java: Added field private String statsProfile = "monitor"; and getter/setter methods | IndicatorPath.java: Added field private Format format = Format.NUMBER; where Format is enum {NUMBER, PERCENTAGE} and getter/setter methods | IndicatorController.java: On method "onUpdateDefaultIndicator()" check if format was changed | update_db.js: Added method "statsProfileOfIndicatorsAsVariable()".

This commit is contained in:
Konstantina Galouni 2023-05-03 13:02:56 +03:00
parent 806e1e16d8
commit 1119c1fdcf
4 changed files with 146 additions and 9 deletions

View File

@ -302,6 +302,20 @@ public class IndicatorController {
}
log.debug("After type check: "+changed);
if((
(indicatorPath.getFormat() == null && oldIndicatorPath.getFormat() != null)
||
(indicatorPath.getFormat() != null && !indicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat()))
) && (
(oldIndicatorPath.getFormat() == null && indicatorPathBasedOnDefault.getFormat() == null)
||
(oldIndicatorPath.getFormat() != null && oldIndicatorPath.getFormat().equals(indicatorPathBasedOnDefault.getFormat()))
)) {
indicatorPathBasedOnDefault.setFormat(indicatorPath.getFormat());
changed = true;
}
log.debug("After type check: "+changed);
// if(indicatorPath.getSource() != null
// && !indicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource())
// && (oldIndicatorPath.getSource().equals(indicatorPathBasedOnDefault.getSource()))) {

View File

@ -13,8 +13,13 @@ enum IndicatorPathType {
// STATISTICS, SEARCH, METRICS, STATS_TOOL,OLD,IMAGE;
//}
enum Format {
NUMBER, PERCENTAGE
}
public class IndicatorPath {
private IndicatorPathType type; // for charts is type of chart {table, bar, column, etc}
private Format format = Format.NUMBER; // for numbers is if number is percentage or not
private String source; // for numbers is the service {statistics, search, metrics} for charts is the tool {stats-tool,old,metrics, image}
private String url;
private List<String> jsonPath;
@ -27,6 +32,7 @@ public class IndicatorPath {
public IndicatorPath(IndicatorPath indicatorPath) {
setType(indicatorPath.getType());
setFormat(indicatorPath.getFormat());
source = indicatorPath.getSource();
url = indicatorPath.getUrl();
jsonPath = indicatorPath.getJsonPath();
@ -55,6 +61,22 @@ public class IndicatorPath {
}
}
public String getFormat() {
if(format == null) {
return null;
}
return format.name();
}
public void setFormat(String format) {
if(format == null) {
this.format = null;
} else {
Format _format = Format.valueOf(format);
this.format = _format;
}
}
public String getSource() {
return source;
}

View File

@ -24,6 +24,7 @@ public class Stakeholder<StringOrTopic> {
private String index_id;
private String index_name;
private String index_shortName;
private String statsProfile = "monitor";
private String logoUrl;
private boolean isUpload = false;
private String name;
@ -45,6 +46,7 @@ public class Stakeholder<StringOrTopic> {
index_id = stakeholder.getIndex_id();
index_name = stakeholder.getIndex_name();
index_shortName = stakeholder.getIndex_shortName();
statsProfile = stakeholder.getStatsProfile();
logoUrl = stakeholder.getLogoUrl();
isUpload = stakeholder.getIsUpload();
name = stakeholder.getName();
@ -112,6 +114,14 @@ public class Stakeholder<StringOrTopic> {
this.index_shortName = index_shortName;
}
public String getStatsProfile() {
return statsProfile;
}
public void setStatsProfile(String statsProfile) {
this.statsProfile = statsProfile;
}
public String getLogoUrl() {
return logoUrl;
}

View File

@ -294,6 +294,94 @@ function addFooterHelpTextForPortalType(portalType) {
}
}
function statsProfileOfIndicatorsAsVariable() {
print("statsProfileOfIndicatorsAsVariable");
numOfNumbers = 0;
numOfCharts = 0;
numOfNonMonitorProfiles = 0;
numOfMonitorProfiles = 0;
numOfNoProfiles = 0;
differentProfiles = new Set();
// indicators = db.indicator.find({"type": "chart"}).map(function (indicator) {
// indicators = db.indicator.find({"type": "number"}).map(function (indicator) {
indicators = db.indicator.find().map(function (indicator) {
return indicator;
});
print(indicators.length);
for (var i = 0; i < indicators.length; i++) {
indicator = indicators[i];
indicatorPaths = indicator.indicatorPaths;
if(indicatorPaths) {
for (var j = 0; j < indicatorPaths.length; j++) {
indicatorPath = indicatorPaths[j];
chartObjectStr = "";
// if(indicator.type == "chart") {
chartObjectStr = indicatorPath.chartObject;
// chartObject = JSON.parse(chartObjectStr);
if(indicator.type == "chart") {
numOfCharts++;
} else {
numOfNumbers++;
}
// if(i==0) {
// if(chartObject.chartDescription != null && chartObject.chartDescription.queries != null) {
// print(chartObject.chartDescription.queries.length);
// for(var z = 0; z < chartObject.chartDescription.queries.length; z++) {
// query = chartObject.chartDescription.queries[z].query;
// print(query.profile);
// query.profile = "((__statsProfile__))";
// }
// }
// indicatorPath.chartObject = JSON.stringify(chartObject);
if(chartObjectStr != null) {
var included = chartObjectStr.includes('"profile":"monitor"');
if (!included) {
numOfNonMonitorProfiles++;
print("Indicator with id: " + indicator._id + " has not monitor profile.");
} else {
numOfMonitorProfiles++;
}
splitted = chartObjectStr.split('"profile":"');
if (splitted.length == 1) {
numOfNoProfiles++;
}
for (var z = 1; z < splitted.length; z = z + 2) {
prof = splitted[z].split('"')[0];
differentProfiles.add(prof);
}
chartObjectStr = chartObjectStr.split('"profile":"monitor"').join('"profile":"((__profile__))"');
chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE All-inclusive"').join('"profile":"((__profile__))"');
chartObjectStr = chartObjectStr.split('"profile":"OpenAIRE Monitor"').join('"profile":"((__profile__))"');
indicatorPath.chartObject = chartObjectStr;
} else {
print("Indicator with id: " + indicator._id + " has no chartObject");
}
}
}
// save indicator
// db.indicator.save(indicator);
}
print("\n");
print("numOfNumbers: "+numOfNumbers);
print("numOfCharts: "+numOfCharts);
print("numOfMonitorProfiles: "+numOfMonitorProfiles);
print("numOfNonMonitorProfiles: "+numOfNonMonitorProfiles);
print("numOfNoProfiles: "+numOfNoProfiles);
print("Different profiles are: ");
for (var item of differentProfiles) {
print(item);
}
}
use monitordb;
// use 1_openaire-mongodb-beta; // dev db
@ -310,12 +398,15 @@ use monitordb;
// uniqueIndexes();
// 04-06-2021 - 24-06-2021
addHomePageInPortalType("funder");
addFooterDivIdForPortalType("funder");
addFooterHelpTextForPortalType("funder");
addHomePageInPortalType("ri");
addFooterDivIdForPortalType("ri");
addFooterHelpTextForPortalType("ri");
addHomePageInPortalType("organization");
addFooterDivIdForPortalType("organization");
addFooterHelpTextForPortalType("organization");
// addHomePageInPortalType("funder");
// addFooterDivIdForPortalType("funder");
// addFooterHelpTextForPortalType("funder");
// addHomePageInPortalType("ri");
// addFooterDivIdForPortalType("ri");
// addFooterHelpTextForPortalType("ri");
// addHomePageInPortalType("organization");
// addFooterDivIdForPortalType("organization");
// addFooterHelpTextForPortalType("organization");
// 11-04-2023
statsProfileOfIndicatorsAsVariable();