Little test with AI + Add the equipment (#8)
Tests using local LLM AI to add comments in the C# files For the flights tunnel, show the total to day/hours For the jump, add the equipment (now just with the wingsuit) Reviewed-on: #8 Co-authored-by: sandre <perso@sebastienandre.com> Co-committed-by: sandre <perso@sebastienandre.com>
This commit was merged in pull request #8.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from "@angular/core";
|
||||
import { HttpClient } from "@angular/common/http";
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { DatePipe } from "@angular/common";
|
||||
import { forkJoin, Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
|
||||
@@ -20,158 +20,204 @@ import { GearService } from "./gear.service";
|
||||
|
||||
@Injectable()
|
||||
export class JumpService extends BaseService {
|
||||
private callsToAdd: Array<Observable<any>>;
|
||||
private callsToAdd: Array<Observable<any>>;
|
||||
|
||||
constructor(private http: HttpClient,
|
||||
private dateService: DateService,
|
||||
private datePipe: DatePipe,
|
||||
private dropzoneService: DropzoneService,
|
||||
private aircraftService: AircraftService,
|
||||
private jumpTypeService: JumpTypeService,
|
||||
private gearService: GearService) {
|
||||
super();
|
||||
}
|
||||
constructor(
|
||||
private http: HttpClient,
|
||||
private dateService: DateService,
|
||||
private datePipe: DatePipe,
|
||||
private dropzoneService: DropzoneService,
|
||||
private aircraftService: AircraftService,
|
||||
private jumpTypeService: JumpTypeService,
|
||||
private gearService: GearService,
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
public getListOfJumps(): Observable<Array<Jump>> {
|
||||
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`, { headers: this.headers })
|
||||
.pipe(map((response) => {
|
||||
return this.mapWithDataInCache(response);
|
||||
}));
|
||||
}
|
||||
public getListOfJumps(): Observable<Array<Jump>> {
|
||||
return this.http
|
||||
.get<
|
||||
Array<JumpResp>
|
||||
>(`${this.apiUrl}/Jump`, { headers: this.headers })
|
||||
.pipe(
|
||||
map((response) => {
|
||||
return this.mapWithDataInCache(response);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
public getJumps(beginIndex: number, endIndex: number): Observable<JumpList> {
|
||||
return this.http.get<JumpListResp>(`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`, { headers: this.headers })
|
||||
.pipe(map(response => {
|
||||
let result: JumpList = {
|
||||
public getJumps(
|
||||
beginIndex: number,
|
||||
endIndex: number,
|
||||
): Observable<JumpList> {
|
||||
return this.http
|
||||
.get<JumpListResp>(
|
||||
`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`,
|
||||
{ headers: this.headers },
|
||||
)
|
||||
.pipe(
|
||||
map((response) => {
|
||||
let result: JumpList = {
|
||||
rows: this.mapWithDataInCache(response.rows),
|
||||
count: response.count
|
||||
};
|
||||
count: response.count,
|
||||
};
|
||||
|
||||
return new JumpList(result);
|
||||
}));
|
||||
}
|
||||
|
||||
public addListOfJump(selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
beginDate: Date,
|
||||
endDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string,
|
||||
isSpecial: boolean): Observable<any[]> {
|
||||
this.callsToAdd = new Array<Observable<any>>();
|
||||
const diffInDays = this.dateService.diffBetweenDates(beginDate, endDate) + 1;
|
||||
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
|
||||
|
||||
for (let i = 1; beginDate.getTime() < endDate.getTime(); i++) {
|
||||
this.addJumps(selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
countOfJumpsPerDay,
|
||||
notes,
|
||||
isSpecial);
|
||||
|
||||
beginDate = this.dateService.addDays(beginDate, 1);
|
||||
return new JumpList(result);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
|
||||
public addListOfJump(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedGear: number,
|
||||
withCutaway: boolean,
|
||||
beginDate: Date,
|
||||
endDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string,
|
||||
isSpecial: boolean,
|
||||
equipment: string,
|
||||
): Observable<any[]> {
|
||||
this.callsToAdd = new Array<Observable<any>>();
|
||||
const diffInDays =
|
||||
this.dateService.diffBetweenDates(beginDate, endDate) + 1;
|
||||
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
|
||||
|
||||
this.addJumps(selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedRig,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
restfJumps,
|
||||
notes,
|
||||
isSpecial);
|
||||
for (let i = 1; beginDate.getTime() < endDate.getTime(); i++) {
|
||||
this.addJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedGear,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
countOfJumpsPerDay,
|
||||
notes,
|
||||
isSpecial,
|
||||
equipment,
|
||||
);
|
||||
|
||||
return forkJoin(this.callsToAdd);
|
||||
}
|
||||
beginDate = this.dateService.addDays(beginDate, 1);
|
||||
}
|
||||
|
||||
public deleteJump(item: Jump) {
|
||||
this.http.delete(`${this.apiUrl}/Jump/${item.id}`, { headers: this.headers }).subscribe();
|
||||
}
|
||||
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
|
||||
|
||||
public updateJump(id: number,
|
||||
isSpecial: boolean,
|
||||
withCutaway: boolean,
|
||||
notes: string) {
|
||||
const jumpData = {
|
||||
id: id,
|
||||
isSpecial: isSpecial,
|
||||
withCutaway: withCutaway,
|
||||
notes: notes
|
||||
};
|
||||
const bodyUpdatedJump = new JumpReq(jumpData);
|
||||
this.addJumps(
|
||||
selectedJumpType,
|
||||
selectedAircraft,
|
||||
selectedDz,
|
||||
selectedGear,
|
||||
withCutaway,
|
||||
beginDate,
|
||||
defaultExitAltitude,
|
||||
defaultDeployAltitude,
|
||||
restfJumps,
|
||||
notes,
|
||||
isSpecial,
|
||||
equipment,
|
||||
);
|
||||
|
||||
return this.http.put(`${this.apiUrl}/Jump/${id}`,
|
||||
bodyUpdatedJump,
|
||||
{ headers: this.headers, });
|
||||
}
|
||||
|
||||
private addJumps(selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedRig: number,
|
||||
withCutaway: boolean,
|
||||
jumpDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string,
|
||||
isSpecial: boolean) {
|
||||
for (let i = 0; i < countOfJumps; i++) {
|
||||
const bodyNewjump: JumpReq = {
|
||||
jumpTypeId: selectedJumpType,
|
||||
aircraftId: selectedAircraft,
|
||||
dropZoneId: selectedDz,
|
||||
withCutaway: withCutaway,
|
||||
exitAltitude: defaultExitAltitude,
|
||||
deployAltitude: defaultDeployAltitude,
|
||||
gearId: selectedRig,
|
||||
notes: notes,
|
||||
id: 0,
|
||||
jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd"),
|
||||
isSpecial: isSpecial
|
||||
};
|
||||
|
||||
let call = this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, { headers: this.headers });
|
||||
|
||||
this.callsToAdd.push(call);
|
||||
return forkJoin(this.callsToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
private mapWithDataInCache(apiResp: Array<JumpResp>): Array<Jump> {
|
||||
let allDropzones: Array<DropZoneResp>;
|
||||
this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
|
||||
let allAircrafts: Array<AircraftResp>;
|
||||
this.aircraftService.getFromCache().subscribe(data => { allAircrafts = data; });
|
||||
let allJumpType: Array<JumpTypeResp>;
|
||||
this.jumpTypeService.getFromCache().subscribe(data => { allJumpType = data; });
|
||||
let allGears: Array<GearResp>;
|
||||
this.gearService.getFromCache().subscribe(data => { allGears = data; });
|
||||
public deleteJump(item: Jump) {
|
||||
this.http
|
||||
.delete(`${this.apiUrl}/Jump/${item.id}`, { headers: this.headers })
|
||||
.subscribe();
|
||||
}
|
||||
|
||||
return apiResp.map((data) => {
|
||||
let tmp = new Jump(data);
|
||||
public updateJump(
|
||||
id: number,
|
||||
isSpecial: boolean,
|
||||
withCutaway: boolean,
|
||||
notes: string,
|
||||
equipment: string,
|
||||
) {
|
||||
const jumpData = {
|
||||
id: id,
|
||||
isSpecial: isSpecial,
|
||||
withCutaway: withCutaway,
|
||||
notes: notes,
|
||||
equipment: equipment,
|
||||
};
|
||||
const bodyUpdatedJump = new JumpReq(jumpData);
|
||||
|
||||
tmp.dropZone = allDropzones.find(d => d.id == data.dropZoneId);
|
||||
tmp.aircraft = allAircrafts.find(d => d.id == data.aircraftId);
|
||||
tmp.jumpType = allJumpType.find(d => d.id == data.jumpTypeId);
|
||||
tmp.gear = allGears.find(d => d.id == data.gearId);
|
||||
return this.http.put(`${this.apiUrl}/Jump/${id}`, bodyUpdatedJump, {
|
||||
headers: this.headers,
|
||||
});
|
||||
}
|
||||
|
||||
return tmp;
|
||||
});
|
||||
}
|
||||
private addJumps(
|
||||
selectedJumpType: number,
|
||||
selectedAircraft: number,
|
||||
selectedDz: number,
|
||||
selectedGear: number,
|
||||
withCutaway: boolean,
|
||||
jumpDate: Date,
|
||||
defaultExitAltitude: number,
|
||||
defaultDeployAltitude: number,
|
||||
countOfJumps: number,
|
||||
notes: string,
|
||||
isSpecial: boolean,
|
||||
equipment: string,
|
||||
) {
|
||||
for (let i = 0; i < countOfJumps; i++) {
|
||||
const bodyNewjump: JumpReq = {
|
||||
jumpTypeId: selectedJumpType,
|
||||
aircraftId: selectedAircraft,
|
||||
dropZoneId: selectedDz,
|
||||
withCutaway: withCutaway,
|
||||
exitAltitude: defaultExitAltitude,
|
||||
deployAltitude: defaultDeployAltitude,
|
||||
gearId: selectedGear,
|
||||
notes: notes,
|
||||
id: 0,
|
||||
jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd"),
|
||||
isSpecial: isSpecial,
|
||||
equipment: equipment,
|
||||
};
|
||||
|
||||
let call = this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, {
|
||||
headers: this.headers,
|
||||
});
|
||||
|
||||
this.callsToAdd.push(call);
|
||||
}
|
||||
}
|
||||
|
||||
private mapWithDataInCache(apiResp: Array<JumpResp>): Array<Jump> {
|
||||
let allDropzones: Array<DropZoneResp>;
|
||||
this.dropzoneService.getFromCache().subscribe((data) => {
|
||||
allDropzones = data;
|
||||
});
|
||||
let allAircrafts: Array<AircraftResp>;
|
||||
this.aircraftService.getFromCache().subscribe((data) => {
|
||||
allAircrafts = data;
|
||||
});
|
||||
let allJumpType: Array<JumpTypeResp>;
|
||||
this.jumpTypeService.getFromCache().subscribe((data) => {
|
||||
allJumpType = data;
|
||||
});
|
||||
let allGears: Array<GearResp>;
|
||||
this.gearService.getFromCache().subscribe((data) => {
|
||||
allGears = data;
|
||||
});
|
||||
|
||||
return apiResp.map((data) => {
|
||||
let tmp = new Jump(data);
|
||||
|
||||
tmp.dropZone = allDropzones.find((d) => d.id == data.dropZoneId);
|
||||
tmp.aircraft = allAircrafts.find((d) => d.id == data.aircraftId);
|
||||
tmp.jumpType = allJumpType.find((d) => d.id == data.jumpTypeId);
|
||||
tmp.gear = allGears.find((d) => d.id == data.gearId);
|
||||
|
||||
return tmp;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user