2024-05-05 03:46:30 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2024 filifa
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-02-01 04:43:23 +00:00
|
|
|
pragma foreign_keys = 0;
|
|
|
|
|
2024-01-28 00:05:45 +00:00
|
|
|
begin;
|
2024-05-05 03:11:20 +00:00
|
|
|
attach database 'lahman-raw.db' as 'raw';
|
2024-01-31 06:09:39 +00:00
|
|
|
|
|
|
|
create temp table teamseasons as
|
|
|
|
select * from teams;
|
2024-01-28 03:07:24 +00:00
|
|
|
|
2024-01-28 03:45:23 +00:00
|
|
|
update teamseasons
|
2024-01-28 03:07:24 +00:00
|
|
|
set teamid = 'WS9'
|
|
|
|
where teamid = 'WAS' and franchid = 'WAS';
|
|
|
|
|
2024-01-28 03:45:23 +00:00
|
|
|
update teamseasons
|
2024-01-28 03:07:24 +00:00
|
|
|
set teamid = 'PHP'
|
|
|
|
where teamid = 'PH4' and franchid = 'PHQ';
|
2024-01-28 03:45:23 +00:00
|
|
|
|
2024-02-04 20:59:16 +00:00
|
|
|
-- set game totals from bbref
|
2024-02-02 02:48:12 +00:00
|
|
|
update teamseasons
|
2024-02-04 20:59:16 +00:00
|
|
|
set G = 160
|
|
|
|
where yearid = 1979 and teamid = 'CHA';
|
2024-02-02 02:48:12 +00:00
|
|
|
|
|
|
|
update teamseasons
|
2024-02-04 20:59:16 +00:00
|
|
|
set G = 161
|
|
|
|
where yearid = 1979 and teamid = 'DET';
|
2024-02-02 02:48:12 +00:00
|
|
|
|
|
|
|
update teamseasons
|
2024-02-04 20:59:16 +00:00
|
|
|
set G = 132
|
|
|
|
where yearid = 1897 and teamid = 'CL4';
|
2024-02-02 02:48:12 +00:00
|
|
|
|
|
|
|
update teamseasons
|
2024-02-04 20:59:16 +00:00
|
|
|
set G = 155
|
|
|
|
where yearid = 1892 and teamid = 'PIT';
|
|
|
|
|
|
|
|
update teamseasons
|
|
|
|
set G = 18
|
|
|
|
where yearid = 1884 and teamid = 'WIL';
|
|
|
|
|
|
|
|
update teamseasons
|
|
|
|
set G = 105
|
|
|
|
where yearid = 1884 and teamid = 'CNU';
|
|
|
|
|
|
|
|
update teamseasons
|
|
|
|
set G = 80
|
|
|
|
where yearid = 1882 and teamid = 'SL4';
|
|
|
|
|
|
|
|
update teamseasons
|
|
|
|
set G = 80
|
|
|
|
where yearid = 1882 and teamid = 'LS2';
|
|
|
|
|
|
|
|
update teamseasons
|
|
|
|
set
|
2024-02-04 22:20:07 +00:00
|
|
|
divid = nullif(divid, ''),
|
2024-02-04 20:59:16 +00:00
|
|
|
G = nullif(G, ''),
|
|
|
|
Ghome = nullif(Ghome, ''),
|
|
|
|
W = nullif(W, ''),
|
|
|
|
L = nullif(L, ''),
|
|
|
|
divwin = nullif(divwin,''),
|
|
|
|
wcwin = nullif(wcwin,''),
|
|
|
|
lgwin = nullif(lgwin,''),
|
|
|
|
wswin = nullif(wswin,''),
|
|
|
|
CG = nullif(CG, ''),
|
|
|
|
SHO = nullif(SHO, ''),
|
|
|
|
SV = nullif(SV, ''),
|
|
|
|
IPouts = nullif(IPouts, ''),
|
|
|
|
H = nullif(H, ''),
|
|
|
|
"2B" = nullif("2B", ''),
|
|
|
|
"3B" = nullif("3B", ''),
|
|
|
|
HR = nullif(HR, ''),
|
|
|
|
ER = nullif(ER, ''),
|
|
|
|
HR = nullif(HR, ''),
|
|
|
|
BB = nullif(BB, ''),
|
|
|
|
SO = nullif(SO, ''),
|
|
|
|
HBP = nullif(HBP, ''),
|
|
|
|
R = nullif(R, ''),
|
2024-02-04 22:20:07 +00:00
|
|
|
SF = nullif(SF, ''),
|
|
|
|
attendance = nullif(attendance, '');
|
2024-02-02 02:48:12 +00:00
|
|
|
|
2024-01-28 03:45:23 +00:00
|
|
|
alter table "teamseasons" drop column "franchID";
|
2024-01-31 06:09:39 +00:00
|
|
|
|
|
|
|
create table if not exists main."teamseasons" (
|
|
|
|
"year" NUMERIC,
|
|
|
|
"league" TEXT,
|
|
|
|
"team" TEXT,
|
|
|
|
"division" TEXT,
|
|
|
|
"Rank" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"G" NUMERIC check (W + L <= G),
|
|
|
|
"Ghome" NUMERIC check (GHome <= G),
|
|
|
|
"W" NUMERIC check (W <= G),
|
|
|
|
"L" NUMERIC check (L <= G),
|
|
|
|
"DivWin" NUMERIC check (divwin in ('Y','N')),
|
|
|
|
"WCWin" NUMERIC check (wcwin in ('Y','N')),
|
|
|
|
"LgWin" NUMERIC check (lgwin in ('Y','N')),
|
|
|
|
"WSWin" NUMERIC check (wswin in ('Y','N')),
|
2024-01-31 06:09:39 +00:00
|
|
|
"R" NUMERIC,
|
|
|
|
"AB" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"H" NUMERIC check (H <= AB),
|
|
|
|
"2B" NUMERIC check ("2B" <= H),
|
|
|
|
"3B" NUMERIC check ("3B" <= H),
|
|
|
|
"HR" NUMERIC check (HR <= H),
|
2024-01-31 06:09:39 +00:00
|
|
|
"BB" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"SO" NUMERIC check (SO <= AB),
|
2024-01-31 06:09:39 +00:00
|
|
|
"SB" NUMERIC,
|
|
|
|
"CS" NUMERIC,
|
|
|
|
"HBP" NUMERIC,
|
|
|
|
"SF" NUMERIC,
|
|
|
|
"RA" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"ER" NUMERIC check (ER <= RA),
|
2024-01-31 06:09:39 +00:00
|
|
|
"ERA" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"CG" NUMERIC check (CG <= G),
|
|
|
|
"SHO" NUMERIC check (SHO <= G),
|
|
|
|
"SV" NUMERIC check (SV <= G),
|
2024-01-31 06:09:39 +00:00
|
|
|
"IPouts" NUMERIC,
|
|
|
|
"HA" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"HRA" NUMERIC check (HRA <= HA),
|
2024-01-31 06:09:39 +00:00
|
|
|
"BBA" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"SOA" NUMERIC check (SOA <= IPouts),
|
2024-01-31 06:09:39 +00:00
|
|
|
"E" NUMERIC,
|
2024-02-04 20:59:16 +00:00
|
|
|
"DP" NUMERIC check (2 * DP <= IPouts),
|
2024-01-31 06:09:39 +00:00
|
|
|
"FP" NUMERIC,
|
|
|
|
"name" NUMERIC,
|
|
|
|
"park" NUMERIC,
|
|
|
|
"attendance" NUMERIC,
|
|
|
|
"BPF" NUMERIC,
|
|
|
|
"PPF" NUMERIC,
|
|
|
|
"teamIDBR" TEXT,
|
|
|
|
"teamIDlahman45" TEXT,
|
|
|
|
"teamIDretro" TEXT,
|
|
|
|
PRIMARY KEY("year","team"),
|
2024-02-02 01:45:40 +00:00
|
|
|
UNIQUE("year","teamIDBR"),
|
|
|
|
UNIQUE("year","teamIDlahman45"),
|
|
|
|
UNIQUE("year","teamIDretro"),
|
2024-01-31 06:09:39 +00:00
|
|
|
foreign key("year") references "seasons"("year"),
|
|
|
|
foreign key("league") references "leagues"("ID"),
|
|
|
|
foreign key("team") references "teams"("ID")
|
|
|
|
);
|
|
|
|
|
|
|
|
insert into main.teamseasons
|
|
|
|
select distinct * from temp."teamseasons";
|
2024-01-28 00:05:45 +00:00
|
|
|
commit;
|