Refactoring
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from '../api.service';
|
||||
import { AeronefByImat, AeronefByYear } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class AeronefsService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAllByImat(): Observable<Array<AeronefByImat>> {
|
||||
return this.apiService.get(`${this._apiVersion}/aeronefs/allByImat`)
|
||||
.pipe(map(data => data.aeronefs));
|
||||
}
|
||||
|
||||
getAllByImatByYear(): Observable<Array<AeronefByYear>> {
|
||||
return this.apiService.get(`${this._apiVersion}/aeronefs/allByImatByYear`)
|
||||
.pipe(map(data => data.aeronefs));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
import { CalculatorResult, WeightSizeRange, weightSizes } from '@models';
|
||||
import { UtilitiesService } from '@services';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CalculatorService {
|
||||
public coeffKgLbs: number = this._utilitiesService.getCoeffKgLbs();
|
||||
public coeffFtM: number = this._utilitiesService.getCoeffFtM();
|
||||
|
||||
constructor(
|
||||
private _utilitiesService: UtilitiesService
|
||||
) { }
|
||||
|
||||
private _getTableColumn(jumps: number): number {
|
||||
let column: number = 0;
|
||||
weightSizes[0].ranges.some((range: WeightSizeRange) => {
|
||||
if (jumps >= range.start && jumps <= range.end) {
|
||||
column = (range.num-1)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
return column;
|
||||
}
|
||||
|
||||
private _getTableLine(weight: number): number {
|
||||
let line: number;
|
||||
const min = 60;
|
||||
const max = 110;
|
||||
if (weight < min) {
|
||||
line = min;
|
||||
} else if (weight > max) {
|
||||
line = max;
|
||||
} else {
|
||||
line = weight;
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
private _isInRange(nb: number, range: WeightSizeRange): boolean {
|
||||
return (nb >= range.start && nb <= range.end);
|
||||
}
|
||||
|
||||
private _reduceLimit(surface: number, percentOff: number): number {
|
||||
return Math.ceil(surface * (100 - percentOff) / 100);
|
||||
}
|
||||
|
||||
public canopySizeCalc(weight: number, jumps: number): CalculatorResult {
|
||||
/* DT48 - 13 mars 2020 */
|
||||
/* const maxRange = 2000; */
|
||||
/* DT48 - 08 février 2024 */
|
||||
const maxRange = 1600;
|
||||
const result: CalculatorResult = {
|
||||
min: 59,
|
||||
min11: 34
|
||||
};
|
||||
if (jumps > maxRange) {
|
||||
return result;
|
||||
}
|
||||
const index: number = (this._getTableLine(weight) - this._getTableLine(0));
|
||||
result.min = weightSizes[index].ranges[this._getTableColumn(jumps)].value!;
|
||||
result.min11 = this._reduceLimit(result.min, 11);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public convertFeet2Meters(size: number): number {
|
||||
return (size * this._utilitiesService.getCoeffFtM());
|
||||
}
|
||||
|
||||
public getCanopySizes(weight: number, reduce = false): number[] {
|
||||
if (weight < 60) {
|
||||
weight = 60;
|
||||
}
|
||||
if (weight > 110) {
|
||||
weight = 110;
|
||||
}
|
||||
const line = (weight - this._getTableLine(0));
|
||||
const data = weightSizes[line];
|
||||
if (reduce) {
|
||||
return data.ranges.map((range: WeightSizeRange): number => {
|
||||
return Math.ceil(range.value! * (100 - 11) / 100);
|
||||
});
|
||||
} else {
|
||||
return data.ranges.map((range: WeightSizeRange): number => {
|
||||
return range.value!;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public getCharge(canopySize: number, nakedWeight: number, equipementWeight: number): number {
|
||||
return (((nakedWeight + equipementWeight) * this.coeffKgLbs) / canopySize);
|
||||
}
|
||||
|
||||
public getRangeNum(jumps: number): number {
|
||||
const data: WeightSizeRange[] = weightSizes[0].ranges;
|
||||
let num: number = 1;
|
||||
/* DT48 - 13 mars 2020 */
|
||||
/* const maxRange = 2000; */
|
||||
/* DT48 - 08 février 2024 */
|
||||
const maxRange = 1600;
|
||||
data.some((range: WeightSizeRange): boolean => {
|
||||
if (jumps >= range.start && jumps <= range.end) {
|
||||
num = range.num;
|
||||
return true;
|
||||
} else if (jumps > maxRange) {
|
||||
num = 9;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
return num;
|
||||
}
|
||||
|
||||
public getStateColor(values: CalculatorResult): string {
|
||||
let color: string = 'danger';
|
||||
if (values.current! >= values.min11 && values.current! < values.min) {
|
||||
color = 'warning';
|
||||
}
|
||||
if (values.current! >= values.min) {
|
||||
color = 'success';
|
||||
}
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from '../api.service';
|
||||
import { CanopyBySize, CanopyByYear, CanopyModelBySize, CanopyModelByYear } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class CanopiesService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAllBySize(): Observable<Array<CanopyBySize>> {
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySize`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
getAllBySizeByYear(): Observable<Array<CanopyByYear>> {
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByYear`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
getAllBySizeByModel(): Observable<Array<CanopyModelBySize>> {
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByModel`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
getAllBySizeByModelByYear(): Observable<Array<CanopyModelByYear>> {
|
||||
return this.apiService.get(`${this._apiVersion}/canopies/allBySizeByModelByYear`)
|
||||
.pipe(map(data => data.canopies));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from '../api.service';
|
||||
import { DropZoneByOaci, DropZoneByYear } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class DropZonesService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
getAllByOaci(): Observable<Array<DropZoneByOaci>> {
|
||||
return this.apiService.get(`${this._apiVersion}/dropzones/allByOaci`)
|
||||
.pipe(map(data => data.dropzones));
|
||||
}
|
||||
|
||||
getAllByOaciByYear(): Observable<Array<DropZoneByYear>> {
|
||||
return this.apiService.get(`${this._apiVersion}/dropzones/allByOaciByYear`)
|
||||
.pipe(map(data => data.dropzones));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './aeronefs.service';
|
||||
export * from './calculator.service';
|
||||
export * from './canopies.service';
|
||||
export * from './dropzones.service';
|
||||
export * from './jumps.service';
|
||||
export * from './jump-table.service';
|
||||
export * from './qcm.service';
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { BehaviorSubject } from "rxjs";
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class JumpTableService {
|
||||
|
||||
tableRefresh: boolean;
|
||||
_tableRefreshBS = new BehaviorSubject<boolean>(false);
|
||||
|
||||
jumpRefresh: boolean;
|
||||
_jumpRefreshBS = new BehaviorSubject<boolean>(false);
|
||||
|
||||
constructor() {
|
||||
this.tableRefresh = false;
|
||||
this.jumpRefresh = false;
|
||||
|
||||
//this._tableRefreshBS.next(this.tableRefresh);
|
||||
//this._jumpRefreshBS.next(this.jumpRefresh);
|
||||
}
|
||||
|
||||
updateTableRefresh(val: boolean) {
|
||||
this.tableRefresh = val;
|
||||
this._tableRefreshBS.next(this.tableRefresh);
|
||||
}
|
||||
|
||||
updateJumpRefresh(val: boolean) {
|
||||
this.jumpRefresh = val;
|
||||
this._jumpRefreshBS.next(this.jumpRefresh);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from '../api.service';
|
||||
import {
|
||||
Jump, JumpByCategorie, JumpByDate, JumpByDay, JumpByModule, JumpFile,
|
||||
JumpList, JumpListConfig, JumpListFilters, JumpPageData,
|
||||
X2Data, SkydiverIdJumps
|
||||
} from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class JumpsService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
query(config: JumpListConfig): Observable<JumpList> {
|
||||
// Convert any filters over to Angular's URLSearchParams
|
||||
/*
|
||||
const params: JumpListFilters = {
|
||||
date: config.filters.date,
|
||||
lieu: config.filters.lieu,
|
||||
oaci: config.filters.oaci,
|
||||
aeronef: config.filters.aeronef,
|
||||
imat: config.filters.imat,
|
||||
hauteur: config.filters.hauteur,
|
||||
voile: config.filters.voile,
|
||||
taille: config.filters.taille,
|
||||
categorie: config.filters.categorie,
|
||||
module: config.filters.module,
|
||||
participants: config.filters.participants,
|
||||
accessoires: config.filters.accessoires,
|
||||
zone: config.filters.zone,
|
||||
author: config.filters.author,
|
||||
limit: config.filters.limit,
|
||||
offset: config.filters.offset,
|
||||
numeroRangeStart: config.filters.numeroRangeStart!,
|
||||
numeroRangeEnd: config.filters.numeroRangeEnd!,
|
||||
tailleRangeStart: config.filters.tailleRangeStart!,
|
||||
tailleRangeEnd: config.filters.tailleRangeEnd!,
|
||||
participantsRangeStart: config.filters.participantsRangeStart!,
|
||||
participantsRangeEnd: config.filters.participantsRangeEnd!,
|
||||
hauteurRangeStart: config.filters.hauteurRangeStart!,
|
||||
hauteurRangeEnd: config.filters.hauteurRangeEnd!
|
||||
};
|
||||
*/
|
||||
const params: JumpListFilters = {} as JumpListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService
|
||||
.get(
|
||||
`${this._apiVersion}/jumps` + ((config.type === 'feed') ? '/feed' : ''),
|
||||
new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params })
|
||||
);
|
||||
}
|
||||
|
||||
get(slug: string): Observable<JumpPageData> {
|
||||
/* return this.apiService.get(`/jumps/${slug}`)
|
||||
.pipe(map(data => {
|
||||
return { jump: data.jump, prevJump: data.prevJump, nextJump: data.nextJump };
|
||||
})); */
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/${slug}`);
|
||||
}
|
||||
|
||||
getAll(): Observable<Array<Jump>> {
|
||||
return this.apiService.get(`${this._apiVersion}/jumps`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllByDate(): Observable<Array<JumpByDate>> {
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByDate`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllByCategorie(): Observable<Array<JumpByCategorie>> {
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByCategorie`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllByDay(config: JumpListConfig): Observable<Array<JumpByDay>> {
|
||||
const params: JumpListFilters = {} as JumpListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByDay`, new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params }))
|
||||
.pipe(map(data => data.days));
|
||||
}
|
||||
|
||||
getAllByModule(): Observable<Array<JumpByModule>> {
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allByModule`).pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getAllFromSkydiverIdApi(config: JumpListConfig): Observable<SkydiverIdJumps> {
|
||||
const params: JumpListFilters = {} as JumpListFilters;
|
||||
Object.assign(params, config.filters);
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/allFromSkydiverIdApi`, new HttpParams({ fromObject: <{
|
||||
[param: string]: string | number | boolean | readonly (string | number | boolean)[];
|
||||
}>params }))
|
||||
.pipe(map(data => data.jumps));
|
||||
}
|
||||
|
||||
getLastJump(): Observable<Jump> {
|
||||
return this.apiService.get(`${this._apiVersion}/jumps/last`).pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
create(jump: Jump): Observable<Jump> {
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/`, { jump: jump }).pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
update(jump: Jump): Observable<Jump> {
|
||||
return this.apiService.put(`${this._apiVersion}/jumps/${jump.slug}`, { jump: jump }).pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
destroy(slug: string): Observable<boolean> {
|
||||
return this.apiService.delete(`${this._apiVersion}/jumps/${slug}`).pipe(map(data => data.deleted));
|
||||
}
|
||||
|
||||
save(jump: Jump): Observable<Jump> {
|
||||
// If we're updating an existing jump
|
||||
if (jump.slug) {
|
||||
return this.apiService.put(`${this._apiVersion}/jumps/${jump.slug}`, { jump: jump }).pipe(map(data => data.jump));
|
||||
|
||||
// Otherwise, create a new jump
|
||||
} else {
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/`, { jump: jump }).pipe(map(data => data.jump));
|
||||
}
|
||||
}
|
||||
|
||||
saveX2Data(slug: string, file: JumpFile, data: X2Data): Observable<Jump> {
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/data/${slug}`, { file: file, data: data })
|
||||
.pipe(map(data => data.jump));
|
||||
}
|
||||
|
||||
saveFile(slug: string, file: JumpFile): Observable<JumpFile> {
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/file/${slug}`, { file: file })
|
||||
.pipe(map(data => data.file));
|
||||
}
|
||||
|
||||
saveKml(slug: string, file: JumpFile): Observable<JumpFile> {
|
||||
return this.apiService.post(`${this._apiVersion}/jumps/kml/${slug}`, { file: file })
|
||||
.pipe(map(data => data.file));
|
||||
}
|
||||
|
||||
getAeronefs() {
|
||||
/*
|
||||
[
|
||||
{
|
||||
'$match': {
|
||||
'aeronef': 'Pilatus'
|
||||
}
|
||||
}, {
|
||||
'$group': {
|
||||
'_id': {
|
||||
'Aeronef': '$aeronef',
|
||||
'Imat': '$imat'
|
||||
},
|
||||
'count': {
|
||||
'$sum': 1
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
*/
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { ApiService } from '../api.service';
|
||||
import { Qcm, QcmCategory, QcmQuestion } from '@models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class QcmService {
|
||||
private _apiVersion = '/v1';
|
||||
constructor(
|
||||
private apiService: ApiService
|
||||
) { }
|
||||
|
||||
get(type: string): Observable<Qcm> {
|
||||
return this.apiService.get(`${this._apiVersion}/qcm/type/${type}`).pipe(map(data => data.qcm));
|
||||
}
|
||||
|
||||
saveChoices(question: object): Observable<QcmQuestion> {
|
||||
return this.apiService.post(`${this._apiVersion}/qcm/choices`, { question: question })
|
||||
.pipe(map(data => data.question));
|
||||
}
|
||||
|
||||
saveQuestions(category: object): Observable<QcmCategory> {
|
||||
return this.apiService.post(`${this._apiVersion}/qcm/questions`, { category: category })
|
||||
.pipe(map(data => data.category));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user