diff --git a/Backend_correct/app.py b/Backend_correct/app.py index 4e4b68b..b30fab1 100644 --- a/Backend_correct/app.py +++ b/Backend_correct/app.py @@ -16,15 +16,14 @@ def recommended_mediators(): input = data.get('request_data', {}) - {liczba_miesiecy, koszt} = calc_stats("2", 25000, True) - print(result) + liczba_miesiecy, koszt = calc_stats("2", 25000, True) top_5 = { "response_type": "recommended_mediators", - "response_data": [{ + "response_data": {"first": { "cost_of_trial": koszt, "time_of_trial": liczba_miesiecy - }, [{ + }, "second": [{ "name": "Mateusz Szpyruk", "specialization": "Prawo podatkowe", "location": input.get("location"), @@ -45,7 +44,7 @@ def recommended_mediators(): "ai_rating": 90, "user_rating": 99, "number_of_opinions": 5 - }]] + }]} } return jsonify(top_5) @@ -99,34 +98,10 @@ def calc_stats(typ,kwota,biegly): else: koszt = koszt_sadu + koszt_adwokata print(f"Średni czas trwania rozprawy typu {mapka[typ]} wynosi {round(liczba_miesiecy,0).to_string(index=False)} miesięcy, a {procent.to_string(index=False)}% spraw trwa dłuzej niz rok, jej minimalny koszt wyniesie {koszt}") - - elif kwota > 100000: - df = pd.read_excel(danePath,sheet_name='okreg') - mask = df['RODZAJ'] == int(typ) - liczba_miesiecy = df[mask]['mean'] - procent = (1 - df[mask]['procent do 12 miesięcy']) * 100 + returnMiesiace = round(liczba_miesiecy,0).to_string(index=False) + print(returnMiesiace, koszt) + return returnMiesiace, koszt - if kwota <= 200000: - koszt_adwokata = 5400 - elif kwota > 200000 and kwota <= 2000000: - koszt_adwokata = 10800 - elif kwota > 2000000 and kwota <= 5000000: - koszt_adwokata = 15000 - elif kwota > 500000: - koszt_adwokata = 25000 - - koszt_sadu = kwota * 0.05 - if koszt_sadu > 20000: - koszt_sadu = 20000 - - if biegly == 'True': - koszt = koszt_sadu + koszt_adwokata + koszt_bieglego - else: - koszt = koszt_sadu + koszt_adwokata - return_string = f"Średni czas trwania rozprawy typu {mapka[TYP]} wynosi {round(liczba_miesiecy,0).to_string(index=False)} miesięcy, a {procent.to_string(index=False)}% spraw trwa krócej niz rok, a jej minimalny koszt wynosi {koszt}" - print(return_string) - - return {liczba_miesiecy, koszt} if __name__ == '__main__': app.run(debug=True) \ No newline at end of file diff --git a/arai-frontend/src/app/backend.service.ts b/arai-frontend/src/app/backend.service.ts index d9ddcc1..2c151a2 100644 --- a/arai-frontend/src/app/backend.service.ts +++ b/arai-frontend/src/app/backend.service.ts @@ -1,5 +1,5 @@ import { EventEmitter, Injectable } from '@angular/core'; -import { GenericRequest, GenericResponse, RecommendedMediatorsResponse, StatisticsOutputResponse, UserInputRequest } from './requests-responses'; +import { GenericRequest, GenericResponse, RecommendedMediatorsResponse, ReturnResponse, StatisticsOutputResponse, UserInputRequest } from './requests-responses'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; @Injectable({ @@ -32,7 +32,7 @@ export class BackendService { } } - public sendMessage(message: GenericRequest): Promise { + public sendMessage(message: GenericRequest): Promise { return new Promise((resolve, reject) => { if (message.request_type === "user_input") { this.userInputArray.push(message as UserInputRequest); @@ -41,7 +41,7 @@ export class BackendService { console.log(`request: `, JSON.stringify(message)); - this.http.post(this.address, JSON.stringify(message), { headers }).subscribe({ + this.http.post(this.address, JSON.stringify(message), { headers }).subscribe({ next: (response) => { console.log(`response: `, response); resolve(response); diff --git a/arai-frontend/src/app/case-input/case-input.component.ts b/arai-frontend/src/app/case-input/case-input.component.ts index 1b41a0d..ab86e05 100644 --- a/arai-frontend/src/app/case-input/case-input.component.ts +++ b/arai-frontend/src/app/case-input/case-input.component.ts @@ -4,8 +4,9 @@ import { MatInputModule } from '@angular/material/input' import { MatCheckboxModule } from '@angular/material/checkbox' import { MatButtonModule } from '@angular/material/button' import { BackendService } from '../backend.service'; -import { GenericRequest, UserInputRequest, userInput } from '../requests-responses'; +import { GenericRequest, ReturnResponse, UserInputRequest, userInput } from '../requests-responses'; import { Router } from '@angular/router'; +import { KosztaService } from '../koszta.service'; @Component({ @@ -24,7 +25,7 @@ export class CaseInputComponent { userInputForm: FormGroup; userInput: userInput | null = null; - constructor(private fb: FormBuilder, private readonly backendService: BackendService, private readonly router: Router) { + constructor(private fb: FormBuilder, private readonly backendService: BackendService, private readonly router: Router, private readonly kosztaService: KosztaService) { this.userInputForm = this.fb.group({ generic_input: [''], trial_value: [], @@ -37,8 +38,9 @@ export class CaseInputComponent { async onSubmit() { this.userInput = this.userInputForm.value; if(this.userInput !== null) { - const result = await this.backendService.sendMessage(new UserInputRequest(this.userInput)); - console.log(`result: `, result); + const result = await this.backendService.sendMessage(new UserInputRequest(this.userInput)) as ReturnResponse; + this.kosztaService.czas = String(result.response_data.first.time_of_trial); + this.kosztaService.koszta = String(result.response_data.first.cost_of_trial); this.router.navigate(['koszt']); } else { console.error(`caseInputComponent, onSubmit, userInput is null!`) diff --git a/arai-frontend/src/app/cost-view/cost-view.component.ts b/arai-frontend/src/app/cost-view/cost-view.component.ts index 3e7842e..98c6b11 100644 --- a/arai-frontend/src/app/cost-view/cost-view.component.ts +++ b/arai-frontend/src/app/cost-view/cost-view.component.ts @@ -3,6 +3,7 @@ import { StatisticsOutputInterface } from '../requests-responses'; import { DatePipe } from '@angular/common'; import { MatButtonModule } from '@angular/material/button'; import { Router } from '@angular/router'; +import { KosztaService } from '../koszta.service'; @Component({ selector: 'app-cost-view', @@ -17,7 +18,14 @@ export class CostViewComponent { time_of_trial: Date.UTC(0, 6, 0, 0, 0, 0, 0) }; -constructor(private readonly router: Router) {} +constructor(private readonly router: Router, private readonly kosztaService: KosztaService) {} + +ngOnInit() { + this.costData = { + cost_of_trial: Number(this.kosztaService.koszta), + time_of_trial: Number(this.kosztaService.czas), + } +} public calculateTimeDifference(utcDateNumber: number): string { const currentDate = new Date(); diff --git a/arai-frontend/src/app/koszta.service.spec.ts b/arai-frontend/src/app/koszta.service.spec.ts new file mode 100644 index 0000000..0b19e19 --- /dev/null +++ b/arai-frontend/src/app/koszta.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { KosztaService } from './koszta.service'; + +describe('KosztaService', () => { + let service: KosztaService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(KosztaService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/arai-frontend/src/app/koszta.service.ts b/arai-frontend/src/app/koszta.service.ts new file mode 100644 index 0000000..a726a17 --- /dev/null +++ b/arai-frontend/src/app/koszta.service.ts @@ -0,0 +1,9 @@ +import { Injectable } from '@angular/core'; + +@Injectable({ + providedIn: 'root' +}) +export class KosztaService { + public koszta: string = ""; + public czas: string = ""; +} diff --git a/arai-frontend/src/app/requests-responses.ts b/arai-frontend/src/app/requests-responses.ts index c77f39d..e5d2352 100644 --- a/arai-frontend/src/app/requests-responses.ts +++ b/arai-frontend/src/app/requests-responses.ts @@ -63,6 +63,19 @@ export class RecommendedMediatorsResponse extends GenericResponse { } } +interface response { + first: { + cost_of_trial: number, + time_of_trial: number + }, + second: RecommendedMediatorsInterface[]; +} + +export class ReturnResponse { + "response_type" = "recommended_mediators"; + "response_data": response +} + export interface StatisticsOutputInterface { "cost_of_trial": number, "time_of_trial": number