feat: correctly show costs

This commit is contained in:
Krzysztof Rudnicki 2024-03-09 21:58:31 +01:00
parent 2dcfa46fc3
commit 6f5ba91446
7 changed files with 63 additions and 40 deletions

View File

@ -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)

View File

@ -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<GenericResponse> {
public sendMessage(message: GenericRequest): Promise<ReturnResponse> {
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<GenericResponse>(this.address, JSON.stringify(message), { headers }).subscribe({
this.http.post<ReturnResponse>(this.address, JSON.stringify(message), { headers }).subscribe({
next: (response) => {
console.log(`response: `, response);
resolve(response);

View File

@ -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!`)

View File

@ -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();

View File

@ -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();
});
});

View File

@ -0,0 +1,9 @@
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class KosztaService {
public koszta: string = "";
public czas: string = "";
}

View File

@ -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