[angular-16-irish-monitor | DONE | CHANGED] Indicators Filters changed the way filters applied, add publiclyFunded Filter

This commit is contained in:
argirok 2024-01-17 15:43:43 +02:00
parent 93ae0db4dd
commit 6034bcfe77
3 changed files with 103 additions and 93 deletions

View File

@ -392,7 +392,7 @@ export class IndicatorUtils {
return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl); return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
} }
public getFullUrlWithFilters(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded: boolean = false, foslvl1:string[]=[], foslvl2:string[]=[] ): string { public getFullUrlWithFilters(stakeholder: Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded: boolean = false, foslvl1:string[]=[], foslvl2:string[]=[], publiclyFunded: "all"| "true"| "false"= "all" ): string {
indicatorPath.filtersApplied = 0; indicatorPath.filtersApplied = 0;
let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url; let replacedUrl = indicatorPath.chartObject ? indicatorPath.chartObject : indicatorPath.url;
if (stakeholder.statsProfile) { if (stakeholder.statsProfile) {
@ -452,6 +452,13 @@ export class IndicatorUtils {
indicatorPath.filtersApplied += filterResults.filtersApplied; indicatorPath.filtersApplied += filterResults.filtersApplied;
} }
} }
if (publiclyFunded && publiclyFunded !="all") {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'publicly-funded', publiclyFunded);
replacedUrl = filterResults.url;
indicatorPath.filtersApplied += filterResults.filtersApplied;
}
}
if (foslvl1) { if (foslvl1) {
if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) { if (indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
let filterResults = this.addFilter(replacedUrl, 'foslvl1', foslvl1); let filterResults = this.addFilter(replacedUrl, 'foslvl1', foslvl1);
@ -477,7 +484,6 @@ export class IndicatorUtils {
if (replacedUrl.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)); replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName));
} }
//Check apply enhancements return this.applySchemaEnhancements( ..);
return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl); return (indicatorPath.chartObject ? indicatorPath.url + encodeURIComponent(replacedUrl) : replacedUrl);
} }

View File

@ -222,103 +222,104 @@ export class IndicatorPath {
} }
export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded" | "foslvl1" | "foslvl2"; export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded" | "foslvl1" | "foslvl2" | "publicly-funded";
export class IndicatorFilterUtils { export class IndicatorFilterUtils {
public static filteredFields = {
static getFilter(fieldPath: string, filterType:FilterType, value:string|string[] =null) { "year":{
if ((filterType == "start_year" || filterType == "end_year") && (fieldPath.indexOf(".year") != -1 || fieldPath.indexOf(".start year") != -1) "result": "result.year",
&& fieldPath.indexOf("indi_pub_downloads_year.year") == -1) { "indi_pub_downloads_year": "indi_pub_downloads_year.year", //exclude indi_pub_downloads_year.year because it throws errors. when there is a solution remove the exclusion
// make it work for any table with field year or start year no matter the type or the table name "indi_pub_downloads":"indi_pub_downloads.result.year",
//exclude indi_pub_downloads_year.year because it throws errors. when there is a solution remove the exclusion "result_apc":"result_apc.result.year",
if (filterType == "start_year") { "result_apc_affiliations":"result_apc_affiliations.result.year",
return '{"groupFilters":[{"field":"' + fieldPath + '","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}'; "result_country":"result_country.result.year",
} else if (filterType == "end_year") { "indi_impact_measures": "indi_impact_measures.result.year",
return '{"groupFilters":[{"field":"' + fieldPath + '","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}'; "project": "project.start year"
} },
"fundingL0":{
"result": "result.project funding level 0",
"project": "project.funding level 0",
"country":"country.organization.project.funding level 0",
"organization":"organization.project.funding level 0"
},
"co-funded":{
"result": "result.No of funders",
},
"foslvl1":
{
"publication":"publication.topics.result.result_fos.lvl1",
"result":"result.result_fos.lvl1",
"indi_pub_downloads":"indi_pub_downloads.result.result_fos.lvl1",
"indi_pub_downloads_year":"indi_pub_downloads_year.result.result_fos.lvl1",
"indi_impact_measures":"indi_impact_measures.result.result_fos.lvl1",
"result_apc":"result_apc.result.result_fos.lvl1",
"result_apc_affiliations":"result_apc_affiliations.result.result_fos.lvl1",
"result_country":"result_country.result.result_fos.lvl1",
"historical_snapshots_irish_fos":"historical_snapshots_irish_fos.lvl1"
},
"foslvl2":{
"publication":"publication.topics.result.result_fos.lvl2",
"result":"result.result_fos.lvl2",
"indi_pub_downloads":"indi_pub_downloads.result.result_fos.lvl2",
"indi_pub_downloads_year":"indi_pub_downloads_year.result.result_fos.lvl2",
"indi_impact_measures":"indi_impact_measures.result.result_fos.lvl2",
"result_apc":"result_apc.result.result_fos.lvl2",
"result_apc_affiliations":"result_apc_affiliations.result.result_fos.lvl2",
"result_country":"result_country.result.result_fos.lvl2",
"historical_snapshots_irish_fos":"historical_snapshots_irish_fos.lvl2"
},
"publicly-funded":{
"result":"result.indi_pub_publicly_funded.publicly_funded",
"indi_pub_downloads":"indi_pub_downloads.result.indi_pub_publicly_funded.publicly_funded",
"indi_pub_downloads_year":"indi_pub_downloads_year.result.indi_pub_publicly_funded.publicly_funded",
"indi_impact_measures":"indi_impact_measures.result.indi_pub_publicly_funded.publicly_funded",
"result_apc":"result_apc.result.indi_pub_publicly_funded.publicly_funded",
"result_apc_affiliations":"result_apc_affiliations.result.indi_pub_publicly_funded.publicly_funded",
"result_country":"result_country.result.indi_pub_publicly_funded.publicly_funded"
} }
if ((filterType == "foslvl1" || filterType == "foslvl2") ){
if (filterType == "foslvl1" && fieldPath.indexOf("result.result_fos.lvl1")!=-1 && value && value.length > 0) {
let filterString = '{"groupFilters":[' ;
let filters = [];
for(let v of value) {
filters.push('{"field":"' + fieldPath + '","type":"=","values":["' + v + '"]}');
}
filterString+=filters.join(", ")
filterString+='],"op":"OR"}'
return filterString;
}
if (filterType == "foslvl1" && fieldPath.indexOf("result.result_fos.lvl2")!=-1 && value && value.length > 0) {
let filterString = '{"groupFilters":[' ;
let filters = [];
for(let v of value) {
filters.push('{"field":"' + (fieldPath.replace(".lvl2",".lvl1")) + '","type":"=","values":["' + v + '"]}');
}
filterString+=filters.join(", ")
filterString+='],"op":"OR"}'
return filterString;
}
if (filterType == "foslvl2" && fieldPath.indexOf("result.result_fos.lvl2")!=-1 && value && value.length > 0) {
let filterString = '{"groupFilters":[' ;
let filters = [];
for(let v of value) {
filters.push('{"field":"' + fieldPath + '","type":"=","values":["' + v + '"]}');
}
filterString+=filters.join(", ")
filterString+='],"op":"OR"}'
return filterString;
}
return "";
} }
let table = fieldPath&&fieldPath.length > 0? fieldPath.split(".")[0]:""; static getFieldForTable(field, table){
if(["publication", "software", "dataset", "other", "result"].indexOf(table)!=-1){ if(["publication", "software", "dataset", "other", "result"].indexOf(table)!=-1){
return this.getResultFilter(table,filterType); return IndicatorFilterUtils.filteredFields[field]["result"];
}else if (table == "project"){ }else{
return this.getProjectFilter(filterType); return IndicatorFilterUtils.filteredFields[field][table];
} }
else if (table == "country"){ }
return this.getCountryFilter(filterType); static getFilter(fieldPath: string, filterType:FilterType, value:string|string[] =null) {
}else if (table == "organization"){ let tablename = fieldPath.split(".")[0];
return this.getOrganizationFilter(filterType); if ((filterType == "start_year" || filterType == "end_year") && (IndicatorFilterUtils.getFieldForTable("year",tablename))){
} if (filterType == "start_year") {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils.getFieldForTable("year",tablename) + '","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
return ""; } else if (filterType == "end_year") {
} return '{"groupFilters":[{"field":"' + IndicatorFilterUtils.getFieldForTable("year",tablename) + '","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
static getResultFilter(table: string = null, filterType:FilterType) {
//works for tables ["publication", "software", "dataset", "other", "result"]
if (filterType == "fundingL0") {
if(properties.useOldStatisticsSchema) {
return '{"groupFilters":[{"field":"' + table + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}else{//new statistcs schema
return '{"groupFilters":[{"field":"' + table + '.project funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
} }
}else if (filterType == "co-funded") { }
return '{"groupFilters":[{"field":"' + table + '.No of funders","type":">","values":["1"]}],"op":"AND"}'; if (filterType == "fundingL0" && IndicatorFilterUtils.getFieldForTable("fundingL0",tablename)) {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils.getFieldForTable("fundingL0",tablename) + '","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}else if (table == "publication" &&(filterType == "foslvl1" || filterType == "foslvl2") ){ }else if (filterType == "co-funded" && IndicatorFilterUtils.getFieldForTable("co-funded",tablename)) {
return '{"groupFilters":[{"field":"' + (filterType == "foslvl1"?"publication.topics.result.result_fos.lvl1":"publication.topics.result.result_fos.lvl2") + '","type":"=","values":["' + ChartHelper.prefix + filterType + ChartHelper.suffix + '"]}],"op":"OR"}'; return '{"groupFilters":[{"field":"' + IndicatorFilterUtils.getFieldForTable("co-funded",tablename) + '","type":">","values":["1"]}],"op":"AND"}';
} }else if (filterType == "publicly-funded" && IndicatorFilterUtils.getFieldForTable("publicly-funded",tablename)) {
return ""; return '{"groupFilters":[{"field":"' + IndicatorFilterUtils.getFieldForTable("publicly-funded",tablename) + '","type":"=","values":["' + (value=="true"?"1":"0") +'"]}],"op":"AND"}';
} }else if (filterType == "foslvl1" && IndicatorFilterUtils.getFieldForTable("foslvl1",tablename) && value && value.length > 0) {
static getProjectFilter( filterType:FilterType) { let filterString = '{"groupFilters":[' ;
//works for table "project" let filters = [];
if (filterType == "fundingL0") { for(let v of value) {
return '{"groupFilters":[{"field":"project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}'; filters.push('{"field":"' + IndicatorFilterUtils.getFieldForTable("foslvl1",tablename) + '","type":"=","values":["' + v + '"]}');
} }
return ""; filterString+=filters.join(", ")
} filterString+='],"op":"OR"}'
static getOrganizationFilter( filterType:FilterType) { return filterString;
//works for table "organization" }else if (filterType == "foslvl2" && IndicatorFilterUtils.getFieldForTable("foslvl2",tablename) && value && value.length > 0) {
if (filterType == "fundingL0") { let filterString = '{"groupFilters":[' ;
return '{"groupFilters":[{"field":"organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}'; let filters = [];
} for(let v of value) {
return ""; filters.push('{"field":"' + IndicatorFilterUtils.getFieldForTable("foslvl2",tablename) + '","type":"=","values":["' + v + '"]}');
} }
static getCountryFilter( filterType:FilterType) { filterString+=filters.join(", ")
//works for table "country" filterString+='],"op":"OR"}'
if (filterType == "fundingL0") { return filterString;
return '{"groupFilters":[{"field":"country.organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
} }
return ""; return "";
} }

View File

@ -206,7 +206,7 @@ export abstract class MonitorIndicatorStakeholderBaseComponent extends Indicator
protected getFullUrl(indicatorPath: IndicatorPath) { protected getFullUrl(indicatorPath: IndicatorPath) {
let fosValues = this.getSelectedFilterValues("fos"); let fosValues = this.getSelectedFilterValues("fos");
return this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, indicatorPath,null, this.periodFilter.selectedFromValue, this.periodFilter.selectedToValue, false, fosValues?fosValues.lvl1:[],fosValues?fosValues.lvl2:[]); return this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, indicatorPath,null, this.periodFilter.selectedFromValue, this.periodFilter.selectedToValue, false, fosValues?fosValues.lvl1:[],fosValues?fosValues.lvl2:[], this.getSelectedFilterValues("publiclyfunded"));
} }
protected setIndicators() { protected setIndicators() {
@ -481,7 +481,10 @@ export abstract class MonitorIndicatorStakeholderBaseComponent extends Indicator
}else{ }else{
values.lvl2.push(filterValue.id) values.lvl2.push(filterValue.id)
} }
}else { }else if(filterId == "publiclyfunded"){
// console.log("publiclyFunded", filterValue)
return filterValue.id;
}else{
values.push(filterValue.id); values.push(filterValue.id);
} }
} }