Mise à jour de 'services'
This commit is contained in:
@@ -2,9 +2,37 @@ import { Injectable } from '@angular/core';
|
|||||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
|
||||||
import { JumpDoc, JumpViewResults } from 'src/app/core/models';
|
import { Jump } from 'src/app/core/models';
|
||||||
import { environment } from 'src/environments/environment';
|
import { environment } from 'src/environments/environment';
|
||||||
|
|
||||||
|
export interface JumpDoc {
|
||||||
|
_id?: string;
|
||||||
|
_rev?: string;
|
||||||
|
type: string;
|
||||||
|
date: string;
|
||||||
|
numero: number,
|
||||||
|
lieu?: string;
|
||||||
|
oaci?: string;
|
||||||
|
aeronef?: string;
|
||||||
|
imat?: string;
|
||||||
|
hauteur?: number,
|
||||||
|
voile?: string;
|
||||||
|
taille?: number,
|
||||||
|
categorie?: string;
|
||||||
|
module?: string;
|
||||||
|
participants?: number,
|
||||||
|
programme?: string;
|
||||||
|
accessoires?: string;
|
||||||
|
zone?: string;
|
||||||
|
dossier?: string;
|
||||||
|
video?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface JumpViewResults {
|
||||||
|
rows: Array<Jump>;
|
||||||
|
total_rows: number;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable({ providedIn: 'root' })
|
@Injectable({ providedIn: 'root' })
|
||||||
export class BackendService {
|
export class BackendService {
|
||||||
private _couchdbUrl = environment.couchdbUrl;
|
private _couchdbUrl = environment.couchdbUrl;
|
||||||
@@ -38,15 +66,6 @@ export class BackendService {
|
|||||||
return this._http.delete(url, this.httpOptions).toPromise();
|
return this._http.delete(url, this.httpOptions).toPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* helper function to save date on updated_at, created_at */
|
|
||||||
getCurrentDate(): Date {
|
|
||||||
return new Date();
|
|
||||||
}
|
|
||||||
|
|
||||||
getCurrentDateFr(): string {
|
|
||||||
return new Date().toLocaleDateString("fr");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* get all docs from couchDB view 'allJumps' */
|
/* get all docs from couchDB view 'allJumps' */
|
||||||
getJumps(): Observable<JumpViewResults> {
|
getJumps(): Observable<JumpViewResults> {
|
||||||
//const url = this._couchdbUrl + '/' + this._couchdbDatabase + '/_design/' + this._couchdbDesign + '/_view/allJumps/';
|
//const url = this._couchdbUrl + '/' + this._couchdbDatabase + '/_design/' + this._couchdbDesign + '/_view/allJumps/';
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
|
import { CalculatorResult, Range, weightSizes } from 'src/app/core/models';
|
||||||
|
import { UtilitiesService } from 'src/app/core/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: Range) => {
|
||||||
|
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;
|
||||||
|
let min = 60;
|
||||||
|
let max = 110;
|
||||||
|
if (weight < min) {
|
||||||
|
line = min;
|
||||||
|
} else if (weight > max) {
|
||||||
|
line = max;
|
||||||
|
} else {
|
||||||
|
line = weight;
|
||||||
|
}
|
||||||
|
return line;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _isInRange(nb: number, range: Range): 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 {
|
||||||
|
let result: CalculatorResult = {
|
||||||
|
min: 59,
|
||||||
|
min11: 34
|
||||||
|
};
|
||||||
|
if (jumps > 2000) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
let 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[] {
|
||||||
|
var data: number[] = [];
|
||||||
|
if (weight < 60) {
|
||||||
|
weight = 60;
|
||||||
|
}
|
||||||
|
if (weight > 110) {
|
||||||
|
weight = 110;
|
||||||
|
}
|
||||||
|
if (weight >= 60 && weight <= 110) {
|
||||||
|
const line = (weight - this._getTableLine(0));
|
||||||
|
let data = weightSizes[line];
|
||||||
|
if (reduce) {
|
||||||
|
return data.ranges.map((range: Range): number => {
|
||||||
|
return Math.ceil(range.value * (100 - 11) / 100);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return data.ranges.map((range: Range): number => {
|
||||||
|
return range.value;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public getCharge(canopySize: number, nakedWeight: number, equipementWeight: number): number {
|
||||||
|
return (((nakedWeight + equipementWeight) * this.coeffKgLbs) / canopySize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public getRangeNum(jumps: number): number {
|
||||||
|
let data: Range[] = weightSizes[0].ranges;
|
||||||
|
let num: number = 1;
|
||||||
|
data.some((range: Range): boolean => {
|
||||||
|
if (jumps >= range.start && jumps < range.end) {
|
||||||
|
num = range.num;
|
||||||
|
return true;
|
||||||
|
} else if (jumps > 2000) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
|
export * from './aeronefs.service';
|
||||||
export * from './api.service';
|
export * from './api.service';
|
||||||
export * from './applications.service';
|
export * from './applications.service';
|
||||||
export * from './auth-guard.service';
|
export * from './auth-guard.service';
|
||||||
export * from './auth-resolver.service';
|
export * from './auth-resolver.service';
|
||||||
export * from './backend.service';
|
export * from './backend.service';
|
||||||
export * from './aeronefs.service';
|
export * from './calculator.service';
|
||||||
export * from './canopies.service';
|
export * from './canopies.service';
|
||||||
export * from './dropzones.service';
|
export * from './dropzones.service';
|
||||||
export * from './jumps.service';
|
export * from './jumps.service';
|
||||||
|
export * from './jump-table.service';
|
||||||
export * from './jwt.service';
|
export * from './jwt.service';
|
||||||
export * from './no-auth-guard.service';
|
export * from './no-auth-guard.service';
|
||||||
export * from './profiles.service';
|
export * from './profiles.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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -55,6 +55,10 @@ export class UtilitiesService {
|
|||||||
return colors;
|
return colors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCurrentDateFr(): string {
|
||||||
|
return new Date().toLocaleDateString("fr");
|
||||||
|
}
|
||||||
|
|
||||||
getSeriesColors(opacity: number, palette: string = 'all'): string[] {
|
getSeriesColors(opacity: number, palette: string = 'all'): string[] {
|
||||||
let colors: string[] = [];
|
let colors: string[] = [];
|
||||||
switch (palette) {
|
switch (palette) {
|
||||||
|
|||||||
Reference in New Issue
Block a user