77from orm_models import get_session , GraphNetSampleGroup
88
99
10- # ── Types ──
11-
1210BucketGroup = namedtuple (
1311 "BucketGroup" ,
1412 ["head_uid" , "op_seq" , "shapes" , "sample_type" , "all_uids_csv" ],
2018)
2119
2220
23- # ── Helpers ──
24-
25-
2621def _new_group_id ():
2722 return str (uuid_module .uuid4 ())
2823
@@ -51,9 +46,6 @@ def _print_stats(stats):
5146 print (f"\n Total: { total_records } records, { total_groups } groups." )
5247
5348
54- # ── Database Queries ──
55-
56-
5749class DB :
5850 def __init__ (self , path ):
5951 self .path = path
@@ -229,39 +221,24 @@ def _insert_groups(session, rows, policy):
229221 return stats
230222
231223
232- # ═══════════════════════════════════════════════════════════════════
233- # Main
234- # ═══════════════════════════════════════════════════════════════════
235-
236-
237- def main ():
238- parser = argparse .ArgumentParser (
239- description = "Generate graph_net_sample_groups (v1 + v2)"
240- )
241- parser .add_argument ("--db_path" , type = str , required = True )
242- parser .add_argument ("--num_dtypes" , type = int , default = 3 )
243- args = parser .parse_args ()
244-
245- db = DB (args .db_path )
224+ def generate_groups (db_path , num_dtypes = 3 ):
225+ """Generate sample groups and save to DB."""
226+ db = DB (db_path )
246227 db .connect ()
247- session = get_session (args .db_path )
248-
228+ session = get_session (db_path )
249229 all_stats = defaultdict (lambda : {"records" : 0 , "groups" : set ()})
250-
251230 try :
252- # V1
253231 buckets = query_bucket_groups (db )
254232 print (f"Bucket groups: { len (buckets )} " )
255233 v1 = _insert_groups (session , generate_v1_groups (buckets ), "bucket_policy_v1" )
256234 _merge_stats (all_stats , v1 )
257235
258- # V2
259236 candidates = query_v2_candidates (db )
260237 print (f"V2 candidates: { len (candidates )} " )
261238 if candidates :
262239 v2 = _insert_groups (
263240 session ,
264- generate_v2_groups (candidates , args . num_dtypes ),
241+ generate_v2_groups (candidates , num_dtypes ),
265242 "bucket_policy_v2" ,
266243 )
267244 _merge_stats (all_stats , v2 )
@@ -276,7 +253,17 @@ def main():
276253
277254 print ("=" * 60 )
278255 _print_stats (all_stats )
279- print ("\n Done!" )
256+ return all_stats
257+
258+
259+ def main ():
260+ parser = argparse .ArgumentParser (
261+ description = "Generate graph_net_sample_groups (v1 + v2)"
262+ )
263+ parser .add_argument ("--db_path" , type = str , required = True )
264+ parser .add_argument ("--num_dtypes" , type = int , default = 3 )
265+ args = parser .parse_args ()
266+ generate_groups (args .db_path , args .num_dtypes )
280267
281268
282269if __name__ == "__main__" :
0 commit comments