Skip to content

Commit 0cd9521

Browse files
committed
Add pitch-related fields to cwsub.
This adds to cwsub all of the fields in cwevent related to pitches - the count, the pitch sequence up to the sub, and the cwevent extended fields which tabulate counts of pitches in the plate appearance up to that point.
1 parent c4fa2fe commit 0cd9521

File tree

2 files changed

+196
-6
lines changed

2 files changed

+196
-6
lines changed

doc/cwsub.rst

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@ in-game player substitutions. It is designed to be used in conjunction
88
with :program:`cwevent` to mitigate a blind spot in the
99
existing tools.
1010

11-
:program:`cwsub` outputs up to ten pieces of
11+
:program:`cwsub` outputs up to 25 pieces of
1212
information about each substitution. All are included by default; which
1313
ones are generated is controlled by the -f switch.
1414

15+
The fields have the same interpretation those with the same name in
16+
:program:`cwevent`. That is to say, you can think of :program:`cwsub` as
17+
extending :program:`cwevent` by treating substitutions as events in
18+
their own right. In particular, the count and pitch counts are cumulative
19+
counts for the plate appearance up to the point of the substitution.
20+
1521
.. list-table:: cwevent standard field numbers
1622
:header-rows: 1
1723
:widths: 5,20,10
@@ -49,5 +55,50 @@ ones are generated is controlled by the -f switch.
4955
* - 9
5056
- Event number
5157
- ``EVENT_ID``
58+
* - 10
59+
- Balls
60+
- ``BALLS_CT``
61+
* - 11
62+
- Strikes
63+
- ``STRIKES_CT``
64+
* - 12
65+
- Pitch sequence
66+
- ``PITCH_SEQ_TX``
67+
* - 13
68+
- number of balls in plate appearance
69+
- ``PA_BALL_CT``
70+
* - 14
71+
- number of called balls in plate appearance
72+
- ``PA_CALLED_BALL_CT``
73+
* - 15
74+
- number of intentional balls in plate appearance
75+
- ``PA_INTENT_BALL_CT``
76+
* - 16
77+
- number of pitchouts in plate appearance
78+
- ``PA_PITCHOUT_BALL_CT``
79+
* - 17
80+
- number of pitches hitting batter in plate appearance
81+
- ``PA_HITBATTER_BALL_CT``
82+
* - 18
83+
- number of other balls in plate appearance
84+
- ``PA_OTHER_BALL_CT``
85+
* - 19
86+
- number of strikes in plate appearance
87+
- ``PA_STRIKE_CT``
88+
* - 20
89+
- number of called strikes in plate appearance
90+
- ``PA_CALLED_STRIKE_CT``
91+
* - 21
92+
- number of swinging strikes in plate appearance
93+
- ``PA_SWINGMISS_STRIKE_CT``
94+
* - 22
95+
- number of foul balls in plate appearance
96+
- ``PA_FOUL_STRIKE_CT``
97+
* - 23
98+
- number of balls in play in plate appearance
99+
- ``PA_INPLAY_STRIKE_CT``
100+
* - 24
101+
- number of other strikes in plate appearance
102+
- ``PA_OTHER_STRIKE_CT``
52103

53104

src/cwtools/cwsub.c

Lines changed: 144 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,13 @@
3535
extern int ascii;
3636

3737
/* Fields to display (-f) */
38-
int fields[10] = {
39-
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
38+
int fields[] = {
39+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
40+
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
41+
1, 1, 1, 1, 1
4042
};
4143

42-
int max_field = 9;
44+
int max_field = 24;
4345

4446
char program_name[20] = "cwsub";
4547

@@ -137,6 +139,128 @@ DECLARE_FIELDFUNC(cwsub_event_number)
137139
gameiter->state->event_count : gameiter->state->event_count + 1);
138140
}
139141

142+
/* Field 10 */
143+
DECLARE_FIELDFUNC(cwsub_balls)
144+
{
145+
if (strlen(gameiter->event->count) >= 2 &&
146+
gameiter->event->count[0] != '?' &&
147+
gameiter->event->count[1] != '?') {
148+
return sprintf(buffer, "%c", gameiter->event->count[0]);
149+
}
150+
else {
151+
return sprintf(buffer, "0");
152+
}
153+
}
154+
155+
/* Field 11 */
156+
DECLARE_FIELDFUNC(cwsub_strikes)
157+
{
158+
if (strlen(gameiter->event->count) >= 2 &&
159+
gameiter->event->count[0] != '?' &&
160+
gameiter->event->count[1] != '?') {
161+
return sprintf(buffer, "%c", gameiter->event->count[1]);
162+
}
163+
else {
164+
return sprintf(buffer, "0");
165+
}
166+
}
167+
168+
/* Field 12 */
169+
DECLARE_FIELDFUNC(cwsub_pitches)
170+
{
171+
/* This bit of code wipes out leading whitespace, which bevent
172+
* does not include in its output */
173+
char *foo = gameiter->event->pitches;
174+
while (foo && isspace(*foo)) {
175+
foo++;
176+
}
177+
return sprintf(buffer, (ascii) ? "\"%s\"" : "%-20s", foo);
178+
}
179+
180+
/* Field 13 */
181+
DECLARE_FIELDFUNC(cwsub_pitches_balls)
182+
{
183+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
184+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_ball_thrown));
185+
}
186+
187+
/* Field 14 */
188+
DECLARE_FIELDFUNC(cwsub_pitches_balls_called)
189+
{
190+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
191+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_ball_called));
192+
}
193+
194+
/* Field 15 */
195+
DECLARE_FIELDFUNC(cwsub_pitches_balls_intentional)
196+
{
197+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
198+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_ball_intentional));
199+
}
200+
201+
/* Field 16 */
202+
DECLARE_FIELDFUNC(cwsub_pitches_balls_pitchout)
203+
{
204+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
205+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_ball_pitchout));
206+
}
207+
208+
/* Field 17 */
209+
DECLARE_FIELDFUNC(cwsub_pitches_balls_hit_batter)
210+
{
211+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
212+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_ball_hit_batter));
213+
}
214+
215+
/* Field 18 */
216+
DECLARE_FIELDFUNC(cwsub_pitches_balls_other)
217+
{
218+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
219+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_ball_other));
220+
}
221+
222+
/* Field 19 */
223+
DECLARE_FIELDFUNC(cwsub_pitches_strikes)
224+
{
225+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
226+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_strike_thrown));
227+
}
228+
229+
/* Field 20 */
230+
DECLARE_FIELDFUNC(cwsub_pitches_strikes_called)
231+
{
232+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
233+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_strike_called));
234+
}
235+
236+
/* Field 21 */
237+
DECLARE_FIELDFUNC(cwsub_pitches_strikes_swinging)
238+
{
239+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
240+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_strike_swinging));
241+
}
242+
243+
/* Field 22 */
244+
DECLARE_FIELDFUNC(cwsub_pitches_strikes_foul)
245+
{
246+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
247+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_strike_foul));
248+
}
249+
250+
/* Field 23 */
251+
DECLARE_FIELDFUNC(cwsub_pitches_strikes_inplay)
252+
{
253+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
254+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_strike_inplay));
255+
}
256+
257+
/* Field 24 */
258+
DECLARE_FIELDFUNC(cwsub_pitches_strikes_other)
259+
{
260+
return sprintf(buffer, (ascii) ? "%d" : "%02d",
261+
cw_pitch_count_pitches(gameiter->event->pitches, cw_pitch_strike_other));
262+
}
263+
140264
static field_struct field_data[] = {
141265
{ cwsub_game_id, "GAME_ID", "game id" },
142266
{ cwsub_inning, "INN_CT", "inning" },
@@ -147,7 +271,22 @@ static field_struct field_data[] = {
147271
{ cwsub_position, "SUB_FLD_CD", "fielding position" },
148272
{ cwsub_removed_player, "REMOVED_ID", "removed player" },
149273
{ cwsub_removed_position, "REMOVED_FLD_CD", "position of removed player" },
150-
{ cwsub_event_number, "EVENT_ID", "event number" }
274+
{ cwsub_event_number, "EVENT_ID", "event number" },
275+
{ cwsub_balls, "BALLS_CT", "balls" },
276+
{ cwsub_strikes, "STRIKES_CT", "strikes" },
277+
{ cwsub_pitches, "PITCH_SEQ_TX", "pitch sequence" },
278+
{ cwsub_pitches_balls, "PA_BALL_CT", "number of balls thrown in plate appearance" },
279+
{ cwsub_pitches_balls_called, "PA_CALLED_BALL_CT", "number of called balls in plate appearance" },
280+
{ cwsub_pitches_balls_intentional, "PA_INTENT_BALL_CT", "number of intentional balls in plate appearance" },
281+
{ cwsub_pitches_balls_pitchout, "PA_PITCHOUT_BALL_CT", "number of pitchouts in plate appearance" },
282+
{ cwsub_pitches_balls_hit_batter, "PA_HITBATTER_BALL_CT", "number of pitches hitting batter in plate appearance" },
283+
{ cwsub_pitches_balls_other, "PA_OTHER_BALL_CT", "number of other balls in plate appearance" },
284+
{ cwsub_pitches_strikes, "PA_STRIKE_CT", "number of strikes thrown in plate appearance" },
285+
{ cwsub_pitches_strikes_called, "PA_CALLED_STRIKE_CT", "number of called strikes in plate appearance" },
286+
{ cwsub_pitches_strikes_swinging, "PA_SWINGMISS_STRIKE_CT", "number of swinging strikes in plate appearance" },
287+
{ cwsub_pitches_strikes_foul, "PA_FOUL_STRIKE_CT", "number of foul balls in plate appearance" },
288+
{ cwsub_pitches_strikes_inplay, "PA_INPLAY_STRIKE_CT", "number of balls in play in plate appearance" },
289+
{ cwsub_pitches_strikes_other, "PA_OTHER_STRIKE_CT", "number of other strikes in plate appearance" }
151290
};
152291

153292
void
@@ -164,7 +303,7 @@ cwsub_process_game(CWGame *game, CWRoster *_visitors, CWRoster *_home)
164303
comma = 0;
165304
strcpy(output_line, "");
166305
buf = output_line;
167-
for (i = 0; i < 10; i++) {
306+
for (i = 0; i <= max_field; i++) {
168307
if (fields[i]) {
169308
if (ascii && comma) {
170309
*(buf++) = ',';

0 commit comments

Comments
 (0)