Project

General

Profile

1
import {DomSanitizer} from "@angular/platform-browser";
2
import {StringUtils} from "../../utils/string-utils.class";
3
import {EnvProperties} from "../../utils/properties/env-properties";
4

    
5
export class CommunityCharts {
6

    
7
  results = {
8
    publication: {name: "Publications", type: "publication", chartId: "Pubs"},
9
    dataset: {name: "Research data", type: "dataset", chartId: "Data"},
10
    software: {name: "Software", type: "software", chartId: "Soft"},
11
    orp: {name: "Other research products", type: "other", chartId: "Other"}
12
  };
13
  types = ["publication", "dataset", "software", "orp"];
14

    
15

    
16
  constructor(private sanitizer: DomSanitizer) {
17

    
18
  }
19

    
20
  getChartsForCommunity(communityId: string, communityName: string, properties:EnvProperties) {
21
    if (properties.useNewStatistisTool) {
22
      return this.getNewToolCharts(communityId, communityName, properties.statisticsFrameNewAPIURL);
23
    }
24
    return this.getOldToolCharts(communityId,  properties.statisticsFrameAPIURL);
25
  }
26

    
27
  private getOldToolCharts(communityId: string, chartsFrameAPIURL: string) {
28
    let chartsInfoMap = {};
29
    for (let type of this.types) {
30
      chartsInfoMap[type + 'Timeline'] = {
31
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart.php?com=query&persistent=false&data=com=query&data={"query":"comTimeline' +
32
          this.results[type].chartId + '","comId":"' + communityId + '","table":"result","fields":[{"fld":"number","agg":"count","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis",' +
33
          '"xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["' + this.results[type].name + '"],"fieldsheaders":["' + this.results[type].name + '"],"in":[{"f":0,"text":"Yearly"}],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},'
34
          + '{"name":"type","values":["' + this.results[type].type + '"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Year"}&w=90%&h=80%'),
35
        title: "" + StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per year"
36
      };
37

    
38
      chartsInfoMap[type + 'Graph'] = {
39
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart.php?com=query&data={"query":"comOA' + this.results[type].chartId + '","comId":"' + communityId +
40
          '","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"bestlicense","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"order":"d","yaxisheaders":[""],"fieldsheaders":[""],"in":[],"filters":[],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"","nulls":true}&w=80%&h=80%'),
41
        title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " access rights"
42
      };
43
      chartsInfoMap[type + 'Projectcolumn'] = {
44
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart.php?com=query&data={"query":"comProject' + this.results[type].chartId +
45
          '","comId":"' + communityId + '","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["' + this.results[type].name + '"],"fieldsheaders":["' + this.results[type].name + '"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["' + this.results[type].type + '"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=70%&h=80%'),
46
        title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per project",
47
      };
48
      chartsInfoMap[type + 'Projectpie'] = {
49
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart.php?com=query&data={"query":"comProject' + this.results[type].chartId +
50
          '","comId":"' + communityId + '","table":"result","fields":[{"fld":"number","agg":"count","type":"pie","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["' + this.results[type].name + '"],"fieldsheaders":["' + this.results[type].name + '"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["' + this.results[type].type + '"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=85%&h=90%'),
51
        title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per project",
52
      },
53
        chartsInfoMap[type + 'Projecttable'] = {
54
          url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'gtable.php?com=query&data={"query":"comProject' + this.results[type].chartId +
55
            '","comId":"' + communityId + '","table":"result","fields":[{"fld":"number","agg":"count","type":"bar","yaxis":1,"c":false}],"xaxis":{"name":"year","agg":"avg"},"group":"","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":"-","s":"-","l":"-","ft":"-","wt":"-"},"yaxisheaders":["' + this.results[type].name + '"],"fieldsheaders":["' + this.results[type].name + '"],"in":[],"filters":[{"name":"year","max":"2013","min":"2007","to":-1},{"name":"result_projects-project-funding_lvl0","values":["FP7"],"to":"-1"},{"name":"type","values":["' + this.results[type].type + '"],"to":"-1"},{"name":"result_projects-project-funding_lvl2","values":["ERC"],"to":"-1"}],"having":[],"incfilters":[],"inchaving":[],"title":"","subtitle":"","xaxistitle":"Project"}&w=70%&h=90%'),
56
          title: " " + StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per project",
57
        };
58

    
59
      if (communityId == "egi") {
60
        //TODO add VO --> available only for
61
      }
62

    
63
    }
64
    return chartsInfoMap;
65
  }
66

    
67
  private getNewToolCharts(communityId: string, communityName: string, chartsFrameAPIURL: string) {
68

    
69
    let chartsInfoMap = {};
70
    for (let type of this.types) {
71
      chartsInfoMap[type + 'Timeline'] = {
72
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart?json=' + StringUtils.URIEncode('{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + this.results[type].name + '","type":"column","query":{"name":"rcd.timeline","parameters":["'+communityId+'","' + this.results[type].type + '"]}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"' + this.results[type].name + '"}},"xAxis":{"title":{"text":"Year"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}')),
73
        title: StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per year"
74
      };
75
      chartsInfoMap[type + 'Graph'] = {
76
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart?json=' + StringUtils.URIEncode('{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + this.results[type].name + '","type":"pie","query":{"select":[{"field":"' + this.results[type].type + '","aggregate":"count"},{"field":"' + this.results[type].type + '.access mode","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.context.name","type":"=","values":["' + communityName + '"]}],"op":"AND"}],"entity":"' + this.results[type].type + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"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"}}}')),
77
        title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " access right"
78
      };
79
      chartsInfoMap[type + 'Projectcolumn'] = {
80
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart?json=' + StringUtils.URIEncode('{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + this.results[type].name + '","type":"bar","query":{"select":[{"field":"' + this.results[type].type + '","aggregate":"count"},{"field":"' + this.results[type].type + '.project.acronym","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.context.name","type":"=","values":["' + communityName + '"]}],"op":"AND"}],"entity":"' + this.results[type].type + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"' + this.results[type].name + '"}},"xAxis":{"title":{}},"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"}}}')),
81
        title: "" + StringUtils.capitalize(this.results[type].name.toLowerCase())+ " per project",
82
      };
83
      chartsInfoMap[type + 'Projectpie'] = {
84
        url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart?json=' + StringUtils.URIEncode('{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + this.results[type].name + '","type":"pie","query":{"select":[{"field":"' + this.results[type].type + '","aggregate":"count"},{"field":"' + this.results[type].type + '.project.acronym","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.context.name","type":"=","values":["' + communityName + '"]}],"op":"AND"}],"entity":"' + this.results[type].type + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"' + this.results[type].name + '"}},"xAxis":{"title":{}},"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"}}}')),
85
        title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per project",
86
      },
87
        chartsInfoMap[type + 'Projecttable'] = {
88
          url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'table?json=' + StringUtils.URIEncode('{"library":"GoogleCharts","tableDescription":{"queriesInfo":[{"name":"' + this.results[type].name + '","type":"bar","query":{"select":[{"field":"' + this.results[type].type + '","aggregate":"count"},{"field":"' + this.results[type].type + '.project.acronym","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.context.name","type":"=","values":["' + communityName + '"]}],"op":"AND"}],"entity":"publication","profile":"OpenAIRE All-inclusive","limit":"30"}}],"columns":[],"options":{"hAxis":{},"vAxis":{},"chartArea":{},"series":[],"exporting":true,"pageSize":30,"isStacked":"false"}}}')),
89
          title: "" + StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per project",
90
        };
91
        //TODO check again
92
      if (communityId == "egi") {
93
        chartsInfoMap[type + 'VOcolumn'] ={
94
            url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'chart?json=' + StringUtils.URIEncode('{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + this.results[type].name + '","type":"bar","query":{"select":[{"field":"' + this.results[type].type + '","aggregate":"count"},{"field":"' + this.results[type].type + '.concept.name","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.context.name","type":"=","values":["' + communityName + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.name","type":"=","values":["EGI virtual organizations"]}],"op":"AND"}],"entity":"' + this.results[type].type + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{},"subtitle":{},"yAxis":{"title":{"text":"' + this.results[type].name + '"}},"xAxis":{"title":{"text":"Projects"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"vertical"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}')),
95
            title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per EGI virtual organization",
96
          };
97
        chartsInfoMap[type + 'VOtable'] ={
98
          url: this.sanitizer.bypassSecurityTrustResourceUrl(chartsFrameAPIURL + 'table?json=' + StringUtils.URIEncode('{"library":"GoogleCharts","tableDescription":{"queriesInfo":[{"name":"Data","type":"bar","query":{"select":[{"field":"' + this.results[type].type + '","aggregate":"count"},{"field":"' + this.results[type].type + '.concept.name","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.context.name","type":"=","values":["EGI Federation"]}],"op":"AND"},{"groupFilters":[{"field":"' + this.results[type].type + '.concept.category.name","type":"=","values":["EGI virtual organizations"]}],"op":"AND"}],"entity":"publication","profile":"OpenAIRE All-inclusive","limit":"30"}}],"columns":[],"options":{"hAxis":{},"vAxis":{},"chartArea":{},"series":[],"exporting":true,"pageSize":30,"isStacked":"false"}}}')),
99
          title: "" +  StringUtils.capitalize(this.results[type].name.toLowerCase()) + " per EGI virtual organization",
100
        };
101

    
102
      }
103
    }
104
    return chartsInfoMap;
105
  }
106

    
107
}
(1-1/2)