bteodoru commited on
Commit
b0af23d
·
verified ·
1 Parent(s): 8d081b4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -45
app.py CHANGED
@@ -1,5 +1,6 @@
1
  from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel, validator, model_validator
 
3
  import pandas as pd
4
  import joblib
5
  import numpy as np
@@ -17,75 +18,45 @@ except Exception as e:
17
  model = None # Setăm modelul ca None în caz de eroare
18
  FEATURE_ORDER = [] # Inițializăm o listă goală pentru a evita erorile ulterioare
19
 
 
 
 
20
 
21
- # Definirea clasei pentru inputuri
22
- # class SoilInput(BaseModel):
23
- # cement_perecent: float
24
- # curing_period: float
25
- # compaction_rate: float
26
 
27
- # @validator('cement_perecent')
28
- # def validate_cement(cls, v):
29
- # if not 0 <= v <= 15:
30
- # raise ValueError("Procentul de ciment trebuie să fie între 0% și 15%")
31
- # return v
32
-
33
- # @validator('curing_period')
34
- # def validate_curing(cls, v):
35
- # if not 1 <= v <= 90:
36
- # raise ValueError("Perioada de maturare trebuie să fie între 1 și 90 zile")
37
- # return v
38
-
39
- # @validator('compaction_rate')
40
- # def validate_compaction(cls, v):
41
- # if not 0.5 <= v <= 1.5:
42
- # raise ValueError("Viteza de compactare trebuie să fie între 0.5 și 1.5 mm/min")
43
- # return v
44
 
45
  class SoilInput(BaseModel):
46
  cement_perecent: float
47
  curing_period: float
48
  compaction_rate: float
49
 
50
- # @model_validator(mode='after')
51
- # def check_cement_and_curing(self):
52
- # cement = values.get('cement_perecent')
53
- # curing = values.get('curing_period')
54
- # if cement == 0:
55
- # values['curing_period'] = 0
56
- # else:
57
- # if not (1 <= curing <= 90):
58
- # raise ValueError("Perioada de maturare trebuie să fie între 1 și 90 zile dacă cement_perecent > 0")
59
- # return values
60
-
61
  @model_validator(mode="after")
62
  def check_cement_and_curing(self):
63
  if self.cement_perecent == 0:
64
  self.curing_period = 0
65
  else:
66
  if not (1 <= self.curing_period <= 90):
67
- raise ValueError("Perioada de maturare trebuie să fie între 1 și 90 zile dacă cement_perecent > 0")
 
68
  return self
69
-
70
- # @model_validator(mode="after")
71
- # def check_cement_and_curing(self):
72
- # if self.cement_percent == 0:
73
- # self.curing_period = 0
74
- # else:
75
- # if not (1 <= self.curing_period <= 90):
76
- # raise ValueError("Invalid curing period")
77
- # return self
78
 
79
  @validator('cement_perecent')
80
  def validate_cement(cls, v):
81
  if not 0 <= v <= 15:
82
- raise ValueError("Procentul de ciment trebuie să fie între 0% și 15%")
 
83
  return v
84
 
85
  @validator('compaction_rate')
86
  def validate_compaction(cls, v):
87
  if not 0.5 <= v <= 1.5:
88
- raise ValueError("Viteza de compactare trebuie să fie între 0.5 și 1.5 mm/min")
 
89
  return v
90
 
91
 
 
1
  from fastapi import FastAPI, HTTPException
2
  from pydantic import BaseModel, validator, model_validator
3
+ from pydantic.errors import PydanticValueError
4
  import pandas as pd
5
  import joblib
6
  import numpy as np
 
18
  model = None # Setăm modelul ca None în caz de eroare
19
  FEATURE_ORDER = [] # Inițializăm o listă goală pentru a evita erorile ulterioare
20
 
21
+ # Definim clase personalizate pentru erori
22
+ class CementPercentError(PydanticValueError):
23
+ msg_template = "Cement percentage must be between 0% and 15%"
24
 
25
+ class CuringPeriodError(PydanticValueError):
26
+ msg_template = "Curing period must be between 1 and 90 days"
 
 
 
27
 
28
+ class CompactionRateError(PydanticValueError):
29
+ msg_template = "Compaction velocity must be between 0.5 and 1.5 mm/min"
30
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  class SoilInput(BaseModel):
33
  cement_perecent: float
34
  curing_period: float
35
  compaction_rate: float
36
 
37
+
 
 
 
 
 
 
 
 
 
 
38
  @model_validator(mode="after")
39
  def check_cement_and_curing(self):
40
  if self.cement_perecent == 0:
41
  self.curing_period = 0
42
  else:
43
  if not (1 <= self.curing_period <= 90):
44
+ raise CuringPeriodError()
45
+ # raise ValueError("Perioada de maturare trebuie să fie între 1 și 90 zile dacă cement_perecent > 0")
46
  return self
 
 
 
 
 
 
 
 
 
47
 
48
  @validator('cement_perecent')
49
  def validate_cement(cls, v):
50
  if not 0 <= v <= 15:
51
+ raise CementPercentError()
52
+ # raise ValueError("Procentul de ciment trebuie să fie între 0% și 15%")
53
  return v
54
 
55
  @validator('compaction_rate')
56
  def validate_compaction(cls, v):
57
  if not 0.5 <= v <= 1.5:
58
+ raise CompactionRateError()
59
+ # raise ValueError("Viteza de compactare trebuie să fie între 0.5 și 1.5 mm/min")
60
  return v
61
 
62