@@ -272,7 +272,7 @@ def get_team_info(entrant_dict):
272272 if not entrant_dict :
273273 return {"name" : "TBD" , "score" : 0 , "players" : []}
274274 e_id = entrant_dict .get ("entrantId" , 0 )
275- score = entrant_dict .get ("score" , 0 )
275+ score = entrant_dict .get ("score" ) or 0
276276 info = entrant_map .get (e_id , {"name" : "TBD" , "players" : []})
277277 return {"name" : info ["name" ], "score" : score , "players" : info ["players" ]}
278278
@@ -291,6 +291,72 @@ def get_team_info(entrant_dict):
291291 m ["visualNum" ] = i
292292 visual_match_map [i ] = m
293293
294+ raw_to_visual = {
295+ m .get ("matchNum" ): v_num for v_num , m in visual_match_map .items ()
296+ }
297+
298+ def find_src (my_entrant , other_entrant , srcs , fallback_idx = 0 ):
299+ """Return the entrantSources entry for my_entrant by matching entrantId."""
300+ my_id = (my_entrant or {}).get ("entrantId" , 0 )
301+ other_id = (other_entrant or {}).get ("entrantId" , 0 )
302+ if my_id != 0 :
303+ found = next ((s for s in srcs if s .get ("entrantId" ) == my_id ), None )
304+ if found :
305+ return found
306+ if other_id != 0 :
307+ found = next ((s for s in srcs if s .get ("entrantId" ) != other_id ), None )
308+ if found :
309+ return found
310+ return srcs [fallback_idx ] if len (srcs ) > fallback_idx else None
311+
312+ def resolve_name (entrant_dict , source_entry , depth = 0 ):
313+ name = get_team_info (entrant_dict )["name" ]
314+ if name not in ("TBD" , "BYE" ):
315+ return name
316+ if not source_entry or depth > 1 :
317+ return "TBD"
318+ raw_src = source_entry .get ("matchNum" )
319+ v_src = raw_to_visual .get (raw_src , raw_src )
320+ src = visual_match_map .get (v_src )
321+ if not src :
322+ return f"Waiting on Match #{ v_src } "
323+ srcs = src .get ("entrantSources" ) or []
324+ src_ea = find_src (src .get ("entrantA" ), src .get ("entrantB" ), srcs , 0 )
325+ src_eb = find_src (src .get ("entrantB" ), src .get ("entrantA" ), srcs , 1 )
326+ a = resolve_name (src .get ("entrantA" ), src_ea , depth + 1 )
327+ b = resolve_name (src .get ("entrantB" ), src_eb , depth + 1 )
328+ if "Waiting on" not in a and "Waiting on" not in b :
329+ a_score = src .get ("entrantA" , {}).get ("score" ) or 0
330+ b_score = src .get ("entrantB" , {}).get ("score" ) or 0
331+ return f"Waiting on Match #{ v_src } ({ a } { a_score } - { b_score } { b } )"
332+ return f"Waiting on Match #{ v_src } ({ a } vs { b } )"
333+
334+ def build_tbd_chain (source_entry ):
335+ if not source_entry :
336+ return ["→ No source match information available" ]
337+ raw_src = source_entry .get ("matchNum" )
338+ v_src = raw_to_visual .get (raw_src , raw_src )
339+ src_match = visual_match_map .get (v_src )
340+ if not src_match :
341+ return [f"→ Waiting on Match #{ v_src } " ]
342+ srcs = src_match .get ("entrantSources" ) or []
343+ src_ea = find_src (
344+ src_match .get ("entrantA" ), src_match .get ("entrantB" ), srcs , 0
345+ )
346+ src_eb = find_src (
347+ src_match .get ("entrantB" ), src_match .get ("entrantA" ), srcs , 1
348+ )
349+ a_name = resolve_name (src_match .get ("entrantA" ), src_ea , depth = 1 )
350+ b_name = resolve_name (src_match .get ("entrantB" ), src_eb , depth = 1 )
351+ if "Waiting on" not in a_name and "Waiting on" not in b_name :
352+ a_score = src_match .get ("entrantA" , {}).get ("score" ) or 0
353+ b_score = src_match .get ("entrantB" , {}).get ("score" ) or 0
354+ return [f"→ Match #{ v_src } : { a_name } { a_score } - { b_score } { b_name } " ]
355+ return [
356+ f"→ Match #{ v_src } [A]: { a_name } " ,
357+ f"→ Match #{ v_src } [B]: { b_name } " ,
358+ ]
359+
294360 current_match = visual_match_map .get (int (target_match_number ))
295361
296362 if not current_match :
@@ -301,6 +367,41 @@ def get_team_info(entrant_dict):
301367 team_a = get_team_info (current_match .get ("entrantA" ))
302368 team_b = get_team_info (current_match .get ("entrantB" ))
303369
370+ sources = current_match .get ("entrantSources" ) or []
371+ team_a_is_tbd = team_a ["name" ] in ("TBD" , "BYE" )
372+ team_b_is_tbd = team_b ["name" ] in ("TBD" , "BYE" )
373+
374+ def tbd_label (src_entry ):
375+ if not src_entry :
376+ return "TBD"
377+ raw = src_entry .get ("matchNum" )
378+ v = raw_to_visual .get (raw , raw )
379+ src_m = visual_match_map .get (v )
380+ if not src_m :
381+ return f"Waiting on Match #{ v } "
382+ srcs_m = src_m .get ("entrantSources" ) or []
383+ src_mea = find_src (src_m .get ("entrantA" ), src_m .get ("entrantB" ), srcs_m , 0 )
384+ src_meb = find_src (src_m .get ("entrantB" ), src_m .get ("entrantA" ), srcs_m , 1 )
385+ a_name = resolve_name (src_m .get ("entrantA" ), src_mea )
386+ b_name = resolve_name (src_m .get ("entrantB" ), src_meb )
387+ a_sc = src_m .get ("entrantA" , {}).get ("score" ) or 0
388+ b_sc = src_m .get ("entrantB" , {}).get ("score" ) or 0
389+ return f"Waiting on Match #{ v } [{ a_name } { a_sc } - { b_sc } { b_name } ]"
390+
391+ if team_a_is_tbd :
392+ src_a = find_src (
393+ current_match .get ("entrantA" ), current_match .get ("entrantB" ), sources , 0
394+ )
395+ team_a ["name" ] = tbd_label (src_a )
396+ team_a ["score" ] = None
397+
398+ if team_b_is_tbd :
399+ src_b = find_src (
400+ current_match .get ("entrantB" ), current_match .get ("entrantA" ), sources , 1
401+ )
402+ team_b ["name" ] = tbd_label (src_b )
403+ team_b ["score" ] = None
404+
304405 match_status = current_match .get ("status" , "unknown" )
305406
306407 # --- IMPROVED TIMING LOGIC ---
@@ -335,8 +436,30 @@ def get_team_info(entrant_dict):
335436 except Exception :
336437 pass
337438
338- team_a_history = []
339- team_b_history = []
439+ team_a_history = (
440+ build_tbd_chain (
441+ find_src (
442+ current_match .get ("entrantA" ),
443+ current_match .get ("entrantB" ),
444+ sources ,
445+ 0 ,
446+ )
447+ )
448+ if team_a_is_tbd
449+ else []
450+ )
451+ team_b_history = (
452+ build_tbd_chain (
453+ find_src (
454+ current_match .get ("entrantB" ),
455+ current_match .get ("entrantA" ),
456+ sources ,
457+ 1 ,
458+ )
459+ )
460+ if team_b_is_tbd
461+ else []
462+ )
340463
341464 for v_num , match in visual_match_map .items ():
342465 if str (v_num ) == str (target_match_number ):
@@ -353,7 +476,20 @@ def get_team_info(entrant_dict):
353476 is_pos_a = t_a_past ["name" ] == team_a ["name" ]
354477 opp_name = t_b_past ["name" ] if is_pos_a else t_a_past ["name" ]
355478
356- if opp_name .upper () not in ["BYE" , "TBD" ]:
479+ if opp_name .upper () == "TBD" :
480+ h_srcs = match .get ("entrantSources" ) or []
481+ opp_dict = (
482+ match .get ("entrantB" ) if is_pos_a else match .get ("entrantA" )
483+ )
484+ my_dict = (
485+ match .get ("entrantA" ) if is_pos_a else match .get ("entrantB" )
486+ )
487+ opp_src = find_src (opp_dict , my_dict , h_srcs )
488+ opp_label = resolve_name (opp_dict , opp_src )
489+ team_a_history .append (
490+ f"Match { v_num } : { team_a ['name' ]} vs { opp_label } "
491+ )
492+ elif opp_name .upper () != "BYE" :
357493 t_score = t_a_past ["score" ] if is_pos_a else t_b_past ["score" ]
358494 o_score = t_b_past ["score" ] if is_pos_a else t_a_past ["score" ]
359495 team_a_history .append (
@@ -368,7 +504,20 @@ def get_team_info(entrant_dict):
368504 is_pos_a = t_a_past ["name" ] == team_b ["name" ]
369505 opp_name = t_b_past ["name" ] if is_pos_a else t_a_past ["name" ]
370506
371- if opp_name .upper () not in ["BYE" , "TBD" ]:
507+ if opp_name .upper () == "TBD" :
508+ h_srcs = match .get ("entrantSources" ) or []
509+ opp_dict = (
510+ match .get ("entrantB" ) if is_pos_a else match .get ("entrantA" )
511+ )
512+ my_dict = (
513+ match .get ("entrantA" ) if is_pos_a else match .get ("entrantB" )
514+ )
515+ opp_src = find_src (opp_dict , my_dict , h_srcs )
516+ opp_label = resolve_name (opp_dict , opp_src )
517+ team_b_history .append (
518+ f"Match { v_num } : { team_b ['name' ]} vs { opp_label } "
519+ )
520+ elif opp_name .upper () != "BYE" :
372521 t_score = t_a_past ["score" ] if is_pos_a else t_b_past ["score" ]
373522 o_score = t_b_past ["score" ] if is_pos_a else t_a_past ["score" ]
374523 team_b_history .append (
0 commit comments