import {Stakeholder, Topic, Category, SubCategory, Indicator, IndicatorPath, ChartHelper, Section} from "../../openaireLibrary/monitor/entities/stakeholder";
import {IndicatorUtils} from "../indicator-utils";

export class StakeholderCreator {

  static createFunderDefaultProfile(funder:Stakeholder):Stakeholder{
    // let funder:Stakeholder = new Stakeholder(null,"funder","dfid","Default Funder Profile","dfsn","default_funder",true,true, null);
    funder['defaultId'] = null;
    funder.topics.push(StakeholderCreator.createResearchProductionTopic(funder));
    funder.topics.push(StakeholderCreator.createOSTopic(funder));
    let collaboration = new Topic("Collaboration","Indexes for collaboration","collaboration", true, true);
    collaboration.categories.push(this.createEmptyCategory("International collaboration","Indicators for international collaborations based on the percentage of research results or patents with at least one co-author from abroad","international-collaboration"));
    collaboration.categories.push(this.createEmptyCategory("EU collaboration","Indicators for EU Collaboration based on the percentage of research results or patents with at least one co-author from another EU organization","eu-collaboration"));
    collaboration.categories.push(this.createEmptyCategory("Industrial collaboration","Indicators for Industrial collaboration based on the percentage of research results or patents with at least one co-author from the industry","industrial-collaboration"));
    collaboration.categories.push(this.createEmptyCategory("Transdisciplinary / transectoral collaboration","Indicators for Transdisciplinary/transectoral collaboration based on the percentage of research results or patents with at least one co-author from another discipline or sector","transdisciplinary-collaboration"));

    funder.topics.push(collaboration);

    funder.topics.push(StakeholderCreator.createEmptyTopic("Diffusion","Indicators based on citations, classifications and usage data: How diverse are the research knowledge resources upon which an article is drawn? How diverse are the venues in which a body of research appears? How diverse are the fields that cite a research result?","diffusion"));
    let impact = new Topic("Impact", "", "impact", true, true);
    impact.categories.push(this.createEmptyCategory("Academic Impact","Indicators based on citations and collaboration, related to MAG classifications.","academic-impact"));
    impact.categories.push(this.createEmptyCategory("Economic Impact","Indicators based on patents and collaboration between industry and academia","economic-impact"));
    impact.categories.push(this.createEmptyCategory("Societal Impact","Indicators that correlate research results with SDGs","societal-impact"));
    funder.topics.push(impact);
    return funder;
  }

  static updateECProfile(funder:Stakeholder){
    //Throughput / Output
    funder.topics[0].categories[0].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Publications", "Publication","publication", "publications",1));
    funder.topics[0].categories[0].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Publications", "Publication","publication", "publications",2));

    funder.topics[0].categories[1].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Research data", "Research data","dataset", "datasets",1));
    funder.topics[0].categories[1].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Research data", "Research data","dataset", "datasets",2));

    funder.topics[0].categories[2].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Software", "Software","software", "software",1));
    funder.topics[0].categories[2].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Software", "Software","software", "software",2));

    funder.topics[0].categories[3].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Other research products", "Other research product","other", "other",1));
    funder.topics[0].categories[3].subCategories.push(StakeholderCreator.createResearchProductionPerType(funder,"Other research products", "Other research product","other", "other",2));


    funder.topics[1].categories[0].subCategories[0].charts.push(new Section("chart","FP7 Section" ));
    funder.topics[1].categories[0].subCategories[0].charts[1].indicators =  this.createOAPerType(funder,"Publications","Publication","publication","publications", 1 );
    funder.topics[1].categories[0].subCategories[0].charts.push(new Section("chart","H2020" ));
    funder.topics[1].categories[0].subCategories[0].charts[2].indicators =  this.createOAPerType(funder,"Publications","Publication","publication","publications", 2 );

    funder.topics[1].categories[0].subCategories[1].charts.push(new Section("chart","FP7 Section" ));
    funder.topics[1].categories[0].subCategories[1].charts[1].indicators =  this.createOAPerType(funder,"Research data", "Research data","dataset", "datasets", 1 );
    funder.topics[1].categories[0].subCategories[1].charts.push(new Section("chart","H2020" ));
    funder.topics[1].categories[0].subCategories[1].charts[2].indicators =   this.createOAPerType(funder,"Research data", "Research data","dataset", "datasets", 2 );

    funder.topics[1].categories[0].subCategories[2].charts.push(new Section("chart","FP7 Section" ));
    funder.topics[1].categories[0].subCategories[2].charts[1].indicators =   this.createOAPerType(funder,"Software", "Software","software", "software", 1 );
    funder.topics[1].categories[0].subCategories[2].charts.push(new Section("chart","H2020" ));
    funder.topics[1].categories[0].subCategories[2].charts[2].indicators =   this.createOAPerType(funder,"Software", "Software","software", "software", 2 );

    funder.topics[1].categories[0].subCategories[3].charts.push(new Section("chart","FP7 Section" ));
    funder.topics[1].categories[0].subCategories[3].charts[1].indicators = this.createOAPerType(funder,"Other research products", "Other research product","other", "other", 1 );
    funder.topics[1].categories[0].subCategories[3].charts.push(new Section("chart","H2020" ));
    funder.topics[1].categories[0].subCategories[3].charts[2].indicators = this.createOAPerType(funder,"Other research products", "Other research product","other", "other", 2 );
    return funder;
  }

  static createEmptyTopic(name: string, description: string, alias: string):Topic{
    let topic = new Topic(name, description, alias, true, true);
    topic.categories.push(this.createEmptyCategory("Overview","","overview"));
    return topic;
  }
  static createEmptyCategory(name: string, description: string, alias: string):Category{
    let cat:Category =  new Category(name, description, alias,true,true);
    cat.subCategories.push(new SubCategory("Overview","","overview",true,true));
    return cat;
  }

  static createResearchProductionTopic(stakeholder:Stakeholder):Topic {
    let topic = new Topic("Throughput / Output", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do...", "research-production", true, true);

    let pubCategory:Category =  new Category("Publications","","publications",true,true);
    topic.categories.push(pubCategory);
    // let pubDefSub = StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications");
    pubCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications",0));
    // pubCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications",1));
    // pubCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications",2));
    let dataCategory:Category =  new Category("Research data","","data",true,true);
    topic.categories.push(dataCategory);
    dataCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Research data", "Research data","dataset", "datasets",0));
    // dataCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Research data", "Research data","dataset", "datasets",1));
    // dataCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Research data", "Research data","dataset", "datasets",2));

    let softwareCategory:Category =  new Category("Software","","software",true,true);
    topic.categories.push(softwareCategory);
    softwareCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Software", "Software","software", "software",0));
    // softwareCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Software", "Software","software", "software",1));
    // softwareCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Software", "Software","software", "software",2));

    let otherCategory:Category =  new Category("Other research products","","other",true,true);
    topic.categories.push(otherCategory);
    otherCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Other research products", "Other research product","other", "other",0));
    // otherCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Other research products", "Other research product","other", "other",1));
    // otherCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Other research products", "Other research product","other", "other",2));


    return topic;

  }
  static createResearchProductionPerType(stakeholder:Stakeholder,typePlural, typeSingl, dbType, dbTypePlural, index:number):SubCategory{

    let fundingFilter = ['',',{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["FP7"]}],"op":"AND"}',
      ',{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["H2020"]}],"op":"AND"}'];
    let categoryTitle=["Overview","FP7","H2020"];
    let chartTitle=["","FP7 ","H2020 "];
    let pubDefSub = new SubCategory(categoryTitle[index], null,categoryTitle[index].toLowerCase(),true, true);
    if(index!=0){
      pubDefSub.recommendedFor.push("ec__________::EC");
    }
    if(index==0) {
      pubDefSub.numbers.push(new Section("number", null, null, stakeholder.alias));
      let n_total = new Indicator("Total " + typePlural, null, "number", "small", true, true, [new IndicatorPath(null, "search",
        "/" + dbTypePlural + "/count?fq=" + (encodeURIComponent("relfunderid exact index_id")) + "&format=json", null, ["total"])]);
      n_total.indicatorPaths[0].filters["fundingL0"] = "&fq=relfundinglevel0_name exact " + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix;
      pubDefSub.numbers[0].indicators.push(n_total);
    }
    if( dbType != "publication" && index == 0) {
      let n_linkedPubs = this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Publications","publication");

        // new Indicator("Linked with Publications", null, "number", "small", true, true, [new IndicatorPath(null, "search",
        // "/resources?query="+encodeURIComponent(" ( (oaftype exact result) and (resulttypeid exact " + dbTypePlural + ") and (relresulttype=publication)  )")+"&fq=" + (encodeURIComponent("relfunderid exact index_id")) + "&page=0&size=0&format=json", null, ["meta","total"])]);
      pubDefSub.numbers[0].indicators.push(n_linkedPubs);
    }

    pubDefSub.charts.push(new Section("chart", null, null, stakeholder.alias));

    let res_timeline = new Indicator("",null, "chart","small",true, true,[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+'.year","aggregate":null}],"filters":[{"groupFilters":[{"field":"'+dbType+'.project.funder","type":"=","values":["'+ChartHelper.prefix+'index_name'+ChartHelper.suffix+'"]}],"op":"AND"},{"groupFilters":[{"field":"'+dbType+'.year","type":">=","values":["'+ChartHelper.prefix+'start_year'+ChartHelper.suffix+'"]},{"field":"'+dbType+'.year","type":"<=","values":["'+ChartHelper.prefix+'end_year'+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":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
    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";
    pubDefSub.charts[0].indicators.push(res_timeline);


    if(dbType == "publication" || dbType == "dataset") {

      let res_types = new Indicator("", null, "chart", "small", true, true,
        [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");
      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");
    pubDefSub.charts[0].indicators.push(res_access_mode);


/*      let res_sci_area = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","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":"30"}}],"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":"Scientific area"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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_sci_area.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " scientific area", "bar");
      res_sci_area.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
      res_sci_area.recommendedFor = ["ec__________::EC"];
      pubDefSub.charts[0].indicators.push(res_sci_area);

      let res_programmes = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'index_name' + ChartHelper.suffix + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.project.funding level 2","type":"!=","values":[" "]}],"op":"AND"}'+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"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":"Programmes"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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_programmes.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " programmes", "bar");
      res_programmes.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
    res_programmes.recommendedFor = ["ec__________::EC"];
      pubDefSub.charts[0].indicators.push(res_programmes);*/

    //{"library":"HighCharts","chartDescription":{"queries":[{"name":"Research Data","type":"bar","query":{"select":[{"field":"dataset","aggregate":"count"},{"field":"dataset.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"dataset.project.funder","type":"=","values":["European Commission"]}],"op":"AND"}],"entity":"dataset","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Scientific Area"},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}
    let datasource = new Indicator("",null, "chart","small",true, true,[new IndicatorPath("bar", "stats-tool", "chart?json=",
      '{"library":"HighCharts","chartDescription":{"queries":[{"name":"'+typePlural+'","type":"'+ChartHelper.prefix+'type'+ChartHelper.suffix+'","query":{"name":"monitor.'+ChartHelper.prefix+'index_shortName'+ChartHelper.suffix+(index==2?".h2020":(index==1?".fp7":""))+'.'+dbTypePlural+'.datasources"}}],"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":"Content provider"}},"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)]);
    datasource.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,chartTitle[index] + typeSingl+" content provider","bar");
    datasource.indicatorPaths[0].parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
    pubDefSub.charts[0].indicators.push(datasource);
    if(dbType == "publication") {
      let journal = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix +(index==2?".h2020":(index==1?".fp7":""))+ '.' + dbTypePlural + '.journals"}}],"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":"Journal"}},"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)]);
      journal.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " journal", "bar");
      journal.indicatorPaths[0].parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts[0].indicators.push(journal);

      let repo = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix +(index==2?".h2020":(index==1?".fp7":""))+ '.' + dbTypePlural + '.repositories"}}],"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":"Repositories"}},"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)]);
      repo.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " repositories", "bar");
      repo.indicatorPaths[0].parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts[0].indicators.push(repo);
    }
    if(dbType == "dataset") {
      let repo = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix + (index==2?".h2020":(index==1?".fp7":""))+'.' + dbTypePlural + '.drepositories"}}],"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":"Data Repositories"}},"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)]);
      repo.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " repositories", "bar");
      repo.indicatorPaths[0].parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts[0].indicators.push(repo);

      let irepo = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix +(index==2?".h2020":(index==1?".fp7":""))+ '.' + dbTypePlural + '.irepositories"}}],"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":"Institutional repositories"}},"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)]);
      irepo.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " institutional repositories", "bar");
      irepo.indicatorPaths[0].parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts[0].indicators.push(irepo);
    }

    if(index ==0) {
      let pid = 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":{"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();
      pubDefSub.charts[0].indicators.push(pid);
    }
    return pubDefSub;
  }
/*  static createOASub(){
    let subCategories:SubCategory[] = [];
    let overviewSub = new SubCategory("Overview", null,"overview",true, true);
    subCategories.push(overviewSub);
    let byScientificAreaSub = new SubCategory("By Scientific Area", null,"scientific-area",true, true);
    subCategories.push(byScientificAreaSub);
    let byProgramSub = new SubCategory("By Programme", null,"programme",true, true);
    subCategories.push(byProgramSub);
    return subCategories;
  }*/
  static createOpenAccessTopic(stakeholder:Stakeholder):Category {
    let category = new Category("Open Access", "", "open-access", true, true);
    category.subCategories.push(this.createOASub(stakeholder,"Publications","Publication","publication","publications"));
    category.subCategories.push(this.createOASub(stakeholder,"Research data","Research data","dataset","datasets"));
    category.subCategories.push(this.createOASub(stakeholder,"Software","Software","software","software"));
    category.subCategories.push(this.createOASub(stakeholder,"Other research products","Other research product","other","other"));
    return category;
  }
  static createOASub(stakeholder:Stakeholder,typePlural, typeSingl, dbType, dbTypePlural ):SubCategory {
    let sub:SubCategory =  new SubCategory(typePlural, null, dbTypePlural, true, true);
    sub.charts.push(new Section("chart", null, null, stakeholder.alias));
    sub.charts[0].indicators = sub.charts[0].indicators.concat( this.createOAPerType(stakeholder,typePlural, typeSingl, dbType, dbTypePlural, 0 ));
    // sub.charts[0].indicators = sub.charts[0].indicators.concat( this.createOAPerType(stakeholder,typePlural, typeSingl, dbType, dbTypePlural, 1 ));
    // sub.charts[0].indicators = sub.charts[0].indicators.concat( this.createOAPerType(stakeholder,typePlural, typeSingl, dbType, dbTypePlural, 2 ));
    return sub;
  }
  static createOAPerType(stakeholder:Stakeholder,typePlural, typeSingl, dbType, dbTypePlural, index:number):Indicator[] {
//default pallette: "colors":["#2f7ed8","#0d233a","#8bbc21","#910000","#1aadce","#492970","#f28f43","#77a1e5","#c42525","#a6c96a"]
    let greenAndGoldPalette = ', "colors":["#239D60","#F8B500"]';
    let fundingFilter = ['', '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["FP7"]}],"op":"AND"}',
      '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["H2020"]}],"op":"AND"}'];
    let fieldValue = ["", "FP7", "H2020"];
    let chartTitle = ["", "FP7 ", "H2020 "];
    let indicators:Indicator[]=[];
    let utils = new IndicatorUtils();

    let open_non_url = "http://88.197.53.71:8080/stats-api/chart?json="+encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Data","type":"pie","color":"#e62020ee","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix +(index==2?".h2020":(index==1?".fp7":""))+ '.' + dbTypePlural+'.oavsnonoa"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"'+chartTitle[index]+' Open Access vs Non Open Access"},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
      encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Data","type":"pie","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix +(index==2?".h2020":(index==1?".fp7":""))+ '.' + dbTypePlural+'.greenvsgold"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
    let open_non_ind:Indicator = new Indicator("", "", "chart", "small", true, true, [utils.generateIndicatorByChartUrl("stats-tool", open_non_url, "pie",stakeholder)])
    open_non_ind.indicatorPaths[0].parameters["index_id"] =  stakeholder.index_shortName.toLowerCase();
    if(index!=0){
      open_non_ind.recommendedFor.push("ec__________::EC");
    }
    indicators.push(open_non_ind);

    if(dbType == "publication") {
      let gold_vs_green_url = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Data","type":"column","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix + (index == 2 ? ".h2020" : (index == 1 ? ".fp7" : "")) + '.' + dbTypePlural + '.greenvsgold"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + ' Green vs Gold"},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
      let gold_vs_green_ind: Indicator = (new Indicator("", "", "chart", "small", true, true, [utils.generateIndicatorByChartUrl("stats-tool", gold_vs_green_url, "pie",stakeholder)]));
      gold_vs_green_ind.indicatorPaths[0].parameters["index_id"] = stakeholder.index_shortName.toLowerCase();
      if (index != 0) {
        gold_vs_green_ind.recommendedFor.push("ec__________::EC");
      }
      indicators.push(gold_vs_green_ind);
      let gold_vs_green_time_url = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Green OA","type":"column","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix + (index == 2 ? ".h2020" : (index == 1 ? ".fp7" : "")) + '.' + dbTypePlural + '.green.year"}},{"name":"Gold OA","type":"column","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix + (index == 2 ? ".h2020" : (index == 1 ? ".fp7" : "")) + '.' + dbTypePlural + '.gold.year"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + ' Green vs Gold Open Access"},"subtitle":{"text":"by year"},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}'+greenAndGoldPalette+'}}');
      let gold_vs_green_time_ind: Indicator = (new Indicator("", "", "chart", "small", true, true, [utils.generateIndicatorByChartUrl("stats-tool", gold_vs_green_time_url, "column",stakeholder)]));
      gold_vs_green_time_ind.indicatorPaths[0].parameters["index_id"] = stakeholder.index_shortName.toLowerCase();
      if (index != 0) {
        gold_vs_green_time_ind.recommendedFor.push("ec__________::EC");
      }
      indicators.push(gold_vs_green_time_ind);
    }

    let top_project_url = "http://88.197.53.71:8080/stats-api/chart?json="+ encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Data","type":"bar","query":{"name":"monitor.'+  ChartHelper.prefix + 'id' + ChartHelper.suffix +(index==2?".h2020":(index==1?".fp7":""))+ '.' + dbTypePlural+'.top10projects"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + 'Top 10 projects"},"subtitle":{"text":"by '+typePlural+'"},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
    let top_project_ind:Indicator = (new Indicator("", "", "chart", "medium", true, true, [utils.generateIndicatorByChartUrl("stats-tool", top_project_url, "column",stakeholder)]));
    top_project_ind.indicatorPaths[0].parameters["index_id"] =  stakeholder.index_shortName.toLowerCase();
    if(index!=0){
      top_project_ind.recommendedFor.push("ec__________::EC");
    }
    indicators.push(top_project_ind);
    if(index == 0) {
      let top_datasources_url = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Data","type":"bar","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix + '.' + dbTypePlural + '.top10datasources"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + 'Top 10 Datasources"},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
      let top_datasources_ind: Indicator = (new Indicator("", "", "chart", "medium", true, true, [utils.generateIndicatorByChartUrl("stats-tool", top_datasources_url, "column",stakeholder)]));
      top_datasources_ind.indicatorPaths[0].parameters["index_id"] = stakeholder.index_shortName.toLowerCase();
      indicators.push(top_datasources_ind);
    }
    if(index != 0) {
      let open_non_fl2 = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent(
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"Open Access","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":['+fundingFilter[index]+',{"groupFilters":[{"field":"' + dbType + '.access mode","type":"=","values":["Open Access"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}},{"name":"Non Open Access","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.access mode","type":"!=","values":["Open Access"]}],"op":"AND"}'+(fundingFilter[index].length >0?', ':'')+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + 'Open Access vs Non Open Access"},"subtitle":{"text":"By Scientific area"},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
      let open_non_fl2_ind: Indicator = (new Indicator("", "", "chart", "medium", true, true, [utils.generateIndicatorByChartUrl("stats-tool", open_non_fl2, "column",stakeholder)]));
      indicators.push(open_non_fl2_ind);
      if (index != 0) {
        open_non_fl2_ind.recommendedFor.push("ec__________::EC");
      }
      if(dbType == "publication") {
        let gold_green__fl2 = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent(
          '{"library":"HighCharts","chartDescription":{"queries":[{"name":"Green OA","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + fieldValue[index] + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.access mode","type":"=","values":["Open Access"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.datasource.type","type":"contains","values":["repo"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}},{"name":"Gold OA","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.access mode","type":"=","values":["Open Access"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + fieldValue[index] + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.datasource.id","type":"starts_with","values":["doaj"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + 'Green vs Gold Open Access"},"subtitle":{"text":"By Scientific area"},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}'+greenAndGoldPalette+'}}');
        let gold_green_ind_fl2: Indicator = (new Indicator("", "", "chart", "medium", true, true, [utils.generateIndicatorByChartUrl("stats-tool", gold_green__fl2, "column",stakeholder)]));
        indicators.push(gold_green_ind_fl2);
        if (index != 0) {
          gold_green_ind_fl2.recommendedFor.push("ec__________::EC");
        }
      }
      let open_non_fl1 = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent(
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"Open Access","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","aggregate":null}],"filters":['+fundingFilter[index]+',{"groupFilters":[{"field":"' + dbType + '.access mode","type":"=","values":["Open Access"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}},{"name":"Non Open Access","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.access mode","type":"!=","values":["Open Access"]}],"op":"AND"}'+(fundingFilter[index].length >0?', ':'')+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + 'Open Access vs Non Open Access"},"subtitle":{"text":"By Programme"},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}}}');
      let open_non_fl1_ind: Indicator = (new Indicator("", "", "chart", "medium", true, true, [utils.generateIndicatorByChartUrl("stats-tool", open_non_fl1, "column",stakeholder)]));
      indicators.push(open_non_fl1_ind);
      if (index != 0) {
        open_non_fl1_ind.recommendedFor.push("ec__________::EC");
      }
      if(dbType == "publication") {
        let gold_green__fl1 = "http://88.197.53.71:8080/stats-api/chart?json=" + encodeURIComponent(
          '{"library":"HighCharts","chartDescription":{"queries":[{"name":"Green OA","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + fieldValue[index] + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.access mode","type":"=","values":["Open Access"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.datasource.type","type":"contains","values":["repo"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}},{"name":"Gold OA","type":"bar","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.access mode","type":"=","values":["Open Access"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + fieldValue[index] + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.datasource.id","type":"starts_with","values":["doaj"]}],"op":"AND"}],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + chartTitle[index] + 'Green vs Gold Open Access"},"subtitle":{"text":"By Programme"},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"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"}'+greenAndGoldPalette+'}}');
        let gold_green_ind_fl1: Indicator = (new Indicator("", "", "chart", "medium", true, true, [utils.generateIndicatorByChartUrl("stats-tool", gold_green__fl1, "column",stakeholder)]));
        // open_non_fl2_ind.indicatorPaths[0].parameters["index_id"] = stakeholder.index_shortName.toLowerCase();
        indicators.push(gold_green_ind_fl1);
        if (index != 0) {
          gold_green_ind_fl1.recommendedFor.push("ec__________::EC");
        }
      }
    }


    return indicators;
  }
  static createOSTopic(stakeholder:Stakeholder):Topic{
    let topic = new Topic("Open Science","","open-science",true,true);
    topic.categories.push(this.createOpenAccessTopic(stakeholder));
   let linked:Category =  new Category("Fair / Linked","Indicators based on FAIR data maturity model will soon be included","linked",true,true);
    topic.categories.push(linked);
    linked.subCategories.push(this.createOSOverviewPerType(stakeholder,"Publications","Publication","publication","publications"));
    linked.subCategories.push(this.createOSOverviewPerType(stakeholder,"Research data","Research data","dataset","datasets"));
    linked.subCategories.push(this.createOSOverviewPerType(stakeholder,"Software","Software","software","software"));
    linked.subCategories.push(this.createOSOverviewPerType(stakeholder,"Other research products","Other research product","other","other"));

    let openInfra:Category =  new Category("Open Infrastructures","Indicators based on the use of services for generating, producing and publishing research","open-infrastructures",true,true);
    openInfra.subCategories.push(new SubCategory("Overview","","overview",true,true));
    topic.categories.push(openInfra);
    return topic;

  }
  static createOSOverviewPerType(stakeholder:Stakeholder,typePlural, typeSingl, dbType, dbTypePlural ):SubCategory {

    let pubDefSub = new SubCategory(typePlural, null, dbTypePlural, true, true);
    pubDefSub.numbers.push(new Section("number", null, null, stakeholder.alias));

    if( dbType != "publication") {
      pubDefSub.numbers[0].indicators.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Publications","publication"));
    }
    if( dbType != "dataset") {
      pubDefSub.numbers[0].indicators.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Research data","dataset"));
    }
    if( dbType != "software") {
      pubDefSub.numbers[0].indicators.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Software","software"));
    }
    if( dbType != "other") {
      pubDefSub.numbers[0].indicators.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Other Research products","other"));
    }
    return pubDefSub;
  }

  static createLinkToIndicator(stakeholder:Stakeholder,typePlural, typeSingl, dbType, linkedToName,linkedToType ):Indicator {
      let n_linkedPubs = new Indicator(typePlural+" linked to "+linkedToName, null, "number", "small", true, true, [new IndicatorPath(null, "search",
        "/resources?query=" + encodeURIComponent(" ( (oaftype exact result) and (resulttypeid exact " + dbType + ") and (relresulttype="+linkedToType+")  )") + "&fq=" + (encodeURIComponent("relfunderid exact index_id")) + "&page=0&size=0&format=json", null, ["meta", "total"])]);
      n_linkedPubs.indicatorPaths[0].filters["fundingL0"] = "&fq=relfundinglevel0_name exact "+ChartHelper.prefix+'fundingL0'+ChartHelper.suffix;
      /*
    filters.set("start_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":">=","values":["'+ChartHelper.prefix+'start_year'+ChartHelper.suffix+'"]}],"op":"AND"}');
    filters.set("end_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":"<=","values":["'+ChartHelper.prefix+'end_year'+ChartHelper.suffix+'"]}],"op":"AND"}');
       */
    return n_linkedPubs;
  }
  static createFundingImpactTopic():Topic{
    let topic = new Topic("Impact/Correlation","Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do...","impact",true,true);

    let pubCategory:Category =  new Category("Publications","","publications",true,true);
    topic.categories.push(pubCategory);
    let pubDefSub = new SubCategory(null, null,null,true, true);
    pubCategory.subCategories.push(pubDefSub);

    let dataCategory:Category =  new Category("Research data","","data",true,true);
    topic.categories.push(dataCategory);
    let dataDefSub = new SubCategory(null, null,null,true, true);
    dataCategory.subCategories.push(dataDefSub);

    let softwareCategory:Category =  new Category("Software","","software",true,true);
    topic.categories.push(softwareCategory);
    let softDefSub = new SubCategory(null, null,null,true, true);
    softwareCategory.subCategories.push(softDefSub);

  /*  let otherCategory:Category =  new Category("Other research products","","other",true,true);
    topic.categories.push(otherCategory);
    let otherDefSub = new SubCategory(null, null,null,true, true);
    otherCategory.subCategories.push(otherDefSub);*/


    return topic;
  }
  createCollaborationTopic():Topic{
    let topic = new Topic("Demo Topic","This is a demo topic","demo-topic",true,true);

    let category1:Category =  new Category("Category 1","This is ","cat-1",true,true);
    topic.categories.push(category1);


    let subCat1 = new SubCategory("Sub-category 1","","sub-cat-1",true,true);
    category1.subCategories.push(subCat1);


    let subCat2 = new SubCategory("Sub-category 2","","sub-cat-2",true,true);
    category1.subCategories.push(subCat2);



    let category2:Category =  new Category("Category 2 - no subcategories","","cat-2",true,true);
    topic.categories.push(category2);
    let defSub = new SubCategory(null, null,null,true, true);
    //defSub.charts.push(new Section("chart", null, null, stakeholder.alias));

    category2.subCategories.push(defSub);

    let chart1 = new Indicator(
      "Chart title goes here","Chart description goes here", "chart","medium",true, true,
      [new IndicatorPath("other", "image","https://visme.co/blog/wp-content/uploads/2017/03/Dogs-vs-Cats-How-much-they-miss-you-relative-to-the-time-you-are-gone.png", null, null)]);
    let chart2 = new Indicator("Chart title goes here","Chart description goes here", "chart","medium",true, true, [new IndicatorPath("other", "image","https://static.boredpanda.com/blog/wp-content/uuuploads/funny-graphs-2/funny-graphs-legs.jpg", null, null)]);
    subCat1.charts[0].indicators.push(chart1);
    subCat2.charts[0].indicators.push(chart2);

    defSub.charts[0].indicators.push(chart1);
    defSub.charts[0].indicators.push(chart2);
    return topic;
  }
}






