Project

General

Profile

« Previous | Next » 

Revision 58853

Working on the new version of the oso - almost done with tha data part of the pages

View differences:

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

  
6 13
@Injectable ()
......
16 23
        overviewMapData.publications = this.rawResultToCountryMapData(series.series.result);
17 24
      } else if (series.series.query.name === 'new.oso.datasets.affiliated') {
18 25
        overviewMapData.datasets = this.rawResultToCountryMapData(series.series.result);
19
      } else if (series.series.query.name === 'new.oso.repositories') {
26
      } else if (series.series.query.name === 'new.oso.repositories.doar_re3data') {
20 27
        overviewMapData.repositories = this.rawResultToCountryMapData(series.series.result);
21
      } else if (series.series.query.name === 'new.oso.journals') {
28
      } else if (series.series.query.name === 'new.oso.journals.doaj') {
22 29
        overviewMapData.journals = this.rawResultToCountryMapData(series.series.result);
23 30
      } else if (series.series.query.name === 'new.oso.oa_policies') {
24 31
        overviewMapData.policies = this.rawResultToCountryMapData(series.series.result);
......
105 112

  
106 113
  }
107 114

  
115
  public createJoinedRepositoriesCountryMap(rawData: RawData) {
116

  
117
    const joinedRepositoriesMap = new Map();
118

  
119
    for (const series of rawData.datasets) {
120
      if (series.series.query.name === 'new.oso.repositories.doar_re3data') {
121

  
122
        for (const rowResult of series.series.result) {
123
          if (joinedRepositoriesMap.has(rowResult.row[1])) {
124
            const simple = joinedRepositoriesMap.get(rowResult.row[1]).simple;
125
            joinedRepositoriesMap.delete(rowResult.row[1]);
126
            joinedRepositoriesMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
127
              doar_re3data: Number(rowResult.row[0]), simple: simple});
128
          } else {
129
            joinedRepositoriesMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
130
              doar_re3data: Number(rowResult.row[0]), simple: 0});
131
          }
132
        }
133

  
134
      } else if (series.series.query.name === 'new.oso.repositories') {
135

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

  
149
    return joinedRepositoriesMap;
150

  
151
  }
152

  
153
  public createJoinedJournalsCountryMap(rawData: RawData) {
154

  
155
    const joinedJournalsMap = new Map();
156

  
157
    for (const series of rawData.datasets) {
158
      if (series.series.query.name === 'new.oso.journals.doaj') {
159

  
160
        for (const rowResult of series.series.result) {
161
          if (joinedJournalsMap.has(rowResult.row[1])) {
162
            const simple = joinedJournalsMap.get(rowResult.row[1]).simple;
163
            joinedJournalsMap.delete(rowResult.row[1]);
164
            joinedJournalsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
165
              doaj: Number(rowResult.row[0]), simple: simple});
166
          } else {
167
            joinedJournalsMap.set(rowResult.row[1], {countryName: rowResult.row[1], countryCode: rowResult.row[2],
168
              doaj: Number(rowResult.row[0]), simple: 0});
169
          }
170
        }
171

  
172
      } else if (series.series.query.name === 'new.oso.journals') {
173

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

  
187
    return joinedJournalsMap;
188

  
189
  }
190

  
108 191
  public convertRawDataToCountryOverviewData(rawData: RawData) {
109 192

  
110 193
    const countryData: CountryOverviewData = new CountryOverviewData();
......
153 236
        datasetsIndicator.total = Number(series.series.result[0].row[2]);
154 237
        europeData.datasets = datasetsIndicator;
155 238

  
239
      } else if (series.series.query.name === 'new.oso.software.oa_percentage') {
240

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

  
247
      } else if (series.series.query.name === 'new.oso.other.oa_percentage') {
248

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

  
156 255
      } else if (series.series.query.name === 'new.oso.repositories.doar_re3data.validated') {
157 256

  
158 257
        const repositoriesIndicator: Indicator = new Indicator();
......
322 421
    return tableData;
323 422
  }
324 423

  
424
  public convertRawDataToPercentageTableData(rawData: RawData) {
425

  
426
    const mapTableData: Map<string, CountryTableData> = new Map();
427

  
428
    for (const series of rawData.datasets) {
429

  
430
      if (series.series.query.name.includes('new.oso.results')
431
        && series.series.query.parameters && series.series.query.parameters[0] === 'publication') {
432
        for (const rowResult of series.series.result) {
433

  
434
          // remove unwanted countries
435
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
436
            continue;
437
          }
438

  
439
          if (mapTableData.has(rowResult.row[4])) {
440
            const countryTableData = mapTableData.get(rowResult.row[4]);
441
            if (rowResult.row[0] !== 'NaN') {
442
              countryTableData.publications = Number(rowResult.row[0]);
443
            }
444
          } else {
445
            const countryTableData: CountryTableData = new CountryTableData();
446
            if (rowResult.row[0] !== 'NaN') {
447
              countryTableData.publications = Number(rowResult.row[0]);
448
            }
449
            countryTableData.name = rowResult.row[3];
450
            countryTableData.code = rowResult.row[4];
451
            mapTableData.set(rowResult.row[4], countryTableData);
452
          }
453
        }
454

  
455
      } else if (series.series.query.name.includes('new.oso.results')
456
        && series.series.query.parameters && series.series.query.parameters[0] === 'dataset') {
457

  
458
        for (const rowResult of series.series.result) {
459

  
460
          // remove unwanted countries
461
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
462
            continue;
463
          }
464

  
465
          if (mapTableData.has(rowResult.row[4])) {
466
            const countryTableData = mapTableData.get(rowResult.row[4]);
467
            if (rowResult.row[0] !== 'NaN') {
468
              countryTableData.datasets = Number(rowResult.row[0]);
469
            }
470
          } else {
471
            const countryTableData: CountryTableData = new CountryTableData();
472
            if (rowResult.row[0] !== 'NaN') {
473
              countryTableData.datasets = Number(rowResult.row[0]);
474
            }
475
            countryTableData.name = rowResult.row[3];
476
            countryTableData.code = rowResult.row[4];
477
            mapTableData.set(rowResult.row[4], countryTableData);
478
          }
479
        }
480
      } else if (series.series.query.name.includes('new.oso.results')
481
        && series.series.query.parameters && series.series.query.parameters[0] === 'software') {
482

  
483
        for (const rowResult of series.series.result) {
484

  
485
          // remove unwanted countries
486
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
487
            continue;
488
          }
489

  
490
          if (mapTableData.has(rowResult.row[4])) {
491
            const countryTableData = mapTableData.get(rowResult.row[4]);
492
            if (rowResult.row[0] !== 'NaN') {
493
              countryTableData.software = Number(rowResult.row[0]);
494
            }
495
          } else {
496
            const countryTableData: CountryTableData = new CountryTableData();
497
            if (rowResult.row[0] !== 'NaN') {
498
              countryTableData.software = Number(rowResult.row[0]);
499
            }
500
            countryTableData.name = rowResult.row[3];
501
            countryTableData.code = rowResult.row[4];
502
            mapTableData.set(rowResult.row[4], countryTableData);
503
          }
504
        }
505
      } else if (series.series.query.name.includes('new.oso.results')
506
        && series.series.query.parameters && series.series.query.parameters[0] === 'other') {
507

  
508
        for (const rowResult of series.series.result) {
509

  
510
          // remove unwanted countries
511
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
512
            continue;
513
          }
514

  
515
          if (mapTableData.has(rowResult.row[4])) {
516
            const countryTableData = mapTableData.get(rowResult.row[4]);
517
            if (rowResult.row[0] !== 'NaN') {
518
              countryTableData.other = Number(rowResult.row[0]);
519
            }
520
          } else {
521
            const countryTableData: CountryTableData = new CountryTableData();
522
            if (rowResult.row[0] !== 'NaN') {
523
              countryTableData.other = Number(rowResult.row[0]);
524
            }
525
            countryTableData.name = rowResult.row[3];
526
            countryTableData.code = rowResult.row[4];
527
            mapTableData.set(rowResult.row[4], countryTableData);
528
          }
529
        }
530
      } else if (series.series.query.name.includes('new.oso.repositories')) {
531

  
532
        for (const rowResult of series.series.result) {
533

  
534
          // remove unwanted countries
535
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
536
            continue;
537
          }
538

  
539
          if (mapTableData.has(rowResult.row[4])) {
540
            const countryTableData = mapTableData.get(rowResult.row[4]);
541
            countryTableData.repositories = Number(rowResult.row[0]);
542
          } else {
543
            const countryTableData: CountryTableData = new CountryTableData();
544
            countryTableData.repositories = Number(rowResult.row[0]);
545
            countryTableData.name = rowResult.row[3];
546
            countryTableData.code = rowResult.row[4];
547
            mapTableData.set(rowResult.row[4], countryTableData);
548
          }
549
        }
550
      } else if (series.series.query.name.includes('new.oso.journals')) {
551

  
552
        for (const rowResult of series.series.result) {
553

  
554
          // remove unwanted countries
555
          if (this.isCountryToBeRemoved(rowResult.row[4])) {
556
            continue;
557
          }
558

  
559
          if (mapTableData.has(rowResult.row[4])) {
560
            const countryTableData = mapTableData.get(rowResult.row[4]);
561
            countryTableData.journals = Number(rowResult.row[0]);
562
          } else {
563
            const countryTableData: CountryTableData = new CountryTableData();
564
            countryTableData.journals = Number(rowResult.row[0]);
565
            countryTableData.name = rowResult.row[3];
566
            countryTableData.code = rowResult.row[4];
567
            mapTableData.set(rowResult.row[4], countryTableData);
568
          }
569
        }
570
      }
571
    }
572

  
573
    const tableData: CountryTableData[] = [];
574

  
575
    mapTableData.forEach((value: CountryTableData, key: string) => {
576
      // console.log(key, value);
577
      tableData.push(value);
578
    });
579

  
580
    return tableData;
581
  }
582

  
583
  public convertRawDataToCountryPageOverviewData(rawData: RawData) {
584

  
585
    const countryPageOverviewData: CountryPageOverviewData = new CountryPageOverviewData();
586

  
587
    for (const series of rawData.datasets) {
588

  
589
      if ((series.series.query.name === 'new.oso.results.oa_percentage.country')
590
        && series.series.query.parameters && series.series.query.parameters[0] === 'publication') {
591

  
592
        countryPageOverviewData.name = series.series.result[0].row[3];
593
        countryPageOverviewData.code = series.series.result[0].row[4];
594

  
595
        const publicationsAffiliatedIndicator: Indicator = new Indicator();
596
        publicationsAffiliatedIndicator.percentage = Number(series.series.result[0].row[0]);
597
        publicationsAffiliatedIndicator.oa = Number(series.series.result[0].row[1]);
598
        publicationsAffiliatedIndicator.total = Number(series.series.result[0].row[2]);
599
        countryPageOverviewData.publicationsAffiliated = publicationsAffiliatedIndicator;
600

  
601
      } else if ((series.series.query.name === 'new.oso.results.oa_percentage.deposited.country')
602
        && series.series.query.parameters && series.series.query.parameters[0] === 'publication') {
603

  
604
        countryPageOverviewData.name = series.series.result[0].row[3];
605
        countryPageOverviewData.code = series.series.result[0].row[4];
606

  
607
        const publicationsDepositedIndicator: Indicator = new Indicator();
608
        publicationsDepositedIndicator.percentage = Number(series.series.result[0].row[0]);
609
        publicationsDepositedIndicator.oa = Number(series.series.result[0].row[1]);
610
        publicationsDepositedIndicator.total = Number(series.series.result[0].row[2]);
611
        countryPageOverviewData.publicationsDeposited = publicationsDepositedIndicator;
612

  
613
      } if ((series.series.query.name === 'new.oso.results.oa_percentage.country')
614
        && series.series.query.parameters && series.series.query.parameters[0] === 'dataset') {
615

  
616
        countryPageOverviewData.name = series.series.result[0].row[3];
617
        countryPageOverviewData.code = series.series.result[0].row[4];
618

  
619
        const datasetsAffiliatedIndicator: Indicator = new Indicator();
620
        datasetsAffiliatedIndicator.percentage = Number(series.series.result[0].row[0]);
621
        datasetsAffiliatedIndicator.oa = Number(series.series.result[0].row[1]);
622
        datasetsAffiliatedIndicator.total = Number(series.series.result[0].row[2]);
623
        countryPageOverviewData.datasetsAffiliated = datasetsAffiliatedIndicator;
624

  
625
      } else if ((series.series.query.name === 'new.oso.results.oa_percentage.deposited.country')
626
        && series.series.query.parameters && series.series.query.parameters[0] === 'dataset') {
627

  
628
        countryPageOverviewData.name = series.series.result[0].row[3];
629
        countryPageOverviewData.code = series.series.result[0].row[4];
630

  
631
        const datasetsDepositedIndicator: Indicator = new Indicator();
632
        datasetsDepositedIndicator.percentage = Number(series.series.result[0].row[0]);
633
        datasetsDepositedIndicator.oa = Number(series.series.result[0].row[1]);
634
        datasetsDepositedIndicator.total = Number(series.series.result[0].row[2]);
635
        countryPageOverviewData.datasetsDeposited = datasetsDepositedIndicator;
636

  
637
      } else if (series.series.query.name === 'new.oso.repositories.doar_re3data.validated.country') {
638

  
639
        countryPageOverviewData.name = series.series.result[0].row[3];
640
        countryPageOverviewData.code = series.series.result[0].row[4];
641

  
642
        const repositoriesIndicator: Indicator = new Indicator();
643
        repositoriesIndicator.percentage = Number(series.series.result[0].row[0]);
644
        repositoriesIndicator.oa = Number(series.series.result[0].row[1]);
645
        repositoriesIndicator.total = Number(series.series.result[0].row[2]);
646
        countryPageOverviewData.repositories = repositoriesIndicator;
647

  
648
      } else if (series.series.query.name === 'new.oso.journals.doaj.validated.country') {
649

  
650
        countryPageOverviewData.name = series.series.result[0].row[3];
651
        countryPageOverviewData.code = series.series.result[0].row[4];
652

  
653
        const journalsIndicator: Indicator = new Indicator();
654
        journalsIndicator.percentage = Number(series.series.result[0].row[0]);
655
        journalsIndicator.oa = Number(series.series.result[0].row[1]);
656
        journalsIndicator.total = Number(series.series.result[0].row[2]);
657
        countryPageOverviewData.journals = journalsIndicator;
658

  
659
      } else if (series.series.query.name === 'new.oso.oa_policies.country') {
660

  
661
        countryPageOverviewData.policies = Number(series.series.result[0].row[0]);
662

  
663
      } else if (series.series.query.name === 'new.oso.funder.country') {
664

  
665
        countryPageOverviewData.funders = Number(series.series.result[0].row[0]);
666

  
667
      } else if (series.series.query.name === 'new.oso.funding_organizations.country') {
668

  
669
        countryPageOverviewData.fundingOrganizations = Number(series.series.result[0].row[0]);
670

  
671
      } else if (series.series.query.name === 'new.oso.ec_funded_organizations.country') {
672

  
673
        countryPageOverviewData.ec_fundedOrganizations = Number(series.series.result[0].row[0]);
674
      }
675
    }
676

  
677
    return countryPageOverviewData;
678
  }
679

  
325 680
  private rawResultToCountryMapData(result: Row[]) {
326 681

  
327 682
    const entityMapData: CountryMapData[] = [];

Also available in: Unified diff