[Monitor dashboard | Trunk]

Enable adding numbers from stats-tool

Adding filters not in the indicator object, but on demand when filters are applied
Use common code for charts and number objects from stats tool



git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@59056 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Argiro Kokogiannaki 2020-07-07 14:08:47 +00:00
parent b69e50e978
commit 887884c260
10 changed files with 300 additions and 122 deletions

View File

@ -49,14 +49,16 @@
"datatables.net": "^1.10.19",
"datatables.net-dt": "^1.10.19",
"jquery": "^3.4.1",
"ng-recaptcha": "^3.0.5",
"ng2-ckeditor": "1.1.9",
"ng2-nouislider": "^1.8.2",
"ngx-json-ld": "0.1.6",
"nouislider": "^14.6.0",
"prom-client": "^11.3.0",
"ts-md5": "^1.2.0",
"tslib": "^1.9.0",
"wikidata-sdk": "^5.2.9",
"zone.js": "^0.8.26",
"ng-recaptcha": "^3.0.5",
"ng2-ckeditor": "1.1.9"
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.13.0",

View File

@ -195,7 +195,7 @@ export class AppComponent implements OnInit, OnDestroy {
}
}
isAdmin() {
public isAdmin() {
return this.user && (Session.isPortalAdministrator(this.user) || Session.isCommunityCurator(this.user) || Session.isMonitorCurator(this.user));
}

View File

@ -28,7 +28,7 @@
</li>
</ng-template>
</ul>
<!-- <div>
<!-- <div>
Filters
<input class="uk-input uk-form-width-medium" placeholder="Funding Stream" type="text" name="fund_level_0"
[(ngModel)]="fundingL0">
@ -37,7 +37,11 @@
[(ngModel)]="startYear">
<input class="uk-input uk-form-width-medium" placeholder="End year" type="text" name="end_year"
[(ngModel)]="endYear">
<button class="uk-button uk-button-primary" (click)="setIndicators()">Apply</button>
<nouislider [connect]="true" [min]="0" [max]="15" [step]="1" [(ngModel)]="someRange"
(ngModelChange)="filter()"></nouislider>
&lt;!&ndash; <double-slider></double-slider>&ndash;&gt;
<button class="uk-button uk-button-primary" (click)="filter()">Apply</button>
</div>-->
<div *ngIf="privateStakeholder">
<div class="uk-text-center uk-height-medium">
@ -130,6 +134,7 @@
{{indicatorPath.type}}
</button>
</div>
<div>Filtered: {{chartsActiveType.get(i + '-' + j).filteredApplied}}</div>
<iframe *ngIf="chartsActiveType.get(i + '-' + j).source !== 'image'"
[src]="chartsActiveType.get(i + '-' + j).safeResourceUrl"
class="uk-width-1-1 uk-height-medium"></iframe>

View File

@ -4,24 +4,20 @@ import {DomSanitizer, Meta, Title} from '@angular/platform-browser';
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
import {Dates, StringUtils} from '../openaireLibrary/utils/string-utils.class';
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
import {Category, ChartHelper, IndicatorPath, Stakeholder, SubCategory, Topic} from "../openaireLibrary/monitor/entities/stakeholder";
import {Category, IndicatorPath, Stakeholder, SubCategory, Topic} from "../openaireLibrary/monitor/entities/stakeholder";
import {StatisticsService} from "../utils/services/statistics.service";
import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
import {FormBuilder, FormControl} from "@angular/forms";
import {IDeactivateComponent} from "../openaireLibrary/utils/can-exit.guard";
import {Subscription} from "rxjs";
import {Session, User} from "../openaireLibrary/login/utils/helper.class";
import {MenuItem} from "../openaireLibrary/sharedComponents/menu";
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
import {StakeholderCreator} from "../utils/entities/stakeholderCreator";
@Component({
selector: 'monitor',
@ -35,6 +31,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
public pageContents = null;
public divContents = null;
public status: number;
public loading: boolean = true;
public isViewPublic: boolean = false;
public indicatorUtils: IndicatorUtils = new IndicatorUtils();
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
@ -52,7 +49,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
endYear;
privateStakeholder = false;
public keyword: FormControl;
public someRange: number[] = [3, 7];
constructor(
private route: ActivatedRoute,
private _router: Router,
@ -66,7 +63,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
private layoutService: LayoutService,
private seoService: SEOService,
private cdr: ChangeDetectorRef,
private sanitizer: DomSanitizer, private _fb: FormBuilder) {
private sanitizer: DomSanitizer, private _fb: FormBuilder, private router: Router) {
this.errorCodes = new ErrorCodes();
this.errorMessages = new ErrorMessagesComponent();
this.status = this.errorCodes.LOADING;
@ -85,6 +82,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
this.user = user;
this.route.params.subscribe(params => {
this.loading = true;
this.activeTopic = null;
this.activeCategory = null;
this.activeSubCategory = null;
@ -96,6 +94,31 @@ export class MonitorComponent implements OnInit, OnDestroy {
var url = data.envSpecific.baseLink + this._router.url;
this.route.queryParams.subscribe(params => {
this.isViewPublic = (params['view'] == 'public');
this.startYear = (params['year'] && params['year'].indexOf("range")==0)?params['year'].split("range")[1].split(":")[0]:null;
this.endYear = (params['year'] && params['year'].indexOf("range")==0)?params['year'].split("range")[1].split(":")[1]:null;
let invalidYears = false;
if(this.startYear && (!this.endYear || !Dates.isValidYear(this.endYear, Dates.currentYear - 20, Dates.currentYear))){
this.endYear = Dates.currentYear;
invalidYears = true;
}
if((!this.startYear || !Dates.isValidYear(this.startYear, Dates.currentYear - 20, Dates.currentYear)) && this.endYear){
this.startYear = Dates.currentYear - 20;
invalidYears = true;
}
if(parseInt(this.startYear, 10) > parseInt(this.endYear, 10)){
this.startYear = this.endYear;
invalidYears = true;
}
if(invalidYears){
this.router.navigate(
[],
{
relativeTo: this.route,
queryParams: { year: 'range'+this.startYear+":"+this.endYear },
queryParamsHandling: 'merge'
});
}
});
if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) {
this.status = this.errorCodes.LOADING;
@ -215,17 +238,25 @@ export class MonitorComponent implements OnInit, OnDestroy {
}
}
}
filter(){
// this.router.navigate([this.searchUtils.baseUrl], {queryParams: this.routerHelper.createQueryParams(this.parameterNames, this.parameterValues)});
this.router.navigate(
[],
{
relativeTo: this.route,
queryParams: { year: 'range'+this.startYear+":"+this.endYear },
queryParamsHandling: 'merge'
});
this.setIndicators();
}
private setIndicators() {
let urls: Map<string, [number, number][]> = new Map<string, [number, number][]>();
this.activeSubCategory.numbers.forEach((section, i) => {
section.indicators.forEach((number, j) => {
if (number.isActive && this.isPublicOrIsMember(number.isPublic)) {
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));
}
let url =this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, number.indicatorPaths[0],this.fundingL0, this.startYear, this.endYear);
const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
const indexes = urls.get(pair) ? urls.get(pair) : [];
indexes.push([i, j]);
@ -235,7 +266,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
});
urls.forEach((indexes, pair) => {
pair = JSON.parse(pair);
this.statisticsService.getNumbers(pair[0], IndicatorUtils.getNumberUrl(this.stakeholder, pair[1])).subscribe(response => {
this.statisticsService.getNumbers(this.statisticsService.getSourceType(pair[0]), pair[1]).subscribe(response => {
indexes.forEach(([i, j]) => {
let result = JSON.parse(JSON.stringify(response));
this.activeSubCategory.numbers[i].indicators[j].indicatorPaths[0].jsonPath.forEach(jsonPath => {
@ -262,7 +293,7 @@ export class MonitorComponent implements OnInit, OnDestroy {
public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
return this.sanitizer.bypassSecurityTrustResourceUrl(
this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath, this.fundingL0, this.startYear, this.endYear)));
this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, indicatorPath, this.fundingL0, this.startYear, this.endYear)));
}
public setActiveChart(i: number, j: number, type: string) {

View File

@ -19,15 +19,18 @@ import {InputModule} from "../openaireLibrary/dashboard/sharedComponents/input/i
import {UserMiniModule} from "../openaireLibrary/login/userMiniModule.module";
import {ClickModule} from "../openaireLibrary/utils/click/click.module";
import {BottomModule} from "../openaireLibrary/sharedComponents/bottom.module";
import { NouisliderModule } from 'ng2-nouislider';
import { DoubleSliderComponent } from './double-slider/double-slider.component';
@NgModule({
imports: [
CommonModule, FormsModule, RouterModule, ErrorMessagesModule,
HelperModule, Schema2jsonldModule, SEOServiceModule, MonitorRoutingModule, SideBarModule, InputModule,
UserMiniModule, ClickModule, BottomModule
UserMiniModule, ClickModule, BottomModule, NouisliderModule
],
declarations: [
MonitorComponent
MonitorComponent,
DoubleSliderComponent
],
providers: [
FreeGuard, PreviousRouteRecorder,

View File

@ -430,11 +430,11 @@
<div dashboard-input [formInput]="indicatorPath.get('url')" type="textarea" rows="3"
label="Number path url"></div>
</div>
<div class="uk-width-1-3@s">
<!--<div class="uk-width-1-3@s">
<div dashboard-input [formInput]="indicatorPath.get('source')" label="Source"
type="select" [options]="indicatorUtils.sourceTypes">
</div>
</div>
</div>-->
</div>
<div formArrayName="jsonPath">
<div class="uk-margin-top uk-margin-bottom uk-text-large">

View File

@ -419,13 +419,14 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
return this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath));
}
public addNumberIndicatorPath(url: string = '', source: string = 'search', jsonPath: FormArray = new FormArray([])) {
public addNumberIndicatorPath(url: string = '',parameters: FormArray = new FormArray([]), source: string = 'search', jsonPath: FormArray = new FormArray([])) {
if(jsonPath.length === 0) {
jsonPath.push(this.fb.control('', Validators.required));
}
this.numberIndicatorPaths.push(this.fb.group({
url: this.fb.control(url, Validators.required),
jsonPath: jsonPath,
// parameters: parameters,
source: this.fb.control(source, Validators.required)
}
));
@ -433,16 +434,21 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
for(let index = 0; index < this.numberIndicatorPaths.length; index++) {
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
if (this.numberIndicatorPaths.at(index).get('url').valid) {
let indicatorPath: IndicatorPath = this.indicatorUtils.parseNumberIndicatortUrl(this.numberIndicatorPaths.at(index).get('source').value, value, this.stakeholder);
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder,this.numberIndicatorPaths.at(index).get('jsonPath').value );
// if(indicatorPath.url.indexOf("index_id") ==-1 && indicatorPath.url.indexOf("index_name") ==-1 && (indicatorPath.url).indexOf("index_shortName") ==-1 ){
//
// }else {
// this.urlParameterizedMessage = "";
// }
if(value != indicatorPath.url) {
/* if(value != indicatorPath.url) {
(this.numberIndicatorPaths.at(index) as FormGroup).get('url').setValue( indicatorPath.url);
}
}*/
if (!this.indicator.indicatorPaths[index]) {
this.indicator.indicatorPaths[index] = indicatorPath;
} else {
this.indicator.indicatorPaths[index] = indicatorPath;
}
}
})
);
@ -544,7 +550,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
defaultId: this.fb.control(this.indicator.defaultId)
});
this.indicator.indicatorPaths.forEach(indicatorPath => {
this.addNumberIndicatorPath(indicatorPath.url, indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath));
this.addNumberIndicatorPath(indicatorPath.url,indicatorPath.parameters, indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath));
});
} else {
this.indicator = new Indicator('', '', 'number', 'small', true, true, []);
@ -630,12 +636,14 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
saveIndicator() {
this.editing = true;
if (this.indicator.type === 'chart') {
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths);
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, true);
this.section = this.charts.find(section => section._id === this.section._id);
} else {
this.indicator = this.numberIndicatorFb.value;
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, false);
this.section = this.numbers.find(section => section._id === this.section._id);
}
console.debug("Indicator to svae");
console.debug(this.indicator);
let path = [
this.stakeholder._id,
this.stakeholder.topics[this.topicIndex]._id,
@ -707,12 +715,12 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV
}
public get isAdministrator(): boolean {
return Session.isPortalAdministrator(this.user);
return this.properties.environment == 'development' || Session.isPortalAdministrator(this.user);
// return Session.isPortalAdministrator(this.user) || Session.isMonitorCurator(this.user) || Session.isCommunityCurator(this.user)
}
refreshIndicator() {
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths);
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths,'chart', true);
this.indicator.indicatorPaths.forEach(indicatorPath => {
indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
});

View File

@ -135,7 +135,6 @@ export class StakeholderCreator {
res_timeline.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,chartTitle[index] + typePlural+" timeline","column");
res_timeline.indicatorPaths[0].parameters["start_year"] = (index == 1?"2014":"2008");
res_timeline.indicatorPaths[0].parameters["end_year"] = "2020";
res_timeline.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
pubDefSub.charts[0].indicators.push(res_timeline);
@ -145,13 +144,11 @@ 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 + 'index_name' + ChartHelper.suffix + '"]}],"op":"AND"}'+fundingFilter[index]+'],"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, chartTitle[index] + typeSingl + " types", "bar");
res_types.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
pubDefSub.charts[0].indicators.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+'index_name'+ChartHelper.suffix+'"]}],"op":"AND"}'+fundingFilter[index]+'],"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":true}}},"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,chartTitle[index] + typeSingl+" access mode","pie");
res_access_mode.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
pubDefSub.charts[0].indicators.push(res_access_mode);
@ -207,7 +204,6 @@ export class StakeholderCreator {
'{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'index_shortName' + 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":true}}},"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["index_shortName"] = stakeholder.index_shortName.toLowerCase();
pid.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
pubDefSub.charts[0].indicators.push(pid);
}
return pubDefSub;

View File

@ -1,7 +1,7 @@
import {
ChartHelper,
Indicator,
IndicatorPath, IndicatorPathType,
ChartHelper, FilterType,
Indicator, IndicatorFilterUtils,
IndicatorPath, IndicatorPathType, IndicatorType,
SourceType,
Stakeholder,
SubCategory,
@ -167,8 +167,9 @@ export class IndicatorUtils {
sourceTypes: Option[] = [
{value: 'search', label: 'Search'},
{value: 'statistics', label: 'Statistics'},
{value: 'metrics', label: 'Metrics'}
]
{value: 'metrics', label: 'Metrics'},
{value: 'stats-tool', label: 'Statistics tool'}
];
isPublic: Option[] = [
{icon: 'public', value: true, label: 'Public'},
@ -222,16 +223,16 @@ export class IndicatorUtils {
['end_year', [Validators.required, Validators.pattern('^\\d+$')]]
]);
public getFullUrl(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startDate: string = null, endDate: string = null): string {
public getFullUrl(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
let replacedUrl = indicatorPath.chartObject;
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
let replacedValue = indicatorPath.parameters[key];
if (startDate && key == "start_year" && indicatorPath.filters["start_year"]) {
replacedValue = (replacedValue < startDate) ? startDate : replacedValue;
if (startYear && key == "start_year" && indicatorPath.filters["start_year"]) {
replacedValue = (replacedValue < startYear) ? startYear : replacedValue;
}
if (endDate && key == "end_year" && indicatorPath.filters["end_year"]) {
replacedValue = (replacedValue > endDate) ? endDate : replacedValue;
if (endYear && key == "end_year" && indicatorPath.filters["end_year"]) {
replacedValue = (replacedValue > endYear) ? endYear : replacedValue;
}
if (key == "index_id") {
replacedValue = stakeholder.index_id;
@ -249,7 +250,7 @@ export class IndicatorUtils {
if (indicatorPath.chartObject) {
if (fundingL0 && indicatorPath.filters["fundingL0"]) {
let newJsonObject = JSON.parse(replacedUrl);
for (let queries of newJsonObject[this.getDescriptionObjectName(newJsonObject)]["queries"]) {
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
queries["query"]["filters"] = [];
}
@ -258,54 +259,202 @@ export class IndicatorUtils {
}
replacedUrl = JSON.stringify(newJsonObject);
}
if (startYear && indicatorPath.filters["start_year"]) {
let newJsonObject = JSON.parse(replacedUrl);
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
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["start_year"].replace(ChartHelper.prefix + "start_year" + ChartHelper.suffix, startYear)));
}
replacedUrl = JSON.stringify(newJsonObject);
}
if (endYear && indicatorPath.filters["end_year"]) {
let newJsonObject = JSON.parse(replacedUrl);
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
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["end_year"].replace(ChartHelper.prefix + "end_year" + ChartHelper.suffix, endYear)));
}
replacedUrl = JSON.stringify(newJsonObject);
}
}
//For numbers
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) !=- 1){
indicatorPath.url = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
}
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) !=- 1){
indicatorPath.url = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
}
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) !=- 1){
indicatorPath.url = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
}
return indicatorPath.url + encodeURIComponent(replacedUrl);
}
public static getNumberUrl(stakeholder:Stakeholder,url:string): string {
let replacedUrl = url;
public getFullUrlWithFilters(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, isNumber:boolean=false): string {
let replacedUrl = indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
if (indicatorPath.parameters) {
Object.keys(indicatorPath.parameters).forEach(key => {
let replacedValue = indicatorPath.parameters[key];
if (startYear && key == "start_year") {
replacedValue = (replacedValue < startYear) ? startYear : replacedValue;
}
if (endYear && key == "end_year") {
replacedValue = (replacedValue > endYear) ? endYear : replacedValue;
}
if (key == "index_id") {
replacedValue = stakeholder.index_id;
}
if (key == "index_name") {
replacedValue = stakeholder.index_name;
}
if (key == "index_shortName") {
replacedValue = stakeholder.index_shortName.toLowerCase();
}
if(url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) !=- 1){
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
});
}
if (fundingL0) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
replacedUrl = filterResults.url;
indicatorPath.filteredApplied = indicatorPath.filteredApplied|| filterResults.filteredApplied;
}
}
if (startYear) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'start_year', startYear);
replacedUrl = filterResults.url;
indicatorPath.filteredApplied = indicatorPath.filteredApplied|| filterResults.filteredApplied;
}
}
if (endYear ) {
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'end_year', endYear);
replacedUrl = filterResults.url;
indicatorPath.filteredApplied = indicatorPath.filteredApplied|| filterResults.filteredApplied;
}
}
//For numbers
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
}
if(url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) !=- 1){
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
}
if(url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) !=- 1){
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) {
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
}
return replacedUrl;
return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
}
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[]): Indicator {
let indicator: Indicator = new Indicator(form.name, form.description, 'chart',
private addFilter(replacedUrl, filterType:FilterType, filterValue){
let newJsonObject = JSON.parse(replacedUrl);
let filterApplied:boolean = false;
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
if(queries["query"]["name"] && !queries["query"]["select"]){
/*
//Uncomment when the named queries filters are defined
//monitor.stakeholderType.name.id.type.fl0
if(queries["query"]["name"].indexOf("monitor.")==-1){
continue;
}
filterApplied = true;
let filterPosition = queries["query"]["name"].split(".").indexOf(filterType=="fundingL0"?'fl0':filterType);
if(filterType == "fundingL0"){
filterApplied = true;
if(filterPosition != -1){
queries["query"]["parameters"][filterPosition-3]=filterValue;
}else{
queries["query"]["name"]=queries["query"]["name"]+".fl0";
queries["query"]["parameters"].push(filterValue);
}
}else {
filterApplied = true;
//start_year end_year
if(filterPosition != -1){
queries["query"]["parameters"][filterPosition-3]=filterValue;
}else{
queries["query"]["name"]=queries["query"]["name"]+".start_year.end_year";
filterPosition = queries["query"]["name"].split(".").indexOf(filterType);
queries["query"]["parameters"].push("0");
queries["query"]["parameters"].push("9999");
queries["query"]["parameters"][filterPosition-3]=filterValue
}
}
console.debug(queries["query"])*/
// it is a name query
continue;
}
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
queries["query"]["filters"] = [];
}
let field = queries["query"]["select"][0]["field"];
// console.debug("Field is"+field)
let filterString = IndicatorFilterUtils.getFilter(field,filterType);
if(filterString){
filterApplied = true;
let filter = JSON.parse(filterString);
let filterposition = IndicatorFilterUtils.filterIndexOf(filter,queries["query"]["filters"]);
if(filterposition){
queries["query"]["filters"][filterposition.filter][filterposition.groupFilter] = filter['groupFilters'][0]["values"][0].replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue);
}
queries["query"]["filters"].push(JSON.parse(filterString.replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)));
}
}
return { "url":JSON.stringify(newJsonObject), "filteredApplied":filterApplied};
}
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type:IndicatorType, addParameters:boolean = true ): Indicator {
let indicator: Indicator = new Indicator(form.name, form.description, type,
form.width, form.isActive, form.isPublic, indicatorPaths, form.defaultId);
indicator._id = form._id;
form.indicatorPaths.forEach((indicatorPath, index) => {
indicator.indicatorPaths[index].type = indicatorPath.type;
indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
if (parameter.key === 'type') {
indicator.indicatorPaths[index].type = parameter.value;
}
});
if(addParameters) {
indicatorPath.parameters.forEach(parameter => {
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
if (parameter.key === 'type') {
indicator.indicatorPaths[index].type = parameter.value;
}
});
}
});
return indicator;
}
parseNumberIndicatortUrl(source: SourceType, url: string, stakeholder:Stakeholder): IndicatorPath {
let indicatorPath = new IndicatorPath(null, source, url, null, []);
try {
if (url.indexOf(encodeURIComponent(stakeholder.index_id)) !== -1) {
url = url.split(encodeURIComponent(stakeholder.index_id)).join(ChartHelper.prefix + "index_id" + ChartHelper.suffix);
generateIndicatorByNumberUrl(source: SourceType, url: string, stakeholder:Stakeholder, jsonPath = []): IndicatorPath {
let indicatorPath = new IndicatorPath(null, source, url, null, jsonPath);
if (source === 'stats-tool') {
indicatorPath.url = url.split("json=")[0] + "json=";
indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
indicatorPath.chartObject = decodeURIComponent(url.indexOf("json=")!=-1?url.split("json=")[1]:"");
let chart = JSON.parse(indicatorPath.chartObject);
this.extractStakeHolders(chart, indicatorPath, stakeholder);
// this.addResultFilters(chart, indicatorPath);
}else {
try {
if (url.indexOf(encodeURIComponent(stakeholder.index_id)) !== -1) {
url = url.split(encodeURIComponent(stakeholder.index_id)).join(ChartHelper.prefix + "index_id" + ChartHelper.suffix);
}
if (url.indexOf(encodeURIComponent(stakeholder.index_name)) !== -1) {
url = url.split(encodeURIComponent(stakeholder.index_name)).join(ChartHelper.prefix + "index_name" + ChartHelper.suffix);
}
if (url.indexOf(encodeURIComponent(stakeholder.index_shortName)) !== -1) {
url = url.split(encodeURIComponent(stakeholder.index_shortName)).join(ChartHelper.prefix + "index_shortName" + ChartHelper.suffix);
}
indicatorPath.url = url;
} catch (e) {
console.error(e);
}
if (url.indexOf(encodeURIComponent(stakeholder.index_name)) !== -1) {
url = url.split(encodeURIComponent(stakeholder.index_name)).join(ChartHelper.prefix + "index_name" + ChartHelper.suffix);
}
if (url.indexOf(encodeURIComponent(stakeholder.index_shortName)) !== -1) {
url = url.split(encodeURIComponent(stakeholder.index_shortName)).join(ChartHelper.prefix + "index_shortName" + ChartHelper.suffix);
}
indicatorPath.url = url;
}
catch(e){
console.error(e);
}
return indicatorPath;
}
@ -341,7 +490,6 @@ 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].split("/stats/")[1] + "data=";
@ -382,6 +530,8 @@ export class IndicatorUtils {
return "chartDescription";
}else if(obj.hasOwnProperty("tableDescription") ){
return "tableDescription";
}else if(obj.hasOwnProperty("series") ){
return "series";
}
}
private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
@ -403,7 +553,7 @@ export class IndicatorUtils {
if(stakeholder.type != "funder"){
return;
}
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
if (!query["query"]["filters"]) {
return;
}
@ -600,28 +750,6 @@ export class IndicatorUtils {
indicatorPath.parameters["yAxisTitle"] = title ? title : "";
}
private addResultFilters(obj, indicatorPath: IndicatorPath) {
let resultTypes = ["publication", "software", "dataset", "other"];
let index = -1;
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
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"]) {
@ -655,18 +783,3 @@ export class IndicatorUtils {
}
}
/*
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%
*/

View File

@ -10,7 +10,7 @@ import {SourceType} from "../../openaireLibrary/monitor/entities/stakeholder";
})
export class StatisticsService {
numberSources: Map<string, string[]> = new Map<string, string[]>();
numberSources: Map<SourceType, string[]> = new Map<SourceType, string[]>();
chartSources: Map<SourceType, string[]> = new Map<SourceType, string[]>();
constructor(private http:HttpClient, private environmentSpecificService: EnvironmentSpecificService) {
@ -18,21 +18,41 @@ export class StatisticsService {
this.numberSources.set('statistics', [properties.statisticsAPIURL]);
this.numberSources.set('search', [properties.searchAPIURLLAst]);
this.numberSources.set('metrics', [properties.metricsAPIURL]);
this.numberSources.set('stats-tool', [properties.statisticsFrameNewAPIURL, "http://marilyn.athenarc.gr:8080/stats-api/", "http://88.197.53.71:8080/stats-api/", "https://stats.madgik.di.uoa.gr/stats-api/"]);
this.chartSources.set('stats-tool', [properties.statisticsFrameNewAPIURL, "http://marilyn.athenarc.gr:8080/stats-api/", "http://88.197.53.71:8080/stats-api/", "https://stats.madgik.di.uoa.gr/stats-api/"]);
this.chartSources.set('old', [properties.statisticsFrameAPIURL]);
this.chartSources.set('metrics', [properties.metricsAPIURL]);
this.chartSources.set('image', [""]);
})
}
getSourceType(source:string):SourceType{
let sourceType: SourceType = 'search';
this.numberSources.forEach((values, key) => {
if(key == source) {
sourceType = key;
getNumbers(source: string, url: string): Observable<any> {
return this.http.get<any>(this.numberSources.get(source) + url);
}
});
return sourceType;
}
getNumbers(source: SourceType, url: string): Observable<any> {
return this.http.get<any>(this.numberSources.get(source)[0] + url);
}
getChartUrl(source: SourceType, url: string): string {
return this.chartSources.get(source)[0] + url;
}
getNumberSource(url: string): SourceType {
let source: SourceType = 'search';
this.numberSources.forEach((values, key) => {
values.forEach((value) => {
if(value !== '' && url.indexOf(value) !== -1) {
source = key;
}
});
});
return source;
}
getChartSource(url: string): SourceType {
let source: SourceType = 'image';
this.chartSources.forEach((values, key) => {