import {Injectable} from '@angular/core'; import {HttpClient} from "@angular/common/http"; import {EnvironmentSpecificService} from "../../openaireLibrary/utils/properties/environment-specific.service"; import {Observable} from "rxjs"; import {SourceType} from "../entities/stakeholder"; @Injectable({ providedIn: 'root' }) export class StatisticsService { numberSources: Map = new Map(); chartSources: Map = new Map(); constructor(private http:HttpClient, private environmentSpecificService: EnvironmentSpecificService) { this.environmentSpecificService.subscribeEnvironment().subscribe(properties => { this.numberSources.set('statistics', properties.statisticsAPIURL); this.numberSources.set('search', properties.searchAPIURLLAst); this.numberSources.set('metrics', properties.metricsAPIURL); this.chartSources.set('stats-tool', properties.statisticsFrameNewAPIURL); this.chartSources.set('old', properties.statisticsFrameAPIURL); this.chartSources.set('metrics', properties.metricsAPIURL); this.chartSources.set('image', ''); }) } getNumbers(source: string, url: string): Observable { return this.http.get(this.numberSources.get(source) + url); } getChartUrl(source: SourceType, url: string): string { return this.chartSources.get(source) + url; } getChartSource(url: string): SourceType { let source: SourceType = 'image'; this.chartSources.forEach((value, key) => { if(value !== '' && url.indexOf(value) !== -1) { source = key; } }); return source; } }