make the rule to apply year filter more generic, but exclude "indi_pub_downloads_year.year" according to #8135

This commit is contained in:
argirok 2022-10-17 14:22:06 +03:00
parent d399f40ad6
commit 1542d476ae
1 changed files with 26 additions and 27 deletions

View File

@ -214,59 +214,58 @@ export class IndicatorPath {
}
export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded";
export class IndicatorFilterUtils{
static getFilter(field: string, filterType:FilterType) {
if(["publication", "software", "dataset", "other", "result"].indexOf(field)!=-1){
return this.getResultFilter(field,filterType);
}else if (field == "project"){
static getFilter(fieldPath: string, filterType:FilterType) {
if((filterType == "start_year" || filterType == "end_year") && (fieldPath.indexOf(".year") != -1 || fieldPath.indexOf(".start year") != -1)
&& fieldPath.indexOf("indi_pub_downloads_year.year") == -1){
// make it work for any table with field year or start year no matter the type or the table name
//exclude indi_pub_downloads_year.year because it throws errors. when there is a solution remove the exclusion
if (filterType == "start_year") {
return '{"groupFilters":[{"field":"' + fieldPath + '","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "end_year") {
return '{"groupFilters":[{"field":"' + fieldPath + '","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
}
let table = fieldPath&&fieldPath.length > 0? fieldPath.split(".")[0]:"";
if(["publication", "software", "dataset", "other", "result"].indexOf(table)!=-1){
return this.getResultFilter(table,filterType);
}else if (table == "project"){
return this.getProjectFilter(filterType);
}
else if (field == "country"){
else if (table == "country"){
return this.getCountryFilter(filterType);
}else if (field == "organization"){
}else if (table == "organization"){
return this.getOrganizationFilter(filterType);
}
}
static getResultFilter(dbType: string = null, filterType:FilterType) {
static getResultFilter(table: string = null, filterType:FilterType) {
//works for tables ["publication", "software", "dataset", "other", "result"]
if (filterType == "fundingL0") {
if(properties.useOldStatisticsSchema) {
return '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
return '{"groupFilters":[{"field":"' + table + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}else{//new statistcs schema
return '{"groupFilters":[{"field":"' + dbType + '.project funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
return '{"groupFilters":[{"field":"' + table + '.project funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
} else if (filterType == "start_year") {
return '{"groupFilters":[{"field":"' + dbType + '.year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "end_year") {
return '{"groupFilters":[{"field":"' + dbType + '.year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
}else if (filterType == "co-funded") {
return '{"groupFilters":[{"field":"' + dbType + '.No of funders","type":">","values":["1"]}],"op":"AND"}';
return '{"groupFilters":[{"field":"' + table + '.No of funders","type":">","values":["1"]}],"op":"AND"}';
}
}
static getProjectFilter( filterType:FilterType) {
//works for table "project"
if (filterType == "fundingL0") {
return '{"groupFilters":[{"field":"project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "start_year") {
return '{"groupFilters":[{"field":"project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "end_year") {
return '{"groupFilters":[{"field":"project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
}
static getOrganizationFilter( filterType:FilterType) {
//works for table "organization"
if (filterType == "fundingL0") {
return '{"groupFilters":[{"field":"organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "start_year") {
return '{"groupFilters":[{"field":"organization.project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "end_year") {
return '{"groupFilters":[{"field":"organization.project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
}
static getCountryFilter( filterType:FilterType) {
//works for table "country"
if (filterType == "fundingL0") {
return '{"groupFilters":[{"field":"country.organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "start_year") {
return '{"groupFilters":[{"field":"country.organization.project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
} else if (filterType == "end_year") {
return '{"groupFilters":[{"field":"country.organization.project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
}