Note that there are some explanatory texts on larger screens.

plurals
  1. POCSV, Searching A String, Get Proper Information, Writing Correct Info In Correct Format
    primarykey
    data
    text
    <p>I'm relatively new to stack overflow, so please bear with me. I, additionally, apologize for the title and any ambiguity, etc.</p> <p>So, here's what I'm trying to do:</p> <p>I'm taking a raw data file, in .CSV format, which contains plays for NBA games for an entire season.</p> <p>The code, based on the game, creates a new file with the appropriate title for the game. It, then, reads each line. </p> <p>Each line contains the game id, the line number (irrelevant), the time remaining, and the 'play info'.</p> <p>I have included an example below (Example 1). </p> <p>The information that needs to be written, which is found below (Example 2), has the 10 players on the court for:</p> <ul> <li>the time the play was recorded</li> <li>the period</li> <li>the time remaining in the period</li> <li>the event type</li> <li>if there is an assist</li> <li>the player credited with the assist</li> <li>if there is a foul</li> <li>the person who was fouled</li> </ul> <p>etc. </p> <p>The 'player' heading designates for whom the initial play was recorded (ie. if a a player made a 'shot' that players name is recorded). The team, for which the play was recorded, is also written.</p> <p>Example 1:</p> <pre><code>GameID, LineNumber, TimeRemaining, Entry 20071030HOULAL, 1, 0:48:00, Start of 1st Quarter 20071030HOULAL, 2, 0:48:00, Jump Ball Brown vs Yao 20071030HOULAL, 3, 0:47:42, [LAL] Walton Jump Shot: Missed 20071030HOULAL, 4, 0:47:41, [LAL] Brown Rebound (Off:1 Def:0) 20071030HOULAL, 5, 0:47:29, [LAL] Bryant Jump Shot: Missed 20071030HOULAL, 6, 0:47:28, [HOU] Alston Rebound (Off:0 Def:1) 20071030HOULAL, 7, 0:47:06, [HOU] Yao Jump Shot: Missed </code></pre> <p>Example 2:</p> <pre><code>a1(away),a2(away), a3(away), a4, a5, h1, h2, h3, h4, h5, period,time,team, etype, assist, away, block, entered, home, left, num, opponent, outof, player, points,possession, reason, result, steal </code></pre> <p>(represents the values stored for each row in the csv file - too confusing to try to include sample data)</p> <p>The problem is this:</p> <p>For each team, there's a player roster. My code gets the player roster, and then creates a roster using only the players' last name, (that's how the player name is recorded.)</p> <p>The first problem arises when accumulating all 10 players for each team, who are on the court.</p> <p>I use an accumulator to store the play data until all 10 players are recorded, and then write the play data, adding in the 10 players.</p> <p>The problem is some players get 'skipped', when the checks are performed on the variables designated as players being on the court.</p> <p>For instance, there is a play recorded for Luther Head, who plays for Houston, but he never gets recorded to <code>a1, a2, a3, a4</code> or <code>a5</code> (The away team for the current game).</p> <p>Here is how I have the "checks" set up, with <code>firstPlayer</code> being the person the play was recorded for and <code>secondPlayer</code> being an additional player that, for example an assist, was recorded for:</p> <pre><code>if team == homeTeam: if h1 == ' ' and firstPlayer != h2 and firstPlayer != h3 and firstPlayer != h4 and firstPlayer != h5: h1 = firstPlayer if h2 == ' ' and firstPlayer != h1 and firstPlayer != h3 and firstPlayer != h4 and firstPlayer != h5: h2 = firstPlayer if h3 == ' ' and firstPlayer != h1 and firstPlayer != h2 and firstPlayer != h4 and firstPlayer != h5: h3 = firstPlayer if h4 == ' ' and firstPlayer != h1 and firstPlayer != h2 and firstPlayer != h3 and firstPlayer != h5: h4 = firstPlayer if h5 == ' ' and firstPlayer != h1 and firstPlayer != h2 and firstPlayer != h3 and firstPlayer != h4: h5 = firstPlayer if team == visitingTeam: if a1 == ' ' and firstPlayer != a2 and firstPlayer != a3 and firstPlayer != a4 and firstPlayer != a5: a1 = firstPlayer if a2 == ' ' and firstPlayer != a1 and firstPlayer != a3 and firstPlayer != a4 and firstPlayer != a5: a2 = firstPlayer if a3 == ' ' and firstPlayer != a1 and firstPlayer != a2 and firstPlayer != a4 and firstPlayer != a5: a3 = firstPlayer if a4 == ' ' and firstPlayer != a1 and firstPlayer != a2 and firstPlayer != a3 and firstPlayer != a5: a4 = firstPlayer if a5 == ' ' and firstPlayer != a1 and firstPlayer != a2 and firstPlayer != a3 and firstPlayer != a4: a5 = firstPlayer if etype != 'sub': &lt;&lt;&lt;&lt;----This type of event is diffent if team == homeTeam and secondPlayer != ' ': if h1 == ' ' and secondPlayer != h2 and secondPlayer != h3 and secondPlayer != h4 and secondPlayer != h5: h1 = secondPlayer if h2 == ' ' and secondPlayer != h1 and secondPlayer != h3 and secondPlayer != h4 and secondPlayer != h5: h2 = secondPlayer if h3 == ' ' and secondPlayer != h1 and secondPlayer != h2 and secondPlayer != h4 and secondPlayer != h5: h3 = secondPlayer if h4 == ' ' and secondPlayer != h1 and secondPlayer != h2 and secondPlayer != h3 and secondPlayer != h5: h4 = secondPlayer if h5 == ' ' and secondPlayer != h1 and secondPlayer != h2 and secondPlayer != h3 and secondPlayer != h4: h5 = secondPlayer if team == visitingTeam and secondPlayer != ' ': if a1 == ' ' and secondPlayer != a2 and secondPlayer != a3 and secondPlayer != a4 and secondPlayer != a5: a1 = secondPlayer if a2 == ' ' and secondPlayer != a1 and secondPlayer != a3 and secondPlayer != a4 and secondPlayer != a5: a2 = secondPlayer if a3 == ' ' and secondPlayer != a1 and secondPlayer != a2 and secondPlayer != a4 and secondPlayer != a5: a3 = secondPlayer if a4 == ' ' and secondPlayer != a1 and secondPlayer != a2 and secondPlayer != a3 and secondPlayer != a5: a4 = secondPlayer if a5 == ' ' and secondPlayer != a1 and secondPlayer != a2 and secondPlayer != a3 and secondPlayer != a4: a5 = secondPlayer </code></pre> <p>I guess that is really the only problem I have.</p> <p>Although, I would like to find a better way to search the string and obtain the information.</p> <p>To obtain the players, I allocate the first half of the string to one variable and the second half to another. Then I split the string <code>(sep = ' ')</code>, so it's in a list. </p> <p>Then I check each string to see if a word is <code>==</code> to any of the players in the roster, depending on which team the play was recorded for.</p> <p>If it's the first string, that player gets assigned the <code>firstPlayer</code> variable, if it's the second, that player gets assigned the <code>secondPlayer</code> variable.</p> <p>When I search for the <code>etype</code> (event type), I just search the string with expressions like:</p> <pre><code>if 'Shot' in string: etype = 'shot' player = firstPlayer if 'Assist' in string: assist = secondPlayer </code></pre> <p>...and so on for the various event types.</p> <p>Please let me know if you need additional info to help answer this question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload