From 1d470dc08438c3fe5b150a9fb022f1904ba0400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Thu, 30 Jan 2020 17:42:02 +0100 Subject: [PATCH] La page des stats avance, on a maintenant des infos --- Back/skydiveLogs-api.Business/StatsService.cs | 8 +- .../src/app/summary/summary.component.ts | 19 +++++ Front/skydivelogs-app/src/models/stats.ts | 14 ++-- .../src/services/stats.service.ts | 81 +++++++++++++++---- 4 files changed, 97 insertions(+), 25 deletions(-) diff --git a/Back/skydiveLogs-api.Business/StatsService.cs b/Back/skydiveLogs-api.Business/StatsService.cs index 9676526..b314186 100644 --- a/Back/skydiveLogs-api.Business/StatsService.cs +++ b/Back/skydiveLogs-api.Business/StatsService.cs @@ -19,7 +19,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.Aircraft.Id, + return allJumps.GroupBy(j => j.Aircraft.Name, j => j, (groupby, jumps) => new Statistic { @@ -33,7 +33,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.DropZone.Id, + return allJumps.GroupBy(j => j.DropZone.Name, j => j, (groupby, jumps) => new Statistic { @@ -47,7 +47,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.JumpType.Id, + return allJumps.GroupBy(j => j.JumpType.Name, j => j, (groupby, jumps) => new Statistic { @@ -61,7 +61,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.Gear.Id, + return allJumps.GroupBy(j => j.Gear.Name, j => j, (groupby, jumps) => new Statistic { diff --git a/Front/skydivelogs-app/src/app/summary/summary.component.ts b/Front/skydivelogs-app/src/app/summary/summary.component.ts index 82c7e8d..cfcb8b7 100644 --- a/Front/skydivelogs-app/src/app/summary/summary.component.ts +++ b/Front/skydivelogs-app/src/app/summary/summary.component.ts @@ -1,4 +1,5 @@ import { Component, OnInit } from '@angular/core'; +import { MatTableDataSource } from '@angular/material'; import { ServiceComm } from '../../services/service-comm.service'; import { StatsService } from '../../services/stats.service'; @@ -22,5 +23,23 @@ export class SummaryComponent implements OnInit { ngOnInit() { this.serviceComm.UpdatedComponentTitle('Summary'); + + const statsResult = this.serviceApi.getStatsOfJumps(); + + statsResult.statsByDz.subscribe(data => { + this.dsNbJumpByDz = new MatTableDataSource(data); + }); + statsResult.statsByAircraft.subscribe(data => { + this.dsNbJumpByAircraft = new MatTableDataSource(data); + }); + statsResult.statsByGear.subscribe(data => { + this.dsNbJumpByGear = new MatTableDataSource(data); + }); + statsResult.statsByJumpType.subscribe(data => { + this.dsNbJumpByType = new MatTableDataSource(data); + }); + statsResult.statsByYear.subscribe(data => { + this.dsNbJumpByYear = new MatTableDataSource(data); + }); } } diff --git a/Front/skydivelogs-app/src/models/stats.ts b/Front/skydivelogs-app/src/models/stats.ts index 215accb..d39f6e1 100644 --- a/Front/skydivelogs-app/src/models/stats.ts +++ b/Front/skydivelogs-app/src/models/stats.ts @@ -1,11 +1,11 @@ -import { Observable } from "rxjs"; +import { Observable } from 'rxjs'; export class StatsResp { - public statsByDz: Observable; - public statsByAircraft: Observable; - public statsByRig: Observable; - public statsByJumpType: Observable; - public statsByYear: Observable; + public statsByDz: Observable>; + public statsByAircraft: Observable>; + public statsByGear: Observable>; + public statsByJumpType: Observable>; + public statsByYear: Observable>; } export class StatsByDzResp { @@ -24,7 +24,7 @@ export class StatsByAircraftResp { public label: string; public nb: number; } -export class StatsByRigResp { +export class StatsByGearResp { constructor(data: any) { Object.assign(this, data); } diff --git a/Front/skydivelogs-app/src/services/stats.service.ts b/Front/skydivelogs-app/src/services/stats.service.ts index 1c23c82..dc55360 100644 --- a/Front/skydivelogs-app/src/services/stats.service.ts +++ b/Front/skydivelogs-app/src/services/stats.service.ts @@ -1,12 +1,14 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; import { environment } from '../environments/environment'; import { StatsResp, StatsByDzResp, StatsByAircraftResp, StatsByJumpTypeResp, - StatsByRigResp, + StatsByGearResp, StatsByYearResp } from '../models/stats'; @@ -20,28 +22,79 @@ export class StatsService { constructor(private http: HttpClient) { } public getStatsOfJumps(): StatsResp { - const resultat = new StatsResp(); - resultat.statsByDz = this.http.get( + const resultats = new StatsResp(); + + resultats.statsByDz = this.getStatsByDz(); + resultats.statsByAircraft = this.getStatsByAircraft(); + resultats.statsByJumpType = this.getStatsByJumpType(); + resultats.statsByGear = this.getStatsByGear(); + resultats.statsByYear = this.getStatsByYear(); + + return resultats; + } + + private getStatsByDz(): Observable> { + return this.http.get>( `${environment.urlApi}/api/Stats/ByDz`, { headers: this.headers } - ); - resultat.statsByAircraft = this.http.get( + ) + .pipe( + map(response => { + const stats = response.map(data => new StatsByDzResp(data)); + return stats; + }) + ); + } + + private getStatsByAircraft(): Observable> { + return this.http.get>( `${environment.urlApi}/api/Stats/ByAircraft`, { headers: this.headers } - ); - resultat.statsByJumpType = this.http.get( + ) + .pipe( + map(response => { + const stats = response.map(data => new StatsByAircraftResp(data)); + return stats; + }) + ); + } + + private getStatsByJumpType(): Observable> { + return this.http.get>( `${environment.urlApi}/api/Stats/ByJumpType`, { headers: this.headers } - ); - resultat.statsByRig = this.http.get( + ) + .pipe( + map(response => { + const stats = response.map(data => new StatsByJumpTypeResp(data)); + return stats; + }) + ); + } + + private getStatsByGear(): Observable> { + return this.http.get>( `${environment.urlApi}/api/Stats/ByGear`, { headers: this.headers } - ); - resultat.statsByYear = this.http.get( + ) + .pipe( + map(response => { + const stats = response.map(data => new StatsByGearResp(data)); + return stats; + }) + ); + } + + private getStatsByYear(): Observable> { + return this.http.get>( `${environment.urlApi}/api/Stats/ByYear`, { headers: this.headers } - ); - - return resultat; + ) + .pipe( + map(response => { + const stats = response.map(data => new StatsByYearResp(data)); + return stats; + }) + ); } }