diff --git a/src/app/app.component.ts b/src/app/app.component.ts index b39ae93..2743087 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -8,6 +8,7 @@ import {UserManagementService} from "./openaireLibrary/services/user-management. import {SideBarService} from "./library/sharedComponents/sidebar/sideBar.service"; import {StakeholderService} from "./services/stakeholder.service"; import {Subscriber} from "rxjs"; +import {StakeholderCreator} from "./utils/entities/stakeholderCreator"; @Component({ selector: 'app-root', @@ -43,12 +44,12 @@ export class AppComponent implements OnInit, OnDestroy{ if(params['stakeholder']) { if(!this.stakeholderService.stakeholder || this.stakeholderService.stakeholder.alias !== params['stakeholder']) { - this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => { + // this.stakeholderService.getStakeholder(this.properties.monitorServiceAPIURL, params['stakeholder']).subscribe(stakeholder => { // stakeholder = Stakeholder.createECStakeholder(); - // let stakeHolder = StakeholderCreator.createFunderFromDefaultProfile("ec","funder","ec__________::EC","European Commission","EC",false,"ec",true,true); - this.stakeholderService.setStakeholder(stakeholder); + let stakeHolder = StakeholderCreator.createFunderFromDefaultProfile("ec","funder","ec__________::EC","European Commission","EC",false,"ec",true,true); + this.stakeholderService.setStakeholder(stakeHolder); this.sidebarService.setOpen(true); - }); + // }); } } else { this.stakeholderService.setStakeholder(null); diff --git a/src/app/monitor/monitor.component.html b/src/app/monitor/monitor.component.html index 991434f..6c95d15 100644 --- a/src/app/monitor/monitor.component.html +++ b/src/app/monitor/monitor.component.html @@ -27,6 +27,17 @@
+
Indicators
diff --git a/src/app/monitor/monitor.component.ts b/src/app/monitor/monitor.component.ts index 58f83e2..d62f74c 100644 --- a/src/app/monitor/monitor.component.ts +++ b/src/app/monitor/monitor.component.ts @@ -11,7 +11,7 @@ import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.com import {HelperService} from "../openaireLibrary/utils/helper/helper.service"; import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; import {StakeholderService} from "../services/stakeholder.service"; -import {Category, IndicatorPath, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder"; +import {Category, ChartHelper, IndicatorPath, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder"; import {StatisticsService} from "../utils/services/statistics.service"; import {Item, Sidebar} from "../utils/entities/sidebar"; import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service"; @@ -38,6 +38,9 @@ export class MonitorComponent implements OnInit, OnDestroy { public chartsActiveType: Map = new Map(); private errorMessages: ErrorMessagesComponent; properties: EnvProperties; + fundingL0; + startYear; + endYear; constructor( private route: ActivatedRoute, @@ -193,7 +196,12 @@ export class MonitorComponent implements OnInit, OnDestroy { let urls: Map = new Map(); this.activeSubCategory.numbers.forEach((number, index) => { if (number.isActive && number.isPublic) { - const pair = JSON.stringify([number.indicatorPaths[0].source, number.indicatorPaths[0].url]); + let url = number.indicatorPaths[0].url; + //add fundingLevel0 filter in the query + if(this.fundingL0 && number.indicatorPaths[0].filters.get("fundingL0")){ + url = url + number.indicatorPaths[0].filters.get("fundingL0").replace(ChartHelper.prefix+'fundingL0'+ChartHelper.suffix,encodeURIComponent(this.fundingL0)); + } + const pair = JSON.stringify([number.indicatorPaths[0].source, url]); const indexes = urls.get(pair) ? urls.get(pair) : []; indexes.push(index); urls.set(pair, indexes); @@ -224,7 +232,7 @@ export class MonitorComponent implements OnInit, OnDestroy { public getUrlByStakeHolder(indicatorPath: IndicatorPath) { return this.sanitizer.bypassSecurityTrustResourceUrl( - this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath))); + this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath, this.fundingL0, this.startYear, this.endYear))); } public setActiveChart(index, type: string) { diff --git a/src/app/services/stakeholder.service.ts b/src/app/services/stakeholder.service.ts index 197bc8b..272d82b 100644 --- a/src/app/services/stakeholder.service.ts +++ b/src/app/services/stakeholder.service.ts @@ -81,11 +81,11 @@ export class StakeholderService { indicatorPath.parameters = new Map(Object.entries(indicatorPath.parameters)); } if(indicatorPath.filters) { - let filters = new Map>(); - Object.entries(indicatorPath.filters).forEach(([key, value]) => { - filters.set(key, new Map(Object.entries(value))); - }); - indicatorPath.filters = filters; + // let filters = new Map>(); + // Object.entries(indicatorPath.filters).forEach(([key, value]) => { + // filters.set(key, new Map(Object.entries(value))); + // }); + indicatorPath.filters = new Map(Object.entries(indicatorPath.filters)); } }); }); diff --git a/src/app/utils/entities/stakeholder.ts b/src/app/utils/entities/stakeholder.ts index 6968413..4ad28e1 100644 --- a/src/app/utils/entities/stakeholder.ts +++ b/src/app/utils/entities/stakeholder.ts @@ -1,4 +1,5 @@ import {SafeResourceUrl} from "@angular/platform-browser"; +import {IndicatorUtils} from "../indicator-utils"; export const ChartHelper={ prefix : "((__", suffix : "__))" @@ -264,6 +265,11 @@ export class Stakeholder { defSub.charts.push(chart1); defSub.charts.push(chart2); + let utils = new IndicatorUtils(); + let url = "https://beta.openaire.eu/stats/chart.php?com=query&data={%22table%22:%22result%22,%22fields%22:[{%22fld%22:%22number%22,%22agg%22:%22count%22,%22type%22:%22bar%22,%22yaxis%22:1,%22c%22:false}],%22xaxis%22:{%22name%22:%22result_datasources-datasource-name%22,%22agg%22:%22avg%22},%22group%22:%22%22,%22color%22:%22%22,%22type%22:%22chart%22,%22size%22:%2220%22,%22sort%22:%22count-number%22,%22yaxisheaders%22:[%22%22],%22fieldsheaders%22:[%22publications%22],%22in%22:[],%22filters%22:[{%22name%22:%22result_projects-project-funding_lvl0%22,%22values%22:[%22H2020%22],%22to%22:%22-1%22},{%22name%22:%22type%22,%22values%22:[%22publication%22],%22to%22:%22-1%22},{%22name%22:%22result_datasources-datasource-type%22,%22exvalues%22:[%22Publication%20Catalogue%22]}],%22having%22:[],%22xStyle%22:{%22r%22:%22-%22,%22s%22:%22-%22,%22l%22:%22-%22,%22ft%22:%22-%22,%22wt%22:%22-%22},%22title%22:%22H2020%20Publications%20by%20datasource%20%28top%2020%29%22,%22subtitle%22:%22%22,%22xaxistitle%22:%22datasource%22,%22order%22:%22d%22}&w=90%"; + defSub.charts.push(new Indicator("Old tool graph","","chart","large",true,true,[utils.generateIndicatorByChartUrl("old",url,"bar")])) + url = "http://88.197.53.71:8080/stats-api/chart?json=%7B%22library%22%3A%22HighCharts%22%2C%22chartDescription%22%3A%7B%22queries%22%3A%5B%7B%22name%22%3A%22Research%20data%22%2C%22type%22%3A%22column%22%2C%22query%22%3A%7B%22select%22%3A%5B%7B%22field%22%3A%22dataset%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22dataset.year%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22dataset.project.funder%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22European%20Commission%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%2C%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22dataset.year%22%2C%22type%22%3A%22%3E%3D%22%2C%22values%22%3A%5B%222008%22%5D%7D%2C%7B%22field%22%3A%22dataset.year%22%2C%22type%22%3A%22%3C%3D%22%2C%22values%22%3A%5B%222020%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22dataset%22%2C%22profile%22%3A%22OpenAIRE%20All-inclusive%22%2C%22limit%22%3A%220%22%7D%7D%5D%2C%22chart%22%3A%7B%22backgroundColor%22%3A%22%23FFFFFFFF%22%2C%22borderColor%22%3A%22%23335cadff%22%2C%22borderRadius%22%3A0%2C%22borderWidth%22%3A0%2C%22plotBorderColor%22%3A%22%23ccccccff%22%2C%22plotBorderWidth%22%3A0%7D%2C%22title%22%3A%7B%22text%22%3A%22Research%20data%20timeline%22%7D%2C%22subtitle%22%3A%7B%7D%2C%22yAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Research%20data%22%7D%7D%2C%22xAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Year%22%7D%7D%2C%22lang%22%3A%7B%22noData%22%3A%22No%20Data%20available%20for%20the%20Query%22%7D%2C%22exporting%22%3A%7B%22enabled%22%3Atrue%7D%2C%22plotOptions%22%3A%7B%22series%22%3A%7B%22dataLabels%22%3A%7B%22enabled%22%3Afalse%7D%7D%7D%2C%22legend%22%3A%7B%22enabled%22%3Atrue%2C%22align%22%3A%22center%22%2C%22verticalAlign%22%3A%22bottom%22%2C%22layout%22%3A%22horizontal%22%7D%2C%22credits%22%3A%7B%22href%22%3Anull%2C%22enabled%22%3Atrue%2C%22text%22%3A%22Created%20by%20OpenAIRE%20via%20HighCharts%22%7D%7D%7D"; + defSub.charts.push(new Indicator("","","chart","large",true,true,[utils.generateIndicatorByChartUrl("stats-tool",url,"bar")])) return topic; } } @@ -362,7 +368,7 @@ export class IndicatorPath { jsonPath:string[]; chartObject:string; parameters:Map; - filters:Map>; + filters:Map; constructor(type: string, source:string, url: string, chartObject:string, jsonPath:string[]){ this.type = type; this.url = url; @@ -370,7 +376,7 @@ export class IndicatorPath { this.jsonPath = jsonPath; this.chartObject =chartObject; this.parameters = new Map(); - this.filters = new Map>(); + this.filters = new Map(); } static createParameters(funderName:string=null, title:string=null, chartType:string=null):Map{ @@ -380,4 +386,11 @@ export class IndicatorPath { parameters.set("type",chartType); return parameters; } + static createResultFilters(dbType:string=null):Map{ + let filters = new Map(); + filters.set("fundingL0",'{"groupFilters":[{"field":"'+dbType+'.project.funding level 0","type":"=","values":["'+ChartHelper.prefix+'fundingL0'+ChartHelper.suffix+'"]}],"op":"AND"}'); + filters.set("start_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":">=","values":["'+ChartHelper.prefix+'start_year'+ChartHelper.suffix+'"]}],"op":"AND"}'); + filters.set("end_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":"<=","values":["'+ChartHelper.prefix+'end_year'+ChartHelper.suffix+'"]}],"op":"AND"}'); + return filters; + } } diff --git a/src/app/utils/entities/stakeholderCreator.ts b/src/app/utils/entities/stakeholderCreator.ts index 83a8910..c5907b6 100644 --- a/src/app/utils/entities/stakeholderCreator.ts +++ b/src/app/utils/entities/stakeholderCreator.ts @@ -87,6 +87,8 @@ export class StakeholderCreator { let n_total = new Indicator("Total "+typePlural,null, "number","small",true, true, [new IndicatorPath(null, "search", "/"+dbTypePlural+"/count?fq="+(encodeURIComponent("relfunderid exact "+stakeholder.index_id))+"&format=json", null,["total"])]); + n_total.indicatorPaths[0].filters.set("fundingL0","&fq=relfundinglevel0_name exact "+ChartHelper.prefix+'fundingL0'+ChartHelper.suffix); + pubDefSub.numbers.push(n_total); if( dbType != "publication") { let n_linkedPubs = this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Publications","publication"); @@ -100,6 +102,7 @@ export class StakeholderCreator { res_timeline.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,typePlural+" timeline","column"); res_timeline.indicatorPaths[0].parameters.set("start_year","2008"); res_timeline.indicatorPaths[0].parameters.set("end_year","2020"); + res_timeline.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType); pubDefSub.charts.push(res_timeline); @@ -109,22 +112,26 @@ export class StakeholderCreator { [new IndicatorPath("column", "stats-tool", "chart?json=", '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.classification","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'funder_name' + ChartHelper.suffix + '"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"0"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Type"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]); res_types.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, typeSingl + " types", "bar"); + res_types.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType); pubDefSub.charts.push(res_types); } let res_access_mode = new Indicator("",null, "chart","small",true, true,[new IndicatorPath("pie", "stats-tool", "chart?json=", '{"library":"HighCharts","chartDescription":{"queries":[{"name":"'+typePlural+'","type":"'+ChartHelper.prefix+'type'+ChartHelper.suffix+'","query":{"select":[{"field":"'+dbType+'","aggregate":"count"},{"field":"'+dbType+'.access mode","aggregate":null}],"filters":[{"groupFilters":[{"field":"'+dbType+'.project.funder","type":"=","values":["'+ChartHelper.prefix+'funder_name'+ChartHelper.suffix+'"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"0"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"'+ChartHelper.prefix+'title'+ChartHelper.suffix+'"},"subtitle":{},"yAxis":{"title":{"text":"'+typePlural+'"}},"xAxis":{"title":{"text":"Year"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]); res_access_mode.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,typeSingl+" acccess mode","pie"); + res_access_mode.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType); pubDefSub.charts.push(res_access_mode); if( dbType != "publication") { let res_sci_area = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=", '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'funder_name' + ChartHelper.suffix + '"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Scientific area"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]); res_sci_area.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, typeSingl + " scientific area", "bar"); + res_sci_area.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType); pubDefSub.charts.push(res_sci_area); let res_programmes = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=", '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'funder_name' + ChartHelper.suffix + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.project.funding level 2","type":"!=","values":[" "]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Programmes"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]); res_programmes.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, typeSingl + " programmes", "bar"); + res_programmes.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType); pubDefSub.charts.push(res_programmes); } //{"library":"HighCharts","chartDescription":{"queries":[{"name":"Research Data","type":"bar","query":{"select":[{"field":"dataset","aggregate":"count"},{"field":"dataset.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"dataset.project.funder","type":"=","values":["European Commission"]}],"op":"AND"}],"entity":"dataset","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Scientific Area"},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}} @@ -165,6 +172,7 @@ export class StakeholderCreator { '{"library":"HighCharts","chartDescription":{"queries":[{"name":"'+typePlural+'","type":"'+ChartHelper.prefix+'type'+ChartHelper.suffix+'","query":{"name":"monitor.'+ChartHelper.prefix+'id'+ChartHelper.suffix+'.'+dbTypePlural+'.pidtypes"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"'+ChartHelper.prefix+'title'+ChartHelper.suffix+'"},"subtitle":{},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]); pid.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,typeSingl+" PIDs","pie"); pid.indicatorPaths[0].parameters.set("id",stakeholder.index_shortName.toLowerCase()); + pid.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType); pubDefSub.charts.push(pid); return pubDefSub; } @@ -238,7 +246,11 @@ export class StakeholderCreator { static createLinkToIndicator(stakeholder:Stakeholder,typePlural, typeSingl, dbType, linkedToName,linkedToType ):Indicator { let n_linkedPubs = new Indicator(typePlural+" linked to "+linkedToName, null, "number", "small", true, true, [new IndicatorPath(null, "search", "/resources?query=" + encodeURIComponent(" ( (oaftype exact result) and (resulttypeid exact " + dbType + ") and (relresulttype="+linkedToType+") )") + "&fq=" + (encodeURIComponent("relfunderid exact " + stakeholder.index_id)) + "&page=0&size=0&format=json", null, ["meta", "total"])]); - + n_linkedPubs.indicatorPaths[0].filters.set("fundingL0","&fq=relfundinglevel0_name exact "+ChartHelper.prefix+'fundingL0'+ChartHelper.suffix); + /* + filters.set("start_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":">=","values":["'+ChartHelper.prefix+'start_year'+ChartHelper.suffix+'"]}],"op":"AND"}'); + filters.set("end_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":"<=","values":["'+ChartHelper.prefix+'end_year'+ChartHelper.suffix+'"]}],"op":"AND"}'); + */ return n_linkedPubs; } static createFundingImpactTopic():Topic{ diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 5ae9614..9e26829 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -1,4 +1,4 @@ -import {ChartHelper, IndicatorPath} from "./entities/stakeholder"; +import {ChartHelper, IndicatorPath, Stakeholder} from "./entities/stakeholder"; export class IndicatorUtils { @@ -20,13 +20,35 @@ export class IndicatorUtils { ignoredParameters = ['funder_name']; - public getFullUrl(indicatorPath: IndicatorPath): string { + public getFullUrl(indicatorPath: IndicatorPath, fundingL0:string = null, startDate:string = null, endDate:string = null):string{ + let replacedUrl = indicatorPath.chartObject; if (indicatorPath.parameters) { - Object.entries(indicatorPath.parameters).forEach((key, value) => { - replacedUrl = replacedUrl.replace(ChartHelper.prefix + key + ChartHelper.suffix, value.toString()); + indicatorPath.parameters.forEach((value, key) => { + let replacedValue = value.toString(); + if( startDate && key == "start_year" && indicatorPath.filters.get("start_year")){ + replacedValue = (replacedValue < startDate)?startDate:replacedValue; + } + if( endDate && key == "end_year" && indicatorPath.filters.get("end_year")){ + replacedValue = (replacedValue > endDate)?endDate:replacedValue; + } + replacedUrl = replacedUrl.replace(ChartHelper.prefix + key + ChartHelper.suffix, replacedValue); }); } + if(indicatorPath.chartObject){ + if(fundingL0 && indicatorPath.filters.get("fundingL0")){ + let newJsonObject = JSON.parse(replacedUrl); + for(let queries of newJsonObject["chartDescription"]["queries"]){ + if(!queries["query"]["filters"] || queries["query"]["filters"].length ==0) { + queries["query"]["filters"] = []; + } + //TODO check how it works if the query already has a filter + queries["query"]["filters"].push(JSON.parse(indicatorPath.filters.get("fundingL0").replace(ChartHelper.prefix + "fundingL0" + ChartHelper.suffix,fundingL0))); + } + replacedUrl = JSON.stringify(newJsonObject); + + } + } return indicatorPath.url + encodeURIComponent(replacedUrl); } @@ -45,9 +67,15 @@ export class IndicatorUtils { this.extractStartYear(chart, indicatorPath); this.extractEndYear(chart, indicatorPath); indicatorPath.chartObject = JSON.stringify(chart); + this.addResultFilters(chart,indicatorPath); } else if (source === 'old') { - indicatorPath.url = url.split("data=")[0] + "data="; - indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1]); + indicatorPath.url = url.split("data=")[0].split("/stats/")[1] + "data="; + indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1].split("&")[0]); + let chart = JSON.parse(indicatorPath.chartObject); + this.extractOldToolTitle(chart,indicatorPath); + this.extractOldToolXTitle(chart,indicatorPath); + this.extractOldToolYTitle(chart,indicatorPath); + indicatorPath.chartObject = JSON.stringify(chart); } else { indicatorPath.url = url; indicatorPath.type = type; @@ -69,23 +97,33 @@ export class IndicatorUtils { private extractFunder(obj, indicatorPath: IndicatorPath) { let funderName; - for (let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]) { - if (filter["groupFilters"][0]["field"].indexOf(".funder") != -1) { - funderName = filter["groupFilters"][0]["values"][0]; - filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "funder_name" + ChartHelper.suffix; - indicatorPath.parameters.set("funder_name", funderName); + for (let query of obj["chartDescription"]["queries"]) { + if(!query["query"]["filters"]){ + return; + } + for (let filter of query["query"]["filters"]) { + if (filter["groupFilters"][0]["field"].indexOf(".funder") != -1) { + funderName = filter["groupFilters"][0]["values"][0]; + filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "funder_name" + ChartHelper.suffix; + indicatorPath.parameters.set("funder_name", funderName); + } } } } private extractStartYear(obj, indicatorPath: IndicatorPath) { let start_year; - for (let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]) { - for (let gfilter of filter["groupFilters"]) { - if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf(">") != -1) { - start_year = gfilter["values"][0]; - gfilter["values"][0] = ChartHelper.prefix + "start_year" + ChartHelper.suffix; - indicatorPath.parameters.set("start_year", start_year); + for (let query of obj["chartDescription"]["queries"]) { + if(!query["query"]["filters"]){ + return; + } + for (let filter of query["query"]["filters"]) { + for (let gfilter of filter["groupFilters"]) { + if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf(">") != -1) { + start_year = gfilter["values"][0]; + gfilter["values"][0] = ChartHelper.prefix + "start_year" + ChartHelper.suffix; + indicatorPath.parameters.set("start_year", start_year); + } } } } @@ -93,20 +131,26 @@ export class IndicatorUtils { private extractEndYear(obj, indicatorPath: IndicatorPath) { let end_year; - for (let filter of obj["chartDescription"]["queries"][0]["query"]["filters"]) { - for (let gfilter of filter["groupFilters"]) { - if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) { - end_year = gfilter["values"][0]; - gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix; - indicatorPath.parameters.set("end_year", end_year); + for (let query of obj["chartDescription"]["queries"]) { + if(!query["query"]["filters"]){ + return; + } + for (let filter of query["query"]["filters"]) { + for (let gfilter of filter["groupFilters"]) { + if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) { + end_year = gfilter["values"][0]; + gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix; + indicatorPath.parameters.set("end_year", end_year); + } } } } } private extractTitle(obj, indicatorPath: IndicatorPath) { - let title = obj["chartDescription"]["title"]["text"]; + let title = ""; if (obj["chartDescription"]["title"]) { + title = obj["chartDescription"]["title"]["text"]; obj["chartDescription"]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix; indicatorPath.parameters.set("title", title); @@ -114,19 +158,84 @@ export class IndicatorUtils { } private extractXTitle(obj, indicatorPath: IndicatorPath) { - let title = obj["chartDescription"]["xAxis"]["title"]["text"]; + let title = ""; if (obj["chartDescription"]["xAxis"]["title"]) { + title = obj["chartDescription"]["xAxis"]["title"]["text"]; obj["chartDescription"]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix; indicatorPath.parameters.set("xAxisTitle", title); } } private extractYTitle(obj, indicatorPath: IndicatorPath) { - let title = obj["chartDescription"]["yAxis"]["title"]["text"]; + let title = ""; if (obj["chartDescription"]["yAxis"]["title"]) { + title = obj["chartDescription"]["yAxis"]["title"]["text"]; obj["chartDescription"]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix; indicatorPath.parameters.set("yAxisTitle", title); } } + private addResultFilters(obj, indicatorPath: IndicatorPath) { + let resultTypes = ["publication","software","dataset","other"]; + let index = -1; + for (let query of obj["chartDescription"]["queries"]) { + if (!query["query"]["select"]) { + return; + } + for (let select of query["query"]["select"]) { + for (var i=0; i < resultTypes.length; i++) { + if(select.field.startsWith(resultTypes[i]) ) { + index = i; + } + } + } + + } + if(index != -1){ + indicatorPath.filters = IndicatorPath.createResultFilters(resultTypes[index]); + } + } + + + private extractOldToolTitle(obj, indicatorPath: IndicatorPath) { + let title = ""; + if (obj["title"]) { + title = obj["title"]; + obj["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix; + indicatorPath.parameters.set("title", title); + + } + } + + private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) { + let title = ""; + if (obj["xaxistitle"]) { + title = obj["xaxistitle"]; + obj["xaxistitle"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix; + indicatorPath.parameters.set("xAxisTitle", title); + } + } + + private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) { + let title = ""; + if (obj["fieldsheaders"] ) { + title = obj["fieldsheaders"]; + obj["fieldsheaders"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix; + indicatorPath.parameters.set("yAxisTitle", title); + } + } } +/* +custom query +http://88.197.53.71:8080/stats-api/chart?json=%7B%22library%22%3A%22HighCharts%22%2C%22chartDescription%22%3A%7B%22queries%22%3A%5B%7B%22name%22%3A%22Publications%22%2C%22type%22%3A%22bar%22%2C%22query%22%3A%7B%22name%22%3A%22monitor.ec.publications.datasources%22%7D%7D%5D%2C%22chart%22%3A%7B%22backgroundColor%22%3A%22%23FFFFFFFF%22%2C%22borderColor%22%3A%22%23335cadff%22%2C%22borderRadius%22%3A0%2C%22borderWidth%22%3A0%2C%22plotBorderColor%22%3A%22%23ccccccff%22%2C%22plotBorderWidth%22%3A0%7D%2C%22title%22%3A%7B%22text%22%3A%22Publication%20content%20provider%22%7D%2C%22subtitle%22%3A%7B%7D%2C%22yAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Publications%22%7D%7D%2C%22xAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Content%20provider%22%7D%7D%2C%22lang%22%3A%7B%22noData%22%3A%22No%20Data%20available%20for%20the%20Query%22%7D%2C%22exporting%22%3A%7B%22enabled%22%3Atrue%7D%2C%22plotOptions%22%3A%7B%22series%22%3A%7B%22dataLabels%22%3A%7B%22enabled%22%3Afalse%7D%7D%7D%2C%22legend%22%3A%7B%22enabled%22%3Atrue%2C%22align%22%3A%22center%22%2C%22verticalAlign%22%3A%22bottom%22%2C%22layout%22%3A%22horizontal%22%7D%2C%22credits%22%3A%7B%22href%22%3Anull%2C%22enabled%22%3Atrue%2C%22text%22%3A%22Created%20by%20OpenAIRE%20via%20HighCharts%22%7D%7D%7D + +query with year filters: +http://88.197.53.71:8080/stats-api/chart?json=%7B%22library%22%3A%22HighCharts%22%2C%22chartDescription%22%3A%7B%22queries%22%3A%5B%7B%22name%22%3A%22Publications%22%2C%22type%22%3A%22column%22%2C%22query%22%3A%7B%22select%22%3A%5B%7B%22field%22%3A%22publication%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22publication.year%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.project.funder%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22European%20Commission%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%2C%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22publication.year%22%2C%22type%22%3A%22%3E%3D%22%2C%22values%22%3A%5B%222008%22%5D%7D%2C%7B%22field%22%3A%22publication.year%22%2C%22type%22%3A%22%3C%3D%22%2C%22values%22%3A%5B%222020%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%5D%2C%22entity%22%3A%22publication%22%2C%22profile%22%3A%22OpenAIRE%20All-inclusive%22%2C%22limit%22%3A%220%22%7D%7D%5D%2C%22chart%22%3A%7B%22backgroundColor%22%3A%22%23FFFFFFFF%22%2C%22borderColor%22%3A%22%23335cadff%22%2C%22borderRadius%22%3A0%2C%22borderWidth%22%3A0%2C%22plotBorderColor%22%3A%22%23ccccccff%22%2C%22plotBorderWidth%22%3A0%7D%2C%22title%22%3A%7B%22text%22%3A%22Publications%20timeline%22%7D%2C%22subtitle%22%3A%7B%7D%2C%22yAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Publications%22%7D%7D%2C%22xAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Year%22%7D%7D%2C%22lang%22%3A%7B%22noData%22%3A%22No%20Data%20available%20for%20the%20Query%22%7D%2C%22exporting%22%3A%7B%22enabled%22%3Atrue%7D%2C%22plotOptions%22%3A%7B%22series%22%3A%7B%22dataLabels%22%3A%7B%22enabled%22%3Afalse%7D%7D%7D%2C%22legend%22%3A%7B%22enabled%22%3Atrue%2C%22align%22%3A%22center%22%2C%22verticalAlign%22%3A%22bottom%22%2C%22layout%22%3A%22horizontal%22%7D%2C%22credits%22%3A%7B%22href%22%3Anull%2C%22enabled%22%3Atrue%2C%22text%22%3A%22Created%20by%20OpenAIRE%20via%20HighCharts%22%7D%7D%7D + +double query +http://88.197.53.71:8080/stats-api/chart?json=%7B%22library%22%3A%22HighCharts%22%2C%22chartDescription%22%3A%7B%22colors%22%3A%5B%22%2342a5f5%22%2C%22%2326a69a%22%2C%22%2390ed7d%22%2C%22%23607d8b%22%2C%22%2300838f%22%2C%22%23689f38%22%2C%22%23e4d354%22%2C%22%232b908f%22%2C%22%23546e7a%22%2C%22%2301579%22%5D%2C%22queries%22%3A%5B%7B%22name%22%3A%22Gold%22%2C%22color%22%3A%22%23f8b500%22%2C%22type%22%3A%22column%22%2C%22query%22%3A%7B%22select%22%3A%5B%7B%22field%22%3A%22result%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22result.year%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22result.project.funder%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22European%20Commission%22%5D%7D%2C%7B%22field%22%3A%22result.project.funding%20level%200%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22H2020%22%5D%7D%2C%7B%22field%22%3A%22result.type%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22publication%22%5D%7D%2C%7B%22field%22%3A%22result.year%22%2C%22type%22%3A%22%3E%3D%22%2C%22values%22%3A%5B%222014%22%5D%7D%2C%7B%22field%22%3A%22result.year%22%2C%22type%22%3A%22%3C%3D%22%2C%22values%22%3A%5B%222019%22%5D%7D%2C%7B%22field%22%3A%22result.access%20mode%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22Open%20Access%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%2C%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22result.datasource.type%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22Journal%22%5D%7D%2C%7B%22field%22%3A%22result.datasource.type%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22Journal%20Aggregator%2FPublisher%22%5D%7D%5D%2C%22op%22%3A%22OR%22%7D%5D%2C%22entity%22%3A%22result%22%2C%22profile%22%3A%22OpenAIRE%20original%22%2C%22limit%22%3A%220%22%7D%7D%2C%7B%22name%22%3A%22Green%22%2C%22color%22%3A%22%23239d60%22%2C%22type%22%3A%22column%22%2C%22query%22%3A%7B%22select%22%3A%5B%7B%22field%22%3A%22result%22%2C%22aggregate%22%3A%22count%22%7D%2C%7B%22field%22%3A%22result.year%22%2C%22aggregate%22%3Anull%7D%5D%2C%22filters%22%3A%5B%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22result.project.funder%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22European%20Commission%22%5D%7D%2C%7B%22field%22%3A%22result.project.funding%20level%200%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22H2020%22%5D%7D%2C%7B%22field%22%3A%22result.type%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22publication%22%5D%7D%2C%7B%22field%22%3A%22result.year%22%2C%22type%22%3A%22%3E%3D%22%2C%22values%22%3A%5B%222014%22%5D%7D%2C%7B%22field%22%3A%22result.year%22%2C%22type%22%3A%22%3C%3D%22%2C%22values%22%3A%5B%222019%22%5D%7D%2C%7B%22field%22%3A%22result.access%20mode%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22Open%20Access%22%5D%7D%5D%2C%22op%22%3A%22AND%22%7D%2C%7B%22groupFilters%22%3A%5B%7B%22field%22%3A%22result.datasource.type%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22Institutional%20Repository%22%5D%7D%2C%7B%22field%22%3A%22result.datasource.type%22%2C%22type%22%3A%22%3D%22%2C%22values%22%3A%5B%22Thematic%20Repository%22%5D%7D%5D%2C%22op%22%3A%22OR%22%7D%5D%2C%22entity%22%3A%22result%22%2C%22profile%22%3A%22OpenAIRE%20original%22%2C%22limit%22%3A%220%22%7D%7D%5D%2C%22chart%22%3A%7B%22backgroundColor%22%3A%22%23FFFFFFFF%22%2C%22borderColor%22%3A%22%23335cadff%22%2C%22borderRadius%22%3A0%2C%22borderWidth%22%3A0%2C%22plotBorderColor%22%3A%22%23ccccccff%22%2C%22plotBorderWidth%22%3A0%7D%2C%22title%22%3A%7B%22text%22%3A%22H2020%20green%20and%20gold%20publications%22%7D%2C%22subtitle%22%3A%7B%22text%22%3A%22over%20time%22%7D%2C%22yAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Publications%22%7D%7D%2C%22xAxis%22%3A%7B%22title%22%3A%7B%22text%22%3A%22Year%22%7D%7D%2C%22lang%22%3A%7B%22noData%22%3A%22No%20Data%20available%20for%20the%20Query%22%7D%2C%22exporting%22%3A%7B%22enabled%22%3Atrue%7D%2C%22plotOptions%22%3A%7B%22series%22%3A%7B%22dataLabels%22%3A%7B%22enabled%22%3Afalse%7D%7D%7D%2C%22legend%22%3A%7B%22enabled%22%3Afalse%2C%22align%22%3A%22center%22%2C%22verticalAlign%22%3A%22bottom%22%2C%22layout%22%3A%22horizontal%22%7D%2C%22credits%22%3A%7B%22href%22%3Anull%2C%22enabled%22%3Atrue%2C%22text%22%3A%22Created%20by%20OpenAIRE%20via%20HighCharts%22%7D%7D%7D + + +//old tool +https://www.openaire.eu/stats/chart.php?com=query&data={%22table%22:%22result%22,%22fields%22:[{%22fld%22:%22number%22,%22agg%22:%22count%22,%22type%22:%22bar%22,%22yaxis%22:1,%22c%22:false}],%22xaxis%22:{%22name%22:%22result_datasources-datasource-name%22,%22agg%22:%22avg%22},%22group%22:%22%22,%22color%22:%22%22,%22type%22:%22chart%22,%22size%22:%2220%22,%22sort%22:%22count-number%22,%22yaxisheaders%22:[%22%22],%22fieldsheaders%22:[%22publications%22],%22in%22:[],%22filters%22:[{%22name%22:%22result_projects-project-funding_lvl0%22,%22values%22:[%22H2020%22],%22to%22:%22-1%22},{%22name%22:%22type%22,%22values%22:[%22publication%22],%22to%22:%22-1%22},{%22name%22:%22result_datasources-datasource-type%22,%22exvalues%22:[%22Publication%20Catalogue%22]}],%22having%22:[],%22xStyle%22:{%22r%22:%22-%22,%22s%22:%22-%22,%22l%22:%22-%22,%22ft%22:%22-%22,%22wt%22:%22-%22},%22title%22:%22H2020%20Publications%20by%20datasource%20%28top%2020%29%22,%22subtitle%22:%22%22,%22xaxistitle%22:%22datasource%22,%22order%22:%22d%22}&w=90% + */