Spaces:
No application file
No application file
Download src/common/data/matches.py from metasoccer/collab: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/spaces/metasoccer/collab/resolve/main/src/common/data/matches.py
- Command line
-
hf download hf://spaces/metasoccer/collab/src/common/data/matches.py
-
curl -L -o matches.py https://huggingface.co/spaces/metasoccer/collab/resolve/main/src/common/data/matches.py
1.66 kB
| from common.data.pvp_tournament import get_editions_by_name | |
| from common.dbconn.metasoccer import execute_query as execute_metasoccer_query | |
| from common.dbconn.retool import execute_query as execute_retool_query | |
| def get_matches(tournament = None, edition = None, start = None, end = None): | |
| edition_by_name = get_editions_by_name(tournament) | |
| if edition is not None and edition_by_name[edition] is not None: | |
| tournament_edition_id = edition_by_name[edition]['tournament_edition_id'] | |
| try: | |
| second_query = f"SELECT unnest(match_ids) FROM pvp_tournament_groups WHERE tournament_edition_id = '{tournament_edition_id}'" | |
| competition_match_ids = execute_metasoccer_query(second_query)['unnest'].tolist() | |
| print("Match IDs fetched successfully") | |
| except Exception as e: | |
| print(f"Error fetching match IDs: {e}") | |
| else: | |
| competition_match_ids = None | |
| if start and end: | |
| query = f""" | |
| SELECT * | |
| FROM mourinho_matches | |
| WHERE datetime BETWEEN '{start}' AND '{end}' | |
| """ | |
| else: | |
| query = "SELECT * FROM mourinho_matches WHERE 1=1" | |
| if competition_match_ids is not None and len(competition_match_ids) > 0: | |
| competition_match_ids_str = "','".join(competition_match_ids) | |
| query += f" AND match_id IN ('{competition_match_ids_str}')" | |
| return execute_retool_query(query) | |
| def get_matches_summaries(edition): | |
| query = f""" | |
| select * from match_summaries | |
| where summary->>'matchId' in ( | |
| SELECT unnest(match_ids) FROM pvp_tournament_groups WHERE tournament_edition_id = '{edition}' | |
| ) | |
| and summary->>'type' in ('Played') | |
| """ | |
| return execute_metasoccer_query(query) |