Skip to content

Commit

Permalink
Add secondary pos
Browse files Browse the repository at this point in the history
  • Loading branch information
TravisL12 committed Sep 14, 2020
1 parent 7f74511 commit 63885b2
Show file tree
Hide file tree
Showing 10 changed files with 18,312 additions and 552 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ The database was named `bigfly.sqlite`, I made a copy of it and used `sqlite3` t
- `SELECT * from <table_name>` simple query use `limit 10` to just see the headers.
- `.output output.csv` to output the query to a CSV file

Additional data for the options was shared to me.

## Queries used

These are some simple queries used to eventually output the data in this site. I added the headers for each of the table outputs.
Expand Down
105 changes: 105 additions & 0 deletions player_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
optionKey

0: { // Sex
0, // Male
1, // Female
},

1 - 3

4: { // Throws
0, // Left
1, // Right
},
5: { // Bats
0, // Left
1, // Right
2, // Switch
},

6 - 7

8 - Personality

9 - 11

12 - Head #

13

14 - Eyebrows #
15 - Hair #
16 - Facial Hair #
17 - Eye black
18 - Helmet Tar
19 - Eyewear
20 - Jersey Number

21

22 - Physique

23 - 24

25 - Elbow Guard
26 - Angle Guard
27 - Elbow
28 - Left Tatoo
29 - Right Tatoo
30 - Left Sleeve
31 - Right Sleeve
32 - Pants

33 - 35

36 - Wristband

37 - 38

39 - Batting Glove
40 - Cleats
41 - Wrist tape

42 - 47

48 - Pitcher Windup
49 - Pitcher Angle
50 - Batting Routine
51 - Batting Stance
52 - Walkup Song

53 - Player Rating !!! (closer to 0 the better)

54 - Position
55 - { // Secondary Position !!!
2,
3,
4,
5,
6,
7,
9,
10, ???
11, ???
12, ???
13, ???
}

56

57 - Pitcher Type
58 - 4F Pitch
59 - 2F Pitch
60 - SB Pitch
61 - CW Pitch
62 - FK Pitch
63 - CB Pitch
64 - SL Pitch
65 - CF Pitch
66 - First Name
67 - Last Name

68 - 91

92 - Bat Style
93 - Bat Grip
6 changes: 5 additions & 1 deletion smb3_db_queries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ GET PLAYERS AND ABILITIES AND TEAMS
- Some duplicate players show up with different traits. Not sure why

select
team.teamName,
vbpi.firstName,
vbpi.lastName,
vbpi.primaryPosition,
Expand All @@ -43,7 +44,8 @@ select
tbp.accuracy,
tbp.age,
traits.trait,
traits.subType
traits.subType,
options.*
from v_baseball_player_info vbpi
join t_baseball_players tbp
on vbpi.baseballPlayerGUID = tbp.GUID
Expand All @@ -53,6 +55,8 @@ join t_baseball_player_local_ids localId
on localId.GUID = tbp.GUID
left join t_baseball_player_traits traits
on localId.localID = traits.baseballPlayerLocalID
left join t_baseball_player_options options
on localId.localID = options.baseballPlayerLocalID
order by vbpi.lastName;

DUPLICATES
Expand Down
56 changes: 23 additions & 33 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React, { useEffect, useState, useCallback } from 'react';
import './App.css';
import Papa from 'papaparse';
import smbCsvData from './smb_info.csv';
import smbCsvData from './smb_data.csv';
import TeamTable from './TeamTable';
import PlayerTypeForm from './PlayerTypeForm';
import { sortBy, uniqBy, values } from 'lodash';
import { compileOptions, createPlayer } from './buildPlayer';
import {
createPlayer,
buildChecklist,
getUniqTeams,
positions,
secondaryPositions,
pitcherPositions,
} from './helper';
import FilterList from './FilterList';
import smbLogo from './smb_logo.png';

const initialFilters = {
positions: buildChecklist(values(positions).slice(1), true),
positions2: buildChecklist(values(secondaryPositions), true),
pitchers: buildChecklist(values(pitcherPositions), true),
name: '',
};
Expand All @@ -42,43 +44,31 @@ const filterPlayers = (filters, players) => {
return uniqBy(players, 'display.name');
};

const loadPlayers = (cb) => {
Papa.parse(smbCsvData, {
download: true,
header: true,
complete: cb,
});
};

function App() {
const [players, setPlayers] = useState([]);
const [filters, setFilters] = useState(initialFilters);
const [selectedOption, setSelectedOption] = useState('Positions');

const getStats = useCallback(() => {
Papa.parse(smbCsvData, {
download: true,
header: true,
complete: ({ data }) => {
const buildPlayers = data.map((player) => createPlayer(player));
setFilters({
...filters,
teams: buildChecklist(sortBy(getUniqTeams(buildPlayers)), true),
});
setPlayers(buildPlayers);
},
});
}, [filters]);

const checkPitcherOnly = useCallback(() => {
const allPositionFiltersOff = values(filters.positions).every((p) => !p);
const somePitcherFiltersOn = values(filters.pitchers).some((p) => p);

setSelectedOption(
allPositionFiltersOff && somePitcherFiltersOn
? 'Pitchers'
: selectedOption
);
}, [filters.positions, filters.pitchers, selectedOption]);

useEffect(() => {
checkPitcherOnly();
}, [checkPitcherOnly]);

useEffect(() => {
getStats();
loadPlayers(({ data }) => {
const options = compileOptions(data);
const buildPlayers = values(options).map((player) =>
createPlayer(player)
);
setFilters({
...filters,
teams: buildChecklist(sortBy(getUniqTeams(buildPlayers)), true),
});
setPlayers(buildPlayers);
});
// eslint-disable-next-line
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/FilterList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { keys, startCase } from "lodash";
import React from 'react';
import { keys, startCase } from 'lodash';

const FilterList = ({ filters, setFilters, filterAttr }) => {
return (
Expand Down
11 changes: 6 additions & 5 deletions src/TeamTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ const TeamTable = ({ players, isPitchers }) => {
</tr>
</thead>
<tbody>
{players.map(({ display, isPitcher }) => (
{players.map(({ display }) => (
<tr key={display.name}>
{headers.map((header) => {
const ratingPercent =
!isNaN(display[header]) &&
!['age', 'trait', 'trait2'].includes(header)
? `${display[header]}%`
: null;
const displayValue =
header === 'position'
? positionsAbbrev[display[header]]
: display[header];

const displayValue = header.includes('position')
? positionsAbbrev[display[header]]
: display[header];

return (
<td className={`player-col player-${header}`} key={header}>
{ratingPercent && (
Expand Down
100 changes: 100 additions & 0 deletions src/buildPlayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { keys, pick, values, mean } from 'lodash';
import { positions, pitcherPositions } from './helper';

const buildAverage = (data, isPitcher) => {
const attributesToAverage = isPitcher
? ['accuracy', 'velocity', 'junk']
: ['arm', 'contact', 'fielding', 'power', 'speed'];
const avgValues = values(pick(data, attributesToAverage));
const averaged = mean(avgValues.map((val) => +val)).toFixed(0);

return { ...data, averaged };
};

export const createPlayer = (info) => {
const isPitcher = info.primaryPosition === '1';
const position = isPitcher
? pitcherPositions[info.pitcherRole]
: positions[info.primaryPosition];
const position2 = !isPitcher ? positions[info['55']] : null;
let pitcherStats = {};
const stats = {
team: info.teamName,
name: `${info.firstName} ${info.lastName}`,
position,
position2,
age: info.age,
power: info.power,
contact: info.contact,
speed: info.speed,
fielding: info.fielding,
arm: info.arm,
};

const traits = {
trait: info.trait,
trait2: info.subType,
};

if (isPitcher) {
pitcherStats = {
velocity: info.velocity,
junk: info.junk,
accuracy: info.accuracy,
};
}

const display = buildAverage(
{ ...stats, ...pitcherStats, ...traits },
isPitcher
);

return {
isPitcher,
display,
info,
};
};

// accuracy: "46"
// age: "22"
// arm: ""
// contact: "38"
// fielding: "98"
// firstName: "Fran"
// junk: "54"
// lastName: "Gipani"
// pitcherRole: "1"
// power: "2"
// primaryPosition: "1"
// speed: "35"
// teamName: "Beewolves"
// velocity: "66"
// trait: "1"
// trait2: "5"

// baseballPlayerLocalID: '1';
// optionKey: '0';
// optionType: '0';
// optionValue: '0';
export const compileOptions = (info) => {
return info.reduce((acc, option) => {
const optionKeys = keys(option);
acc[option.baseballPlayerLocalID] = acc[option.baseballPlayerLocalID] ?? {
id: option.baseballPlayerLocalID,
};

optionKeys.forEach((key) => {
if (
!acc[option.baseballPlayerLocalID][key] &&
!['optionKey', 'optionType', 'optionValue'].includes(key)
) {
acc[option.baseballPlayerLocalID][key] = option[key];
} else if (key === 'optionKey') {
acc[option.baseballPlayerLocalID][option.optionKey] =
option.optionValue;
}
});
return acc;
}, {});
};
Loading

0 comments on commit 63885b2

Please sign in to comment.