-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAA_USECASE_ALGO_RUN_PKG
272 lines (240 loc) · 11.9 KB
/
AA_USECASE_ALGO_RUN_PKG
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
create or replace PACKAGE AA_USECASE_ALGO_RUN_PKG AS
/*********************************************************
Usecase 1 - Employee Attrition Training - TESTED OK
Author: Snehotosh Banerjee
Date: 20/01/2017
*********************************************************/
PROCEDURE AA_UC1_ATTRITION_TRAIN_RUN_PRC;
PROCEDURE AA_UC1_ATTRITION_PRED_RUN_PRC;
/*********************************************************
Usecase 2 - Employee Performance Training - TESTED OK
Author: Snehotosh Banerjee
Date: 20/01/2017
**********************************************************/
PROCEDURE AA_UC2_PERF_TRAIN_RUN_PRC;
PROCEDURE AA_UC2_PERF_PRED_RUN_PRC;
/*********************************************************
Usecase 3 - Employee Profiling - TESTED OK
Author: Snehotosh Banerjee
Date: 20/01/2017
*********************************************************/
PROCEDURE AA_UC3_PROFILE_TRAIN_RUN_PRC;
/*********************************************************
Usecase 5 - Forecasting Payroll Cost - TESTED OK
Author: Snehotosh Banerjee
Date: 27/01/2017
*********************************************************/
PROCEDURE AA_UC5_FORECAST_TRAIN_RUN_PRC;
PROCEDURE AA_UC5_FC_TRN_DEPT_RUN_PRC;
PROCEDURE AA_UC5_FC_TRN_BP_DEPT_RUN_PRC;
PROCEDURE AA_UC5_FC_TRN_VP_DEPT_RUN_PRC;
END AA_USECASE_ALGO_RUN_PKG;
create or replace PACKAGE BODY AA_USECASE_ALGO_RUN_PKG AS
/*******************************************************************************
Calling Procedure - UC1 - Attrition
********************************************************************************/
PROCEDURE AA_UC1_ATTRITION_TRAIN_RUN_PRC IS
BEGIN
AA_USECASE_ALGO_LIB_PKG.AA_UC1_TRAIN_PRC(
p_sql => 'select NATIONALITY, GENDER,AGE,MARITAL_STATUS,TENURE,CHNG_COMPA_L4Y,CHNG_COMPA_LY,AVG_PERF_L4Y,
CHNG_SICKLV_L4Y,CHNG_SICKLV_LY,DEPT_CHNG_L4Y,PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y,ISCHURN
FROM AA_COMMN_MDL_TRAIN_TBL WHERE AGE <=55',
p_is_bal_reqd => 'Y',
p_perc_os => 1000,
p_perc_us => 100,
p_trn_ratio => 0.8,
p_tgt_class_label => 'Y');
END;
/*******************************************************************************
Calling Procedure - UC2 - Performance
'select NATIONALITY, GENDER,AGE,MARITAL_STATUS,TENURE,CHNG_COMPA_L4Y,CHNG_COMPA_LY,AVG_PERF_L4Y,
CHNG_SICKLV_L4Y,CHNG_SICKLV_LY,DEPT_CHNG_L4Y,PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y,
PERF_CATEG1 FROM AA_COMMN_MDL_TRAIN_TBL'
********************************************************************************/
PROCEDURE AA_UC2_PERF_TRAIN_RUN_PRC IS
BEGIN
AA_USECASE_ALGO_LIB_PKG.AA_UC2_TRAIN_PRC(
p_sql => 'select NATIONALITY, GENDER,AGE,TENURE,AVG_PERF_L4Y,CHNG_SICKLV_L4Y,CHNG_SICKLV_LY,DEPT_CHNG_L4Y,
PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y,AVG_UNPLV_L4Y,AVG_UNAUTH_L4Y,PERF_CATEG1 FROM AA_COMMN_MDL_TRAIN_TBL',
p_is_bal_reqd => 'N',
p_perc_os => 300,
p_perc_us => 200,
p_trn_ratio => 0.8);
END;
/*******************************************************************************
Calling the Procedure - UC3 - Profiling
'SELECT EMPID,NATIONALITY, GENDER,AGE,MARITAL_STATUS,TENURE,CHNG_COMPA_L4Y,
CHNG_COMPA_LY,AVG_PERF_L4Y,CHNG_SICKLV_L4Y,CHNG_SICKLV_LY,DEPT_CHNG_L4Y,
PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y
FROM AA_COMMN_MDL_TRAIN_TBL'
********************************************************************************/
PROCEDURE AA_UC3_PROFILE_TRAIN_RUN_PRC IS
BEGIN
AA_USECASE_ALGO_LIB_PKG.AA_UC3_PRC(
p_sql => 'SELECT EMPID,AGE,MARITAL_STATUS,TENURE,CHNG_COMPA_L4Y,AVG_PERF_L4Y,CHNG_SICKLV_L4Y,DEPT_CHNG_L4Y,
PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y
FROM AA_COMMN_MDL_TRAIN_TBL',
p_isDendoReqd => 'N');
END;
/*******************************************************************************
Calling the Procedure - UC5 - Payroll Cost
********************************************************************************/
PROCEDURE AA_UC5_FORECAST_TRAIN_RUN_PRC IS
BEGIN
AA_USECASE_ALGO_LIB_PKG.AA_UC5_PRC(p_sql => 'select YRMON,PAYROLL_COST from AA_PAYROLL_COST_TRAIN',
p_is_seasonal => 'T' ,
p_ts_measure_col => 'PAYROLL_COST',
p_ts_time_col => 'YRMON',
p_forecast_period => 12 ,
p_start_win => 2011,
p_end_win => 2016,
p_trend_win => 72);
END;
/*******************************************************************************
Calling the Procedure - UC5 - Payroll Cost
********************************************************************************/
PROCEDURE AA_UC5_FC_TRN_DEPT_RUN_PRC IS
sqlText VARCHAR2(4000):= '';
sql_trunc_stmt varchar2(4000);
sql_trunc_img_stmt varchar2(4000);
v_count NUMBER:=0;
v_count_img NUMBER:=0;
v_tab_name VARCHAR2(30):='AA_UC5_FORECAST_DEPT_TBL';
v_tab_img_name VARCHAR2(30):='AA_UC5_FORECAST_DEPT_IMG_TBL';
ex EXCEPTION;
BEGIN
/* Target table drop code */
sql_trunc_stmt:= 'TRUNCATE TABLE '||v_tab_name;
sql_trunc_img_stmt:= 'TRUNCATE TABLE '||v_tab_img_name;
/* Checking whether table exists */
select count(*) INTO v_count from AA_UC5_FORECAST_DEPT_TBL;
select count(*) INTO v_count_img from AA_UC5_FORECAST_DEPT_IMG_TBL;
/* Checking whether table exists */
IF v_count > 0 THEN
execute immediate sql_trunc_stmt;
END IF;
IF v_count_img > 0 THEN
execute immediate sql_trunc_img_stmt;
END IF;
/* Running Model PER Department */
FOR rec in (select distinct deptno,dname from AA_PAYROLL_COST_DEPT_TRAIN)
LOOP
sqlText:='select YRMON,PAYROLL_COST from AA_PAYROLL_COST_DEPT_TRAIN where DEPTNO = '''||rec.DEPTNO||''' ORDER BY YR,MON_NUM';
AA_USECASE_ALGO_LIB_PKG.AA_UC5_DEPT_PRC(p_sql => sqlText,
p_is_seasonal => 'T' ,
p_ts_measure_col => 'PAYROLL_COST',
p_ts_time_col => 'YRMON',
p_forecast_period => 12 ,
p_start_win => 2011,
p_end_win => 2016,
p_trend_win => 72,
p_deptno => rec.DEPTNO,
p_dname => rec.DNAME
);
END LOOP;
END;
PROCEDURE AA_UC5_FC_TRN_BP_DEPT_RUN_PRC IS
sqlText VARCHAR2(4000):= '';
sql_trunc_stmt varchar2(4000);
sql_trunc_img_stmt varchar2(4000);
v_count NUMBER:=0;
v_count_img NUMBER:=0;
v_tab_name VARCHAR2(30):='AA_UC5_FC_BPAY_DEPT_TBL';
v_tab_img_name VARCHAR2(30):='AA_UC5_FC_BPAY_DEPT_IMG_TBL';
ex EXCEPTION;
BEGIN
/* Target table drop code */
sql_trunc_stmt:= 'TRUNCATE TABLE '||v_tab_name;
sql_trunc_img_stmt:= 'TRUNCATE TABLE '||v_tab_img_name;
/* Checking whether table exists */
select count(*) INTO v_count from AA_UC5_FC_BPAY_DEPT_TBL;
select count(*) INTO v_count_img from AA_UC5_FC_BPAY_DEPT_IMG_TBL;
/* Checking whether table exists */
IF v_count > 0 THEN
execute immediate sql_trunc_stmt;
END IF;
IF v_count_img > 0 THEN
execute immediate sql_trunc_img_stmt;
END IF;
/* Running Model PER Department */
FOR rec in (select distinct deptno,dname from AA_PAYROLL_COST_DEPT_TRAIN)
LOOP
sqlText:='select YRMON,BASE_PAY as PAYROLL_COST from AA_PAYROLL_COST_DEPT_TRAIN where DEPTNO = '''||rec.DEPTNO||''' ORDER BY YR,MON_NUM';
AA_USECASE_ALGO_LIB_PKG.AA_UC5_DEPT_PRC(p_sql => sqlText,
p_is_seasonal => 'T' ,
p_ts_measure_col => 'PAYROLL_COST',
p_ts_time_col => 'YRMON',
p_forecast_period => 12 ,
p_start_win => 2011,
p_end_win => 2016,
p_trend_win => 72,
p_deptno => rec.DEPTNO,
p_dname => rec.DNAME
);
END LOOP;
END;
PROCEDURE AA_UC5_FC_TRN_VP_DEPT_RUN_PRC IS
sqlText VARCHAR2(4000):= '';
sql_trunc_stmt varchar2(4000);
sql_trunc_img_stmt varchar2(4000);
v_count NUMBER:=0;
v_count_img NUMBER:=0;
v_tab_name VARCHAR2(30):='AA_UC5_FC_VARPAY_DEPT_TBL';
v_tab_img_name VARCHAR2(30):='AA_UC5_FC_VARPAY_DEPT_IMG_TBL';
ex EXCEPTION;
BEGIN
/* Target table drop code */
sql_trunc_stmt:= 'TRUNCATE TABLE '||v_tab_name;
sql_trunc_img_stmt:= 'TRUNCATE TABLE '||v_tab_img_name;
/* Checking whether table exists */
select count(*) INTO v_count from AA_UC5_FC_VARPAY_DEPT_TBL;
select count(*) INTO v_count_img from AA_UC5_FC_VARPAY_DEPT_IMG_TBL;
/* Checking whether table exists */
IF v_count > 0 THEN
execute immediate sql_trunc_stmt;
END IF;
IF v_count_img > 0 THEN
execute immediate sql_trunc_img_stmt;
END IF;
/* Running Model PER Department */
FOR rec in (select distinct deptno,dname from AA_PAYROLL_COST_DEPT_TRAIN)
LOOP
sqlText:='select YRMON,VARIABLE_PAY from AA_PAYROLL_COST_DEPT_TRAIN where DEPTNO = '''||rec.DEPTNO||''' ORDER BY YR,MON_NUM';
AA_USECASE_ALGO_LIB_PKG.AA_UC5_DEPT_PRC(p_sql => sqlText,
p_is_seasonal => 'T' ,
p_ts_measure_col => 'VARIABLE_PAY',
p_ts_time_col => 'YRMON',
p_forecast_period => 12 ,
p_start_win => 2011,
p_end_win => 2016,
p_trend_win => 72,
p_deptno => rec.DEPTNO,
p_dname => rec.DNAME
);
END LOOP;
END;
/*******************************************************************************
****************************ALL USECASE PREDICTION******************************
CHANGE THE p_test_sql Table Name
********************************************************************************/
PROCEDURE AA_UC1_ATTRITION_PRED_RUN_PRC IS
BEGIN
AA_USECASE_ALGO_LIB_PKG.AA_PREDICTION_UC1_PRC(
p_test_sql => 'select EMPID,NATIONALITY, GENDER,AGE,MARITAL_STATUS,TENURE,CHNG_COMPA_L4Y,CHNG_COMPA_LY,AVG_PERF_L4Y,
CHNG_SICKLV_L4Y,CHNG_SICKLV_LY,DEPT_CHNG_L4Y,PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y,ISCHURN
FROM AA_COMMN_MDL_TRAIN_TBL',
p_train_tab_name => 'AA_COMMN_MDL_TRAIN_TBL',
p_ds_name => 'dsRF_churn_store',
p_out_table_name => 'AA_UC1_PRED_OUTPUT_TBL'
);
END;
PROCEDURE AA_UC2_PERF_PRED_RUN_PRC IS
BEGIN
AA_USECASE_ALGO_LIB_PKG.AA_PREDICTION_UC2_PRC(p_test_sql => 'select EMPID,NATIONALITY, GENDER,AGE,TENURE,AVG_PERF_L4Y,CHNG_SICKLV_L4Y,CHNG_SICKLV_LY,DEPT_CHNG_L4Y,
PROMO_L4Y,SALREV_L4Y,SVR_CHNG_L4Y,AVG_UNPLV_L4Y,AVG_UNAUTH_L4Y,PERF_CATEG1 FROM AA_COMMN_MDL_TRAIN_TBL',
p_train_tab_name => 'AA_COMMN_MDL_TRAIN_TBL',
p_ds_name => 'dsRF_perf_store',
p_out_table_name => 'AA_UC2_PRED_OUTPUT_TBL'
);
END;
END AA_USECASE_ALGO_RUN_PKG;