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

  1. GameRoot adds a SwingLog component at boot.
  2. It listens to GameEvents.PlayEnded (one per pitch, after the result is known), and since #47 also to PitchThrown (remembers the strikes before the pitch), SwingStarted (captures SwingInput.PressTime - pitch.ArrivalTime and the bat aim at the press, because a click to skip the flight moves PressTime on before the play ends) and CountChanged. See Game Events.
  3. It skips the line when the game isn’t ready, the report has no swing, the at-bat is spectating, or SwingInput.Bot is set (the dev bot is batting, not a player).
  4. 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>.csv so every file holds one header.
  5. It appends the line to Application.persistentDataPath/swings.csv. A new file gets the header first.
  6. 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

ColumnMeaning
timeLocal time, yyyy-MM-dd HH:mm:ss
modecage, coop, daily or run
parkBallpark id
difficultyThe run’s difficulty (empty in the cage)
inningInning number
batterBatter id (e.g. slugger = Baked Bean)
pitch, pitch_mphPitch type id and shown speed
in_zone1 if the pitch was in the strike zone
special_ballThe map’s ball effect (PitchData.effect; the boss slot is not logged)
outcomeTake, Whiff or Contact
timing_msContact: 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_cmWhere on the bat, from the sweet spot (+ = toward the tip)
zone, grade, greenSour / Nice / Perfect, WEAK…PERFECT, 1 / 0
aim_x, aim_yHeld direction at contact (-1 left / +1 right; +1 W / -1 S)
spray_deg, launch_deg, exit_mph, curveThe hit (curve in m/s^2, + = toward right field)
resulthome_run, foul, out, whiff, called_strike or ball
distance_ftCarry 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 grade per player. Many WEAK means the aim helper isn’t being read well.
  • Aim error: contact_offset_cm against zone. A lean to + means players hit off the tip; - means jammed.
  • Timing error: timing_ms for whiffs (real time) and contacts (direction-based) by pitch and special_ball.
  • Held aim use: how often aim_y is 1 (W) and its home run rate per park.
  • Home run rate: result = home_run over contacts, compare with the balance-sim figures in HitTables.
  • 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

WhatValueWhere to tune
File nameswings.csvSwingLog.FileName
Columns31 (24 before #47)SwingLog.Header (public since #47)
Contact timing scale45 degrees of spray = 60 msSwingResolver.FromContact (timingOffset)
Swings before YOU fits30YouBot.MinSwings

In the code

FileWhat it does
Assets/_Project/Scripts/Batting/SwingLog.csOnPlayEnded, Line, PressColumns, SetAsideOldFormat, Header, FilePath, LoggedThisSession
Assets/_Project/Scripts/Batting/SwingResult.cscontactOffset (added for the log), timingOffset, Grade
Assets/_Project/Scripts/Batting/SwingInput.csPressTime, and Bot (set while the dev bot bats)
Assets/_Project/Scripts/Sim/YouBot.csReads the file back and fits a bot to it (Sim Lab)
Assets/_Project/Scripts/Core/GameRoot.csAdds the component
Assets/_Project/Scripts/UI/DevMenu.csPROGRESS 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 no press_ms column, so the YOU bot can’t fit from it.
  • press_ms is the real button time; timing_ms on a contact is read from the bat face. Use press_ms for timing error (that’s what YOU does); timing_ms still means two things.
  • timing_ms means 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_strike come from in_zone; a foul is foul whatever the count.
  • The under value (ball above or below the bat’s axis) is not logged.