88from pydantic import BaseModel
99from pyfirebase_mapswipe import models as firebase_models
1010from shapely import to_wkt
11- from shapely .geometry .point import Point
1211from ulid import ULID
1312
1413from apps .common .models import AssetMimetypeEnum , AssetTypeEnum
2221)
2322from main .bulk_managers import BulkCreateManager
2423from project_types .base import project as base_project
25- from project_types .street .api_calls import StreetRawGroupItem , get_image_metadata
24+ from project_types .street .api_calls import StreetFeature , get_image_metadata
2625from utils import fields as custom_fields
27- from utils .common import create_json_dump
26+ from utils .common import Grouping , create_json_dump
2827from utils .custom_options .models import CustomOption
2928
3029logger = logging .getLogger (__name__ )
@@ -59,8 +58,8 @@ class StreetProject(
5958 StreetProjectProperty ,
6059 StreetTaskGroupProperty ,
6160 StreetTaskProperty ,
62- StreetRawGroupItem ,
63- list [ tuple [ int , Point ] ],
61+ Grouping [ StreetFeature ] ,
62+ Grouping [ StreetFeature ],
6463 ],
6564):
6665 project_property_class = StreetProjectProperty
@@ -73,7 +72,7 @@ def __init__(self, project: Project):
7372 assert project .project_type == ProjectTypeEnum .STREET , f"{ type (self )} is defined for STREET"
7473
7574 @typing .override
76- def validate (self ) -> StreetRawGroupItem :
75+ def validate (self ) -> Grouping [ StreetFeature ] :
7776 """Validate project before creating groups."""
7877 self .project .update_processing_status (Project .ProcessingStatus .VALIDATING_GEOMETRY , True )
7978
@@ -105,13 +104,14 @@ def create_tasks(
105104 self ,
106105 / ,
107106 group : ProjectTaskGroup ,
108- raw_group : list [ tuple [ int , Point ] ],
107+ raw_group : Grouping [ StreetFeature ],
109108 ) -> int :
110109 """Create tasks for a group."""
111110 bulk_mgr = BulkCreateManager (chunk_size = 1000 )
112111 tasks_count = 0
112+ features = list (zip (raw_group ["feature_ids" ], raw_group ["features" ], strict = True ))
113113
114- for f_id , feature in raw_group :
114+ for f_id , feature in features :
115115 geometry_str = to_wkt (feature )
116116
117117 bulk_mgr .add (
@@ -131,17 +131,18 @@ def create_tasks(
131131 return tasks_count
132132
133133 @typing .override
134- def create_groups (self , resp : StreetRawGroupItem ):
134+ def create_groups (self , resp : Grouping [ StreetFeature ] ):
135135 self .project .update_processing_status (Project .ProcessingStatus .GENERATING_GROUPS_AND_TASKS , True )
136- number_of_groups = math .ceil (len (resp ["ids " ]) / self .project .group_size )
136+ number_of_groups = math .ceil (len (resp ["feature_ids " ]) / self .project .group_size )
137137
138138 for group_id in range (number_of_groups ):
139139 start_index = group_id * self .project .group_size
140140 end_index = start_index + self .project .group_size
141141
142- group_features = resp ["geometries" ][start_index :end_index ]
143- group_feature_ids = resp ["ids" ][start_index :end_index ]
144- features = list (zip (group_feature_ids , group_features , strict = True ))
142+ features = Grouping [StreetFeature ](
143+ feature_ids = resp ["feature_ids" ][start_index :end_index ],
144+ features = resp ["features" ][start_index :end_index ],
145+ )
145146 new_group = ProjectTaskGroup .objects .create (
146147 firebase_id = f"g{ group_id } " ,
147148 project_id = self .project .pk ,
@@ -153,7 +154,10 @@ def create_groups(self, resp: StreetRawGroupItem):
153154 )
154155
155156 # Create new tasks for this group
156- total_tasks = self .create_tasks (new_group , features )
157+ total_tasks = self .create_tasks (
158+ group = new_group ,
159+ raw_group = features ,
160+ )
157161 logger .info ("Created %s tasks for group: %s" , total_tasks , new_group .pk )
158162
159163 @typing .override
0 commit comments