2020-01-08 12:00:50 +01:00
|
|
|
import {
|
|
|
|
ChartHelper,
|
|
|
|
Indicator,
|
|
|
|
IndicatorPath, IndicatorPathType,
|
|
|
|
SourceType,
|
|
|
|
Stakeholder,
|
|
|
|
SubCategory,
|
|
|
|
Topic
|
|
|
|
} from "./entities/stakeholder";
|
2019-12-06 14:52:26 +01:00
|
|
|
import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
|
2019-12-23 16:18:15 +01:00
|
|
|
import {Option} from "../openaireLibrary/dashboard/sharedComponents/input/input.component";
|
2019-11-13 15:27:07 +01:00
|
|
|
|
2019-11-29 13:14:49 +01:00
|
|
|
export class StakeholderUtils {
|
|
|
|
types: Option[] = [
|
|
|
|
{value: 'funder', label: 'Funder'}
|
|
|
|
];
|
|
|
|
|
2019-11-29 14:35:13 +01:00
|
|
|
isPublic: Option[] = [
|
2019-11-29 13:14:49 +01:00
|
|
|
{icon: 'public', value: true, label: 'Public'},
|
|
|
|
{icon: 'lock', value: false, label: 'Private'},
|
|
|
|
];
|
|
|
|
|
2019-11-29 14:35:13 +01:00
|
|
|
isActive: Option[] = [
|
2019-11-29 13:14:49 +01:00
|
|
|
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
|
|
|
|
{icon: 'brightness_1', value: false, label: 'Inactive'},
|
|
|
|
];
|
|
|
|
|
|
|
|
isPublicIcon: Map<boolean, string> = new Map([
|
|
|
|
[true, 'public'],
|
|
|
|
[false, 'lock']
|
|
|
|
]);
|
|
|
|
|
|
|
|
isActiveIcon: string = 'brightness_1';
|
2019-11-29 14:35:13 +01:00
|
|
|
|
2019-11-29 15:46:40 +01:00
|
|
|
public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[]): Stakeholder {
|
|
|
|
funder.topics = defaultTopics;
|
2019-11-29 14:35:13 +01:00
|
|
|
for (let topic of funder.topics) {
|
2020-01-09 14:15:39 +01:00
|
|
|
console.log('id:' + topic._id);
|
|
|
|
topic.defaultId = topic._id;
|
2019-12-05 13:01:27 +01:00
|
|
|
topic._id = null;
|
2020-01-09 14:15:39 +01:00
|
|
|
console.log('defaultId:' + topic.defaultId);
|
2019-11-29 14:35:13 +01:00
|
|
|
for (let category of topic.categories) {
|
2020-01-09 14:15:39 +01:00
|
|
|
category.defaultId = category._id;
|
2019-12-05 13:01:27 +01:00
|
|
|
category._id = null;
|
2019-11-29 14:35:13 +01:00
|
|
|
let subTokeep: SubCategory[] = [];
|
|
|
|
for (let subCategory of category.subCategories) {
|
2020-01-09 14:15:39 +01:00
|
|
|
subCategory.defaultId = subCategory._id;
|
2019-12-05 13:01:27 +01:00
|
|
|
subCategory._id = null;
|
2020-01-09 14:15:39 +01:00
|
|
|
if (!subCategory.recommendedFor || subCategory.recommendedFor.length == 0 || subCategory.recommendedFor.indexOf(funder.index_id) != -1) {
|
2019-11-29 14:35:13 +01:00
|
|
|
subTokeep.push(subCategory);
|
|
|
|
}
|
2020-01-08 12:00:50 +01:00
|
|
|
for (let section of subCategory.charts) {
|
|
|
|
let chartsTokeep: Indicator[] = [];
|
2020-01-09 14:15:39 +01:00
|
|
|
section.defaultId = section._id;
|
|
|
|
section.stakeholderAlias = funder.alias;
|
2020-01-08 12:00:50 +01:00
|
|
|
section._id = null;
|
|
|
|
for (let indicator of section.indicators) {
|
2020-01-09 14:15:39 +01:00
|
|
|
indicator.defaultId = indicator._id;
|
2020-01-08 12:00:50 +01:00
|
|
|
indicator._id = null;
|
2020-01-09 14:15:39 +01:00
|
|
|
if (!indicator.recommendedFor || indicator.recommendedFor.length == 0 || indicator.recommendedFor.indexOf(funder.index_id) != -1) {
|
2020-01-08 12:00:50 +01:00
|
|
|
chartsTokeep.push(indicator);
|
|
|
|
}
|
|
|
|
for (let indicatorPath of indicator.indicatorPaths) {
|
|
|
|
if (indicatorPath.parameters) {
|
|
|
|
Object.keys(indicatorPath.parameters).forEach(key => {
|
|
|
|
if (indicatorPath.parameters[key].indexOf("_funder_name_") != -1) {
|
|
|
|
indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_name_", funder.index_name);
|
|
|
|
} else if (indicatorPath.parameters[key].indexOf("_funder_id_") != -1) {
|
|
|
|
indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_id_", funder.index_id);
|
|
|
|
} else if (indicatorPath.parameters[key].indexOf("_fsn_") != -1) {
|
|
|
|
indicatorPath.parameters[key] = indicatorPath.parameters[key].toString().replace("_fsn_", funder.index_shortName.toLowerCase());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2019-11-29 14:35:13 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-08 12:00:50 +01:00
|
|
|
section.indicators = chartsTokeep;
|
2019-11-29 14:35:13 +01:00
|
|
|
}
|
2020-01-08 12:00:50 +01:00
|
|
|
for (let section of subCategory.numbers) {
|
2020-01-09 14:15:39 +01:00
|
|
|
section.defaultId = section._id;
|
|
|
|
section.stakeholderAlias = funder.alias;
|
2020-01-08 12:00:50 +01:00
|
|
|
section._id = null;
|
|
|
|
for(let indicator of section.indicators) {
|
2020-01-09 14:15:39 +01:00
|
|
|
indicator.defaultId = indicator._id;
|
2020-01-08 12:00:50 +01:00
|
|
|
indicator._id = null;
|
|
|
|
for (let indicatorPath of indicator.indicatorPaths) {
|
|
|
|
indicatorPath.url = indicatorPath.url.replace("_funder_id_", funder.index_id);
|
|
|
|
// if(indicatorPath.parameters) {
|
|
|
|
// indicatorPath.parameters.forEach((value: string, key: string) => {
|
|
|
|
// if (value.indexOf("_funder_name_")!=-1) {
|
|
|
|
// indicatorPath.parameters.set(key,value.toString().replace("_funder_name_", funder.index_name));
|
|
|
|
// }else if (value.indexOf("_fsn_")!=-1) {
|
|
|
|
// indicatorPath.parameters.set(key,value.toString().replace("_fsn_", funder.index_shortName.toLowerCase()));
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
}
|
2019-11-29 14:35:13 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
category.subCategories = subTokeep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return funder;
|
|
|
|
}
|
2019-12-06 14:52:26 +01:00
|
|
|
|
|
|
|
aliasValidator(elements: any[]): ValidatorFn {
|
|
|
|
return (control: AbstractControl): { [key: string]: boolean } | null => {
|
2019-12-23 14:54:37 +01:00
|
|
|
if (control.value && elements.find(element =>
|
|
|
|
element.alias === control.value
|
2019-12-06 14:52:26 +01:00
|
|
|
)) {
|
2019-12-23 14:54:37 +01:00
|
|
|
return {'alias': true};
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO need to be fixed
|
|
|
|
generateAlias(name: string): string {
|
2019-12-23 14:54:37 +01:00
|
|
|
let alias = name.toLowerCase();
|
|
|
|
while (alias.includes(' / ') || alias.includes(' ')) {
|
|
|
|
alias = alias.replace(' / ', '-');
|
|
|
|
alias = alias.replace(' ', '-');
|
|
|
|
}
|
|
|
|
return alias;
|
2019-12-06 14:52:26 +01:00
|
|
|
}
|
2019-11-29 13:14:49 +01:00
|
|
|
}
|
|
|
|
|
2019-11-08 16:47:47 +01:00
|
|
|
export class IndicatorUtils {
|
|
|
|
|
2019-11-24 17:30:04 +01:00
|
|
|
chartTypes: Option[] = [
|
|
|
|
{value: 'pie', label: 'Pie'},
|
|
|
|
{value: 'table', label: 'Table'},
|
|
|
|
{value: 'line', label: 'Line'},
|
|
|
|
{value: 'column', label: 'Column'},
|
|
|
|
{value: 'bar', label: 'Bar'},
|
|
|
|
{value: 'other', label: 'Other'}
|
|
|
|
];
|
|
|
|
|
|
|
|
chartSizes: Option[] = [
|
|
|
|
{value: 'small', label: 'Small'},
|
|
|
|
{value: 'medium', label: 'Medium'},
|
|
|
|
{value: 'large', label: 'Large'}
|
|
|
|
];
|
|
|
|
|
2019-11-29 14:35:13 +01:00
|
|
|
isPublic: Option[] = [
|
2019-11-24 17:30:04 +01:00
|
|
|
{icon: 'public', value: true, label: 'Public'},
|
|
|
|
{icon: 'lock', value: false, label: 'Private'},
|
|
|
|
];
|
|
|
|
|
2019-11-29 14:35:13 +01:00
|
|
|
isActive: Option[] = [
|
2019-11-24 17:30:04 +01:00
|
|
|
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
|
|
|
|
{icon: 'brightness_1', value: false, label: 'Inactive'},
|
|
|
|
];
|
|
|
|
|
|
|
|
chartTypesIcons: Map<string, string> = new Map([
|
2019-11-08 16:47:47 +01:00
|
|
|
['pie', 'pie_chart'],
|
|
|
|
['table', 'table_chart'],
|
|
|
|
['line', 'show_chart'],
|
|
|
|
['column', 'bar_chart'],
|
2019-11-28 11:30:56 +01:00
|
|
|
['bar', 'notes'],
|
2019-11-24 17:30:04 +01:00
|
|
|
['other', 'perm_media']
|
2019-11-08 16:47:47 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
isPublicIcon: Map<boolean, string> = new Map([
|
|
|
|
[true, 'public'],
|
|
|
|
[false, 'lock']
|
|
|
|
]);
|
|
|
|
|
|
|
|
isActiveIcon: string = 'brightness_1';
|
2019-11-13 15:27:07 +01:00
|
|
|
|
2019-11-20 11:32:28 +01:00
|
|
|
ignoredParameters = ['funder_name'];
|
|
|
|
|
2019-11-24 17:30:04 +01:00
|
|
|
parametersValidators: Map<string, any> = new Map<string, any>([
|
|
|
|
['start_year', [Validators.required, Validators.pattern('^\\d+$')]],
|
|
|
|
['end_year', [Validators.required, Validators.pattern('^\\d+$')]]
|
|
|
|
]);
|
|
|
|
|
|
|
|
public getFullUrl(indicatorPath: IndicatorPath, fundingL0: string = null, startDate: string = null, endDate: string = null): string {
|
2019-11-20 13:55:23 +01:00
|
|
|
|
2019-11-14 16:20:51 +01:00
|
|
|
let replacedUrl = indicatorPath.chartObject;
|
2019-11-19 15:25:19 +01:00
|
|
|
if (indicatorPath.parameters) {
|
2019-11-24 17:30:04 +01:00
|
|
|
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;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
2019-11-24 17:30:04 +01:00
|
|
|
if (endDate && key == "end_year" && indicatorPath.filters["end_year"]) {
|
|
|
|
replacedValue = (replacedValue > endDate) ? endDate : replacedValue;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
2019-12-05 17:10:00 +01:00
|
|
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
|
2019-11-14 16:20:51 +01:00
|
|
|
});
|
|
|
|
}
|
2019-12-23 14:54:37 +01:00
|
|
|
console.info("replacedUrl:" + replacedUrl)
|
2019-11-24 17:30:04 +01:00
|
|
|
if (indicatorPath.chartObject) {
|
|
|
|
if (fundingL0 && indicatorPath.filters["fundingL0"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
let newJsonObject = JSON.parse(replacedUrl);
|
2019-11-24 17:30:04 +01:00
|
|
|
for (let queries of newJsonObject["chartDescription"]["queries"]) {
|
|
|
|
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
|
2019-11-20 13:55:23 +01:00
|
|
|
queries["query"]["filters"] = [];
|
|
|
|
}
|
|
|
|
//TODO check how it works if the query already has a filter
|
2019-11-29 14:35:13 +01:00
|
|
|
queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["fundingL0"].replace(ChartHelper.prefix + "fundingL0" + ChartHelper.suffix, fundingL0)));
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
|
|
|
replacedUrl = JSON.stringify(newJsonObject);
|
|
|
|
}
|
|
|
|
}
|
2019-11-14 16:20:51 +01:00
|
|
|
return indicatorPath.url + encodeURIComponent(replacedUrl);
|
|
|
|
}
|
2019-11-13 15:27:07 +01:00
|
|
|
|
2019-11-24 17:30:04 +01:00
|
|
|
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[]): Indicator {
|
|
|
|
let indicator: Indicator = new Indicator(form.name, form.description, 'chart',
|
|
|
|
form.width, form.isActive, form.isPublic, indicatorPaths);
|
|
|
|
indicator._id = form.id;
|
|
|
|
form.indicatorPaths.forEach((indicatorPath, index) => {
|
|
|
|
indicatorPath.parameters.forEach(parameter => {
|
|
|
|
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
|
2019-11-29 14:35:13 +01:00
|
|
|
if (parameter.key === 'type') {
|
2019-11-24 17:30:04 +01:00
|
|
|
indicator.indicatorPaths[index].type = parameter.value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return indicator;
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:00:50 +01:00
|
|
|
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath {
|
|
|
|
let indicatorPath = new IndicatorPath('other', source, "", "", []);
|
2019-11-19 15:25:19 +01:00
|
|
|
if (source === 'stats-tool') {
|
|
|
|
indicatorPath.url = url.split("json=")[0] + "json=";
|
|
|
|
indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
|
2019-11-13 15:27:07 +01:00
|
|
|
indicatorPath.chartObject = decodeURIComponent(url.split("json=")[1]);
|
|
|
|
let chart = JSON.parse(indicatorPath.chartObject);
|
|
|
|
indicatorPath.type = this.extractType(chart, indicatorPath);
|
2019-12-23 14:54:37 +01:00
|
|
|
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
|
2019-11-19 15:25:19 +01:00
|
|
|
this.extractTitle(chart, indicatorPath);
|
2019-12-23 14:54:37 +01:00
|
|
|
this.extractSubTitle(chart, indicatorPath);
|
2019-11-19 15:25:19 +01:00
|
|
|
this.extractXTitle(chart, indicatorPath);
|
|
|
|
this.extractYTitle(chart, indicatorPath);
|
2019-12-23 14:54:37 +01:00
|
|
|
this.extractFunder(chart, indicatorPath, stakeholder);
|
2019-11-19 15:25:19 +01:00
|
|
|
this.extractStartYear(chart, indicatorPath);
|
|
|
|
this.extractEndYear(chart, indicatorPath);
|
2019-11-13 15:27:07 +01:00
|
|
|
indicatorPath.chartObject = JSON.stringify(chart);
|
2019-11-24 17:30:04 +01:00
|
|
|
this.addResultFilters(chart, indicatorPath);
|
2019-11-19 15:25:19 +01:00
|
|
|
} else if (source === 'old') {
|
2019-11-20 13:55:23 +01:00
|
|
|
indicatorPath.url = url.split("data=")[0].split("/stats/")[1] + "data=";
|
|
|
|
indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1].split("&")[0]);
|
2019-11-29 15:46:40 +01:00
|
|
|
indicatorPath.type = type;
|
2019-11-20 13:55:23 +01:00
|
|
|
let chart = JSON.parse(indicatorPath.chartObject);
|
2019-11-24 17:30:04 +01:00
|
|
|
this.extractOldToolTitle(chart, indicatorPath);
|
|
|
|
this.extractOldToolXTitle(chart, indicatorPath);
|
|
|
|
this.extractOldToolYTitle(chart, indicatorPath);
|
2019-11-20 13:55:23 +01:00
|
|
|
indicatorPath.chartObject = JSON.stringify(chart);
|
2019-11-19 15:25:19 +01:00
|
|
|
} else {
|
|
|
|
indicatorPath.url = url;
|
|
|
|
indicatorPath.type = type;
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
return indicatorPath;
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
|
2020-01-08 12:00:50 +01:00
|
|
|
private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
|
2019-11-19 15:25:19 +01:00
|
|
|
let defaultTypes = ["column", "bar", "pie"];
|
|
|
|
let type = obj["chartDescription"]["queries"][0]["type"];
|
|
|
|
if (defaultTypes.indexOf(type) == -1) {
|
2019-11-13 15:27:07 +01:00
|
|
|
type = defaultTypes [0];
|
2019-11-19 15:25:19 +01:00
|
|
|
} else {
|
|
|
|
obj["chartDescription"]["queries"][0]["type"] = ChartHelper.prefix + "type" + ChartHelper.suffix;
|
2019-11-24 17:30:04 +01:00
|
|
|
indicatorPath.parameters['type'] = type;
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
2019-12-23 14:54:37 +01:00
|
|
|
private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
2019-11-13 15:27:07 +01:00
|
|
|
let funderName;
|
2019-11-20 13:55:23 +01:00
|
|
|
for (let query of obj["chartDescription"]["queries"]) {
|
2019-11-24 17:30:04 +01:00
|
|
|
if (!query["query"]["filters"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
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;
|
2019-12-23 14:54:37 +01:00
|
|
|
indicatorPath.parameters["funder_name"] = stakeholder.index_name;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
|
|
|
private extractStartYear(obj, indicatorPath: IndicatorPath) {
|
2019-11-13 15:27:07 +01:00
|
|
|
let start_year;
|
2019-11-20 13:55:23 +01:00
|
|
|
for (let query of obj["chartDescription"]["queries"]) {
|
2019-11-24 17:30:04 +01:00
|
|
|
if (!query["query"]["filters"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
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;
|
2019-11-29 14:35:13 +01:00
|
|
|
indicatorPath.parameters["start_year"] = start_year;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
|
|
|
private extractEndYear(obj, indicatorPath: IndicatorPath) {
|
2019-11-13 15:27:07 +01:00
|
|
|
let end_year;
|
2019-11-20 13:55:23 +01:00
|
|
|
for (let query of obj["chartDescription"]["queries"]) {
|
2019-11-24 17:30:04 +01:00
|
|
|
if (!query["query"]["filters"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
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;
|
2019-11-29 14:35:13 +01:00
|
|
|
indicatorPath.parameters["end_year"] = end_year;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
2019-12-23 14:54:37 +01:00
|
|
|
private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
|
|
|
let name = "";
|
|
|
|
for (let query of obj["chartDescription"]["queries"]) {
|
|
|
|
if (query["query"]["name"]) {
|
|
|
|
name = query["query"]["name"];
|
|
|
|
let stakeholderSN = name.split('.')[1];
|
|
|
|
console.log("Funder is:" + stakeholderSN);
|
|
|
|
query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "FSN" + ChartHelper.suffix +"." + name.split('.' + stakeholderSN + ".")[1];
|
|
|
|
indicatorPath.parameters["FSN"] = stakeholder.index_shortName.toLowerCase();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:25:19 +01:00
|
|
|
private extractTitle(obj, indicatorPath: IndicatorPath) {
|
2019-11-20 13:55:23 +01:00
|
|
|
let title = "";
|
2019-11-19 15:25:19 +01:00
|
|
|
if (obj["chartDescription"]["title"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
title = obj["chartDescription"]["title"]["text"];
|
2019-11-19 15:25:19 +01:00
|
|
|
obj["chartDescription"]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
|
2019-12-23 14:54:37 +01:00
|
|
|
indicatorPath.parameters["title"] = title ? title : "";
|
2019-11-13 15:27:07 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2019-12-23 14:54:37 +01:00
|
|
|
|
2019-12-05 17:10:00 +01:00
|
|
|
private extractSubTitle(obj, indicatorPath: IndicatorPath) {
|
|
|
|
let subtitle = "";
|
|
|
|
if (obj["chartDescription"]["subtitle"]) {
|
|
|
|
subtitle = obj["chartDescription"]["subtitle"]["text"];
|
2019-12-23 14:54:37 +01:00
|
|
|
obj["chartDescription"]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
|
|
|
|
indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
|
2019-12-05 17:10:00 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
|
|
|
private extractXTitle(obj, indicatorPath: IndicatorPath) {
|
2019-11-20 13:55:23 +01:00
|
|
|
let title = "";
|
2019-11-19 15:25:19 +01:00
|
|
|
if (obj["chartDescription"]["xAxis"]["title"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
title = obj["chartDescription"]["xAxis"]["title"]["text"];
|
2019-11-19 15:25:19 +01:00
|
|
|
obj["chartDescription"]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
2019-12-23 14:54:37 +01:00
|
|
|
indicatorPath.parameters["xAxisTitle"] = title ? title : ""
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
|
|
|
private extractYTitle(obj, indicatorPath: IndicatorPath) {
|
2019-11-20 13:55:23 +01:00
|
|
|
let title = "";
|
2019-11-19 15:25:19 +01:00
|
|
|
if (obj["chartDescription"]["yAxis"]["title"]) {
|
2019-11-20 13:55:23 +01:00
|
|
|
title = obj["chartDescription"]["yAxis"]["title"]["text"];
|
2019-11-19 15:25:19 +01:00
|
|
|
obj["chartDescription"]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
2019-12-23 14:54:37 +01:00
|
|
|
indicatorPath.parameters["yAxisTitle"] = title ? title : ""
|
2019-11-13 15:27:07 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-24 17:30:04 +01:00
|
|
|
|
2019-11-20 13:55:23 +01:00
|
|
|
private addResultFilters(obj, indicatorPath: IndicatorPath) {
|
2019-11-24 17:30:04 +01:00
|
|
|
let resultTypes = ["publication", "software", "dataset", "other"];
|
|
|
|
let index = -1;
|
2019-11-20 13:55:23 +01:00
|
|
|
for (let query of obj["chartDescription"]["queries"]) {
|
|
|
|
if (!query["query"]["select"]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let select of query["query"]["select"]) {
|
2019-11-24 17:30:04 +01:00
|
|
|
for (var i = 0; i < resultTypes.length; i++) {
|
|
|
|
if (select.field.startsWith(resultTypes[i])) {
|
2019-11-20 13:55:23 +01:00
|
|
|
index = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-11-24 17:30:04 +01:00
|
|
|
if (index != -1) {
|
2019-11-20 13:55:23 +01:00
|
|
|
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;
|
2019-11-24 17:30:04 +01:00
|
|
|
indicatorPath.parameters["title"] = title;
|
2019-11-20 13:55:23 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) {
|
|
|
|
let title = "";
|
|
|
|
if (obj["xaxistitle"]) {
|
|
|
|
title = obj["xaxistitle"];
|
|
|
|
obj["xaxistitle"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
2019-11-24 17:30:04 +01:00
|
|
|
indicatorPath.parameters["xAxisTitle"] = title;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) {
|
|
|
|
let title = "";
|
2019-11-24 17:30:04 +01:00
|
|
|
if (obj["fieldsheaders"]) {
|
2019-12-23 14:54:37 +01:00
|
|
|
title = Array.isArray(obj["fieldsheaders"]) ? obj["fieldsheaders"][0] : obj["fieldsheaders"];
|
|
|
|
if (Array.isArray(obj["fieldsheaders"])) {
|
2019-11-29 15:58:52 +01:00
|
|
|
obj["fieldsheaders"][0] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
2019-12-23 14:54:37 +01:00
|
|
|
} else {
|
2019-11-29 15:58:52 +01:00
|
|
|
obj["fieldsheaders"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
|
|
|
}
|
2019-11-24 17:30:04 +01:00
|
|
|
indicatorPath.parameters["yAxisTitle"] = title;
|
2019-11-20 13:55:23 +01:00
|
|
|
}
|
|
|
|
}
|
2019-11-13 15:27:07 +01:00
|
|
|
|
2019-11-08 16:47:47 +01:00
|
|
|
}
|
2019-11-24 17:30:04 +01:00
|
|
|
|
2019-11-20 13:55:23 +01:00
|
|
|
/*
|
|
|
|
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%
|
|
|
|
|
|
|
|
|
|
|
|
//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%
|
|
|
|
*/
|