feat(chalice): changed empty insights categories handling
This commit is contained in:
parent
51249127fd
commit
197c7fc8d8
2 changed files with 5 additions and 22 deletions
|
|
@ -308,6 +308,10 @@ def query_click_rage_by_period(project_id, start_time, end_time, conn=None):
|
|||
|
||||
def fetch_selected(project_id, data: schemas_ee.GetInsightsSchema):
|
||||
output = {}
|
||||
if data.categories is None or len(data.categories) == 0:
|
||||
data.categories = []
|
||||
for v in schemas_ee.InsightCategories:
|
||||
data.categories.append(v)
|
||||
with ch_client.ClickHouseClient() as conn:
|
||||
if schemas_ee.InsightCategories.errors in data.categories:
|
||||
output[schemas_ee.InsightCategories.errors] = query_most_errors_by_period(project_id=project_id,
|
||||
|
|
|
|||
|
|
@ -51,17 +51,7 @@ class GetInsightsSchema(BaseModel):
|
|||
startTimestamp: int = Field(TimeUTC.now(-7))
|
||||
endTimestamp: int = Field(TimeUTC.now())
|
||||
# time_step: int = Field(default=3600)
|
||||
categories: List[InsightCategories] = Field(..., min_items=1)
|
||||
|
||||
# This is used to handle wrong values sent by the UI
|
||||
@root_validator(pre=True)
|
||||
def transform(cls, values):
|
||||
if values.get("categories") is None or len(values.get("categories")) == 0:
|
||||
values["categories"] = []
|
||||
for v in InsightCategories:
|
||||
values["categories"].append(v.value)
|
||||
|
||||
return values
|
||||
categories: List[InsightCategories] = Field(...)
|
||||
|
||||
class Config:
|
||||
alias_generator = schemas.attribute_to_camel_case
|
||||
|
|
@ -163,17 +153,6 @@ class CreateCardSchema(schemas.CreateCardSchema):
|
|||
def restrictions(cls, values):
|
||||
return values
|
||||
|
||||
# This is used to handle wrong values sent by the UI
|
||||
@root_validator(pre=True)
|
||||
def transform_ee(cls, values):
|
||||
if values.get("metricType") == schemas.MetricType.insights and (
|
||||
values.get("metricValue") is None or len(values.get("metricValue")) == 0):
|
||||
values["metricValue"] = []
|
||||
for v in InsightCategories:
|
||||
values["metricValue"].append(v.value)
|
||||
|
||||
return values
|
||||
|
||||
@root_validator
|
||||
def validator(cls, values):
|
||||
values = super().validator(values)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue