Skip to content

Commit

Permalink
fully completed code with display
Browse files Browse the repository at this point in the history
  • Loading branch information
wolff01 committed May 3, 2024
1 parent c42d3f4 commit 6b39834
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Project Prototype

TODO: The result of your work will be the delivery of some type of proof-of-concept prototype which will likely contain software programming solutions (i.e., Python code, HTML pages, or similar). All source code for the prototype must be stored in this directory. If your prototype uses data, please create `data/` subdirectory in `src/` and include your data file(s) in `src/data/` directory.
The result of your work will be the delivery of some type of proof-of-concept prototype which will likely contain software programming solutions (i.e., Python code, HTML pages, or similar). All source code for the prototype must be stored in this directory. If your prototype uses data, please create `data/` subdirectory in `src/` and include your data file(s) in `src/data/` directory.

To allow the user to experience and execute your prototype, you must first explain how to set up the initial conditions to run or use the artifact. Be sure to offer explicit details and instructions regarding the installation of the necessary foundational libraries, drivers, external software projects, containers and similar types of tertiary software which are involved in executing your artifact. Once these initial software installations have been completed, then you are asked to offer the necessary instructions for actually executing the artifact. For this, please provide all command line parameters or associated bash commands for execution. Please remember that users are unwilling to "figure-out" how to use code in absence of the essential instructions concerning the execution of project artifacts.

## Key Features

TODO: Outline the main technical features of your prototype.
The code in the prototype consists of

## Requirements

Expand Down
6 changes: 3 additions & 3 deletions src/data.csv
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"Gurriel Jr., Lourdes","666971","2023","450",".353",".46","333","755"
"Ruiz, Keibert","660688","2023","467",".394",".319","354","610"
"Riley, Austin","663586","2023","475",".352",".492","399","978"
"Canha, Mark","592192","2023","362","30.9","36.7","246","621"
"Canha, Mark","592192","2023","362",".309",".367","246","621"
"Rooker Jr., Brent","667670","2023","295",".373",".495","304","687"
"Profar, Jurickson","595777","2023","374",".377",".318","262","731"
"Hayes, Ke'Bryan","663647","2023","393",".341",".483","301","578"
Expand All @@ -114,7 +114,7 @@
"Lindor, Francisco","596019","2023","472",".358",".439","387","929"
"Thomas, Lane","657041","2023","459",".368",".407","369","776"
"Schwarber, Kyle","656941","2023","373",".343",".488","351","805"
"Hernández, Enrique","571771","2023","374",."31",".337","278","640"
"Hernández, Enrique","571771","2023","374",".31",".337","278","640"
"De La Cruz, Bryan","650559","2023","442",".41",".425","453","782"
"Betts, Mookie","605141","2023","482",".425",".485","230","803"
"Nimmo, Brandon","607043","2023","451",".335",".479","267","939"
Expand All @@ -132,4 +132,4 @@
"Tucker, Kyle","663656","2023","492",".354",".459","274","934"
"Báez, Javier","595879","2023","389",".289",".397","480","591"
"Straw, Myles","664702","2023","377",".34",".233","210","667"
"Volpe, Anthony","683011","2023","377",.355",".43","335","784"
"Volpe, Anthony","683011","2023","377",".355",".43","335","784"
73 changes: 52 additions & 21 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,79 @@
import csv
import streamlit as st
import pandas as pd

def sum_csv_part(filename, start_row, end_row, start_col, end_col):
with open(filename, 'r') as file:
csv_reader = csv.reader(file)
data = list(csv_reader)

# Ensure start_row and end_row are within the range of rows
start_row = max(0, min(start_row, len(data)-1))
end_row = max(start_row, min(end_row, len(data)-1))

# Ensure start_col and end_col are within the range of columns
start_col = max(0, min(start_col, len(data[0])-1))
end_col = max(start_col, min(end_col, len(data[0])-1))

sums = []
for i in range(start_row, end_row + 1):
row_sum = 0 # Initialize sum variable for each row
for j in range(start_col, end_col + 1):
try:
row_sum += float(data[i][j]) # Accumulate values for each row
except ValueError:
print("ValueError: Invalid literal for float():", data[i][j])
print("Sum of values in row", i+1, ":", row_sum)
row_sum = sum(float(data[i][j]) for j in range(start_col, end_col + 1))
sums.append(row_sum)
return sums

def multiply_csv_part(filename, start_row, end_row, start_col, end_col):
with open(filename, 'r') as file:
csv_reader = csv.reader(file)
data = list(csv_reader)

# Ensure start_row and end_row are within the range of rows
start_row = max(0, min(start_row, len(data)-1))
end_row = max(start_row, min(end_row, len(data)-1))

# Ensure start_col and end_col are within the range of columns
start_col = max(0, min(start_col, len(data[0])-1))
end_col = max(start_col, min(end_col, len(data[0])-1))

products = []
for i in range(start_row, end_row + 1):
row_product = 1 # Initialize product variable for each row as 1
for j in range(start_col, end_col + 1):
try:
row_product *= float(data[i][j]) # Accumulate values for each row
except ValueError:
print("ValueError: Invalid literal for float():", data[i][j])
print("Product of values in row", i+1, ":", row_product)

sum_csv_part('data.csv', 1, 3, 6, 7)
multiply_csv_part('data.csv', 1, 3, 3, 4)
row_product = float(data[i][start_col]) * float(data[i][end_col])
products.append(row_product)
return products

def divide_csv_part(filename, start_row, end_row, start_col, end_col):
sums = sum_csv_part(filename, start_row, end_row, start_col, end_col)
products_1 = multiply_csv_part(filename, start_row, end_row, 3, 4)
products_2 = multiply_csv_part(filename, start_row, end_row, 3, 5)

division_results_1 = []
division_results_2 = []
for sum_val, prod_val in zip(sums, products_1):
if sum_val != 0:
division_results_2.append(prod_val / sum_val)
else:
division_results_2.append(float('NaN'))

for sum_val, prod_val in zip(sums, products_2):
if sum_val != 0:
division_results_1.append(prod_val / sum_val)
else:
division_results_1.append(float('NaN'))

st.title("Swing Efficiency %")

a = {'Names': print_csv_row_range(filename, 1, 135),'Swing Efficiency %': division_results_1}
df = pd.DataFrame.from_dict(a, orient='index')
df = df.transpose()

sort_column = st.selectbox('Select column to sort by:', df.columns)
df_sorted = df.sort_values(by=sort_column, ascending=False)

st.table(df_sorted)

def print_csv_row_range(filename, start_row_index, end_row_index):
with open(filename, 'r') as file:
csv_reader = csv.reader(file)
rows = list(csv_reader)
result = []
for row_index in range(start_row_index, min(end_row_index + 1, len(rows))):
result.append(rows[row_index][0]) # Exclude the last element of the row
return result


divide_csv_part('data.csv', 1, 135, 6, 7)

0 comments on commit 6b39834

Please sign in to comment.