Add typed category route metadata
This commit is contained in:
+77
-17
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from typing import Any
|
||||
|
||||
try:
|
||||
@@ -63,7 +64,41 @@ def cast_count_adjustment(
|
||||
}
|
||||
|
||||
|
||||
def select_category_item_route(
|
||||
@dataclass(frozen=True)
|
||||
class CategoryItemRoute:
|
||||
category: dict[str, Any]
|
||||
subcategory: dict[str, Any]
|
||||
women_count: int
|
||||
men_count: int
|
||||
count_adjustment: dict[str, int]
|
||||
content_axis: str
|
||||
item: Any
|
||||
item_text: str
|
||||
item_name: str
|
||||
item_axis_values: dict[str, Any]
|
||||
item_template_metadata: dict[str, Any]
|
||||
formatter_hints: dict[str, Any]
|
||||
is_pose_category: bool
|
||||
|
||||
def as_dict(self) -> dict[str, Any]:
|
||||
return {
|
||||
"category": self.category,
|
||||
"subcategory": self.subcategory,
|
||||
"women_count": self.women_count,
|
||||
"men_count": self.men_count,
|
||||
"count_adjustment": dict(self.count_adjustment),
|
||||
"content_axis": self.content_axis,
|
||||
"item": self.item,
|
||||
"item_text": self.item_text,
|
||||
"item_name": self.item_name,
|
||||
"item_axis_values": dict(self.item_axis_values),
|
||||
"item_template_metadata": dict(self.item_template_metadata),
|
||||
"formatter_hints": dict(self.formatter_hints),
|
||||
"is_pose_category": self.is_pose_category,
|
||||
}
|
||||
|
||||
|
||||
def select_category_item_route_result(
|
||||
*,
|
||||
category_choice: str,
|
||||
subcategory_choice: str,
|
||||
@@ -74,7 +109,7 @@ def select_category_item_route(
|
||||
men_count: int,
|
||||
hardcore_position_config: dict[str, Any] | None = None,
|
||||
categories: list[dict[str, Any]] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
) -> CategoryItemRoute:
|
||||
source_categories = category_policy.load_category_library() if categories is None else categories
|
||||
parsed_hardcore_position_config = hardcore_position_config or {}
|
||||
requested_women_count = women_count
|
||||
@@ -126,18 +161,43 @@ def select_category_item_route(
|
||||
item_text = sanitize_hardcore_environment_anchors(item_text)
|
||||
item_axis_values = sanitize_hardcore_axis_values(item_axis_values)
|
||||
|
||||
return {
|
||||
"category": category,
|
||||
"subcategory": subcategory,
|
||||
"women_count": women_count,
|
||||
"men_count": men_count,
|
||||
"count_adjustment": count_adjustment,
|
||||
"content_axis": content_axis,
|
||||
"item": item,
|
||||
"item_text": item_text,
|
||||
"item_name": item_name,
|
||||
"item_axis_values": item_axis_values,
|
||||
"item_template_metadata": item_template_metadata,
|
||||
"formatter_hints": template_policy.formatter_hints(item_template_metadata),
|
||||
"is_pose_category": is_pose_category,
|
||||
}
|
||||
return CategoryItemRoute(
|
||||
category=category,
|
||||
subcategory=subcategory,
|
||||
women_count=women_count,
|
||||
men_count=men_count,
|
||||
count_adjustment=count_adjustment,
|
||||
content_axis=content_axis,
|
||||
item=item,
|
||||
item_text=item_text,
|
||||
item_name=item_name,
|
||||
item_axis_values=item_axis_values,
|
||||
item_template_metadata=item_template_metadata,
|
||||
formatter_hints=template_policy.formatter_hints(item_template_metadata),
|
||||
is_pose_category=is_pose_category,
|
||||
)
|
||||
|
||||
|
||||
def select_category_item_route(
|
||||
*,
|
||||
category_choice: str,
|
||||
subcategory_choice: str,
|
||||
seed_config: dict[str, int],
|
||||
seed: int,
|
||||
row_number: int,
|
||||
women_count: int,
|
||||
men_count: int,
|
||||
hardcore_position_config: dict[str, Any] | None = None,
|
||||
categories: list[dict[str, Any]] | None = None,
|
||||
) -> dict[str, Any]:
|
||||
return select_category_item_route_result(
|
||||
category_choice=category_choice,
|
||||
subcategory_choice=subcategory_choice,
|
||||
seed_config=seed_config,
|
||||
seed=seed,
|
||||
row_number=row_number,
|
||||
women_count=women_count,
|
||||
men_count=men_count,
|
||||
hardcore_position_config=hardcore_position_config,
|
||||
categories=categories,
|
||||
).as_dict()
|
||||
|
||||
Reference in New Issue
Block a user