Skip to content

Commit

Permalink
Updating stats query to pull stats from full at-bats. Updating pitch …
Browse files Browse the repository at this point in the history
…and swing distribution queries to merge data from old contract.
  • Loading branch information
Kellan Wampler committed Dec 21, 2023
1 parent ac51e23 commit d4cf201
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions api/queries/pitch_distribution.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ with dedup_events as (
DISTINCT ON(transaction_hash, log_index) *
FROM wyrm_labels
WHERE label='moonworm-alpha'
AND address='0xde191e8c352BA59F95cf19f0931cCbBcc7B60934'
AND (address='0xde191e8c352BA59F95cf19f0931cCbBcc7B60934' OR address='0x9270df8d907A99E5024dc3532657a5cF9C7A4889')
AND log_index IS NOT NULL
), SessionResolved as (
SELECT
address as contract_address,
label_data->'args'->>'sessionID' as session_id,
label_data->'args'->>'outcome' as outcome,
label_data->'args'->>'batterAddress' as batter_address,
Expand All @@ -18,6 +19,7 @@ with dedup_events as (
WHERE label_data->>'name'='SessionResolved'
), PitchRevealed as (
SELECT
address as contract_address,
label_data->'args'->>'sessionID' as session_id,
label_data->'args'->'pitch'-> 1 as pitch_speed,
label_data->'args'->'pitch'-> 2 as pitch_vertical,
Expand All @@ -32,7 +34,7 @@ with dedup_events as (
pitch_vertical,
pitch_horizontal,
count(*) as pitch_count
FROM SessionResolved LEFT JOIN PitchRevealed ON SessionResolved.session_id = PitchRevealed.session_id
FROM SessionResolved LEFT JOIN PitchRevealed ON (SessionResolved.contract_address=PitchRevealed.contract_address AND SessionResolved.session_id = PitchRevealed.session_id)
GROUP BY pitcher_address, pitcher_token_id, pitch_speed, pitch_vertical, pitch_horizontal
ORDER BY pitch_speed, pitch_vertical, pitch_horizontal
)
Expand Down
4 changes: 2 additions & 2 deletions api/queries/player_stats_atbat.sql
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ with dedup_events as (
label_data->'args'->>'pitcherTokenID' as pitcher_token_id,
log_index
FROM dedup_events
WHERE label_data->>'name'='AtBatProgress' AND label_data->'args'->>'outcome'!=0
WHERE label_data->>'name'='AtBatProgress' AND label_data->'args'->>'outcome'!='0'
), batter_stats as (
SELECT
SUM(CASE
Expand Down Expand Up @@ -67,7 +67,7 @@ with dedup_events as (
SUM(CASE
WHEN outcome = '7' THEN 1 ELSE 0
END) as in_play_outs,
count(*) as total_pitscher_events,
count(*) as total_pitcher_events,
pitcher_address,
pitcher_token_id
FROM AtBats
Expand Down
6 changes: 4 additions & 2 deletions api/queries/swing_distribution.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ with dedup_events as (
DISTINCT ON(transaction_hash, log_index) *
FROM wyrm_labels
WHERE label='moonworm-alpha'
AND address='0xde191e8c352BA59F95cf19f0931cCbBcc7B60934'
AND (address='0xde191e8c352BA59F95cf19f0931cCbBcc7B60934' OR address='0x9270df8d907A99E5024dc3532657a5cF9C7A4889')
AND log_index IS NOT NULL
), SessionResolved as (
SELECT
address as contract_address,
label_data->'args'->>'sessionID' as session_id,
label_data->'args'->>'outcome' as outcome,
label_data->'args'->>'batterAddress' as batter_address,
Expand All @@ -18,6 +19,7 @@ with dedup_events as (
WHERE label_data->>'name'='SessionResolved'
), SwingRevealed as (
SELECT
address as contract_address,
label_data->'args'->>'sessionID' as session_id,
label_data->'args'->'swing'-> 1 as swing_type,
label_data->'args'->'swing'-> 2 as swing_vertical,
Expand All @@ -32,7 +34,7 @@ with dedup_events as (
swing_vertical,
swing_horizontal,
count(*) as swing_count
FROM SessionResolved LEFT JOIN SwingRevealed ON SessionResolved.session_id = SwingRevealed.session_id
FROM SessionResolved LEFT JOIN SwingRevealed ON (SessionResolved.contract_address=SwingRevealed.contract_address AND SessionResolved.session_id = SwingRevealed.session_id)
GROUP BY batter_address, batter_token_id, swing_type, swing_vertical, swing_horizontal
ORDER BY swing_type, swing_vertical, swing_horizontal
)
Expand Down

0 comments on commit d4cf201

Please sign in to comment.