Mathober2023_Counting

Mathober2023_Counting

Counting TurnOvers

PassUnCount

For the 8th Prompt Of Mathober: Counting, PassUnCount takes Python Data Scraping and SonicPi Sonification to Sort and Count NCAA Assist Leaders who also turn the ball over. Then some tweaking and layering was done.

Poem

Wanting to Make the Pass
But it didn't Make it Through
Try and Try Again
But The Results Don’t Seem to Blend
As the Dribbles Go Fast
And the Squeaks can be Heard From the Shoes
What Pass Selection Do You Choose,
To Finally Make it Through

Audio

IllestPreacha · PassUnCount.MP3

Code

Python - WebScraping and Data Sorting

import sys
import pandas as pd

#turning the cbssports NCAA Assist Page into a Data Frame
NCAA_APG = pd.read_html('https://www.cbssports.com/college-basketball/stats/player/assists-turnovers/all-conf/all-pos/leaders/?sortdir=descending&sortcol=apg')

#NCAA PPG list into DataFrame
NCAA_APG_DF = NCAA_APG[0] 

# get the names of the columns
NCAA_APG_DF.columns

#players that have a higher A/TO than 3
NCAA_APG_Eff = NCAA_APG_DF.loc[(NCAA_APG_DF['A/TO  Assists Per Turnover'] > 3)]

#players that have a lower A/TO than 3
NCAA_APG_Not_Eff = NCAA_APG_DF.loc[(NCAA_APG_DF['A/TO  Assists Per Turnover'] < 3)]

#sorting it based on the assist turnover
NCAA_APG_Eff.sort_values(by=['A/TO  Assists Per Turnover', 'APG  Assists Per Game'], ascending=False)

Python Code - Timer that Speaks to SonicPi

import time
import random as rd
import math

#osc module to communicate with sonic
from pythonosc import osc_message_builder
from pythonosc import udp_client


def ncaa(t): #take in the value t
     print('\n' + str(NCAA_APG_Not_Eff['TO  Turnovers'].iloc[t]))    #print the turnover amount per every two seconds 

def countdown(t):
    while t:
        mins, secs = divmod(t, 60)
        timer = '{:02d}:{:02d}'.format(mins, secs)
        print(timer, end="\r")
        time.sleep(1)

        if t % 1 == 0:
           ncaa(t)

        sender = udp_client.SimpleUDPClient('127.0.0.1', 4560)
        sender.send_message('/pattern1', [int(NCAA_APG_Not_Eff['TO  Turnovers'].iloc[t]),rd.randint(54,79)])
        t -= 1


# input time in seconds
t = input("Enter the time in seconds: ")

# function call
countdown(int(t))

SonicPi

live_loop :phase1 do
  use_real_time
  a, b, c, d = sync "/osc*/pattern1"
  with_fx :flanger, mix: rrand(0.1,0.9) do
    use_synth [:beep,:bnoise,:saw,:piano,:piano,:piano].choose
    play a
  end
end