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34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
aux_global_id_to_code = {
    7911: 'G',
    7912: 'S',
    7913: 'DB',
    7914: 'D',
    7915: 'T',
    7916: 'C',
    7917: 'F',
    7918: 'E',
    7919: 'L',
    7920: 'M',
    7921: 'B',
    7922: 'H',
    7925: 'PL',
    7926: 'CL'
}

ball_kind = {
    -1: '-',
    31: 'Fastball (4-seam)',
    32: 'Slider',
    33: 'Vertical Slider',
    34: 'Slurve',
    35: 'Curve',
    36: 'Slow Curve',
    37: 'Power Curve',
    38: 'Knuckle Curve',
    39: 'Forkball',
    40: 'Splitter',
    41: 'Changeup',
    42: 'Sinker',
    43: 'Screwball',
    44: 'Palmball',
    45: 'Knuckleball',
    46: 'Shootball',
    47: 'Fastball (2-seam)',
    48: 'Fastball (1-seam)',
    49: 'Cutter',
    50: 'Eephus', # technically "super" eephus but I haven't encountered a normal one yet
    51: 'Hard Sinker',
    52: 'Hard Slider',
}

ball_kind_code = {
    -1: '-',
    31: '4S',
    32: 'SL',
    33: 'VS',
    34: 'SV',
    35: 'CU',
    36: 'SC',
    37: 'PC',
    38: 'KC',
    39: 'FO',
    40: 'FS',
    41: 'CH',
    42: 'SI',
    43: 'SB',
    44: 'PB',
    45: 'KN',
    46: 'SH',
    47: '2S',
    48: '1S',
    49: 'FC',
    50: 'EP', # technically "super" eephus but I haven't encountered a normal one yet
    51: 'HS',
    52: 'HL'
}

general_ball_kind = {
    -1: '-',
    31: 'Fastball (4-seam)',
    32: 'Slider',
    33: 'Vertical Slider',
    34: 'Slurve',
    35: 'Curve',
    36: 'Curve',
    37: 'Curve',
    38: 'Curve',
    39: 'Splitter',
    40: 'Splitter',
    41: 'Changeup',
    42: 'Sinker',
    43: 'Screwball',
    44: 'Palmball',
    45: 'Knuckleball',
    46: 'Sinker',
    47: 'Sinker',
    48: 'Sinker',
    49: 'Cutter',
    50: 'Eephus', # technically "super" eephus but I haven't encountered a normal one yet
    51: 'Sinker',
    52: 'Vertical Slider',
}

general_ball_kind_code = {
    -1: '-',
    31: '4S',
    32: 'SL',
    33: 'VS',
    34: 'SV',
    35: 'CU',
    36: 'CU',
    37: 'CU',
    38: 'CU',
    39: 'FS',
    40: 'FS',
    41: 'CH',
    42: 'SI',
    43: 'SB',
    44: 'PB',
    45: 'KN',
    46: 'SI',
    47: 'SI',
    48: 'SI',
    49: 'FC',
    50: 'EP', # technically "super" eephus but I haven't encountered a normal one yet
    51: 'SI',
    52: 'VS'
}

lr = {1: 'l', 2: 'r'}

presult = {
    0: 'None',
    101: 'Foul',
    102: 'Single',
    103: 'Hit by pitch',
    104: 'Double',
    105: 'Triple',
    106: 'Home run',
    107: 'Error',
    108: 'Groundout',
    109: 'Flyout',
    110: 'Lineout',
    111: 'Groundout (Double play)',
    112: 'Foul fly',
    113: 'Foul line (?)',
    114: 'Sacrifice bunt',
    115: 'Sacrifice fly',
    116: 'Swinging strike',
    117: 'Looking strike',
    118: 'Ball',
    119: 'Walk',
    120: 'Balk',
    121: 'Batter interference',
    122: 'Catcher interference',
    123: 'Uncaught third strike',
    124: 'Sacrifice hit error',
    125: 'Sacrifice fly error',
    126: "Fielder's choice",
    128: "Sacrifice fielder's choice",
    129: 'Bunt strikeout',
    130: 'Swinging strikeout',
    131: 'Looking strikeout',
    133: 'Inside-the-park home run',
    134: 'Pitcher delay',
    135: 'Balk',
    139: 'Intentional walk',
    140: 'Groundout (Double play)',
    141: 'Unknown'
}

bresult = {
    0: '空振り三振',
    1: '単打', # 1b gb p
    2: '単打', # 1b gb c
    3: '単打', # 1b gb 1b
    4: '単打', # 1b gb 2b
    5: '単打', # 1b gb 3b? ld
    6: '単打', # 1b gb ss
    7: '単打', # 1b gb lf? ld
    8: '単打', # 1b gb cf
    9: '単打', # 1b gb rf
    10: '2塁打', # 2b gb p

    12: '2塁打', # 2b gb 1b
    13: '2塁打', # 2b gb 2b
    14: '2塁打', # 2b gb 3b? ld
    15: '2塁打', # 2b gb ss
    16: '2塁打', # 2b gb lf? ld
    17: '2塁打', # 2b gb cf
    18: '2塁打', # 2b gb rf

    22: '3塁打', # 3b gb 2b

    25: '3塁打', # 3b gb lf? ld
    26: '3塁打', # 3b gb cf
    27: '3塁打', # 3b gb rf
    28: '本塁打(ランニング)', # ihr lf?
    29: '本塁打(ランニング)', # ihr cf?
    30: '本塁打(ランニング)', # ihr rf?

    31: '空振り三振',
    32: '振逃げ',
    33: '振逃げ',
    34: '四球',
    35: 'フライ', # fb cf
    36: '死球',
    37: '打撃妨害',
    38: '守備妨害',

    39: '犠打野選',
    40: 'ゴロ', #gb p
    41: 'ゴロ', #gb c
    42: 'ゴロ', #gb 1b
    43: 'ゴロ', #gb 2b
    44: 'ゴロ', #gb 3b
    45: 'ゴロ', #gb ss
    46: 'ゴロ', #gb lf
    47: 'ゴロ', #gb cf
    48: 'ゴロ', #gb rf

    49: 'フライ', # fb p
    50: 'フライ', # fb c
    51: 'フライ', # fb 1b
    52: 'フライ', # fb 2b
    53: 'フライ', # fb 3b
    54: 'フライ', # fb ss
    55: 'フライ', # fb lf
    56: 'フライ', # fb cf
    57: 'フライ', # fb rf
    58: 'ライナー', # ld p
    60: 'ライナー', # ld 1b
    61: 'ライナー', # ld 2b
    62: 'ライナー', # ld 3b
    63: 'ライナー', # ld ss
    64: 'ライナー', # ld lf

    66: 'ライナー', # ld rf
    67: '犠打',
    68: '犠打',
    69: '犠打',
    70: '犠打',
    71: '犠打',
    79: '犠飛', # sac fly lf
    80: '犠飛', # sac fly cf
    81:'犠飛', # sac fly rf
    82: '邪飛',
    83: '邪飛',
    84: '邪飛',
    85: '邪飛',
    86: '邪飛',
    87: '邪飛',
    88: '邪飛',

    90: '邪飛',
    91: 'ゴロ(併殺打)',
    92: 'ゴロ(併殺打)',
    93: 'ゴロ(併殺打)',
    94: 'ゴロ(併殺打)',
    95: 'ゴロ(併殺打)',
    96: 'ゴロ(併殺打)',

    100: '失策出塁',
    101: '失策出塁',
    102: '失策出塁',
    103: '失策出塁',
    104: '失策出塁',
    105: '失策出塁',
    106: '失策出塁',
    107: '失策出塁',
    108: '失策出塁',
    109: '野選',
    110: '野選',
    111: '野選',
    112: '野選',
    113: '野選',
    114: '野選',
    115: '犠打失策',
    116: '犠飛失策',

    208: '本塁打', # hr lf?

    210: '本塁打', # hr cf?
    212: '本塁打', # hr rf?

    214: '見送り三振',
    215: '犠打野選',
    216: '犠打野選',

    218: '犠打野選',

    229: '振逃げ',

    234: '邪直',

    236: '邪直',

    241: '3バント失敗',

    258: '規則違反',

    267: '打撃妨害',

    338: '?'
}

game_kind = {
    1: 'CL Regular Season',
    2: 'PL Regular Season',
    3: 'Nippon Series',
    4: 'All-Star Game',
    5: 'Spring Training',
    11: 'Farm Championship',
    26: 'Interleague',
    35: 'CL Climax Series First Stage',
    36: 'CL Climax Series Final Stage',
    37: 'PL Climax Series First Stage',
    38: 'PL Climax Series Final Stage'
}

ball_kind_code_to_color = {
    '-': 'C0',
    '4S': 'crimson',
    'SL': 'gold',
    'VS': 'khaki',
    'SV': 'lightsteelblue',
    'CU': 'paleturquoise',
    'SC': 'royalblue',
    'PC': 'turquoise',
    'KC': 'rebeccapurple',
    'FO': 'darkturquoise',
    'FS': 'cadetblue',
    'CH': 'mediumseagreen',
    'SI': 'orange',
    'SB': 'lightgreen',
    'PB': 'yellowgreen',
    'KN': 'mediumblue',
    'SH': 'tomato',
    '2S': 'orangered',
    '1S': 'lightsalmon',
    'FC': 'sienna',
    'EP': 'darkgray', # technically "super" eephus but I haven't encountered a normal one yet
    'HS': 'darkorange',
    'HL': 'darkkhaki'
}


def get_text_color_from_color(color):
  if color in ['gold', 'khaki', 'paleturquoise', 'turquoise']:
    return 'black'
  return 'white'

ball_kind_to_color = {ball_kind: ball_kind_code_to_color[ball_kind_code[code]] for code, ball_kind in ball_kind.items()}

team_name_short = {
    'G': 'Yomiuri',
    'S': 'Yakult',
    'DB': 'DeNA',
    'D': 'Chunichi',
    'T': 'Hanshin',
    'C': 'Hiroshima',
    'F': 'Nipponham',
    'E': 'Rakuten',
    'L': 'Seibu',
    'M': 'Lotte',
    'B': 'ORIX',
    'H': 'SoftBank',
    'PL': 'Pacific League',
    'CL': 'Central League',
    'WL': 'Western League', # Why is this in the data?
    'EL': 'Eastern League', # Same with this
}

team_to_color = {
    'G': '#f69727',
    'S': '#abcd05', 
    'DB': '#004a8f', 
    'D': '#08b1e8',
    'T': '#ffe100', 
    'C': '#f92b20',
    'F': '#016299', 
    'E': '#7d001a', 
    'L': '#00214b', 
    'M': '#efefef', 
    'B': '#baa834', 
    'H': '#fcc700',
    'PL': '#01a9e4',
    'CL': '#129144',
    'WL': '#552a8d',
    'EL': '#068ed9'
}

team_names_short_to_color = {team_name: team_to_color[team] for team, team_name in team_name_short.items()}

def get_text_color_from_team(team):
  if team in ['DB', 'F', 'L', 'E', 'DeNA', 'Nipponham', 'Seibu', 'Rakuten']:
    return 'white'
  else:
    return 'black'