Skip to content

ricLuo/Python_Test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python_Test

Terminology

  1. Subject: A field that is grouped on; analogous to SQL's "GROUP BY"
    clause.
  2. Split: A filter used to restrict a dataset; analogous to SQL's "WHERE"
    clause.
    • vs LHH: "versus left-handed hitters"
    • vs RHH: "versus right-handed hitters"
    • vs LHP: "versus left-handed pitchers"
    • vs RHP: "versus right-handed pitchers"
  3. Stat: A metric that is calculated from the aggregated data. There are
    four basic stats to be calculated that should be familiar to any baseball fan.
    • AVG
    • OBP
    • SLG
    • OPS

Instructions

  1. Create a GitLab account (if you don't already have one).
  2. Clone this repository to your machine.
  3. Install it using pip install -r requirements.txt
  4. Modify run.py to perform the following steps when called via python run.py:
    1. Read in ./data/raw/pitchdata.csv
    2. Perform grouping/aggregations of each combination from
      ./data/reference/combinations.txt to create tables/dataframes.
    3. Round the stat to a max of three decimal places.
    4. Only include subjects with PA >= 25.
    5. Combine each individual table/dataframe into a single one with the
      following column headers:
      • SubjectId (e.g. 108, 119, etc)
      • Stat (e.g. the name of the stat "AVG", "OBP", etc.)
      • Split (e.g. "vs LHP", "vs RHH", etc.)
      • Subject (e.g. "HitterId", "PitcherTeamId", etc.)
      • Value (e.g. the value of the Stat 0.350, 1.03, 0.5, etc)
    6. Sort the table/dataframe on the first four columns (each in ascending
      order).
    7. Save the csv to ./data/processed/output.csv
  5. Run the test suite by opening a command-line, cd in to the repo, and running
    the following command: pytest -v
  6. Upload to a new repository under your own GitLab/GitHub/BitBucket account.
  7. Email the link to your repository to Andrew Pautz ([email protected]).

Example

Let's take the first combination to be processed from combinations.txt:

AVG,HitterId,vs RHP

... the equivalent SQL would look something like:

SELECT
  HitterId AS SubjectId,
  'AVG' AS Stat,
  'vs RHP' AS Split,
  'HitterId' AS Subject,
  ROUND(CAST(SUM(H) AS FLOAT)/SUM(AB), 3) AS Value
FROM ./data/raw/pitchdata.csv
WHERE PitcherSide = 'R'
GROUP BY HitterId
HAVING SUM(PA) >= 25

Goals

Your submission will be scored on 5 aspects:

  1. Accuracy: The output data must be 100% accurate.
  2. Readability: The easier it is to understand, the better.
  3. Performant: It should ideally take just 1-2 seconds to finish.
  4. Development Time: Try to submit within a day.
  5. Installable: Make it installable via pip install -r requirements.txt

Additional Info

  • Use any third party libraries you'd like so long as they're installed via
    the requirements.txt file. We use pandas heavily, but if you're more
    comfortable using numpy or something entirely else feel free to do so.
  • You don't need to limit your modifications to run.py. You can add/edit any
    other file in the repo with the exception of anything in:
    • ./tests
    • ./data/raw
    • ./data/reference
  • Code should generally be pep8 compliant.
    • Documentation isn't required, but wouldn't be frowned upon.
    • If you need to go a bit over 80 chars ... no problem.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages