Last active 2 months ago

Revision 4d51bf2030503e39917b2eedcd8540ca8da4862f

stats-v3-migration.sql Raw
1rename table stats_games to stats_sessions;
2create table stats_games
3(
4 id int unsigned auto_increment primary key,
5 uuid uuid default uuid() not null comment 'legacy campaignID' unique,
6 date_start bigint not null comment 'unix timestamp',
7 date_start_finale int null comment 'unix timestamp of finale',
8 date_end bigint null comment 'unix timestamp',
9 duraton_game bigint as (`date_end` - `date_start`) comment 'seconds of game',
10 duration_finale bigint as (`date_end` - `date_start_finale`) comment 'seconds of finale',
11 map_id varchar(64) not null comment 'map id of last chapter',
12 gamemode varchar(64) not null,
13 difficulty tinyint null comment '0=easy, 1=normal, 2=advanced, 3=expert',
14 server_tags varchar(255) not null comment 'comma separated list of tags',
15 stat_version tinyint unsigned not null comment 'version of metrics',
16 index stats_games_gamemode_index (gamemode),
17 index stats_games_map_id_index (map_id)
18);
19insert into stats_games (uuid, date_start, date_start_finale, date_end, map_id, gamemode, difficulty, server_tags, stat_version)
20# add stats_games data from session data
21SELECT campaignID, date_start, date_end-finale_time, date_end, map, gamemode, difficulty, server_tags, 0
22FROM stats_sessions group by campaignID
23order by id asc;
24alter table stats_sessions
25 add game_id int unsigned not null after id,
26 # moved to games
27 drop map,
28 drop gamemode,
29 drop difficulty,
30 drop finale_time,
31 drop server_tags,
32 drop DamageDealt,
33 # renamed columns for consistency
34 change zombie_kills kills_common int unsigned default 0 not null,
35 change melee_kills kills_melee smallint(10) unsigned default 0 not null,
36 change SurvivorDamage damage_dealt int unsigned default 0 not null,
37 change SurvivorFFCount damage_dealt_friendly_count mediumint unsigned default 0 not null,
38 change SurvivorFFTakenCount damage_taken_friendly_count int null,
39 change SurvivorFFDamage damage_dealt_friendly int null,
40 change SurvivorFFTakenDamage damage_taken_friendly int null,
41 change MedkitsUsed used_kit_self tinyint(10) unsigned default 0 not null comment 'heal self',
42 change FirstAidShared used_kit_other tinyint(10) unsigned default 0 not null comment 'healed teammate',
43 change PillsUsed used_pills smallint(10) unsigned default 0 not null,
44 change MolotovsUsed used_molotov smallint(10) unsigned default 0 not null,
45 change PipebombsUsed used_pipebomb smallint(10) unsigned default 0 not null,
46 change BoomerBilesUsed used_bile smallint(10) unsigned default 0 not null,
47 change AdrenalinesUsed used_adrenaline smallint(10) unsigned default 0 not null,
48 change DefibrillatorsUsed used_defib smallint(10) unsigned default 0 not null,
49 change DamageTaken damage_taken int unsigned default 0 not null,
50 change ReviveOtherCount times_revived_other smallint(10) unsigned default 0 not null,
51 change Incaps times_incapped smallint(10) unsigned default 0 not null,
52 change Deaths deaths tinyint(10) unsigned default 0 not null,
53 change boomer_kills kills_boomer smallint(10) unsigned not null,
54 change smoker_kills kills_smoker smallint(10) unsigned not null,
55 change jockey_kills kills_jockey smallint(10) unsigned not null,
56 change hunter_kills kills_hunter smallint(10) unsigned not null,
57 change spitter_kills kills_spitter smallint(10) unsigned not null,
58 change charger_kills kills_charger smallint(10) unsigned not null,
59 change SpecialInfectedKills kills_all_specials int unsigned as (`kills_boomer` + `kills_smoker` + `kills_jockey` + `kills_hunter` + `kills_spitter` + `kills_charger`),
60 modify honks smallint unsigned default 0 null comment 'clowns honked',
61 change WitchesCrowned witches_crowned smallint(8) unsigned default 0 not null,
62 change SmokersSelfCleared smokers_selfcleared smallint(8) unsigned default 0 not null,
63 change RocksHitBy rocks_hitby smallint(8) unsigned default 0 not null,
64 change RocksDodged rocks_dodged smallint(8) unsigned default 0 not null,
65 change HuntersDeadstopped hunters_deadstopped smallint(8) unsigned default 0 not null,
66 change TimesPinned times_pinned smallint(8) unsigned default 0 not null,
67 change ClearedPinned times_cleared_pinned smallint(8) unsigned default 0 null comment 'helped pinned teammate',
68 change BoomedTeammates times_boomed_teammates smallint unsigned default 0 not null,
69 change TimesBoomed times_boomed smallint(8) unsigned default 0 not null,
70 change DamageToTank damage_dealt_tank mediumint unsigned default 0 not null comment 'dmg to tank',
71 change DamageToWitch damage_dealt_witch mediumint unsigned default 0 not null comment 'dmg to witch',
72 change CarAlarmsActivated caralarms_activated tinyint unsigned default 0 not null,
73 # new metrics
74 add longest_shot_distance float null,
75 add times_hanging smallint unsigned default 0 null after times_revived_other,
76 add kills_tank smallint unsigned null after kills_all_specials,
77 add kills_witch smallint unsigned null after kills_tank,
78 add kills_fire smallint unsigned null comment 'gascan/molotov' after kills_witch,
79 add kills_pipebomb smallint unsigned null after kills_fire,
80 add kills_minigun smallint unsigned null after kills_pipebomb,
81 add seconds_alive int unsigned not null,
82 add seconds_idle int unsigned not null,
83 add seconds_dead int unsigned default 0,
84 add seconds_total int unsigned as (seconds_alive + seconds_idle + seconds_dead);
85# get new game id, update seconds_* (not perfect but whatever)
86update stats_sessions u
87join stats_games g on g.uuid = u.campaignID
88SET u.game_id=g.id, u.seconds_alive=duration*60, u.seconds_idle=u.minutes_idle*60;
89# drop rest of columns and add fk
90alter table stats_sessions
91 drop duration,
92 drop date_start,
93 drop date_end,
94 drop minutes_idle,
95 drop index stats_games_campaignID_index,
96 drop key campaignID,
97 drop column campaignID,
98 add constraint stats_sessions_stats_games_id_fk
99 foreign key (game_id)
100 references stats_games (id)
101 on update cascade on delete cascade;
102alter table stats_users
103 change survivor_deaths deaths int(11) unsigned default 0 not null,
104 drop infected_deaths,
105 change survivor_damage_rec damage_taken bigint(11) unsigned default 0 not null,
106 change survivor_damage_give damage_dealt bigint(11) unsigned default 0 not null,
107 add damage_dealt_friendly_count mediumint unsigned default 0 not null,
108 add damage_taken_friendly_count mediumint unsigned default 0 null,
109 drop infected_damage_rec,
110 drop infected_damage_give,
111 add pickups_bile int(11) unsigned default 0 not null after pickups_molotov,
112 change pickups_pipe_bomb pickups_pipebomb int(11) unsigned default 0 not null,
113 add pickups_adrenaline int null after pickups_pills,
114 change survivor_incaps times_incapped int(11) unsigned default 0 not null,
115 change pickups_pain_pills pickups_pills int(11) unsigned default 0 not null after pickups_pipebomb,
116 add times_hanging int(11) unsigned default 0 not null comment 'ledge grabs' after times_incapped,
117 change revived_others times_revived_other int(11) unsigned default 0 not null,
118 change melee_kills kills_melee int(11) unsigned default 0 not null comment 'kils with melee',
119 change tanks_killed kills_tank int unsigned default 0 not null,
120 change tanks_killed_solo kills_tank_solo int unsigned default 0 not null,
121 change tanks_killed_melee kills_tank_melee int unsigned default 0 not null comment 'with melee',
122 change survivor_ff damage_dealt_friendly int unsigned default 0 not null,
123 change survivor_ff_rec damage_taken_friendly int default 0 null comment 'ff recv',
124 change common_kills kills_common int unsigned default 0 null,
125 change common_headshots kills_common_headshots int unsigned default 0 not null,
126 change damage_to_tank damage_dealt_tank int unsigned default 0 null,
127 drop column damage_as_tank,
128 change damage_witch damage_dealt_witch int unsigned default 0 not null,
129 change packs_used used_ammo_packs int unsigned default 0 not null,
130 change ff_kills kills_friendly int unsigned default 0 not null comment 'teammates killed',
131 change damage_molotov damage_dealt_fire int unsigned default 0 not null comment 'gascan/molotov',
132 change kills_molotov kills_fire int unsigned default 0 not null comment 'gascan/molotov',
133 change kills_pipe kills_pipebomb int unsigned default 0 not null,
134 change clowns_honked honks smallint unsigned default 0 not null comment 'clown honks',
135 change boomer_mellos times_boomed_teammates int default 0 null comment 'popped boomer and got someone boomed',
136 change boomer_mellos_self times_boomed_self smallint default 0 null comment 'popped boomer and got self boomed',
137 add times_boomed smallint default 0 null after times_boomed_self,
138 change heal_self used_kit_self int(11) unsigned default 0 not null comment 'healed self',
139 change heal_others used_kit_other int(11) unsigned default 0 not null comment 'healed teammate',
140 add used_kit int(11) as (used_kit_self + used_kit_other) comment 'any usage',
141 change defibs_used used_defib int(11) unsigned default 0 not null after used_kit_other,
142 change pills_used used_pills int(11) unsigned default 0 not null,
143 change adrenaline_used used_adrenaline int(11) unsigned default 0 not null after used_pills,
144 change revived times_revived int(11) unsigned default 0 not null comment 'self got incapped',
145 change cleared_pinned times_cleared_pinned int unsigned default 0 not null comment 'helped survivor that was pinned',
146 add rocks_dodged int unsigned default 0 not null after rocks_hitby,
147 add seconds_alive int unsigned not null,
148 add seconds_idle int unsigned not null,
149 add seconds_dead int unsigned default 0,
150 add seconds_total int unsigned as (seconds_alive + seconds_idle + seconds_dead),
151 change throws_puke used_bile int unsigned default 0 not null comment 'throws',
152 change throws_molotov used_molotov int unsigned default 0 not null comment 'throws',
153 change throws_pipe used_pipebomb int unsigned default 0 not null comment 'throws';
154
155update stats_users
156set seconds_alive = minutes_played * 60, seconds_idle = minutes_idle * 60;
157alter table stats_users
158 drop minutes_played,
159 drop minutes_idle;