2019-10-24 09:44:29 +02:00
|
|
|
import {Injectable} from '@angular/core';
|
|
|
|
import {HttpClient} from "@angular/common/http";
|
|
|
|
import {Observable} from "rxjs";
|
2020-06-03 15:44:03 +02:00
|
|
|
import {SourceType} from "../../openaireLibrary/monitor/entities/stakeholder";
|
2020-11-13 17:42:12 +01:00
|
|
|
import {properties} from "../../../environments/environment";
|
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-07-07 16:08:47 +02:00
|
|
|
numberSources: Map<SourceType, string[]> = new Map<SourceType, string[]>();
|
2020-06-02 14:45:08 +02:00
|
|
|
chartSources: Map<SourceType, string[]> = new Map<SourceType, string[]>();
|
2019-10-24 09:44:29 +02:00
|
|
|
|
2020-11-13 17:42:12 +01:00
|
|
|
constructor(private http:HttpClient) {
|
2020-06-02 14:45:08 +02:00
|
|
|
this.numberSources.set('statistics', [properties.statisticsAPIURL]);
|
|
|
|
this.numberSources.set('search', [properties.searchAPIURLLAst]);
|
|
|
|
this.numberSources.set('metrics', [properties.metricsAPIURL]);
|
2021-04-12 09:58:53 +02:00
|
|
|
this.numberSources.set('stats-tool', [properties.monitorStatsFrameUrl, "http://marilyn.athenarc.gr:8080/stats-api/", "http://88.197.53.71:8080/stats-api/", "https://stats.madgik.di.uoa.gr/stats-api/","https://beta.services.openaire.eu/stats-tool/","https://services.openaire.eu/stats-tool/","https://services.openaire.eu/monitor-stats-tool/"]);
|
|
|
|
this.chartSources.set('stats-tool', [properties.monitorStatsFrameUrl, "http://marilyn.athenarc.gr:8080/stats-api/", "http://88.197.53.71:8080/stats-api/", "https://stats.madgik.di.uoa.gr/stats-api/","https://beta.services.openaire.eu/stats-tool/","https://services.openaire.eu/stats-tool/","https://services.openaire.eu/monitor-stats-tool/"]);
|
2020-06-02 14:45:08 +02:00
|
|
|
this.chartSources.set('old', [properties.statisticsFrameAPIURL]);
|
|
|
|
this.chartSources.set('metrics', [properties.metricsAPIURL]);
|
|
|
|
this.chartSources.set('image', [""]);
|
|
|
|
}
|
2020-07-07 16:08:47 +02:00
|
|
|
getSourceType(source:string):SourceType{
|
|
|
|
let sourceType: SourceType = 'search';
|
|
|
|
this.numberSources.forEach((values, key) => {
|
|
|
|
if(key == source) {
|
|
|
|
sourceType = key;
|
2019-10-24 09:44:29 +02:00
|
|
|
|
2020-07-07 16:08:47 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
return sourceType;
|
|
|
|
}
|
2020-11-05 00:11:00 +01:00
|
|
|
|
2020-07-07 16:08:47 +02:00
|
|
|
getNumbers(source: SourceType, url: string): Observable<any> {
|
2020-11-05 00:11:00 +01:00
|
|
|
if(source !== null) {
|
|
|
|
return this.http.get<any>(this.numberSources.get(source)[0] + url);
|
|
|
|
} else {
|
|
|
|
return this.http.get<any>(url);
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
2020-08-06 09:34:41 +02:00
|
|
|
getNumberUrl(source: string, url: string): string {
|
|
|
|
return this.numberSources.get(this.getSourceType(source))[0] + url;
|
|
|
|
}
|
2020-07-07 16:08:47 +02:00
|
|
|
getNumberSource(url: string): SourceType {
|
|
|
|
let source: SourceType = 'search';
|
|
|
|
this.numberSources.forEach((values, key) => {
|
|
|
|
values.forEach((value) => {
|
|
|
|
if(value !== '' && url.indexOf(value) !== -1) {
|
|
|
|
source = key;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return source;
|
|
|
|
}
|
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
|
|
|
}
|