rename status handler
This commit is contained in:
parent
76f58ecba0
commit
42ac7c17db
@ -1,3 +1,3 @@
|
|||||||
from delta_barth.errors import STATE_HANDLER
|
from delta_barth.errors import STATUS_HANDLER
|
||||||
|
|
||||||
__all__ = ["STATE_HANDLER"]
|
__all__ = ["STATUS_HANDLER"]
|
||||||
|
|||||||
@ -10,7 +10,7 @@ from xgboost import XGBRegressor
|
|||||||
|
|
||||||
from delta_barth.analysis import parse
|
from delta_barth.analysis import parse
|
||||||
from delta_barth.constants import COL_MAP_SALES_PROGNOSIS, FEATURES_SALES_PROGNOSIS
|
from delta_barth.constants import COL_MAP_SALES_PROGNOSIS, FEATURES_SALES_PROGNOSIS
|
||||||
from delta_barth.errors import STATE_HANDLER
|
from delta_barth.errors import STATUS_HANDLER
|
||||||
from delta_barth.types import CustomerDataSalesForecast, DataPipeStates, PipeResult
|
from delta_barth.types import CustomerDataSalesForecast, DataPipeStates, PipeResult
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -103,7 +103,7 @@ def sales_per_customer(
|
|||||||
|
|
||||||
# check data availability
|
# check data availability
|
||||||
if len(df_cust) < min_num_data_points:
|
if len(df_cust) < min_num_data_points:
|
||||||
return PipeResult(status=STATE_HANDLER.pipe_states.TOO_FEW_POINTS, data=None)
|
return PipeResult(status=STATUS_HANDLER.pipe_states.TOO_FEW_POINTS, data=None)
|
||||||
else:
|
else:
|
||||||
# Entwicklung der Umsätze: definierte Zeiträume Monat
|
# Entwicklung der Umsätze: definierte Zeiträume Monat
|
||||||
df_cust["year"] = df_cust["date"].dt.year
|
df_cust["year"] = df_cust["date"].dt.year
|
||||||
@ -142,4 +142,4 @@ def sales_per_customer(
|
|||||||
test = test.reset_index(drop=True)
|
test = test.reset_index(drop=True)
|
||||||
|
|
||||||
# umsetzung, prognose
|
# umsetzung, prognose
|
||||||
return PipeResult(status=STATE_HANDLER.pipe_states.SUCCESS, data=test)
|
return PipeResult(status=STATUS_HANDLER.pipe_states.SUCCESS, data=test)
|
||||||
|
|||||||
@ -7,9 +7,8 @@ import requests
|
|||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from requests import Response
|
from requests import Response
|
||||||
|
|
||||||
from delta_barth.constants import HTTP_BASE_CONTENT_HEADERS
|
|
||||||
from delta_barth.errors import (
|
from delta_barth.errors import (
|
||||||
STATE_HANDLER,
|
STATUS_HANDLER,
|
||||||
UnspecifiedRequestType,
|
UnspecifiedRequestType,
|
||||||
)
|
)
|
||||||
from delta_barth.types import (
|
from delta_barth.types import (
|
||||||
@ -115,12 +114,12 @@ class Session:
|
|||||||
status: Status
|
status: Status
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
response = LoginResponse(**resp.json())
|
response = LoginResponse(**resp.json())
|
||||||
status = STATE_HANDLER.pipe_states.SUCCESS
|
status = STATUS_HANDLER.pipe_states.SUCCESS
|
||||||
self._add_session_token(response.token)
|
self._add_session_token(response.token)
|
||||||
else:
|
else:
|
||||||
response = LoginResponse(token="")
|
response = LoginResponse(token="")
|
||||||
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
||||||
status = STATE_HANDLER.api_error(err)
|
status = STATUS_HANDLER.api_error(err)
|
||||||
|
|
||||||
return response, status
|
return response, status
|
||||||
|
|
||||||
@ -138,11 +137,11 @@ class Session:
|
|||||||
response = None
|
response = None
|
||||||
status: Status
|
status: Status
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
status = STATE_HANDLER.SUCCESS
|
status = STATUS_HANDLER.SUCCESS
|
||||||
self._remove_session_token()
|
self._remove_session_token()
|
||||||
else:
|
else:
|
||||||
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
||||||
status = STATE_HANDLER.api_error(err)
|
status = STATUS_HANDLER.api_error(err)
|
||||||
|
|
||||||
return response, status
|
return response, status
|
||||||
|
|
||||||
@ -172,14 +171,14 @@ class Session:
|
|||||||
# TODO use to check for catching unknown exceptions
|
# TODO use to check for catching unknown exceptions
|
||||||
# response = LoginResponse(**resp.json())
|
# response = LoginResponse(**resp.json())
|
||||||
response = LoginResponse(token=self.session_token)
|
response = LoginResponse(token=self.session_token)
|
||||||
status = STATE_HANDLER.SUCCESS
|
status = STATUS_HANDLER.SUCCESS
|
||||||
elif resp.status_code == 401:
|
elif resp.status_code == 401:
|
||||||
self._remove_session_token()
|
self._remove_session_token()
|
||||||
response, status = self.login()
|
response, status = self.login()
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
response = LoginResponse(token="")
|
response = LoginResponse(token="")
|
||||||
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
||||||
status = STATE_HANDLER.api_error(err)
|
status = STATUS_HANDLER.api_error(err)
|
||||||
|
|
||||||
return response, status
|
return response, status
|
||||||
|
|
||||||
|
|||||||
@ -7,7 +7,7 @@ import requests
|
|||||||
from pydantic import BaseModel, PositiveInt, SkipValidation
|
from pydantic import BaseModel, PositiveInt, SkipValidation
|
||||||
|
|
||||||
from delta_barth.api.common import combine_route
|
from delta_barth.api.common import combine_route
|
||||||
from delta_barth.errors import STATE_HANDLER
|
from delta_barth.errors import STATUS_HANDLER
|
||||||
from delta_barth.types import DelBarApiError, Status
|
from delta_barth.types import DelBarApiError, Status
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -55,10 +55,10 @@ def get_sales_prognosis_data(
|
|||||||
status: Status
|
status: Status
|
||||||
if resp.status_code == 200:
|
if resp.status_code == 200:
|
||||||
response = SalesPrognosisResponse(**resp.json())
|
response = SalesPrognosisResponse(**resp.json())
|
||||||
status = STATE_HANDLER.SUCCESS
|
status = STATUS_HANDLER.SUCCESS
|
||||||
else:
|
else:
|
||||||
response = SalesPrognosisResponse(daten=tuple())
|
response = SalesPrognosisResponse(daten=tuple())
|
||||||
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
err = DelBarApiError(status_code=resp.status_code, **resp.json())
|
||||||
status = STATE_HANDLER.api_error(err)
|
status = STATUS_HANDLER.api_error(err)
|
||||||
|
|
||||||
return response, status
|
return response, status
|
||||||
|
|||||||
@ -147,4 +147,4 @@ class StatusHandler:
|
|||||||
raise _construct_exception(UApiError, descr, msg, add_info)
|
raise _construct_exception(UApiError, descr, msg, add_info)
|
||||||
|
|
||||||
|
|
||||||
STATE_HANDLER: Final[StatusHandler] = StatusHandler()
|
STATUS_HANDLER: Final[StatusHandler] = StatusHandler()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user