[Monitor Dashboard|Trunk]

Indicators form: add input fields for data titles of the chart

indicator-utils: generateIndicatorByChartUrl:
	-more checks for library (Google/highcharts) and table/chart
	-parsing for Google charts (a little different schema than highcharts)
	-parsing for google tables (parse stakeholder filter)
	-make sure connect new charts work (the stakeholder should be ri)
	-prepare new parameterized queries (should be checked when available)
		-- if the format is monitor.funder/ri/organization parse only if the stakeholder is type funder/ri/organization
	-any other case just keep the url (won't work for default profile)
	-Simple Stats tool queries add check for stakeholder type
		-- if stakeholder is funder/ri/organization parse funder/ri/organization filter
	


git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@58796 d315682c-612b-4755-9ff5-7f18f6832af3
This commit is contained in:
Argiro Kokogiannaki 2020-05-28 09:35:57 +00:00
parent 7737ecaa42
commit 7c72562336
2 changed files with 171 additions and 46 deletions

View File

@ -365,6 +365,14 @@
<div dashboard-input [formInput]="getParameter(i, 'yAxisTitle').get('value')"
label="Y-Axis Title"></div>
</div>
<div *ngIf="getParameter(i, 'data_title_0')" class="uk-width-1-3@s">
<div dashboard-input [formInput]="getParameter(i, 'data_title_0').get('value')"
label="Data title"></div>
</div>
<div *ngIf="getParameter(i, 'data_title_1')" class="uk-width-1-3@s">
<div dashboard-input [formInput]="getParameter(i, 'data_title_1').get('value')"
label="Data title"></div>
</div>
<div *ngIf="getParameter(i, 'start_year')" class="uk-width-1-3@s">
<div dashboard-input [formInput]="getParameter(i, 'start_year').get('value')"
label="Year (From)"></div>

View File

@ -244,22 +244,36 @@ export class IndicatorUtils {
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath {
let indicatorPath = new IndicatorPath('other', source, "", "", []);
try {
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.split("json=")[1]);
let chart = JSON.parse(indicatorPath.chartObject);
// console.debug(indicatorPath);
//HighCharts
if (indicatorPath.url == "chart?json=") {
if (chart["library"] && chart["library"] == "HighCharts") {
indicatorPath.type = this.extractType(chart, indicatorPath);
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
} else {
indicatorPath.type = "column"
}
this.extractTitle(chart, indicatorPath);
this.extractSubTitle(chart, indicatorPath);
this.extractXTitle(chart, indicatorPath);
this.extractYTitle(chart, indicatorPath);
this.extractFunder(chart, indicatorPath, stakeholder);
}
if (indicatorPath.url == "chart?json=" || indicatorPath.url == "table?json=") {
// common for tables and other chart types
this.extractDataTitle(chart, indicatorPath);
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
this.extractStakeHolders(chart, indicatorPath, stakeholder);
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=";
indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1].split("&")[0]);
@ -273,9 +287,22 @@ export class IndicatorUtils {
indicatorPath.url = url;
indicatorPath.type = type;
}
}catch(e){
console.error(e);
indicatorPath.url = url;
indicatorPath.type = type;
}
// console.debug(indicatorPath.parameters);
// console.debug(indicatorPath.chartObject);
return indicatorPath;
}
private getQueryObjectName(obj){
if(obj["library"] && obj["library"] == "GoogleCharts"){
return "queriesInfo";
}else if(obj["library"] && obj["library"] == "HighCharts") {
return "queries";
}
}
private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
let defaultTypes = ["column", "bar", "pie"];
let type = obj["chartDescription"]["queries"][0]["type"];
@ -287,26 +314,73 @@ export class IndicatorUtils {
}
return type;
}
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
this.extractFunder(obj, indicatorPath, stakeholder);
this.extractRI(obj, indicatorPath, stakeholder);
this.extractOrganization(obj, indicatorPath, stakeholder);
}
private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
let funderName;
for (let query of obj["chartDescription"]["queries"]) {
if(stakeholder.type != "funder"){
return;
}
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
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 + "index_name" + ChartHelper.suffix;
indicatorPath.parameters["index_name"] = stakeholder.index_name;
}else if (filter["groupFilters"][0]["field"].indexOf(".funder.id") != -1) {
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
}
}
}
}
private extractRI(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
if(stakeholder.type != "ri"){
return;
}
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
if (!query["query"]["filters"]) {
return;
}
for (let filter of query["query"]["filters"]) {
if (filter["groupFilters"][0]["field"].indexOf(".context.name") != -1) {
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
indicatorPath.parameters["index_name"] = stakeholder.index_name;
}else if (filter["groupFilters"][0]["field"].indexOf(".context.id") != -1) {
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
}
}
}
}
private extractOrganization(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
if(stakeholder.type != "organization"){
return;
}
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
if (!query["query"]["filters"]) {
return;
}
for (let filter of query["query"]["filters"]) {
if (filter["groupFilters"][0]["field"].indexOf(".organization.name") != -1) {
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
indicatorPath.parameters["index_name"] = stakeholder.index_name;
}else if (filter["groupFilters"][0]["field"].indexOf(".organization.id") != -1) {
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
}
}
}
}
private extractStartYear(obj, indicatorPath: IndicatorPath) {
let start_year;
for (let query of obj["chartDescription"]["queries"]) {
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
if (!query["query"]["filters"]) {
return;
}
@ -324,7 +398,7 @@ export class IndicatorUtils {
private extractEndYear(obj, indicatorPath: IndicatorPath) {
let end_year;
for (let query of obj["chartDescription"]["queries"]) {
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
if (!query["query"]["filters"]) {
return;
}
@ -342,24 +416,61 @@ export class IndicatorUtils {
private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
let name = "";
for (let query of obj["chartDescription"]["queries"]) {
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
//monitor.{{stakeholderType}}.{{queryname}}
//parameters: stakeholderId*, type
if (query["query"]["name"]) {
name = query["query"]["name"];
let parameters = (query["query"]["parameters"])?query["query"]["parameters"]:[];
if(name.split('.')[0] == "rcd" && parameters.length > 0 && stakeholder.type=="ri") {
//rcd.{{queryname}}
parameters[0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
}else if(name.split('.')[0] == "monitor" && parameters.length == 0 && stakeholder.type=="funder"){
// old saved queries without params
//monitor.{{funder_shortName}}.{{type}}.{{queryname}}
let stakeholderSN = name.split('.')[1];
query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "index_shortName" + ChartHelper.suffix +"." + name.split('.' + stakeholderSN + ".")[1];
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
}else if(name.split('.')[0] == "monitor" && parameters.length > 0 && name.split('.')[1] == stakeholder.type) {
// new parameterized queries
//monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}}
if( name.split('.').length > 3 && name.split('.')[3] == "id") {
parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
indicatorPath.parameters["index_id"] = stakeholder.index_id;
}else if( name.split('.').length > 3 && name.split('.')[3] == "shortname") {
parameters[0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
}else if( name.split('.').length > 3 && name.split('.')[3] == "name") {
parameters[0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
indicatorPath.parameters["index_name"] = stakeholder.index_name;
}
}
}
}
}
private extractDataTitle(obj, indicatorPath: IndicatorPath) {
let index = 0;
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
if (query["name"]) {
let name = query["name"];
query["name"] = ChartHelper.prefix + "data_title_"+index + ChartHelper.suffix;
indicatorPath.parameters["data_title_"+index] = name;
}
index++;
}
}
private extractTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj["chartDescription"]["title"]) {
if (obj["library"] && obj["library"] == "HighCharts" &&obj["chartDescription"]["title"]) {
title = obj["chartDescription"]["title"]["text"];
obj["chartDescription"]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
indicatorPath.parameters["title"] = title ? title : "";
}else if (obj["library"] && obj["library"] == "GoogleCharts" && obj["chartDescription"]["options"]["title"]) {
title = obj["chartDescription"]["options"]["title"];
obj["chartDescription"]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
}
indicatorPath.parameters["title"] = title ? title : "";
}
private extractSubTitle(obj, indicatorPath: IndicatorPath) {
@ -373,26 +484,32 @@ export class IndicatorUtils {
private extractXTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj["chartDescription"]["xAxis"]["title"]) {
if (obj["library"] && obj["library"] == "HighCharts" && obj["chartDescription"]["xAxis"]["title"]) {
title = obj["chartDescription"]["xAxis"]["title"]["text"];
obj["chartDescription"]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
indicatorPath.parameters["xAxisTitle"] = title ? title : ""
}else if (obj["library"] && obj["library"] == "GoogleCharts" && obj["chartDescription"]["options"]["hAxis"]["title"]) {
title = obj["chartDescription"]["options"]["hAxis"]["title"];
obj["chartDescription"]["options"]["hAxis"]["title"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
}
indicatorPath.parameters["xAxisTitle"] = title ? title : "";
}
private extractYTitle(obj, indicatorPath: IndicatorPath) {
let title = "";
if (obj["chartDescription"]["yAxis"]["title"]) {
if (obj["library"] && obj["library"] == "HighCharts" && obj["chartDescription"]["yAxis"]["title"]) {
title = obj["chartDescription"]["yAxis"]["title"]["text"];
obj["chartDescription"]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
indicatorPath.parameters["yAxisTitle"] = title ? title : ""
}else if (obj["library"] && obj["library"] == "GoogleCharts" && obj["chartDescription"]["options"]["vAxis"]["title"]) {
title = obj["chartDescription"]["options"]["vAxis"]["title"];
obj["chartDescription"]["options"]["vAxis"]["title"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
}
indicatorPath.parameters["yAxisTitle"] = title ? title : "";
}
private addResultFilters(obj, indicatorPath: IndicatorPath) {
let resultTypes = ["publication", "software", "dataset", "other"];
let index = -1;
for (let query of obj["chartDescription"]["queries"]) {
for (let query of obj[(obj["chartDescription"]?"chartDescription":"tableDescription")][this.getQueryObjectName(obj)]) {
if (!query["query"]["select"]) {
return;
}