diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java index b1de9e7..86cccb4 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java @@ -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()))) { diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java index 3814476..63bc04a 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/IndicatorPath.java @@ -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 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; } diff --git a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java index 524eb08..d47a749 100644 --- a/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java +++ b/src/main/java/eu/dnetlib/uoamonitorservice/entities/Stakeholder.java @@ -24,6 +24,7 @@ public class Stakeholder { 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 { 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 { this.index_shortName = index_shortName; } + public String getStatsProfile() { + return statsProfile; + } + + public void setStatsProfile(String statsProfile) { + this.statsProfile = statsProfile; + } + public String getLogoUrl() { return logoUrl; } diff --git a/update_db.js b/update_db.js index 459a080..0af2edc 100644 --- a/update_db.js +++ b/update_db.js @@ -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(); \ No newline at end of file