2019-10-24 09:44:29 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
import {EnvironmentSpecificService} from "../../openaireLibrary/utils/properties/environment-specific.service";
|
|
|
|
import {Observable} from "rxjs";
|
2020-01-08 12:00:50 +01:00
|
|
|
import {SourceType} from "../entities/stakeholder";
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
|
2019-11-19 15:25:19 +01:00
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
2019-10-24 09:44:29 +02:00
|
|
|
export class StatisticsService {
|
|
|
|
|
2020-06-02 14:45:08 +02:00
|
|
|
numberSources: Map<string, string[]> = new Map<string, string[]>();
|
|
|
|
chartSources: Map<SourceType, string[]> = new Map<SourceType, string[]>();
|
2019-10-24 09:44:29 +02:00
|
|
|
|
2020-06-02 14:45:08 +02:00
|
|
|
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, "http://marilyn.athenarc.gr:8080/stats-api/", "http://88.197.53.71:8080/stats-api/", "https://stats.madgik.di.uoa.gr/stats-api/"]);
|
|
|
|
this.chartSources.set('old', [properties.statisticsFrameAPIURL]);
|
|
|
|
this.chartSources.set('metrics', [properties.metricsAPIURL]);
|
|
|
|
this.chartSources.set('image', [""]);
|
|
|
|
})
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
getNumbers(source: string, url: string): Observable<any> {
|
|
|
|
return this.http.get<any>(this.numberSources.get(source) + url);
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:00:50 +01:00
|
|
|
getChartUrl(source: SourceType, url: string): string {
|
2020-06-02 14:45:08 +02:00
|
|
|
return this.chartSources.get(source)[0] + url;
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
2019-11-19 15:25:19 +01:00
|
|
|
|
2020-01-08 12:00:50 +01:00
|
|
|
getChartSource(url: string): SourceType {
|
|
|
|
let source: SourceType = 'image';
|
2020-06-02 14:45:08 +02:00
|
|
|
this.chartSources.forEach((values, key) => {
|
|
|
|
values.forEach((value) => {
|
2019-11-19 15:25:19 +01:00
|
|
|
if(value !== '' && url.indexOf(value) !== -1) {
|
|
|
|
source = key;
|
|
|
|
}
|
2020-06-02 14:45:08 +02:00
|
|
|
});
|
2019-11-19 15:25:19 +01:00
|
|
|
});
|
|
|
|
return source;
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|