Project

General

Profile

1
import { Injectable } from '@angular/core';
2
import { RawData, Row } from '../domain/raw-data';
3
import {
4
  CountryOverviewData,
5
  CountryMapData,
6
  EuropeData,
7
  OverviewMapData,
8
  CountryTableData,
9
  CountryPageOverviewData, RnDExpenditure
10
} from '../domain/overview-map-data';
11
import {Indicator} from '../domain/overview-data';
12
import {TreemapHighchartsData} from '../domain/treemap-highcharts-data';
13

    
14
@Injectable ()
15
export class DataHandlerService {
16

    
17
  public convertRawDataToLastUpdateDate(rawData: RawData) {
18

    
19
    let lastUpdateDate: string;
20

    
21
    for (const series of rawData.datasets) {
22

    
23
      if (series.series.query.name === 'creation_date') {
24
        lastUpdateDate = series.series.result[0].row[0];
25
      }
26
    }
27

    
28
    return lastUpdateDate;
29
  }
30

    
31
  public convertRawMapDataToMapData(rawData: RawData) {
32

    
33
    const overviewMapData: OverviewMapData = new OverviewMapData();
34

    
35
    for (const series of rawData.datasets) {
36

    
37
      if (series.series.query.name === 'new.oso.publications.peer_reviewed.affiliated') {
38
        overviewMapData.publications = this.rawResultToCountryMapData(series.series.result);
39
      } else if (series.series.query.name === 'oso.results.affiliated' && series.series.query.parameters.includes('dataset')) {
40
        overviewMapData.datasets = this.rawResultToCountryMapData(series.series.result);
41
      } else if (series.series.query.name === 'oso.repositories.doar_re3data') {
42
        overviewMapData.repositories = this.rawResultToCountryMapData(series.series.result);
43
      } else if (series.series.query.name === 'oso.journals.doaj') {
44
        overviewMapData.journals = this.rawResultToCountryMapData(series.series.result);
45
      } else if (series.series.query.name === 'oso.oa_policies') {
46
        overviewMapData.policies = this.rawResultToCountryMapData(series.series.result);
47
      }
48
    }
49

    
50
    // console.log('Overview map data (data-handler)', overviewMapData);
51

    
52
    return overviewMapData;
53
  }
54

    
55
  public createJoinedPublicationsCountryMap(rawData: RawData) {
56

    
57
    const joinedPublicationsMap = new Map();
58

    
59
    for (const series of rawData.datasets) {
60
      if (series.series.query.name === 'new.oso.publications.peer_reviewed.affiliated') {
61

    
62
        for (const rowResult of series.series.result) {
63
          if (joinedPublicationsMap.has(rowResult.row[1])) {
64
            const deposited = joinedPublicationsMap.get(rowResult.row[1]).deposited;
65
            joinedPublicationsMap.delete(rowResult.row[1]);
66
            joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
67
              affiliated: Number(rowResult.row[0]), deposited: deposited});
68
          } else {
69
            joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
70
              affiliated: Number(rowResult.row[0]), deposited: 0});
71
          }
72
        }
73

    
74
      } else if (series.series.query.name === 'new.oso.publications.peer_reviewed.deposited') {
75

    
76
        for (const rowResult of series.series.result) {
77
          if (joinedPublicationsMap.has(rowResult.row[1])) {
78
            const affiliated = joinedPublicationsMap.get(rowResult.row[1]).affiliated;
79
            joinedPublicationsMap.delete(rowResult.row[1]);
80
            joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
81
              affiliated: affiliated, deposited: Number(rowResult.row[0])});
82
          }
83
          joinedPublicationsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
84
            affiliated: 0, deposited: Number(rowResult.row[0])});
85
        }
86
      }
87
    }
88

    
89
    return joinedPublicationsMap;
90
  }
91

    
92
  public createJoinedDatasetsCountryMap(rawData: RawData) {
93

    
94
    const joinedDatasetsMap = new Map();
95

    
96
    for (const series of rawData.datasets) {
97
      if (series.series.query.name === 'oso.results.affiliated' && series.series.query.parameters.includes('dataset')) {
98

    
99
        for (const rowResult of series.series.result) {
100
          if (joinedDatasetsMap.has(rowResult.row[1])) {
101
            const deposited = joinedDatasetsMap.get(rowResult.row[1]).deposited;
102
            joinedDatasetsMap.delete(rowResult.row[1]);
103
            joinedDatasetsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
104
              affiliated: Number(rowResult.row[0]), deposited: deposited});
105
          } else {
106
            joinedDatasetsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
107
              affiliated: Number(rowResult.row[0]), deposited: 0});
108
          }
109
        }
110

    
111
      } else if (series.series.query.name === 'oso.results.deposited' && series.series.query.parameters.includes('dataset')) {
112

    
113
        for (const rowResult of series.series.result) {
114
          if (joinedDatasetsMap.has(rowResult.row[1])) {
115
            const affiliated = joinedDatasetsMap.get(rowResult.row[1]).affiliated;
116
            joinedDatasetsMap.delete(rowResult.row[1]);
117
            joinedDatasetsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
118
              affiliated: affiliated, deposited: Number(rowResult.row[0])});
119
          }
120
          joinedDatasetsMap.set(rowResult.row[1], { countryName: rowResult.row[1], countryCode: rowResult.row[2],
121
            affiliated: 0, deposited: Number(rowResult.row[0])});
122
        }
123
      }
124
    }
125

    
126
    return joinedDatasetsMap;
127

    
128
  }
129

    
130
  public createJoinedRepositoriesCountryMap(rawData: RawData) {
131

    
132
    const joinedRepositoriesMap = new Map();
133

    
134
    for (const series of rawData.datasets) {
135
      if (series.series.query.name === 'oso.repositories.doar_re3data') {
136

    
137
        for (const rowResult of series.series.result) {
138
          if (joinedRepositoriesMap.has(rowResult.row[1])) {
139
            const simple = joinedRepositoriesMap.get(rowResult.row[1]).simple;
140
            joinedRepositoriesMap.delete(rowResult.row[1]);
141
            joinedRepositoriesMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
142
              doar_re3data: Number(rowResult.row[0]), simple: simple});
143
          } else {
144
            joinedRepositoriesMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
145
              doar_re3data: Number(rowResult.row[0]), simple: 0});
146
          }
147
        }
148

    
149
      } else if (series.series.query.name === 'oso.repositories') {
150

    
151
        for (const rowResult of series.series.result) {
152
          if (joinedRepositoriesMap.has(rowResult.row[1])) {
153
            const doar_re3data = joinedRepositoriesMap.get(rowResult.row[1]).doar_re3data;
154
            joinedRepositoriesMap.delete(rowResult.row[1]);
155
            joinedRepositoriesMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
156
              doar_re3data: doar_re3data, simple: Number(rowResult.row[0])});
157
          }
158
          joinedRepositoriesMap.set(rowResult.row[1], { countryName: rowResult.row[1], countryCode: rowResult.row[2],
159
            doar_re3data: 0, simple: Number(rowResult.row[0])});
160
        }
161
      }
162
    }
163

    
164
    return joinedRepositoriesMap;
165

    
166
  }
167

    
168
  public createJoinedJournalsCountryMap(rawData: RawData) {
169

    
170
    const joinedJournalsMap = new Map();
171

    
172
    for (const series of rawData.datasets) {
173
      if (series.series.query.name === 'oso.journals.doaj') {
174

    
175
        for (const rowResult of series.series.result) {
176
          if (joinedJournalsMap.has(rowResult.row[1])) {
177
            const simple = joinedJournalsMap.get(rowResult.row[1]).simple;
178
            joinedJournalsMap.delete(rowResult.row[1]);
179
            joinedJournalsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
180
              doaj: Number(rowResult.row[0]), simple: simple});
181
          } else {
182
            joinedJournalsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
183
              doaj: Number(rowResult.row[0]), simple: 0});
184
          }
185
        }
186

    
187
      } else if (series.series.query.name === 'oso.journals') {
188

    
189
        for (const rowResult of series.series.result) {
190
          if (joinedJournalsMap.has(rowResult.row[1])) {
191
            const doaj = joinedJournalsMap.get(rowResult.row[1]).doaj;
192
            joinedJournalsMap.delete(rowResult.row[1]);
193
            joinedJournalsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
194
              doaj: doaj, simple: Number(rowResult.row[0])});
195
          }
196
          joinedJournalsMap.set(rowResult.row[1], { countryName: rowResult.row[1], countryCode: rowResult.row[2],
197
            doaj: 0, simple: Number(rowResult.row[0])});
198
        }
199
      }
200
    }
201

    
202
    return joinedJournalsMap;
203

    
204
  }
205

    
206
  public convertRawDataToCountryOverviewData(rawData: RawData) {
207

    
208
    const countryData: CountryOverviewData = new CountryOverviewData();
209

    
210
    for (const series of rawData.datasets) {
211

    
212
      if (series.series.query.name === 'new.oso.publications.peer_reviewed.affiliated.country') {
213
        countryData.publicationsAffiliated = Number(series.series.result[0].row[0]);
214
      } else if (series.series.query.name === 'new.oso.publications.peer_reviewed.deposited.country') {
215
        countryData.publicationsDeposited = Number(series.series.result[0].row[0]);
216
      } else if (series.series.query.name === 'oso.results.affiliated.country' && series.series.query.parameters.includes('dataset')) {
217
        countryData.datasetsAffiliated = Number(series.series.result[0].row[0]);
218
      } else if (series.series.query.name === 'oso.results.deposited.country' && series.series.query.parameters.includes('dataset')) {
219
        countryData.datasetsDeposited = Number(series.series.result[0].row[0]);
220
      } else if (series.series.query.name === 'oso.repositories.doar_re3data.country') {
221
        countryData.repositories = Number(series.series.result[0].row[0]);
222
      } else if (series.series.query.name === 'oso.journals.doaj.country') {
223
        countryData.journals = Number(series.series.result[0].row[0]);
224
      } else if (series.series.query.name === 'oso.oa_policies.country') {
225
        countryData.policies = Number(series.series.result[0].row[0]);
226
      }
227
    }
228

    
229
    return countryData;
230
  }
231

    
232
  public convertRawDataToEuropeOverviewData(rawData: RawData) {
233

    
234
    const europeData: EuropeData = new EuropeData();
235

    
236
    for (const series of rawData.datasets) {
237

    
238
      if (series.series.query.name === 'new.oso.publications.peer_reviewed.oa_percentage') {
239

    
240
        const publicationsIndicator: Indicator = new Indicator();
241
        publicationsIndicator.percentage = Number(series.series.result[0].row[0]);
242
        publicationsIndicator.oa = Number(series.series.result[0].row[1]);
243
        publicationsIndicator.total = Number(series.series.result[0].row[2]);
244
        europeData.publications = publicationsIndicator;
245

    
246
      } else if (series.series.query.name === 'oso.results.oa_percentage' && series.series.query.parameters.includes('dataset')) {
247

    
248
        const datasetsIndicator: Indicator = new Indicator();
249
        datasetsIndicator.percentage = Number(series.series.result[0].row[0]);
250
        datasetsIndicator.oa = Number(series.series.result[0].row[1]);
251
        datasetsIndicator.total = Number(series.series.result[0].row[2]);
252
        europeData.datasets = datasetsIndicator;
253

    
254
      } else if (series.series.query.name === 'oso.results.oa_percentage' && series.series.query.parameters.includes('software')) {
255

    
256
        const softwareIndicator: Indicator = new Indicator();
257
        softwareIndicator.percentage = Number(series.series.result[0].row[0]);
258
        softwareIndicator.oa = Number(series.series.result[0].row[1]);
259
        softwareIndicator.total = Number(series.series.result[0].row[2]);
260
        europeData.software = softwareIndicator;
261

    
262
      } else if (series.series.query.name === 'oso.results.oa_percentage' && series.series.query.parameters.includes('other')) {
263

    
264
        const otherIndicator: Indicator = new Indicator();
265
        otherIndicator.percentage = Number(series.series.result[0].row[0]);
266
        otherIndicator.oa = Number(series.series.result[0].row[1]);
267
        otherIndicator.total = Number(series.series.result[0].row[2]);
268
        europeData.other = otherIndicator;
269

    
270
      } else if (series.series.query.name === 'oso.repositories.doar_re3data.validated') {
271

    
272
        const repositoriesIndicator: Indicator = new Indicator();
273
        repositoriesIndicator.percentage = Number(series.series.result[0].row[0]);
274
        repositoriesIndicator.oa = Number(series.series.result[0].row[1]);
275
        repositoriesIndicator.total = Number(series.series.result[0].row[2]);
276
        europeData.repositories = repositoriesIndicator;
277

    
278
      } else if (series.series.query.name === 'oso.journals.doaj.validated') {
279

    
280
        const journalsIndicator: Indicator = new Indicator();
281
        journalsIndicator.percentage = Number(series.series.result[0].row[0]);
282
        journalsIndicator.oa = Number(series.series.result[0].row[1]);
283
        journalsIndicator.total = Number(series.series.result[0].row[2]);
284
        europeData.journals = journalsIndicator;
285

    
286
      } else if (series.series.query.name === 'oso.oa_policies.europe') {
287

    
288
        const policiesIndicator: Indicator = new Indicator();
289
        policiesIndicator.percentage = Number(series.series.result[0].row[0]);
290
        policiesIndicator.oa = Number(series.series.result[0].row[1]);
291
        policiesIndicator.total = Number(series.series.result[0].row[2]);
292
        europeData.policies = policiesIndicator;
293

    
294
      }
295
    }
296

    
297
    return europeData;
298
  }
299

    
300
  public convertRawDataToAbsoluteTableData(rawData: RawData) {
301

    
302
    const mapTableData: Map<string, CountryTableData> = new Map();
303

    
304
    for (const series of rawData.datasets) {
305

    
306
      if (series.series.query.name.includes('oso.results') && series.series.query.parameters.includes('publication')) {
307
        for (const rowResult of series.series.result) {
308

    
309
          // remove unwanted countries
310
          if (this.isCountryToBeRemoved(rowResult.row[2])) {
311
            continue;
312
          }
313

    
314
          if (mapTableData.has(rowResult.row[2])) {
315
            const countryTableData = mapTableData.get(rowResult.row[2]);
316
            countryTableData.publications = Number(rowResult.row[0]);
317
          } else {
318
            const countryTableData: CountryTableData = new CountryTableData();
319
            countryTableData.publications = Number(rowResult.row[0]);
320
            countryTableData.name = rowResult.row[1];
321
            countryTableData.code = rowResult.row[2];
322
            mapTableData.set(rowResult.row[2], countryTableData);
323
          }
324
        }
325

    
326
      } else if (series.series.query.name.includes('oso.results') && series.series.query.parameters.includes('dataset')) {
327

    
328
        for (const rowResult of series.series.result) {
329

    
330
          // remove unwanted countries
331
          if (this.isCountryToBeRemoved(rowResult.row[2])) {
332
            continue;
333
          }
334

    
335
          if (mapTableData.has(rowResult.row[2])) {
336
            const countryTableData = mapTableData.get(rowResult.row[2]);
337
            countryTableData.datasets = Number(rowResult.row[0]);
338
          } else {
339
            const countryTableData: CountryTableData = new CountryTableData();
340
            countryTableData.datasets = Number(rowResult.row[0]);
341
            countryTableData.name = rowResult.row[1];
342
            countryTableData.code = rowResult.row[2];
343
            mapTableData.set(rowResult.row[2], countryTableData);
344
          }
345
        }
346
      } else if (series.series.query.name.includes('oso.results') && series.series.query.parameters.includes('software')) {
347

    
348
        for (const rowResult of series.series.result) {
349

    
350
          // remove unwanted countries
351
          if (this.isCountryToBeRemoved(rowResult.row[2])) {
352
            continue;
353
          }
354

    
355
          if (mapTableData.has(rowResult.row[2])) {
356
            const countryTableData = mapTableData.get(rowResult.row[2]);
357
            countryTableData.software = Number(rowResult.row[0]);
358
          } else {
359
            const countryTableData: CountryTableData = new CountryTableData();
360
            countryTableData.software = Number(rowResult.row[0]);
361
            countryTableData.name = rowResult.row[1];
362
            countryTableData.code = rowResult.row[2];
363
            mapTableData.set(rowResult.row[2], countryTableData);
364
          }
365
        }
366
      } else if (series.series.query.name.includes('oso.results') && series.series.query.parameters.includes('other')) {
367

    
368
        for (const rowResult of series.series.result) {
369

    
370
          // remove unwanted countries
371
          if (this.isCountryToBeRemoved(rowResult.row[2])) {
372
            continue;
373
          }
374

    
375
          if (mapTableData.has(rowResult.row[2])) {
376
            const countryTableData = mapTableData.get(rowResult.row[2]);
377
            countryTableData.other = Number(rowResult.row[0]);
378
          } else {
379
            const countryTableData: CountryTableData = new CountryTableData();
380
            countryTableData.other = Number(rowResult.row[0]);
381
            countryTableData.name = rowResult.row[1];
382
            countryTableData.code = rowResult.row[2];
383
            mapTableData.set(rowResult.row[2], countryTableData);
384
          }
385
        }
386
      } else if (series.series.query.name.includes('oso.repositories')) {
387

    
388
        for (const rowResult of series.series.result) {
389

    
390
          // remove unwanted countries
391
          if (this.isCountryToBeRemoved(rowResult.row[2])) {
392
            continue;
393
          }
394

    
395
          if (mapTableData.has(rowResult.row[2])) {
396
            const countryTableData = mapTableData.get(rowResult.row[2]);
397
            countryTableData.repositories = Number(rowResult.row[0]);
398
          } else {
399
            const countryTableData: CountryTableData = new CountryTableData();
400
            countryTableData.repositories = Number(rowResult.row[0]);
401
            countryTableData.name = rowResult.row[1];
402
            countryTableData.code = rowResult.row[2];
403
            mapTableData.set(rowResult.row[2], countryTableData);
404
          }
405
        }
406
      } else if (series.series.query.name.includes('oso.journals')) {
407

    
408
        for (const rowResult of series.series.result) {
409

    
410
          // remove unwanted countries
411
          if (this.isCountryToBeRemoved(rowResult.row[2])) {
412
            continue;
413
          }
414

    
415
          if (mapTableData.has(rowResult.row[2])) {
416
            const countryTableData = mapTableData.get(rowResult.row[2]);
417
            countryTableData.journals = Number(rowResult.row[0]);
418
          } else {
419
            const countryTableData: CountryTableData = new CountryTableData();
420
            countryTableData.journals = Number(rowResult.row[0]);
421
            countryTableData.name = rowResult.row[1];
422
            countryTableData.code = rowResult.row[2];
423
            mapTableData.set(rowResult.row[2], countryTableData);
424
          }
425
        }
426
      }
427
    }
428

    
429
    const tableData: CountryTableData[] = [];
430

    
431
    mapTableData.forEach((value: CountryTableData, key: string) => {
432
      // console.log(key, value);
433
      tableData.push(value);
434
    });
435

    
436
    return tableData;
437
  }
438

    
439
  public convertRawDataToPercentageTableData(rawData: RawData) {
440

    
441
    const mapTableData: Map<string, CountryTableData> = new Map();
442

    
443
    for (const series of rawData.datasets) {
444

    
445
      if (series.series.query.name.includes('oso.results')
446
        && series.series.query.parameters && series.series.query.parameters[0] === 'publication') {
447
        for (const rowResult of series.series.result) {
448

    
449
          // remove unwanted countries
450
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
451
            continue;
452
          }
453

    
454
          if (mapTableData.has(rowResult.row[4])) {
455
            const countryTableData = mapTableData.get(rowResult.row[4]);
456
            if (rowResult.row[0] !== 'NaN') {
457
              countryTableData.publications = Number(rowResult.row[0]);
458
            }
459
          } else {
460
            const countryTableData: CountryTableData = new CountryTableData();
461
            if (rowResult.row[0] !== 'NaN') {
462
              countryTableData.publications = Number(rowResult.row[0]);
463
            }
464
            countryTableData.name = rowResult.row[3];
465
            countryTableData.code = rowResult.row[4];
466
            mapTableData.set(rowResult.row[4], countryTableData);
467
          }
468
        }
469

    
470
      } else if (series.series.query.name.includes('oso.results')
471
        && series.series.query.parameters && series.series.query.parameters[0] === 'dataset') {
472

    
473
        for (const rowResult of series.series.result) {
474

    
475
          // remove unwanted countries
476
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
477
            continue;
478
          }
479

    
480
          if (mapTableData.has(rowResult.row[4])) {
481
            const countryTableData = mapTableData.get(rowResult.row[4]);
482
            if (rowResult.row[0] !== 'NaN') {
483
              countryTableData.datasets = Number(rowResult.row[0]);
484
            }
485
          } else {
486
            const countryTableData: CountryTableData = new CountryTableData();
487
            if (rowResult.row[0] !== 'NaN') {
488
              countryTableData.datasets = Number(rowResult.row[0]);
489
            }
490
            countryTableData.name = rowResult.row[3];
491
            countryTableData.code = rowResult.row[4];
492
            mapTableData.set(rowResult.row[4], countryTableData);
493
          }
494
        }
495
      } else if (series.series.query.name.includes('oso.results')
496
        && series.series.query.parameters && series.series.query.parameters[0] === 'software') {
497

    
498
        for (const rowResult of series.series.result) {
499

    
500
          // remove unwanted countries
501
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
502
            continue;
503
          }
504

    
505
          if (mapTableData.has(rowResult.row[4])) {
506
            const countryTableData = mapTableData.get(rowResult.row[4]);
507
            if (rowResult.row[0] !== 'NaN') {
508
              countryTableData.software = Number(rowResult.row[0]);
509
            }
510
          } else {
511
            const countryTableData: CountryTableData = new CountryTableData();
512
            if (rowResult.row[0] !== 'NaN') {
513
              countryTableData.software = Number(rowResult.row[0]);
514
            }
515
            countryTableData.name = rowResult.row[3];
516
            countryTableData.code = rowResult.row[4];
517
            mapTableData.set(rowResult.row[4], countryTableData);
518
          }
519
        }
520
      } else if (series.series.query.name.includes('oso.results')
521
        && series.series.query.parameters && series.series.query.parameters[0] === 'other') {
522

    
523
        for (const rowResult of series.series.result) {
524

    
525
          // remove unwanted countries
526
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
527
            continue;
528
          }
529

    
530
          if (mapTableData.has(rowResult.row[4])) {
531
            const countryTableData = mapTableData.get(rowResult.row[4]);
532
            if (rowResult.row[0] !== 'NaN') {
533
              countryTableData.other = Number(rowResult.row[0]);
534
            }
535
          } else {
536
            const countryTableData: CountryTableData = new CountryTableData();
537
            if (rowResult.row[0] !== 'NaN') {
538
              countryTableData.other = Number(rowResult.row[0]);
539
            }
540
            countryTableData.name = rowResult.row[3];
541
            countryTableData.code = rowResult.row[4];
542
            mapTableData.set(rowResult.row[4], countryTableData);
543
          }
544
        }
545
      } else if (series.series.query.name.includes('oso.repositories')) {
546

    
547
        for (const rowResult of series.series.result) {
548

    
549
          // remove unwanted countries
550
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
551
            continue;
552
          }
553

    
554
          if (mapTableData.has(rowResult.row[4])) {
555
            const countryTableData = mapTableData.get(rowResult.row[4]);
556
            countryTableData.repositories = Number(rowResult.row[0]);
557
          } else {
558
            const countryTableData: CountryTableData = new CountryTableData();
559
            countryTableData.repositories = Number(rowResult.row[0]);
560
            countryTableData.name = rowResult.row[3];
561
            countryTableData.code = rowResult.row[4];
562
            mapTableData.set(rowResult.row[4], countryTableData);
563
          }
564
        }
565
      } else if (series.series.query.name.includes('oso.journals')) {
566

    
567
        for (const rowResult of series.series.result) {
568

    
569
          // remove unwanted countries
570
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
571
            continue;
572
          }
573

    
574
          if (mapTableData.has(rowResult.row[4])) {
575
            const countryTableData = mapTableData.get(rowResult.row[4]);
576
            countryTableData.journals = Number(rowResult.row[0]);
577
          } else {
578
            const countryTableData: CountryTableData = new CountryTableData();
579
            countryTableData.journals = Number(rowResult.row[0]);
580
            countryTableData.name = rowResult.row[3];
581
            countryTableData.code = rowResult.row[4];
582
            mapTableData.set(rowResult.row[4], countryTableData);
583
          }
584
        }
585
      }
586
    }
587

    
588
    const tableData: CountryTableData[] = [];
589

    
590
    mapTableData.forEach((value: CountryTableData, key: string) => {
591
      // console.log(key, value);
592
      tableData.push(value);
593
    });
594

    
595
    return tableData;
596
  }
597

    
598
  public convertRawDataToIndicatorsTableData(rawData: RawData) {
599

    
600
    const mapTableData: Map<string, CountryTableData> = new Map();
601

    
602
    for (const series of rawData.datasets) {
603

    
604
      if (series.series.query.name.includes('oso.results.pid_percentage')) {
605
        for (const rowResult of series.series.result) {
606

    
607
          const pidIndicator = new Indicator();
608

    
609
          // remove unwanted countries
610
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
611
            continue;
612
          }
613

    
614
          if (mapTableData.has(rowResult.row[3])) {
615
            const countryTableData = mapTableData.get(rowResult.row[3]);
616
            pidIndicator.total = Number(rowResult.row[2]);
617
            pidIndicator.oa = Number(rowResult.row[1]);
618
            if (rowResult.row[0] !== 'NaN') {
619
              pidIndicator.percentage = Number(rowResult.row[0]);
620
            }
621
            countryTableData.pid = pidIndicator;
622
          } else {
623
            const countryTableData: CountryTableData = new CountryTableData();
624
            pidIndicator.total = Number(rowResult.row[2]);
625
            pidIndicator.oa = Number(rowResult.row[1]);
626
            if (rowResult.row[0] !== 'NaN') {
627
              pidIndicator.percentage = Number(rowResult.row[0]);
628
            }
629
            countryTableData.pid = pidIndicator;
630
            countryTableData.name = rowResult.row[4];
631
            countryTableData.code = rowResult.row[3];
632
            mapTableData.set(rowResult.row[3], countryTableData);
633
          }
634
        }
635

    
636
      } else if (series.series.query.name.includes('oso.results.licence_percentage')) {
637

    
638
        for (const rowResult of series.series.result) {
639

    
640
          const licenceIndicator = new Indicator();
641

    
642
          // remove unwanted countries
643
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
644
            continue;
645
          }
646

    
647
          if (mapTableData.has(rowResult.row[3])) {
648
            const countryTableData = mapTableData.get(rowResult.row[3]);
649
            licenceIndicator.total = Number(rowResult.row[2]);
650
            licenceIndicator.oa = Number(rowResult.row[1]);
651
            if (rowResult.row[0] !== 'NaN') {
652
              licenceIndicator.percentage = Number(rowResult.row[0]);
653
            }
654
            countryTableData.licence = licenceIndicator;
655
          } else {
656
            const countryTableData: CountryTableData = new CountryTableData();
657
            licenceIndicator.total = Number(rowResult.row[2]);
658
            licenceIndicator.oa = Number(rowResult.row[1]);
659
            if (rowResult.row[0] !== 'NaN') {
660
              licenceIndicator.percentage = Number(rowResult.row[0]);
661
            }
662
            countryTableData.licence = licenceIndicator;
663
            countryTableData.name = rowResult.row[4];
664
            countryTableData.code = rowResult.row[3];
665
            mapTableData.set(rowResult.row[3], countryTableData);
666
          }
667
        }
668
      } else if (series.series.query.name.includes('oso.results.green_percentage')) {
669

    
670
        for (const rowResult of series.series.result) {
671

    
672
          const greenIndicator = new Indicator();
673

    
674
          // remove unwanted countries
675
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
676
            continue;
677
          }
678

    
679
          if (mapTableData.has(rowResult.row[3])) {
680
            const countryTableData = mapTableData.get(rowResult.row[3]);
681
            greenIndicator.total = Number(rowResult.row[2]);
682
            greenIndicator.oa = Number(rowResult.row[1]);
683
            if (rowResult.row[0] !== 'NaN') {
684
              greenIndicator.percentage = Number(rowResult.row[0]);
685
            }
686
            countryTableData.green = greenIndicator;
687
          } else {
688
            const countryTableData: CountryTableData = new CountryTableData();
689
            greenIndicator.total = Number(rowResult.row[2]);
690
            greenIndicator.oa = Number(rowResult.row[1]);
691
            if (rowResult.row[0] !== 'NaN') {
692
              greenIndicator.percentage = Number(rowResult.row[0]);
693
            }
694
            countryTableData.green = greenIndicator;
695
            countryTableData.name = rowResult.row[4];
696
            countryTableData.code = rowResult.row[3];
697
            mapTableData.set(rowResult.row[3], countryTableData);
698
          }
699
        }
700
      } else if (series.series.query.name.includes('oso.results.gold_percentage')) {
701

    
702
        for (const rowResult of series.series.result) {
703

    
704
          const goldIndicator = new Indicator();
705

    
706
          // remove unwanted countries
707
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
708
            continue;
709
          }
710

    
711
          if (mapTableData.has(rowResult.row[3])) {
712
            const countryTableData = mapTableData.get(rowResult.row[3]);
713
            goldIndicator.total = Number(rowResult.row[2]);
714
            goldIndicator.oa = Number(rowResult.row[1]);
715
            if (rowResult.row[0] !== 'NaN') {
716
              goldIndicator.percentage = Number(rowResult.row[0]);
717
            }
718
            countryTableData.gold = goldIndicator;
719
          } else {
720
            const countryTableData: CountryTableData = new CountryTableData();
721
            goldIndicator.total = Number(rowResult.row[2]);
722
            goldIndicator.oa = Number(rowResult.row[1]);
723
            if (rowResult.row[0] !== 'NaN') {
724
              goldIndicator.percentage = Number(rowResult.row[0]);
725
            }
726
            countryTableData.gold = goldIndicator;
727
            countryTableData.name = rowResult.row[4];
728
            countryTableData.code = rowResult.row[3];
729
            mapTableData.set(rowResult.row[3], countryTableData);
730
          }
731
        }
732
      } else if (series.series.query.name.includes('oso.results.cc_licence_percentage')) {
733

    
734
        for (const rowResult of series.series.result) {
735

    
736
          const ccLicenceIndicator = new Indicator();
737

    
738
          // remove unwanted countries
739
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
740
            continue;
741
          }
742

    
743
          if (mapTableData.has(rowResult.row[3])) {
744
            const countryTableData = mapTableData.get(rowResult.row[3]);
745
            ccLicenceIndicator.total = Number(rowResult.row[2]);
746
            ccLicenceIndicator.oa = Number(rowResult.row[1]);
747
            if (rowResult.row[0] !== 'NaN') {
748
              ccLicenceIndicator.percentage = Number(rowResult.row[0]);
749
            }
750
            countryTableData.cc_licence = ccLicenceIndicator;
751
          } else {
752
            const countryTableData: CountryTableData = new CountryTableData();
753
            ccLicenceIndicator.total = Number(rowResult.row[2]);
754
            ccLicenceIndicator.oa = Number(rowResult.row[1]);
755
            if (rowResult.row[0] !== 'NaN') {
756
              ccLicenceIndicator.percentage = Number(rowResult.row[0]);
757
            }
758
            countryTableData.cc_licence = ccLicenceIndicator;
759
            countryTableData.name = rowResult.row[4];
760
            countryTableData.code = rowResult.row[3];
761
            mapTableData.set(rowResult.row[3], countryTableData);
762
          }
763
        }
764
      } else if (series.series.query.name.includes('oso.results.abstract_percentage')) {
765

    
766
        for (const rowResult of series.series.result) {
767

    
768
          const abstractIndicator = new Indicator();
769

    
770
          // remove unwanted countries
771
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
772
            continue;
773
          }
774

    
775
          if (mapTableData.has(rowResult.row[3])) {
776
            const countryTableData = mapTableData.get(rowResult.row[3]);
777
            abstractIndicator.total = Number(rowResult.row[2]);
778
            abstractIndicator.oa = Number(rowResult.row[1]);
779
            if (rowResult.row[0] !== 'NaN') {
780
              abstractIndicator.percentage = Number(rowResult.row[0]);
781
            }
782
            countryTableData.abstract = abstractIndicator;
783
          } else {
784
            const countryTableData: CountryTableData = new CountryTableData();
785
            abstractIndicator.total = Number(rowResult.row[2]);
786
            abstractIndicator.oa = Number(rowResult.row[1]);
787
            if (rowResult.row[0] !== 'NaN') {
788
              abstractIndicator.percentage = Number(rowResult.row[0]);
789
            }
790
            countryTableData.abstract = abstractIndicator;
791
            countryTableData.name = rowResult.row[4];
792
            countryTableData.code = rowResult.row[3];
793
            mapTableData.set(rowResult.row[3], countryTableData);
794
          }
795
        }
796
      } else if (series.series.query.name.includes('new.oso.results.funders_collab_percentage')) {
797

    
798
        for (const rowResult of series.series.result) {
799

    
800
          const fundersCollabIndicator = new Indicator();
801

    
802
          // remove unwanted countries
803
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
804
            continue;
805
          }
806

    
807
          if (mapTableData.has(rowResult.row[3])) {
808
            const countryTableData = mapTableData.get(rowResult.row[3]);
809
            fundersCollabIndicator.total = Number(rowResult.row[2]);
810
            fundersCollabIndicator.oa = Number(rowResult.row[1]);
811
            if (rowResult.row[0] !== 'NaN') {
812
              fundersCollabIndicator.percentage = Number(rowResult.row[0]);
813
            }
814
            countryTableData.funders_collab = fundersCollabIndicator;
815
          } else {
816
            const countryTableData: CountryTableData = new CountryTableData();
817
            fundersCollabIndicator.total = Number(rowResult.row[2]);
818
            fundersCollabIndicator.oa = Number(rowResult.row[1]);
819
            if (rowResult.row[0] !== 'NaN') {
820
              fundersCollabIndicator.percentage = Number(rowResult.row[0]);
821
            }
822
            countryTableData.funders_collab = fundersCollabIndicator;
823
            countryTableData.name = rowResult.row[4];
824
            countryTableData.code = rowResult.row[3];
825
            mapTableData.set(rowResult.row[3], countryTableData);
826
          }
827
        }
828
      } else if (series.series.query.name.includes('new.oso.results.projects_collab_percentage')) {
829

    
830
        for (const rowResult of series.series.result) {
831

    
832
          const projectsCollabIndicator = new Indicator();
833

    
834
          // remove unwanted countries
835
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
836
            continue;
837
          }
838

    
839
          if (mapTableData.has(rowResult.row[3])) {
840
            const countryTableData = mapTableData.get(rowResult.row[3]);
841
            projectsCollabIndicator.total = Number(rowResult.row[2]);
842
            projectsCollabIndicator.oa = Number(rowResult.row[1]);
843
            if (rowResult.row[0] !== 'NaN') {
844
              projectsCollabIndicator.percentage = Number(rowResult.row[0]);
845
            }
846
            countryTableData.projects_collab = projectsCollabIndicator;
847
          } else {
848
            const countryTableData: CountryTableData = new CountryTableData();
849
            projectsCollabIndicator.total = Number(rowResult.row[2]);
850
            projectsCollabIndicator.oa = Number(rowResult.row[1]);
851
            if (rowResult.row[0] !== 'NaN') {
852
              projectsCollabIndicator.percentage = Number(rowResult.row[0]);
853
            }
854
            countryTableData.projects_collab = projectsCollabIndicator;
855
            countryTableData.name = rowResult.row[4];
856
            countryTableData.code = rowResult.row[3];
857
            mapTableData.set(rowResult.row[3], countryTableData);
858
          }
859
        }
860
      } else if (series.series.query.name.includes('new.oso.results.authors_collab_percentage')) {
861

    
862
        for (const rowResult of series.series.result) {
863

    
864
          const authorsCollabIndicator = new Indicator();
865

    
866
          // remove unwanted countries
867
          if (this.isCountryToBeRemoved(rowResult.row[3])) {
868
            continue;
869
          }
870

    
871
          if (mapTableData.has(rowResult.row[3])) {
872
            const countryTableData = mapTableData.get(rowResult.row[3]);
873
            authorsCollabIndicator.total = Number(rowResult.row[2]);
874
            authorsCollabIndicator.oa = Number(rowResult.row[1]);
875
            if (rowResult.row[0] !== 'NaN') {
876
              authorsCollabIndicator.percentage = Number(rowResult.row[0]);
877
            }
878
            countryTableData.authors_collab = authorsCollabIndicator;
879
          } else {
880
            const countryTableData: CountryTableData = new CountryTableData();
881
            authorsCollabIndicator.total = Number(rowResult.row[2]);
882
            authorsCollabIndicator.oa = Number(rowResult.row[1]);
883
            if (rowResult.row[0] !== 'NaN') {
884
              authorsCollabIndicator.percentage = Number(rowResult.row[0]);
885
            }
886
            countryTableData.authors_collab = authorsCollabIndicator;
887
            countryTableData.name = rowResult.row[4];
888
            countryTableData.code = rowResult.row[3];
889
            mapTableData.set(rowResult.row[3], countryTableData);
890
          }
891
        }
892
      }
893
    }
894

    
895
    const tableData: CountryTableData[] = [];
896

    
897
    mapTableData.forEach((value: CountryTableData, key: string) => {
898
      // console.log(key, value);
899
      tableData.push(value);
900
    });
901

    
902
    return tableData;
903
  }
904

    
905
  public convertRawDataToLeadingOpenScienceData(rawData: RawData) {
906

    
907
    const leadingOpenScienceData: CountryOverviewData[] = [];
908

    
909
    for (const series of rawData.datasets) {
910
      if (series.series.query.name === 'new.oso.mobile.overview') {
911
        for (const rowResult of series.series.result) {
912

    
913
          const countryOverviewData: CountryOverviewData = new CountryOverviewData();
914
          countryOverviewData.name = rowResult.row[1];
915
          countryOverviewData.code = rowResult.row[0];
916
          countryOverviewData.publicationsAffiliated = Number(rowResult.row[2]);
917
          countryOverviewData.publicationsDeposited = Number(rowResult.row[3]);
918

    
919
          leadingOpenScienceData.push(countryOverviewData);
920
        }
921
      }
922
    }
923

    
924
    return leadingOpenScienceData;
925
  }
926

    
927
  public convertRawDataToCountryPageOverviewData(rawData: RawData) {
928

    
929
    const countryPageOverviewData: CountryPageOverviewData = new CountryPageOverviewData();
930

    
931
    for (const series of rawData.datasets) {
932

    
933
      if ((series.series.query.name === 'new.oso.publications.peer_reviewed.oa_percentage.country')
934
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
935

    
936
        countryPageOverviewData.name = series.series.result[0].row[3];
937
        countryPageOverviewData.code = series.series.result[0].row[4];
938

    
939
        const publicationsAffiliatedIndicator: Indicator = new Indicator();
940
        publicationsAffiliatedIndicator.percentage = Number(series.series.result[0].row[0]);
941
        publicationsAffiliatedIndicator.oa = Number(series.series.result[0].row[1]);
942
        publicationsAffiliatedIndicator.total = Number(series.series.result[0].row[2]);
943
        countryPageOverviewData.publicationsAffiliated = publicationsAffiliatedIndicator;
944

    
945
      } else if ((series.series.query.name === 'new.oso.publications.peer_reviewed.oa_percentage.deposited.country')
946
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
947

    
948
        countryPageOverviewData.name = series.series.result[0].row[3];
949
        countryPageOverviewData.code = series.series.result[0].row[4];
950

    
951
        const publicationsDepositedIndicator: Indicator = new Indicator();
952
        publicationsDepositedIndicator.percentage = Number(series.series.result[0].row[0]);
953
        publicationsDepositedIndicator.oa = Number(series.series.result[0].row[1]);
954
        publicationsDepositedIndicator.total = Number(series.series.result[0].row[2]);
955
        countryPageOverviewData.publicationsDeposited = publicationsDepositedIndicator;
956

    
957
      } else if ((series.series.query.name === 'oso.results.oa_percentage.country')
958
        && series.series.query.parameters && series.series.query.parameters[1] === 'dataset'
959
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
960

    
961
        countryPageOverviewData.name = series.series.result[0].row[3];
962
        countryPageOverviewData.code = series.series.result[0].row[4];
963

    
964
        const datasetsAffiliatedIndicator: Indicator = new Indicator();
965
        datasetsAffiliatedIndicator.percentage = Number(series.series.result[0].row[0]);
966
        datasetsAffiliatedIndicator.oa = Number(series.series.result[0].row[1]);
967
        datasetsAffiliatedIndicator.total = Number(series.series.result[0].row[2]);
968
        countryPageOverviewData.datasetsAffiliated = datasetsAffiliatedIndicator;
969

    
970
      } else if ((series.series.query.name === 'oso.results.oa_percentage.deposited.country')
971
        && series.series.query.parameters && series.series.query.parameters[0] === 'dataset'
972
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
973

    
974
        countryPageOverviewData.name = series.series.result[0].row[3];
975
        countryPageOverviewData.code = series.series.result[0].row[4];
976

    
977
        const datasetsDepositedIndicator: Indicator = new Indicator();
978
        datasetsDepositedIndicator.percentage = Number(series.series.result[0].row[0]);
979
        datasetsDepositedIndicator.oa = Number(series.series.result[0].row[1]);
980
        datasetsDepositedIndicator.total = Number(series.series.result[0].row[2]);
981
        countryPageOverviewData.datasetsDeposited = datasetsDepositedIndicator;
982

    
983
      } else if (series.series.query.name === 'oso.repositories.doar_re3data.validated.country'
984
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
985

    
986
        countryPageOverviewData.name = series.series.result[0].row[3];
987
        countryPageOverviewData.code = series.series.result[0].row[4];
988

    
989
        const repositoriesIndicator: Indicator = new Indicator();
990
        repositoriesIndicator.percentage = Number(series.series.result[0].row[0]);
991
        repositoriesIndicator.oa = Number(series.series.result[0].row[1]);
992
        repositoriesIndicator.total = Number(series.series.result[0].row[2]);
993
        countryPageOverviewData.repositories = repositoriesIndicator;
994

    
995
      } else if (series.series.query.name === 'oso.journals.doaj.validated.country'
996
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
997

    
998
        countryPageOverviewData.name = series.series.result[0].row[3];
999
        countryPageOverviewData.code = series.series.result[0].row[4];
1000

    
1001
        const journalsIndicator: Indicator = new Indicator();
1002
        journalsIndicator.percentage = Number(series.series.result[0].row[0]);
1003
        journalsIndicator.oa = Number(series.series.result[0].row[1]);
1004
        journalsIndicator.total = Number(series.series.result[0].row[2]);
1005
        countryPageOverviewData.journals = journalsIndicator;
1006

    
1007
      } else if (series.series.query.name === 'oso.oa_policies.country'
1008
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1009

    
1010
        countryPageOverviewData.policies = Number(series.series.result[0].row[0]);
1011

    
1012
      } else if (series.series.query.name === 'oso.rnd.country'
1013
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1014

    
1015
        const rndExpenditure: RnDExpenditure = new RnDExpenditure();
1016
        rndExpenditure.expenditure = Number(series.series.result[0].row[0]);
1017
        rndExpenditure.year = Number(series.series.result[0].row[1]);
1018
        countryPageOverviewData.rndExpenditure = rndExpenditure;
1019

    
1020
      } else if (series.series.query.name === 'oso.funder.country'
1021
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1022

    
1023
        countryPageOverviewData.funders = Number(series.series.result[0].row[0]);
1024

    
1025
      } else if (series.series.query.name === 'oso.funding_organizations.country'
1026
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1027

    
1028
        countryPageOverviewData.fundingOrganizations = Number(series.series.result[0].row[0]);
1029

    
1030
      } else if (series.series.query.name === 'oso.ec_funded_organizations.country'
1031
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1032

    
1033
        countryPageOverviewData.ec_fundedOrganizations = Number(series.series.result[0].row[0]);
1034

    
1035
      } else if (series.series.query.name === 'new.oso.ec_funded_projects.country'
1036
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1037

    
1038
        countryPageOverviewData.ec_fundedProjects = Number(series.series.result[0].row[0]);
1039
      }
1040
    }
1041

    
1042
    return countryPageOverviewData;
1043
  }
1044

    
1045
  public convertRawDataToCountryPageOAData(rawData: RawData) {
1046

    
1047
    const countryPageOverviewData: CountryPageOverviewData = new CountryPageOverviewData();
1048

    
1049
    for (const series of rawData.datasets) {
1050

    
1051
      if ((series.series.query.name === 'new.oso.publications.peer_reviewed.oa_percentage.country')
1052
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1053

    
1054
        countryPageOverviewData.name = series.series.result[0].row[3];
1055
        countryPageOverviewData.code = series.series.result[0].row[4];
1056

    
1057
        const publicationsAffiliatedIndicator: Indicator = new Indicator();
1058
        publicationsAffiliatedIndicator.percentage = Number(series.series.result[0].row[0]);
1059
        publicationsAffiliatedIndicator.oa = Number(series.series.result[0].row[1]);
1060
        publicationsAffiliatedIndicator.total = Number(series.series.result[0].row[2]);
1061
        countryPageOverviewData.publicationsAffiliated = publicationsAffiliatedIndicator;
1062

    
1063
      } else  if ((series.series.query.name === 'oso.results.oa_percentage.country')
1064
        && series.series.query.parameters && series.series.query.parameters[1] === 'dataset'
1065
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1066

    
1067
        countryPageOverviewData.name = series.series.result[0].row[3];
1068
        countryPageOverviewData.code = series.series.result[0].row[4];
1069

    
1070
        const datasetsAffiliatedIndicator: Indicator = new Indicator();
1071
        datasetsAffiliatedIndicator.percentage = Number(series.series.result[0].row[0]);
1072
        datasetsAffiliatedIndicator.oa = Number(series.series.result[0].row[1]);
1073
        datasetsAffiliatedIndicator.total = Number(series.series.result[0].row[2]);
1074
        countryPageOverviewData.datasetsAffiliated = datasetsAffiliatedIndicator;
1075

    
1076
      } else if ((series.series.query.name === 'oso.results.oa_percentage.country')
1077
        && series.series.query.parameters && series.series.query.parameters[1] === 'software'
1078
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1079

    
1080
        countryPageOverviewData.name = series.series.result[0].row[3];
1081
        countryPageOverviewData.code = series.series.result[0].row[4];
1082

    
1083
        const softwareIndicator: Indicator = new Indicator();
1084
        softwareIndicator.percentage = Number(series.series.result[0].row[0]);
1085
        softwareIndicator.oa = Number(series.series.result[0].row[1]);
1086
        softwareIndicator.total = Number(series.series.result[0].row[2]);
1087
        countryPageOverviewData.software = softwareIndicator;
1088

    
1089
      } else if ((series.series.query.name === 'oso.results.oa_percentage.country')
1090
        && series.series.query.parameters && series.series.query.parameters[1] === 'other'
1091
        && series.series.result && series.series.result.length > 0 && series.series.result[0].row) {
1092

    
1093
        countryPageOverviewData.name = series.series.result[0].row[3];
1094
        countryPageOverviewData.code = series.series.result[0].row[4];
1095

    
1096
        const otherIndicator: Indicator = new Indicator();
1097
        otherIndicator.percentage = Number(series.series.result[0].row[0]);
1098
        otherIndicator.oa = Number(series.series.result[0].row[1]);
1099
        otherIndicator.total = Number(series.series.result[0].row[2]);
1100
        countryPageOverviewData.other = otherIndicator;
1101

    
1102
      }
1103
    }
1104

    
1105
    return countryPageOverviewData;
1106
  }
1107

    
1108
  public convertRawDataToTreemapHighchartsData(rawData: RawData) {
1109

    
1110
    const treeMapData: TreemapHighchartsData[] = [];
1111

    
1112
    for (const series of rawData.datasets) {
1113
      // let index = 1;
1114
      for (const rowResult of series.series.result) {
1115

    
1116
        const treeMapItemData: TreemapHighchartsData = new TreemapHighchartsData();
1117
        treeMapItemData.name = rowResult.row[1];
1118
        treeMapItemData.value = Number(rowResult.row[0]);
1119
        treeMapItemData.colorValue = Number(rowResult.row[0]);
1120
        // treeMapItemData.colorValue = index;
1121

    
1122
        treeMapData.push(treeMapItemData);
1123

    
1124
        // index = index + 1;
1125
      }
1126
    }
1127

    
1128
    return treeMapData;
1129
  }
1130

    
1131
  private rawResultToCountryMapData(result: Row[]) {
1132

    
1133
    const entityMapData: CountryMapData[] = [];
1134
    for (const rowResult of result) {
1135

    
1136
      // remove unwanted countries
1137
      if (this.isCountryToBeRemoved(rowResult.row[2])) {
1138
        continue;
1139
      }
1140

    
1141
      const countryMapData: CountryMapData = new CountryMapData();
1142
      countryMapData.value = Number(rowResult.row[0]);
1143
      countryMapData.name = rowResult.row[1];
1144
      countryMapData.code = rowResult.row[2];
1145

    
1146
      entityMapData.push(countryMapData);
1147
    }
1148

    
1149
    return entityMapData;
1150
  }
1151

    
1152
  private isCountryToBeRemoved(countryCode: string) {
1153
    return (countryCode === 'GG' || countryCode === 'FO' || countryCode === 'GI' || countryCode === 'VA' || countryCode === 'IM'
1154
      || countryCode === 'JE' || countryCode === 'LI' || countryCode === 'MC' || countryCode === 'SM' || countryCode === 'SJ'
1155
      || countryCode === 'AX');
1156
  }
1157
}
(1-1/4)