Skip to content

Commit

Permalink
display res
Browse files Browse the repository at this point in the history
  • Loading branch information
mahithapen committed Dec 3, 2023
1 parent 03bc5a0 commit 790fb73
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions src/view/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import pandas as pd
import requests
import zipfile
import json
import shutil

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
Expand Down Expand Up @@ -228,42 +227,58 @@ def parse_file_for_correct_section(file_path, start_marker):
return data

# Define the specific start marker
start_marker = "'players': {'player_1': {'frames':"
start_marker = "{'player_1': {'frames':"

# Parse the file for the specific section starting at the defined marker
parsed_correct_section = parse_file_for_correct_section(st.session_state.result_string_path, start_marker)

def extract_player_team_stats(data_str):
# Initialize variables to hold formatted data as strings
formatted_players = ""
formatted_teams = ""
formatted_team1 = ""
formatted_team2 = ""
current_team = None

# Splitting the string into lines
lines = data_str.split(',')

# Process each line
for line in lines:
# Check and format player data
if any(key in line for key in ['frames', 'field_goals_attempted', 'field_goals', 'points', 'field_goal_percentage']):

if "'team1'" in line:
current_team = 'team1'
elif "'team2'" in line:
current_team = 'team2'
if any(key in line for key in ['frames']):
line = line.replace("{", "").replace("}", "").replace("'", "")
formatted_players +="\n"+ line.strip() + "\n"
if any(key in line for key in ['field_goals_attempted', 'field_goals', 'points', 'field_goal_percentage']):
line = line.replace("{", "").replace("}", "").replace("'", "")
formatted_players += line.strip() + "\n"

# Check and format team data

elif any(key in line for key in ['shots_attempted', 'shots_made', 'points', 'field_goal_percentage']):
formatted_teams += line.strip() + "\n"
line = line.replace("{", "").replace("}", "").replace("'", "").strip()
if current_team == 'team1':
formatted_team1 += line + "\n"
elif current_team == 'team2':
formatted_team2 += line + "\n"
if "ball:" in formatted_players:
formatted_players = formatted_players.split("ball:")[0]

return formatted_players, formatted_teams
return formatted_players, formatted_team1, formatted_team2

# Sample usage with the parsed_correct_section string
formatted_players, formatted_teams = extract_player_team_stats(parsed_correct_section)
formatted_players, formatted_team1, formatted_team2 = extract_player_team_stats(parsed_correct_section)

def display_stats():
# Display player statistics
st.markdown("### Player Statistics")
st.text(formatted_players)

# Display team statistics
st.markdown("### Team Statistics")
st.text(formatted_teams)
st.markdown("### Team 1 Statistics")
st.text(formatted_team1)

st.markdown("### Team 2 Statistics")
st.text(formatted_team2)

# Call the function in your Streamlit app


# Call the function in your Streamlit app
display_stats()
Expand Down

0 comments on commit 790fb73

Please sign in to comment.