Swing Log
In short
Every pitch you see (swing, whiff or take) is appended as one line to
swings.csv. It is for tuning the batting numbers (Batting/HitTables) from real play, and since #47 it is what the Sim Lab’s YOU bot is fitted from, so testers can send the file in and a bot plays a thousand runs the way they bat. It is local only. Nothing is uploaded. Co-op pitches you only watch and the dev bot’s own pitches are not logged.
How it works
GameRootadds aSwingLogcomponent at boot.- It listens to
GameEvents.PlayEnded(one per pitch, after the result is known), and since #47 also toPitchThrown(remembers the strikes before the pitch),SwingStarted(capturesSwingInput.PressTime - pitch.ArrivalTimeand the bat aim at the press, because a click to skip the flight movesPressTimeon before the play ends) andCountChanged. See Game Events. - It skips the line when the game isn’t ready, the report has no swing, the at-bat is spectating, or
SwingInput.Botis set (the dev bot is batting, not a player). - On the first write of a session it checks the file’s first line: a header that isn’t the current one means an older layout, and the file is moved aside as
swings-until-<yyyy-MM-dd-HHmmss>.csvso every file holds one header. - It appends the line to
Application.persistentDataPath/swings.csv. A new file gets the header first. - A write error logs one warning (“Swing log: couldn’t write …”) and never stops the game.
Where the file is. Application.persistentDataPath with company DefaultCompany and product RoguelikeHomeRunDerby (ProjectSettings). On Windows that is normally %USERPROFILE%\AppData\LocalLow\DefaultCompany\RoguelikeHomeRunDerby\swings.csv. The Dev menu’s PROGRESS page shows “SWING LOG (n pitches this session)”, the full path, and an OPEN THE LOG’S FOLDER button. See Dev Menu and Shortcuts.
Columns
| Column | Meaning |
|---|---|
time | Local time, yyyy-MM-dd HH:mm:ss |
mode | cage, coop, daily or run |
park | Ballpark id |
difficulty | The run’s difficulty (empty in the cage) |
inning | Inning number |
batter | Batter id (e.g. slugger = Baked Bean) |
pitch, pitch_mph | Pitch type id and shown speed |
in_zone | 1 if the pitch was in the strike zone |
special_ball | The map’s ball effect (PitchData.effect; the boss slot is not logged) |
outcome | Take, Whiff or Contact |
timing_ms | Contact: from the bat face angle, spray / 45 x 60 ms (- = early). Whiff: real ms between the barrel crossing the aim point and the pitch arriving. Empty on a take |
contact_offset_cm | Where on the bat, from the sweet spot (+ = toward the tip) |
zone, grade, green | Sour / Nice / Perfect, WEAK…PERFECT, 1 / 0 |
aim_x, aim_y | Held direction at contact (-1 left / +1 right; +1 W / -1 S) |
spray_deg, launch_deg, exit_mph, curve | The hit (curve in m/s^2, + = toward right field) |
result | home_run, foul, out, whiff, called_strike or ball |
distance_ft | Carry distance (contact only) |
press_ms (#47) | When the swing button went down against when the ball arrived, in ms (- = before arrival). Empty on a take, or when the press belonged to another pitch |
bat_aim_x, bat_aim_y (#47) | Where the bat was aimed at the press (plate plane, m). Empty on a take |
plate_x, plate_y (#47) | Where the ball crossed the plate plane (m) |
strikes (#47) | Strikes before this pitch |
boss_ball (#47) | The pitcher’s own special ball (PitchData.bossEffect), None when there is none |
Contact-only columns are empty for takes and whiffs. Commas inside values become spaces. Numbers use the invariant culture (a dot for decimals). The YOU bot reads the file by column name (YouBot.Parse), so new columns can be added at the end without breaking it; it needs outcome, press_ms, plate_x and plate_y to exist at all.
How to read it
Open it in a spreadsheet. Useful cuts:
- Grade spread: count
gradeper player. Many WEAK means the aim helper isn’t being read well. - Aim error:
contact_offset_cmagainstzone. A lean to + means players hit off the tip; - means jammed. - Timing error:
timing_msfor whiffs (real time) and contacts (direction-based) bypitchandspecial_ball. - Held aim use: how often
aim_yis 1 (W) and its home run rate perpark. - Home run rate:
result = home_runover contacts, compare with the balance-sim figures inHitTables. - Let a bot do it: F1 > BOT > YOUR SWINGS or the Sim Lab window show the fit (timing spread and lean, aim spread, chase rate) once the file holds 30 swings; LOAD A LOG in the window fits a bot to a file someone sent (Sim Lab).
Numbers
| What | Value | Where to tune |
|---|---|---|
| File name | swings.csv | SwingLog.FileName |
| Columns | 31 (24 before #47) | SwingLog.Header (public since #47) |
| Contact timing scale | 45 degrees of spray = 60 ms | SwingResolver.FromContact (timingOffset) |
| Swings before YOU fits | 30 | YouBot.MinSwings |
In the code
| File | What it does |
|---|---|
Assets/_Project/Scripts/Batting/SwingLog.cs | OnPlayEnded, Line, PressColumns, SetAsideOldFormat, Header, FilePath, LoggedThisSession |
Assets/_Project/Scripts/Batting/SwingResult.cs | contactOffset (added for the log), timingOffset, Grade |
Assets/_Project/Scripts/Batting/SwingInput.cs | PressTime, and Bot (set while the dev bot bats) |
Assets/_Project/Scripts/Sim/YouBot.cs | Reads the file back and fits a bot to it (Sim Lab) |
Assets/_Project/Scripts/Core/GameRoot.cs | Adds the component |
Assets/_Project/Scripts/UI/DevMenu.cs | PROGRESS page: count and folder button |
Gotchas
- The file only grows. There is no rotation or size cap; delete it by hand to start over. The only move-aside is the one-time header change (
swings-until-<date>.csv); a set-aside file has nopress_mscolumn, so the YOU bot can’t fit from it. press_msis the real button time;timing_mson a contact is read from the bat face. Usepress_msfor timing error (that’s what YOU does);timing_msstill means two things.timing_msmeans two different things: a real time for whiffs, a direction converted to ms for contacts. Do not mix them in one average.- Forced Dev menu hits (insta-home-run bat, TEST HITS) are logged too, as normal lines.
ball/called_strikecome fromin_zone; a foul isfoulwhatever the count.- The
undervalue (ball above or below the bat’s axis) is not logged.
Related
- Batting Explained: what the columns measure
- Batting Feedback: what the player was shown for the same swing
- Save System:
save.jsonandrun.jsonlive in the same folder - Editor Tools and Tests: BattingModelTest
- Sim Lab: the YOU bot fitted from this file