import {Injectable} from '@angular/core'; import {Http, Response} from '@angular/http'; import {Observable} from 'rxjs/Observable'; import {Metrics} from '../utils/entities/metrics'; import 'rxjs/add/operator/do'; import{EnvProperties} from '../utils/properties/env-properties'; @Injectable() export class MetricsService { metrics: Metrics; constructor(private http: Http ) {} getMetrics (id: string, entityType: string, properties:EnvProperties):any { console.info("getMetrics in service"); let url = properties.metricsAPIURL+entityType+"/"+id+"/clicks"; let key = url; return this.http.get((properties.useCache)? (properties.cacheUrl+encodeURIComponent(url)): url) .map(res => res.json()) .map(res => this.parseMetrics(res["downloads"], res["views"], res["total_downloads"], res["total_views"], res["total_openaire_views"], res["total_openaire_downloads"], res["pageviews"], properties)); } parseMetrics(downloads: any, views: any, totalDownloads: string, totalViews: string, totalOpenaireViews: string, totalOpenaireDownloads: string, pageViews: string, properties:EnvProperties): any { this.metrics = new Metrics(); this.metrics.totalDownloads = totalDownloads; this.metrics.totalViews = totalViews; this.metrics.totalOpenaireViews = totalOpenaireViews; this.metrics.totalOpenaireDownloads = totalOpenaireDownloads; this.metrics.pageViews = pageViews; this.metrics.infos = new Map(); for(let i=0; i