-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSP_PlaysWithPredictions.sql
More file actions
105 lines (90 loc) · 3.44 KB
/
Copy pathSP_PlaysWithPredictions.sql
File metadata and controls
105 lines (90 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
USE [NFL]
GO
/****** Object: StoredProcedure [RP].[SP_PlaysWithPredictions] Script Date: 8/2/2020 1:12:44 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: rsc
-- Create date: 2020-07-22_1835
-- Description: insert into categorical predictions table; for use in PBI
-- =============================================
ALTER PROCEDURE [RP].[SP_PlaysWithPredictions]
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sqlvar_ID_ForecastIteration INT
SET @sqlvar_ID_ForecastIteration = (SELECT MAX([PK_ID_ForecastIteration]) FROM [NFL].[RP].[TBL_ForecastIteration])
DECLARE @sqlvar_ID_ForecastParameter_RF INT
SET @sqlvar_ID_ForecastParameter_RF = (SELECT MAX([PK_ID_ForecastParameter_RF]) FROM [NFL].[RP].[TBL_ForecastParameters_RF])
DECLARE @sqlvar_ID_AggregatedResults INT
SET @sqlvar_ID_AggregatedResults = (SELECT MAX([PK_ID_AggregatedResults]) FROM [NFL].[RP].[TBL_AggregatedResults] WHERE [FK_ID_ForecastIteration] = @sqlvar_ID_ForecastIteration)
--SELECT *
--FROM [NFL].[RP].[TBL_Results]
--WHERE [FK_ID_AggregatedResults] = @sqlvar_ID_AggregatedResults
SELECT
tPredix.[FK_ID_ForecastIteration]
, tPredix.[Prediction]
, tPredix.[CVType]
, tPlay.[home_team]
, tPlay.[away_team]
, tPlay.[posteam]
, tPlay.[defteam]
, tPlay.[yardline_100]
, tPlay.[game_date]
, tPlay.[quarter_seconds_remaining]
, tPlay.[half_seconds_remaining]
, tPlay.[game_seconds_remaining]
, tPlay.[game_half]
, tPlay.[drive]
, tPlay.[sp]
, tPlay.[qtr]
, tPlay.[down]
, tPlay.[ydstogo]
, tPlay.[ydsnet]
, tPlay.[play_type]
, tPlay.[yards_gained]
, tPlay.[shotgun]
, tPlay.[no_huddle]
, tPlay.[qb_kneel]
, tPlay.[qb_spike]
, tPlay.[qb_scramble]
, tPlay.[pass_location]
, tPlay.[air_yards]
, tPlay.[yards_after_catch]
, tPlay.[run_location]
, tPlay.[run_gap]
, tPlay.[home_timeouts_remaining]
, tPlay.[away_timeouts_remaining]
, tPlay.[posteam_timeouts_remaining]
, tPlay.[defteam_timeouts_remaining]
, tPlay.[total_home_score]
, tPlay.[total_away_score]
, tPlay.[posteam_score]
, tPlay.[defteam_score]
, tPlay.[score_differential]
, ABS(tPlay.[score_differential]) AS [score_differential_ABS]
, tPlay.[penalty]
, tPlay.[replay_or_challenge]
, tPlay.[play_id]
, tPlay.[game_id]
, tPlay.[PK_ID_Play]
, CASE WHEN tPredix.[Prediction] = -1 AND tPlay.[play_type] = 'run' THEN 1 ELSE 0 END AS [Run]
, CASE WHEN tPredix.[Prediction] = -1 AND tPlay.[play_type] = 'pass' THEN 1 ELSE 0 END AS [Play Action Error]
, CASE WHEN tPredix.[Prediction] = 1 AND tPlay.[play_type] = 'run' THEN 1 ELSE 0 END AS [Draw Error]
, CASE WHEN tPredix.[Prediction] = 1 AND tPlay.[play_type] = 'pass' THEN 1 ELSE 0 END AS [Pass]
, CASE WHEN tPredix.[Prediction] = -1 AND tPlay.[play_type] = 'run' THEN 'Run'
WHEN tPredix.[Prediction] = -1 AND tPlay.[play_type] = 'pass' THEN 'Play Action Error'
WHEN tPredix.[Prediction] = 1 AND tPlay.[play_type] = 'run' THEN 'Draw Error'
WHEN tPredix.[Prediction] = 1 AND tPlay.[play_type] = 'pass' THEN 'Pass' END
AS [PredictionType]
FROM [NFL].[RP].[TBL_Predictions_Categorical] tPredix
INNER JOIN [NFL].[RP].[TBL_Play] tPlay
ON tPredix.[FK_ID_Observation] = tPlay.[PK_ID_Play]
--INNER JOIN [NFL].[RP].[VW_FullPlays_Modified] vFullPlays
--ON tPlay.[PK_ID_Play] = vFullPlays.[PK_ID_Play]
WHERE [FK_ID_AggregatedResults] = @sqlvar_ID_AggregatedResults
ORDER BY tPlay.[PK_ID_Play] ASC
END
GO