Command line apps for hacking on baseball stats

Related tags

Utility roto-swift
Overview

Thes are some swift command line apps I use to hack on my roto baseball league.

No warranty or claim of usability what-so-ever. This represents work I did in my free time for my own enjoyment. It is not intended to represent production quality work. Many sins lurk within, not the least of include:

  • Domain logic not fully baked. This could be considered a decent start but I haven't examined enough actual use cases to determine how they should actually be constructed
  • Hard coded files names. These could eventually be legit command line tools, but that's a ways off. I'm the only person using this thing.
  • Comments, logs and debug code sprinkled throughout.
  • Hard coded files point to a directory on my dev machine. It would be cool if someone else could run the most recent projections, but not today.
  • Duplicated code. This code has prioritized getting things done so I don't annoy my wife by hacking on Swift on my days off.
  • Non uniform output. Some scripts output to a csv file, some print to the standard output. So it goes.
  • Error handling non-existent. If the file formats change, things just don't work and you have to dig a bit to find out why.
  • Not many unit tests.

You need to have Swift installed on your machine to run this. Most people do this by downloading Xcode and installing the command line tools. Consult google for more directions.

That said, here are the apps:

AtBatSimulator

Takes a list of batter and pitcher projections and runs a bunch of simulated At Bats. This is used to make sure the algorithm that predicts the outcomes is reasonable.

Note: the id used for the pitcher and hitter is hardcoded in the code. Maybe someday I'll extract them to a parameter

Drafter

This was used to detect the best player to draft in a draft with Major league and Minor league players.

FreeAgentFinder

Scrape a list of the League's rosters and compare that to projected values to determine the best available free agent.

GameSimulator

This takes hitter and pitcher projections, and an output of a CouchManagers draft CSV and simulates a game between two teams. Output to screen

HitterAuctionValues

Takes a list of hitter projections, and converts Roto auction values for it.

League values are hardcoded inside convertProjectionsFileToActionValues. Someday I'll make it configurable

LeagueRostersScrape

  • Scrape league roster data from a copied-and-saved text file from a Rosters page from an ESPN league.
  • Imports projected auction values for hitters and pitchers from a csv
  • Correlates the roster players with their auction value and prints out a primitive power ranking.

See sample directory for expected formats. Downloadable and especially ESPN formats are likely to change in the future. They were last known to work March, 2019.

swift run LeagueRostersScrape --hitters data/FanGraphs-batters-2019-03-16.csv --pitchers data/FanGraphs-pitchers-2019-03-16.csv --rosters data/ESPN-rosters-2019-05-29.txt

PlayerRelativeValues

Scrapes a csv of team rosters and compares them to csv's of project Fangraphs auction values. This show the relative value of a player.

swift run PlayerRelativeValues --hitters data/FanGraphs-batters-2019-03-16.csv --pitchers data/FanGraphs-pitchers-2019-03-16.csv --auction data/PlayerRelativeValues.auctionvalues.csv

ProjectionsToAuctionValues

Takes a csv of raw stat projections and converts them to auction values. It uses an algorithm similar to this site. Note: my code was written before this blog post, but I didn't invent the algorithm anyway.

ProjectionsToAuctionValuesPitchers

Turns out things like ERA & WHIP need to be calculated differently (a lower value is better), so a different script is used to calculate pitcher values.

HitterAuctionValues

swift run HitterAuctionValues --hitters data/Zips-projections-2020-batters.csv --output data/Zips-projections-2020-batters-auction-values.csv

TeamRelativeValues

This takes a scrape of the league rosters and adds the values for all the players on their team. It is used to estimate which teams have the best chance of winning. Turns out I can often predict the league winners before the season even starts.

swift run TeamRelativeValues --hitters data/FanGraphs-batters-2019-03-16.csv --pitchers data/FanGraphs-pitchers-2019-03-16.csv --auction data/TeamRelativeValues.auctionvalues.csv

LeagueSimulator

RotoSwift

Common code that is shared between all the scripts.

Math

Some methods for calculating statistics like Mean, Z Score and Standard Deviation

Models

First pass at domain models. Mostly light weight swift structs.

Repository

Class used to turning data from various file formats to usable Models.

Roster

Code to build up the league rosters from a scraped text file. It's used by FreeAgentFinder.

How do I compile the apps?

swift build

How do I run one of the apps?

  • Change the filename variables in the swift app to point to something on your local machine
  • .build/debug/TeamRelativeValues to run a file from your working directory

To build and run an app in one command

swift build && .build/debug/PlayerRelativeValues

Run unit tests (not there are many... shame on me)

swift test

How can I hack on this?

Go ahead. You can edit the files in your text editor of choice. If you use Xcode and add new files, you'll need to have swift update the xcodeproj

swift package generate-xcodeproj

Note: this isn't needed for other editors than don't use the xcodeproj.

What is aiai?

Something that should be cleaned up. If something like that was committed to a production repository I'd feel ashamed, but this is not one of those...

You might also like...
BFKit is a collection of useful classes and categories to develop Apps faster.

Swift Version • What does it do • Language support • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog •

Message passing between iOS apps and extensions.
Message passing between iOS apps and extensions.

MMWormhole MMWormhole creates a bridge between an iOS or OS X extension and its containing application. The wormhole is meant to be used to pass data

IOS-Bootcamp-Examples - Learn to Swift while building apps - With IOS Development Bootcamp
IOS-Bootcamp-Examples - Learn to Swift while building apps - With IOS Development Bootcamp

IOS-Bootcamp-Examples Learn to Swift while building apps - With IOS Development

An open source Instapaper clone that features apps and extensions that use native UI Components for Mac and iOS.
An open source Instapaper clone that features apps and extensions that use native UI Components for Mac and iOS.

TODO: Screenshot outdated Hipstapaper - iOS and Mac Reading List App A macOS, iOS, and iPadOS app written 100% in SwiftUI. Hipstapaper is an app that

Lightweight app to view your WoT (BB, Blitz) stats (XVM based)
Lightweight app to view your WoT (BB, Blitz) stats (XVM based)

KTTC Lite Приложение для танкистов, следящих за своей статистикой! Функционал Базовая статистика аккаунта WoT, WoT Blitz Расширенная статистика XVM (W

KovidStatz - A very simple app to display covid stats worldwide or country wise
KovidStatz - A very simple app to display covid stats worldwide or country wise

KovidStatz A very simple app to display covid stats worldwide or country wise. T

iOS 14 widget for stats on COVID -19.
iOS 14 widget for stats on COVID -19.

A Covid-19 Tracking Widget for iOS 14 WidgetKit WidgetKit gives users ready access to content in apps by putting widgets on the iOS Home screen or mac

ipatool is a command line tool that allows you to search for iOS apps on the App Store and download a copy of the app package, known as an ipa file.
ipatool is a command line tool that allows you to search for iOS apps on the App Store and download a copy of the app package, known as an ipa file.

ipatool is a command line tool that allows you to search for iOS apps on the App Store and download a copy of the app package, known as an ipa file.

Install and debug iPhone apps from the command line, without using Xcode

ios-deploy Install and debug iOS apps from the command line. Designed to work on un-jailbroken devices. Requirements macOS You need to have a valid iO

Repository to store the projects made during the 100 Days of Swift challenge by Paul Hudson of Hacking with Swift.

100DaysOfSwift 📱 Repository to store the projects made during the 100 Days of Swift challenge by Paul Hudson of Hacking with Swift. Days 1-12: Introd

All the projects from 100 Days of SwiftUI, as taught by Paul Hudson (Hacking with Swift)

100 Days of SwiftUI 19 projects of increasing complexity built with SwiftUI. These projects were built as part of an iOS development course taught by

Accessbility workshop by hacking with swift. Make every app more usefull for the all the users
Accessbility workshop by hacking with swift. Make every app more usefull for the all the users

Accessibility Accessbility workshop by hacking with swift. Make every app more u

This is the ninth project from Hacking With Swift 100 days of Swift course.

Petitions Viewer This is the ninth project from Hacking With Swift 100 days of S

DiceChallenge - Hacking with SwiftUI Challenge - Dice simulator
DiceChallenge - Hacking with SwiftUI Challenge - Dice simulator

Some Dices Hacking with SwiftUI challenge turned into a real app available at th

This is my copy of the "Ultimate Portfolio Project" tutorial series in Hacking with Swift+.

UltimatePortfolio This is my version of the "Ultimate Portfolio Project" tutorial series in Hacking with Swift+. I What have I learned in this series?

This SwiftUI project is a result of the third 'milestone' in "Hacking With Swift's 100 Days of SwiftUI".

exercise-tracker This SwiftUI project is a result of the third 'milestone' in "Hacking With Swift's 100 Days of SwiftUI". In this exercise tracking ap

This SwiftUI project is a result of the first 'milestone' in "Hacking With Swift's 100 Days of SwiftUI".

rock-paper-scissors-trainer This SwiftUI project is a result of the first 'milestone' in "Hacking With Swift's 100 Days of SwiftUI". In this simple ro

This SwiftUI project is a result of the second 'milestone' in "Hacking With Swift's 100 Days of SwiftUI".

mutiplication-tables This SwiftUI project is a result of the second 'milestone' in "Hacking With Swift's 100 Days of SwiftUI". In this simple multipli

Beak 🐦 Peck into your Swift files from the command line

Beak 🐦 Peck into your Swift files from the command line Beak can take a standard Swift file and then list and run any public global functions in it v

Owner
Jaim Zuber
Jaim Zuber
Swift library and command line tool that interacts with the mach-o file format.

MachO-Reader Playground project to learn more about the Mach-O file format. How to run swift run MachO-Reader <path-to-binary> You should see a simila

Gonzalo 5 Jun 25, 2022
This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app.

?? X-BundleIcon This is a command line tool to extract an app icon. this sample will extract the icon 16x16 from Safari app. xbi com.apple.Safari 16 /

Rui Aureliano 3 Sep 1, 2022
Lock a terminal command to the efficiency or performance cores on a big.LITTLE ARM processor

CPU-Lock Lock a terminal command to the efficiency or performance cores on a big.LITTLE ARM processor (Designed for Apple Silicon). Usage Download the

BitesPotatoBacks 0 Aug 11, 2022
OwO.swift Badges go here in one line for the master branch ONLY.

OwO.swift Badges go here in one line for the master branch ONLY. Badges can also go in the header line. Short description describing the application/l

Spotlight 2 May 28, 2022
BudouX: the machine learning powered line break organizer tool

BudouX.swift BudouX Swift implementation. BudouX is the machine learning powered

griffin-stewie 39 Dec 31, 2022
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Fabrizio Brancati 992 Dec 2, 2022
Vaccine is a framework that aims to make your apps immune to recompile-disease.

Vaccine Description Vaccine is a framework that aims to make your apps immune to recompile-disease. Vaccine provides a straightforward way to make you

Christoffer Winterkvist 298 Dec 23, 2022
Updeto is a simple package that help update checker for iOS Apps

Updeto is a simple package that will help you to check if the currently installed version is the same as the latest one available on App Store.

Manuel Sánchez 8 Jul 8, 2022
Tools and helpers to make building apps faster and safer.

The UBFoundation framework provides a set of useful tools and helpers to make building apps faster and safer.

Ubique 7 Dec 19, 2022
Verify New Zealand COVID Passes in iOS apps using Swift

NzCovidPass-Swift Swift library for verification of the NZ Covid Vaccination Pas

Gallagher Security 4 Jul 19, 2022