sql files
This commit is contained in:
403
onetime/dataloadfunctions/field/FTDRY_SUM_ODS.sql
Executable file
403
onetime/dataloadfunctions/field/FTDRY_SUM_ODS.sql
Executable file
@@ -0,0 +1,403 @@
|
||||
|
||||
|
||||
|
||||
|
||||
drop function if exists staging2.fn_FTDRY_SUM_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_SUM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_files_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __test_instance_id int;
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __files_syspk int :=p_files_syspk;
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare _error int;
|
||||
begin
|
||||
|
||||
__files_syspk := p_files_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_FTDRY_SUM_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTDRY
|
||||
Sheet Format: FTDRY_SUM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTDRY_SUM_TRX()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_engine_hp,
|
||||
rated_rpm,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_engine_hp::numeric,
|
||||
rated_rpm::numeric,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_kg_front::numeric,
|
||||
tractor_weight_kg_rear::numeric,
|
||||
tractor_weight_kg_total::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_sum_trac_h1_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary_tractor_info a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk
|
||||
)where a.file_syspk =__files_syspk;
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
implement_type,
|
||||
implement_size,
|
||||
hitch_category,
|
||||
implement_weight,
|
||||
soil_type,
|
||||
soil_moisture_content_pct,
|
||||
soil_bulk_density_g_per_cc,
|
||||
soil_cone_index,
|
||||
field_condition,
|
||||
season,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
make_of_implement,
|
||||
implement_type,
|
||||
implement_size,
|
||||
hitch_category,
|
||||
trim('kg' from implement_weight)::numeric,
|
||||
soil_type,
|
||||
moisture_content::numeric soil_moisture_content_pct,
|
||||
bulk_density_g_cc::numeric soil_bulk_density_g_per_cc,
|
||||
trim(' Kpa' from soil_cone_index)::numeric soil_cone_index,
|
||||
field_condition,
|
||||
season,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_sum_implement_block where trx_record=1;
|
||||
|
||||
insert into transactional.field_perf_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_iteration_number,
|
||||
test_condition,
|
||||
test_date,
|
||||
tractor_model,
|
||||
engine_rpm_set,
|
||||
pto_rpm_set,
|
||||
gear_used,
|
||||
nominal_speed_kmph,
|
||||
engine_rpm_drop_on_straight_1st_pass,
|
||||
engine_rpm_drop_on_turn_1st_pass,
|
||||
depth_of_cut_cm,
|
||||
no_load_speed_kmph,
|
||||
on_load_speed_kmph,
|
||||
wheel_slippage_pct,
|
||||
fuel_consumption_lit_per_hr,
|
||||
area_covered_acr_per_hr,
|
||||
fuel_consumption_lit_per_acr,
|
||||
fuel_consumption_var_pct_lit_per_hr,
|
||||
area_covered_var_pct_acr_per_hr,
|
||||
fuel_consumption_var_pct_lit_per_acr,
|
||||
engine_smoke_on_load,
|
||||
engine_acceleration_smoke,
|
||||
draft_response,
|
||||
tractor_steer_ability,
|
||||
tractor_braking_perf,
|
||||
front_visibility,
|
||||
implement_accessibility,
|
||||
front_wheel_dragging_at_turning,
|
||||
front_end_lifting_during_operation,
|
||||
rpm_recovery_time,
|
||||
engine_vibration,
|
||||
engine_sound,
|
||||
implement_lifting_per_lowering_response,
|
||||
pulverization_index,
|
||||
pulverization_quality,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
test_iterationnumber::numeric,
|
||||
test_condition,
|
||||
test_date::date,
|
||||
tractor_model,
|
||||
engine_rpm_set::numeric,
|
||||
pto_rpm_set::numeric,
|
||||
gear_used,
|
||||
nominal_speed_kmph::numeric,
|
||||
engine_rpm_drop_on_straight engine_rpm_drop_on_straight_1st_pass ,
|
||||
engine_rpm_drop_on_turn engine_rpm_drop_on_turn_1st_pass,
|
||||
depth_of_cut_cm,
|
||||
no_load_speed_kmph::numeric,
|
||||
on_load_speed_kmph::numeric,
|
||||
wheel_slippage_::numeric wheel_slippage_pct,
|
||||
fuel_consumption_lit_hr::numeric fuel_consumption_lit_per_hr,
|
||||
area_covered_acr_hr::numeric area_covered_acr_per_hr,
|
||||
fuel_consumption_lit_acr::numeric fuel_consumption_lit_per_acr ,
|
||||
fuel_consumption_lit_hr_2::numeric ,
|
||||
area_covered_acr_hr_2::numeric ,
|
||||
fuel_consumption_lit_acr_2::numeric ,
|
||||
engine_smoke_on_load,
|
||||
engine_acceleration_smoke ,
|
||||
draft_response,
|
||||
tractor_steer_ability,
|
||||
tractor_braking_performance,
|
||||
front_visibility,
|
||||
implement_accessibility,
|
||||
front_wheel_dragging_at_turning,
|
||||
front_end_lifting_during_operation,
|
||||
rpm_recovery_time,
|
||||
engine_vibration,
|
||||
engine_sound,
|
||||
implement_lifting_lowering_response implement_lifting_per_lowering_response,
|
||||
pulverization_index,
|
||||
pulverization_quality,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_sum_test_condition_1_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_iteration_number,
|
||||
test_condition,
|
||||
test_date,
|
||||
tractor_model,
|
||||
engine_rpm_set,
|
||||
pto_rpm_set,
|
||||
gear_used,
|
||||
nominal_speed_kmph,
|
||||
engine_rpm_drop_on_straight_1st_pass,
|
||||
engine_rpm_drop_on_turn_1st_pass,
|
||||
depth_of_cut_cm,
|
||||
no_load_speed_kmph,
|
||||
on_load_speed_kmph,
|
||||
wheel_slippage_pct,
|
||||
fuel_consumption_lit_per_hr,
|
||||
area_covered_acr_per_hr,
|
||||
fuel_consumption_lit_per_acr,
|
||||
fuel_consumption_var_pct_lit_per_hr,
|
||||
area_covered_var_pct_acr_per_hr,
|
||||
fuel_consumption_var_pct_lit_per_acr,
|
||||
engine_smoke_on_load,
|
||||
engine_acceleration_smoke,
|
||||
draft_response,
|
||||
tractor_steer_ability,
|
||||
tractor_braking_perf,
|
||||
front_visibility,
|
||||
implement_accessibility,
|
||||
front_wheel_dragging_at_turning,
|
||||
front_end_lifting_during_operation,
|
||||
rpm_recovery_time,
|
||||
engine_vibration,
|
||||
engine_sound,
|
||||
implement_lifting_per_lowering_response,
|
||||
pulverization_index,
|
||||
pulverization_quality,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
test_iterationnumber::numeric,
|
||||
test_condition,
|
||||
test_date::date,
|
||||
tractor_model,
|
||||
engine_rpm_set::numeric,
|
||||
pto_rpm_set::numeric,
|
||||
gear_used,
|
||||
nominal_speed_kmph::numeric,
|
||||
engine_rpm_drop_on_straight engine_rpm_drop_on_straight_1st_pass ,
|
||||
engine_rpm_drop_on_turn engine_rpm_drop_on_turn_1st_pass,
|
||||
depth_of_cut_cm,
|
||||
no_load_speed_kmph::numeric,
|
||||
on_load_speed_kmph::numeric,
|
||||
wheel_slippage_::numeric wheel_slippage_pct,
|
||||
fuel_consumption_lit_hr::numeric fuel_consumption_lit_per_hr,
|
||||
area_covered_acr_hr::numeric area_covered_acr_per_hr,
|
||||
fuel_consumption_lit_acr::numeric fuel_consumption_lit_per_acr ,
|
||||
fuel_consumption_lit_hr_2::numeric ,
|
||||
area_covered_acr_hr_2::numeric ,
|
||||
fuel_consumption_lit_acr_2::numeric ,
|
||||
engine_smoke_on_load,
|
||||
engine_acceleration_smoke ,
|
||||
draft_response,
|
||||
tractor_steer_ability,
|
||||
tractor_braking_performance,
|
||||
front_visibility,
|
||||
implement_accessibility,
|
||||
front_wheel_dragging_at_turning,
|
||||
front_end_lifting_during_operation,
|
||||
rpm_recovery_time,
|
||||
engine_vibration,
|
||||
engine_sound,
|
||||
implement_lifting_lowering_response implement_lifting_per_lowering_response,
|
||||
pulverization_index,
|
||||
pulverization_quality,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_sum_test_condition_2_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_1,
|
||||
test_mgr_comments =b.test_manager_comments_1
|
||||
from staging2.ftdry_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =1;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_2,
|
||||
test_mgr_comments =b.test_manager_comments_2
|
||||
from staging2.ftdry_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =2;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_3,
|
||||
test_mgr_comments =b.test_manager_comments_3
|
||||
from staging2.ftdry_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =3;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_4,
|
||||
test_mgr_comments =b.test_manager_comments_4
|
||||
from staging2.ftdry_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =4;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =1 and a.file_syspk =__files_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =2 and a.file_syspk =__files_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =3 and a.file_syspk =__files_syspk;
|
||||
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =4 and a.file_syspk =__files_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__files_syspk;
|
||||
|
||||
update transactional.field_perf_summary
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__files_syspk;
|
||||
|
||||
update transactional.field_perf_summary
|
||||
set engine_rpm_drop_on_straight_1st_pass =replace(engine_rpm_drop_on_straight_1st_pass,' to ','-'),
|
||||
engine_rpm_drop_on_turn_1st_pass=replace(engine_rpm_drop_on_turn_1st_pass,' to ','-'),
|
||||
depth_of_cut_cm=replace(depth_of_cut_cm,' to ','-')
|
||||
where file_mnemonic = 'FTDRY';
|
||||
|
||||
update transactional.field_perf_summary_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__files_syspk;
|
||||
|
||||
UPDATE transactional.field_perf_summary
|
||||
SET
|
||||
--updating RPM drop straight 1st pass:
|
||||
erpmdrop_straight_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 1))::numeric,
|
||||
erpmdrop_straight_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2))::numeric end,
|
||||
--updating RPM drop turn 1st pass:
|
||||
erpmdrop_turn_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 1))::numeric,
|
||||
erpmdrop_turn_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2))::numeric end,
|
||||
--updating depth of cut:
|
||||
depth_of_cut_cm_low = trim(split_part(trim(depth_of_cut_cm), '-', 1))::numeric,
|
||||
depth_of_cut_cm_high= case trim(split_part(trim(depth_of_cut_cm), '-', 2))
|
||||
when '' then null
|
||||
else trim('cm' from split_part(trim(depth_of_cut_cm), '-', 2))::numeric end
|
||||
where file_mnemonic = 'FTDRY';
|
||||
|
||||
update transactional.field_perf_summary_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__files_syspk;
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __files_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTDRY_SUM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
688
onetime/dataloadfunctions/field/FTDRY_SUM_STG2.sql
Executable file
688
onetime/dataloadfunctions/field/FTDRY_SUM_STG2.sql
Executable file
@@ -0,0 +1,688 @@
|
||||
drop function if exists staging2.fn_FTDRY_SUM_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_SUM_Block(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare err_query int;
|
||||
declare err_block text;
|
||||
begin
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_FTDRY_SUM_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: FTDRY
|
||||
Sheet Format: FTDRY_SUM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTDRY_SUM_Block (20,1,'FTDRY','FTDRY_SUM',258);
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
truncate staging2.ftdry_sum_trac_h1_block;
|
||||
truncate staging2.ftdry_sum_implement_block;
|
||||
truncate staging2.ftdry_sum_test_condition_1_block;
|
||||
truncate staging2.ftdry_sum_test_condition_2_block;
|
||||
truncate staging2.ftdry_sum_comments_by_block;
|
||||
truncate staging2.stg_specific_table_ftdry_sum;
|
||||
truncate staging2.stg_process_table_ftdry_sum;
|
||||
|
||||
|
||||
|
||||
execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* transfer data from generic to specific for ftdry*/
|
||||
execute 'insert into staging2.stg_specific_table_ftdry_sum
|
||||
select * from staging1.staging_generic_table a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
select count(*) into err_query from staging2.stg_specific_table_ftdry_sum;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for FTDRY Summary',
|
||||
detail = 'No data in table stg_specific_table_ftdry_sum',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_ftdry_sum set column2 = TRIM (TRAILING FROM column2 );
|
||||
update staging2.stg_specific_table_ftdry_sum set column2 = TRIM (LEADING FROM column2 );
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified ;
|
||||
|
||||
/* keyword match in config table*/
|
||||
|
||||
execute 'update transactional.source_config a set f1_source = replace(f1_source,''_1'','''')
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_ftdry_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_ftdry_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a set f1_source = replace(f1_source,''_2'','''')
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_ftdry_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update staging2.stg_specific_table_ftdry_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a set row_previous_number=row_number_start-1
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from transactional.source_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* config file last field update as null otherwise it picks up next format row number*/
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end = null where f1_modified =''Test Manager Comments_2'' and
|
||||
a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*inserting run_time in config*/
|
||||
execute 'update transactional.source_config a
|
||||
set run_time=current_timestamp where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers for each block in process table*/
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Model''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Make of Implement''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_1:''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_1''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_1''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_2:''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_2''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_2''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
/* blocks data loading start - FTDRY_SUM_Trac_H1_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_SUM_Trac_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
|
||||
err_block:='FTDRY_SUM_Trac_H1_Block';
|
||||
|
||||
insert into staging2.FTDRY_SUM_Trac_H1_Block
|
||||
(
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Engine_HP,
|
||||
Rated_RPM,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type,
|
||||
FIP_Type,
|
||||
Steering_Type,
|
||||
Tractor_Weight_kg_Front,
|
||||
Tractor_Weight_kg_Rear,
|
||||
Tractor_Weight_kg_Total,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_ftdry_sum
|
||||
where block_tag='FTDRY_SUM_Trac_H1'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.FTDRY_SUM_Trac_H1_Block set trx_record =0
|
||||
where tractor_model = '0';
|
||||
|
||||
update staging2.FTDRY_SUM_Trac_H1_Block
|
||||
set trx_record=0 where block_row_number=1;
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Trac_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Trac_H1_Block');
|
||||
|
||||
/* blocks data loading start -FTDRY_SUM_Implement_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_SUM_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='FTDRY_SUM_Implement_Block';
|
||||
insert into staging2.FTDRY_SUM_Implement_Block
|
||||
(
|
||||
Make_of_Implement,
|
||||
Implement_Type,
|
||||
Implement_Size,
|
||||
Hitch_Category,
|
||||
Implement_Weight,
|
||||
Soil_Type,
|
||||
Moisture_Content ,
|
||||
Bulk_Density_g_cc ,
|
||||
Soil_Cone_index,
|
||||
Field_Condition ,
|
||||
Season,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_ftdry_sum
|
||||
where block_tag='FTDRY_SUM_Implement';
|
||||
|
||||
update staging2.FTDRY_SUM_Implement_Block
|
||||
set trx_record=0 where block_row_number in(1,3);
|
||||
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Implement_Block');
|
||||
|
||||
/* blocks data loading start -FTDRY_SUM_Test_Condition_1_Block*/
|
||||
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_SUM_Test_Condition_1_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='FTDRY_SUM_Test_Condition_1_Block';
|
||||
insert into staging2.FTDRY_SUM_Test_Condition_1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight,
|
||||
Engine_RPM_Drop_on_turn,
|
||||
Depth_of_cut_cm,
|
||||
No_load_speed_kmph,
|
||||
On_load_speed_kmph,
|
||||
wheel_slippage_,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,
|
||||
column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_1''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
|
||||
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_1_Block
|
||||
set test_iterationnumber=1;
|
||||
|
||||
insert into staging2.FTDRY_SUM_Test_Condition_1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight,
|
||||
Engine_RPM_Drop_on_turn,
|
||||
Depth_of_cut_cm,
|
||||
No_load_speed_kmph,
|
||||
On_load_speed_kmph,
|
||||
wheel_slippage_,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column8::text,
|
||||
column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_1''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_1_Block
|
||||
set test_iterationnumber=2
|
||||
where test_iterationnumber is null;
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_1_Block a
|
||||
set Test_Condition= b.first_value from (SELECT
|
||||
test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber)
|
||||
FROM (
|
||||
SELECT
|
||||
test_iterationnumber,
|
||||
Test_Condition,
|
||||
sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition
|
||||
FROM staging2.FTDRY_SUM_Test_Condition_1_Block
|
||||
ORDER BY test_iterationnumber ASC
|
||||
) as q) b where a.test_iterationnumber =b.test_iterationnumber;
|
||||
|
||||
delete from staging2.FTDRY_SUM_Test_Condition_1_Block where tractor_model = '0' or engine_rpm_set = '0';
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_1_Block set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%';
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_1_Block set fuel_consumption_lit_hr_2 = left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3),
|
||||
Area_covered_acr_hr_2 = left(Area_covered_acr_hr_2,length(Area_covered_acr_hr_2)-3) ,
|
||||
Fuel_consumption_lit_Acr_2 = left(Fuel_consumption_lit_Acr_2,length(Fuel_consumption_lit_Acr_2)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
|
||||
|
||||
delete from staging2.FTDRY_SUM_Test_Condition_1_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTDRY_SUM_Test_Condition_1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Test_Condition_1_Block');
|
||||
|
||||
|
||||
/* blocks data loading start -FTDRY_SUM_Test_Condition_2_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_SUM_Test_Condition_2_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='FTDRY_SUM_Test_Condition_2_Block';
|
||||
insert into staging2.FTDRY_SUM_Test_Condition_2_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight,
|
||||
Engine_RPM_Drop_on_turn,
|
||||
Depth_of_cut_cm,
|
||||
No_load_speed_kmph,
|
||||
On_load_speed_kmph,
|
||||
wheel_slippage_,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_2''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text,
|
||||
a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_2_Block
|
||||
set test_iterationnumber=3;
|
||||
|
||||
insert into staging2.FTDRY_SUM_Test_Condition_2_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight,
|
||||
Engine_RPM_Drop_on_turn,
|
||||
Depth_of_cut_cm,
|
||||
No_load_speed_kmph,
|
||||
On_load_speed_kmph,
|
||||
wheel_slippage_,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column8::text,column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_sum where block_tag=''FTDRY_SUM_Test_Condition_2''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text,
|
||||
a_32 text,a_33 text,a_34 text,a_35 text,a_36 text);
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_2_Block
|
||||
set test_iterationnumber=4
|
||||
where test_iterationnumber is null;
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_2_Block a
|
||||
set Test_Condition= b.first_value from (SELECT
|
||||
test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber)
|
||||
FROM (
|
||||
SELECT
|
||||
test_iterationnumber,
|
||||
Test_Condition,
|
||||
sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition
|
||||
FROM staging2.FTDRY_SUM_Test_Condition_2_Block
|
||||
ORDER BY test_iterationnumber ASC
|
||||
) as q) b where a.test_iterationnumber =b.test_iterationnumber;
|
||||
|
||||
delete from staging2.FTDRY_SUM_Test_Condition_2_Block where tractor_model = '0' or engine_rpm_set = '0';
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_2_Block set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%';
|
||||
|
||||
update staging2.FTDRY_SUM_Test_Condition_2_Block set fuel_consumption_lit_hr_2 = left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3),
|
||||
Area_covered_acr_hr_2 = left(Area_covered_acr_hr_2,length(Area_covered_acr_hr_2)-3) ,
|
||||
Fuel_consumption_lit_Acr_2 = left(Fuel_consumption_lit_Acr_2,length(Fuel_consumption_lit_Acr_2)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
|
||||
|
||||
|
||||
delete from staging2.FTDRY_SUM_Test_Condition_2_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTDRY_SUM_Test_Condition_2_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Test_Condition_2_Block');
|
||||
|
||||
|
||||
/* blocks data loading start -FTDRY_SUM_Comments_By_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_SUM_Comments_By_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='FTDRY_SUM_Comments_By_Block';
|
||||
|
||||
insert into staging2.FTDRY_SUM_Comments_By_Block (dummy_f) values ('dummy');
|
||||
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_1=
|
||||
(select column3 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Engineer_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_3=
|
||||
(select column3 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Engineer_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_1=
|
||||
(select column3 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Manager_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_3=
|
||||
(select column3 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Manager_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_2=
|
||||
(select column8 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Egnineer_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_engineer_comments_4=
|
||||
(select column8 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Engineer_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_2=
|
||||
(select column8 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Manager_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set test_manager_comments_4=
|
||||
(select column8 from staging2.stg_process_table_ftdry_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTDRY_SUM_Manager_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
|
||||
|
||||
delete from staging2.FTDRY_SUM_Comments_By_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTDRY_SUM_Comments_By_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_SUM_Comments_By_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTDRY_SUM_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
376
onetime/dataloadfunctions/field/FTDRY_TRS_ODS.sql
Executable file
376
onetime/dataloadfunctions/field/FTDRY_TRS_ODS.sql
Executable file
@@ -0,0 +1,376 @@
|
||||
drop function if exists staging2.fn_FTDRY_TRS_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_TRS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __test_instance_id int;
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare _error int;
|
||||
declare __test_master_id int;
|
||||
declare __test_tractor_id int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_FTDRY_TRS_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTDRY
|
||||
Sheet Format: FTDRY_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTDRY_TRS_TRX()
|
||||
--***************************************************************/
|
||||
--
|
||||
--delete from transactional.test_instance where file_syspk =836;
|
||||
--
|
||||
--delete from transactional.test_instance_engine_info where file_syspk =836;
|
||||
--
|
||||
--delete from transactional.test_instance_implement_info where file_syspk =836;
|
||||
--
|
||||
--delete from transactional.test_instance_tractor_info where file_syspk =836;
|
||||
--
|
||||
--
|
||||
--delete from transactional.test_instance_trailer_info where file_syspk =836;
|
||||
--
|
||||
--delete from transactional.test_instance_tyre_info where file_syspk =836;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location_name,
|
||||
soil_moisture_content_pct,
|
||||
soil_bulk_density_g_per_cc,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test,
|
||||
test_report_date,
|
||||
season,
|
||||
type_of_soil,
|
||||
soil_cone_index,
|
||||
field_condition,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
report_reference_no test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location test_location_name,
|
||||
soil_moisture_content_::numeric soil_moisture_content_pct ,
|
||||
soil_bulk_density_g_cc::int soil_bulk_density_g_per_cc,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test::date,
|
||||
report_date::date test_report_date,
|
||||
season,
|
||||
type_of_soil,
|
||||
trim(' Kpa' from soil_cone_index_kpa)::int soil_cone_index,
|
||||
field_condition,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_trs_h1_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
tractor_engine_hp,
|
||||
fip_type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
wheel_drive_type,
|
||||
egr_yn,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
mechanical_ballast_rear_in_kg,
|
||||
water_ballast_rear_75_pct ,
|
||||
Mechanical_Ballast_Front,
|
||||
mechanical_ballast_front_kg ,
|
||||
Total_Ballast_Weight,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP::float,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading::numeric,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD wheel_drive_type ,
|
||||
EGR_Yes_No egr_yn,
|
||||
Brake_Type ,
|
||||
PTO_Type ,
|
||||
Standard_PTO_Speed_RPM::numeric,
|
||||
EPTO_Speed_RPM,
|
||||
Tractor_Weight_kg_Front::numeric tractor_weight_front_kg ,
|
||||
Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg ,
|
||||
Tractor_Weight_kg_Total::numeric tractor_weight_total_kg ,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
Mechanical_Ballast_Rear_in_KG::numeric mechanical_ballast_rear_in_kg ,
|
||||
Water_Ballast_Rear water_ballast_rear_75_pct ,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg::numeric mechanical_ballast_front_kg ,
|
||||
Total_Ballast_Weight::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
|
||||
) where file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info a
|
||||
set test_tractor_yn ='Y' where syspk in
|
||||
(select min(syspk) from transactional.test_instance_tractor_info b
|
||||
where b.file_syspk =a.file_syspk)
|
||||
and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_tractor_yn ='N'
|
||||
where test_tractor_yn is null and file_syspk =__file_syspk;
|
||||
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
'front',
|
||||
front_tyre_make tyre_make,
|
||||
front_tyre_size tyre_size,
|
||||
front_tyre_pressure_psi::int tyre_pressure_psi
|
||||
from staging2.ftdry_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.tyre_type ='front' and a.file_syspk =__file_syspk;
|
||||
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
'rear',
|
||||
rear_tyre_make tyre_make,
|
||||
rear_tyre_size tyre_size,
|
||||
rear_tyre_pressure_psi::int tyre_pressure_psi
|
||||
from staging2.ftdry_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.tyre_type ='rear' and a.file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
low_idle_observed ,
|
||||
high_idle_observed ,
|
||||
rated_rpm ,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
low_idle::int low_idle_observed ,
|
||||
high_idle::int high_idle_observed ,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_trs_engine_rpm_block
|
||||
where trx_record=1;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.test_instance_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
make_of_implement,
|
||||
no_of_disc_blades_bottoms,
|
||||
cutting_width_m,
|
||||
implement_weight_kg,
|
||||
hitch_category,
|
||||
span_for_mounted_implement_mm ,
|
||||
mast_height_for_mounted_implement_mm,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
make_of_implement,
|
||||
no_of_bottoms_tyne_disc_blade no_of_disc_blades_bottoms,
|
||||
cutting_width_m,
|
||||
trim('kg' from implement_weight_kg)::numeric,
|
||||
hitch_category,
|
||||
span_cm_for_mounted_implement::numeric span_for_mounted_implement_cm ,
|
||||
mast_height_cm_for_mounted_implement::numeric mast_height_for_mounted_implement_cm,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftdry_trs_implement_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set report_template_no=b.report_template_no,
|
||||
report_template_rev_no=b.report_template_rev_no,
|
||||
report_template_rev_date =b.report_template_rev_date
|
||||
from staging2.ftdry_trs_implement_block b where trx_record=1
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='Field';
|
||||
select syspk from transactional.test_instance_tractor_info into __test_tractor_id
|
||||
where file_syspk =__file_syspk and test_tractor_yn ='Y';
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_engine_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tyre_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1)
|
||||
where file_syspk = __file_syspk;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTDRY_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
413
onetime/dataloadfunctions/field/FTDRY_TRS_STG2.sql
Executable file
413
onetime/dataloadfunctions/field/FTDRY_TRS_STG2.sql
Executable file
@@ -0,0 +1,413 @@
|
||||
/*FTDRY_starts*/
|
||||
drop function if exists staging2.fn_FTDRY_TRS_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTDRY_TRS_Block(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare err_query int;
|
||||
declare err_block text;
|
||||
begin
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_FTDRY_TRS_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: FTDRY
|
||||
Sheet Format: FTDRY_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTDRY_TRS_Block(20,1,'FTDRY','FTDRY_TRS',257);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
truncate staging2.FTDRY_TRS_H1_INT;
|
||||
truncate staging2.ftdry_trs_h1_block ;
|
||||
truncate staging2.ftdry_trs_implement_block ;
|
||||
truncate staging2.ftdry_trs_spec_block;
|
||||
truncate staging2.ftdry_trs_engine_rpm_block;
|
||||
truncate staging2.stg_specific_table_ftdry_trs;
|
||||
truncate staging2.stg_process_table_ftdry_trs;
|
||||
|
||||
|
||||
execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* transfer data from generic to specific for ftdry*/
|
||||
|
||||
execute 'insert into staging2.stg_specific_table_ftdry_trs
|
||||
select * from staging1.staging_generic_table a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
select count(*) into err_query from staging2.stg_specific_table_ftdry_trs;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for FTDRY Tractor Specifications',
|
||||
detail = 'No data in table stg_specific_table_ftdry_trs',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
/* trimming data */
|
||||
|
||||
update staging2.stg_specific_table_ftdry_trs set column2 = TRIM (TRAILING FROM column2 );
|
||||
update staging2.stg_specific_table_ftdry_trs set column2 = TRIM (LEADING FROM column2 );
|
||||
--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified);
|
||||
--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source) ;
|
||||
--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified;
|
||||
|
||||
/* keyword match in config table*/
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_ftdry_trs b
|
||||
where upper(F1_source)= upper(column2)
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_ftdry_trs a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column2)
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a set row_previous_number=row_number_start-1
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from transactional.source_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* config file last field update as null otherwise it picks up next format row number*/
|
||||
execute 'update transactional.source_config a set row_read_end = null
|
||||
where f1_modified =''Implement Details'' and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*inserting run_time in config*/
|
||||
execute 'update transactional.source_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* tagging block_row_numbers for each block in process table*/
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications Sheet''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Engine RPM Data:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftdry_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftdry_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and a.column2 <> ''''
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Implement Details'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/*insert data into h1_int */
|
||||
|
||||
insert into staging2.FTDRY_TRS_H1_INT(
|
||||
column2,column3,column4,column5,column6,column7,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,block_row_number
|
||||
from staging2.stg_process_table_ftdry_trs a where block_tag='FTDRY_TRS_H1'
|
||||
order by block_row_number;
|
||||
|
||||
insert into staging2.FTDRY_TRS_H1_INT(column2,column3)
|
||||
select 'Date of Test',column5
|
||||
from staging2.FTDRY_TRS_H1_INT
|
||||
where block_row_number=1;
|
||||
|
||||
insert into staging2.FTDRY_TRS_H1_INT(column2,column3)
|
||||
select 'Report Date',column7
|
||||
from staging2.FTDRY_TRS_H1_INT
|
||||
where block_row_number=1;
|
||||
|
||||
|
||||
insert into staging2.FTDRY_TRS_H1_INT(column2,column3)
|
||||
select column5,column6
|
||||
from staging2.FTDRY_TRS_H1_INT where block_row_number between 4 and 7;
|
||||
|
||||
|
||||
|
||||
/*inserting data into block -FTDRY_TRS_H1_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_TRS_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
|
||||
err_block:='FTDRY_TRS_H1_Block';
|
||||
insert into staging2.FTDRY_TRS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Report_Reference_No,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location,
|
||||
Soil_Moisture_Content_,
|
||||
Soil_Bulk_Density_g_cc,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test,
|
||||
Report_Date,
|
||||
Season,
|
||||
Type_of_Soil,
|
||||
Soil_Cone_Index_kPa,
|
||||
Field_Condition
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text]) AS val
|
||||
FROM staging2.FTDRY_TRS_H1_INT
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text);
|
||||
|
||||
|
||||
delete from staging2.FTDRY_TRS_H1_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTDRY_TRS_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_H1_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTDRY_TRS_SPEC_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_TRS_SPEC_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
|
||||
err_block:='FTDRY_TRS_SPEC_Block';
|
||||
|
||||
insert into staging2.FTDRY_TRS_SPEC_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
Front_Tyre_Make,
|
||||
Front_Tyre_Size,
|
||||
Front_Tyre_Pressure_psi,
|
||||
Rear_Tyre_Make,
|
||||
Rear_Tyre_Size,
|
||||
Rear_Tyre_Pressure_psi ,
|
||||
Tractor_Weight_kg_Front ,
|
||||
Tractor_Weight_kg_Rear ,
|
||||
Tractor_Weight_kg_Total,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
Mechanical_Ballast_Rear_in_KG ,
|
||||
Water_Ballast_Rear,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_trs where block_tag=''FTDRY_TRS_SPEC''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text);
|
||||
|
||||
update staging2.FTDRY_TRS_SPEC_Block set trx_record=0
|
||||
where tractor_make is null and tractor_sr_no is null;
|
||||
|
||||
update staging2.FTDRY_TRS_SPEC_Block set trx_record=0
|
||||
where (tractor_model is null and front_tyre_make is null) or (tractor_model is null and rear_tyre_make is null);
|
||||
|
||||
|
||||
delete from staging2.FTDRY_TRS_SPEC_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTDRY_TRS_SPEC_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_SPEC_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTDRY_TRS_Engine_RPM_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_TRS_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
|
||||
err_block:='FTDRY_TRS_Engine_RPM_Block';
|
||||
insert into staging2.FTDRY_TRS_Engine_RPM_Block
|
||||
(
|
||||
dummy_f,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_trs where block_tag=''FTDRY_TRS_Engine_RPM''
|
||||
or (block_tag=''FTDRY_TRS_SPEC'' and block_row_number in (1,2,3))
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text);
|
||||
|
||||
update staging2.FTDRY_TRS_Engine_RPM_Block set trx_record=0
|
||||
where tractor_make is null and tractor_sr_no is null;
|
||||
|
||||
delete from staging2.FTDRY_TRS_Engine_RPM_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTDRY_TRS_Engine_RPM_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_Engine_RPM_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTDRY_TRS_Implement_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTDRY_TRS_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
|
||||
err_block:='FTDRY_TRS_Implement_Block';
|
||||
insert into staging2.FTDRY_TRS_Implement_Block
|
||||
(
|
||||
dummy_f,
|
||||
Name_of_Implement,
|
||||
Type_of_Implement,
|
||||
Make_of_Implement,
|
||||
No_of_bottoms_Tyne_Disc_Blade,
|
||||
Cutting_Width_m,
|
||||
Implement_Weight_Kg,
|
||||
Hitch_Category,
|
||||
Span_cm_For_Mounted_Implement,
|
||||
Mast_Height_cm_For_Mounted_Implement
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
|
||||
FROM staging2.stg_process_table_ftdry_trs where block_tag=''FTDRY_TRS_Implement''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text);
|
||||
|
||||
update staging2.FTDRY_TRS_Implement_Block set trx_record=0
|
||||
where name_of_implement is null;
|
||||
|
||||
update staging2.FTDRY_TRS_Implement_Block set dummy_f='dummy' where dummy_f is null;
|
||||
|
||||
update staging2.FTDRY_TRS_Implement_Block set report_template_no= (select column2 from staging2.stg_process_table_ftdry_trs where block_row_number=10 and block_tag='FTDRY_TRS_Implement');
|
||||
|
||||
|
||||
update staging2.FTDRY_TRS_Implement_Block set report_template_rev_no= (select column4 from staging2.stg_process_table_ftdry_trs where block_row_number=10 and block_tag='FTDRY_TRS_Implement');
|
||||
|
||||
|
||||
update staging2.FTDRY_TRS_Implement_Block set report_template_rev_date= (select column6 from staging2.stg_process_table_ftdry_trs where block_row_number=10 and block_tag='FTDRY_TRS_Implement');
|
||||
|
||||
|
||||
execute 'update staging2.FTDRY_TRS_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTDRY_TRS_Implement_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTDRY_TRS_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
401
onetime/dataloadfunctions/field/FTHLG_SUM_ods.sql
Executable file
401
onetime/dataloadfunctions/field/FTHLG_SUM_ods.sql
Executable file
@@ -0,0 +1,401 @@
|
||||
drop function if exists staging2.fn_FTHLG_SUM_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_SUM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __test_instance_id int;
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare _error int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_FTHLG_SUM_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTHLG
|
||||
Sheet Format: FTHLG_SUM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTHLG_SUM_TRX();
|
||||
***************************************************************/
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_engine_hp,
|
||||
rated_rpm,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make ,
|
||||
tractor_engine_hp::numeric,
|
||||
rated_rpm::numeric,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_kg_front::numeric tractor_weight_front_kg,
|
||||
tractor_weight_kg_rear::numeric tractor_weight_rear_kg,
|
||||
tractor_weight_kg_total::numeric tractor_weight_total_kg,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.fthlg_sum_trac_h1_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_trailer_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
trailer_type,
|
||||
tire_size_and_inflation_pressure_psi,
|
||||
no_of_axle,
|
||||
no_of_wheels,
|
||||
trailer_gross_weight_kg,
|
||||
tractor_rwc_to_hitch_point_center_dist_mm,
|
||||
tractor_hitch_ht_mm,
|
||||
trailer_hitch_height_above_ground_level_mm,
|
||||
gradient_slope_1_degree,
|
||||
gradient_slope_2_degree,
|
||||
tractor_hitch_type,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
Trailer_Type,
|
||||
Tire_size_and_inflation_pressure_psi,
|
||||
No_Of_Axle::numeric ,
|
||||
No_Of_Wheels::numeric,
|
||||
Trailer_Gross_Weight_Kg::numeric,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm::numeric,
|
||||
Tractor_Hitch_Height_from_Ground_mm::numeric,
|
||||
Trailer_hitch_Height_above_ground_level_mm::numeric,
|
||||
Gradient_Slope_1_Degree::numeric,
|
||||
Gradient_Slope_2_degree::numeric,
|
||||
Tractor_Hitch_Type,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.FTHLG_SUM_Trail_Type_Block where trx_record=1;
|
||||
|
||||
insert into transactional.field_perf_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_iteration_number,
|
||||
test_condition,
|
||||
test_date,
|
||||
tractor_model,
|
||||
fuel_consumption_lit_per_hr,
|
||||
mileage_km_per_ltr,
|
||||
avg_speed_of_travel_kmph,
|
||||
total_dist_travelled_km,
|
||||
gear_used_on_straight_road,
|
||||
straight_road_rpm_drop,
|
||||
gear_used_on_up_slope_1,
|
||||
up_slope_rpm_drop_1,
|
||||
gear_used_on_up_slope_2,
|
||||
up_slope_rpm_drop_2,
|
||||
gear_used_on_down_slope,
|
||||
down_slope_rpm_shoot_up,
|
||||
fuel_consumption_var_lit_per_hr,
|
||||
mileage_var_km_per_ltr,
|
||||
fuel_consumption_var_pct_lit_per_hr,
|
||||
mileage_var_pct_km_per_ltr,
|
||||
engine_smoke_on_load,
|
||||
engine_acceleration_smoke,
|
||||
range_gear_shifting,
|
||||
speed_gear_shifting,
|
||||
tractor_steer_ability,
|
||||
tractor_braking_perf,
|
||||
front_visibility,
|
||||
implement_accessibility,
|
||||
front_end_lifting_during_operation,
|
||||
rpm_recovery_time,
|
||||
engine_vibration,
|
||||
engine_sound,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
test_iterationnumber::numeric,
|
||||
Test_Condition,
|
||||
Test_Date::date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr::numeric fuel_consumption_lit_per_hr ,
|
||||
Mileage_Km_Ltr ::numeric mileage_km_per_ltr ,
|
||||
Average_speed_of_travel_kmph::numeric avg_speed_of_travel_kmph ,
|
||||
Total_distance_travelled_km::numeric total_dist_travelled_km ,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1 ,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
fuel_consumption_lit_hr_2::numeric ,
|
||||
Mileage_Km_Ltr_2::numeric ,
|
||||
fuel_consumption_lit_hr_3::numeric ,
|
||||
Mileage_Km_Ltr_3::numeric,
|
||||
engine_smoke_on_load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance tractor_braking_perf ,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.fthlg_sum_test_condition_1_block
|
||||
where trx_record=1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_iteration_number,
|
||||
test_condition,
|
||||
test_date,
|
||||
tractor_model,
|
||||
fuel_consumption_lit_per_hr,
|
||||
mileage_km_per_ltr,
|
||||
avg_speed_of_travel_kmph,
|
||||
total_dist_travelled_km,
|
||||
gear_used_on_straight_road,
|
||||
straight_road_rpm_drop,
|
||||
gear_used_on_up_slope_1,
|
||||
up_slope_rpm_drop_1,
|
||||
gear_used_on_up_slope_2,
|
||||
up_slope_rpm_drop_2,
|
||||
gear_used_on_down_slope,
|
||||
down_slope_rpm_shoot_up,
|
||||
fuel_consumption_var_lit_per_hr,
|
||||
mileage_var_km_per_ltr,
|
||||
fuel_consumption_var_pct_lit_per_hr,
|
||||
mileage_var_pct_km_per_ltr,
|
||||
engine_smoke_on_load,
|
||||
engine_acceleration_smoke,
|
||||
range_gear_shifting,
|
||||
speed_gear_shifting,
|
||||
tractor_steer_ability,
|
||||
tractor_braking_perf,
|
||||
front_visibility,
|
||||
implement_accessibility,
|
||||
front_end_lifting_during_operation,
|
||||
rpm_recovery_time,
|
||||
engine_vibration,
|
||||
engine_sound,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
test_iterationnumber::numeric,
|
||||
Test_Condition,
|
||||
Test_Date::date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr::numeric fuel_consumption_lit_per_hr ,
|
||||
Mileage_Km_Ltr ::numeric mileage_km_per_ltr ,
|
||||
Average_speed_of_travel_kmph::numeric avg_speed_of_travel_kmph ,
|
||||
Total_distance_travelled_km::numeric total_dist_travelled_km ,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1 ,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
fuel_consumption_lit_hr_2::numeric ,
|
||||
Mileage_Km_Ltr_2::numeric,
|
||||
fuel_consumption_lit_hr_3::numeric ,
|
||||
Mileage_Km_Ltr_3::numeric,
|
||||
engine_smoke_on_load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance tractor_braking_perf ,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.fthlg_sum_test_condition_2_block
|
||||
where trx_record=1;
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary_tractor_info a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk
|
||||
)where a.file_syspk =__file_syspk;
|
||||
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_1,
|
||||
test_mgr_comments =b.test_manager_comments_1
|
||||
from staging2.fthlg_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =1;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_2,
|
||||
test_mgr_comments =b.test_manager_comments_2
|
||||
from staging2.fthlg_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =2;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_3,
|
||||
test_mgr_comments =b.test_manager_comments_3
|
||||
from staging2.fthlg_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =3;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_4,
|
||||
test_mgr_comments =b.test_manager_comments_4
|
||||
from staging2.fthlg_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =4;
|
||||
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary_trailer_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =1 and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =2 and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =3 and a.file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =4 and a.file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.field_perf_summary
|
||||
set straight_road_rpm_drop =replace(straight_road_rpm_drop,' to ','-'),
|
||||
up_slope_rpm_drop_1 =replace(up_slope_rpm_drop_1,' to ','-'),
|
||||
up_slope_rpm_drop_2 =replace(up_slope_rpm_drop_2,' to ','-'),
|
||||
down_slope_rpm_shoot_up=replace(down_slope_rpm_shoot_up,' to ','-')
|
||||
where file_mnemonic = 'FTHLG';
|
||||
|
||||
|
||||
|
||||
UPDATE transactional.field_perf_summary
|
||||
SET
|
||||
--updating RPM drop straight:
|
||||
erpmdrop_straight_1stpass_low = trim(split_part(trim(straight_road_rpm_drop), '-', 1))::numeric,
|
||||
erpmdrop_straight_1stpass_high = case trim(split_part(trim(straight_road_rpm_drop), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(straight_road_rpm_drop), '-', 2))::numeric end,
|
||||
--updating RPM drop up slop 1st pass:
|
||||
erpmdrop_turn_1stpass_low = trim(split_part(trim(up_slope_rpm_drop_1), '-', 1))::numeric,
|
||||
erpmdrop_turn_1stpass_high = case trim(split_part(trim(up_slope_rpm_drop_1), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(up_slope_rpm_drop_1), '-', 2))::numeric end,
|
||||
--updating RPM drop up slop 2nd pass:
|
||||
erpmdrop_turn_2ndpass_low = trim(split_part(trim(up_slope_rpm_drop_2), '-', 1))::numeric,
|
||||
erpmdrop_turn_2ndpass_high = case trim(split_part(trim(up_slope_rpm_drop_2), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(up_slope_rpm_drop_2), '-', 2))::numeric end,
|
||||
--updating down slope rpm shoot up :
|
||||
erpmdrop_turn_3rdpass_low = trim(split_part(trim(down_slope_rpm_shoot_up), '-', 1))::numeric,
|
||||
erpmdrop_turn_3rdpass_high = case trim(split_part(trim(down_slope_rpm_shoot_up), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(down_slope_rpm_shoot_up), '-', 2))::numeric end
|
||||
where file_mnemonic = 'FTHLG';
|
||||
|
||||
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTHLG_SUM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
792
onetime/dataloadfunctions/field/FTHLG_SUM_stg2.sql
Executable file
792
onetime/dataloadfunctions/field/FTHLG_SUM_stg2.sql
Executable file
@@ -0,0 +1,792 @@
|
||||
drop function if exists staging2.fn_FTHLG_SUM_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_SUM_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare err_query int;
|
||||
declare err_block text;
|
||||
|
||||
begin
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_FTHLG_SUM_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: FTHLG
|
||||
Sheet Format: FTHLG_SUM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_fthlg_sum_block(20,1,'FTHLG','FTHLG_SUM',259);
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
truncate staging2.FTHLG_SUM_Trac_H1_Block;
|
||||
truncate staging2.FTHLG_SUM_Trail_Type_Block;
|
||||
truncate staging2.FTHLG_SUM_Test_Condition_1_Block;
|
||||
truncate staging2.FTHLG_SUM_Test_Condition_2_Block;
|
||||
truncate staging2.FTHLG_SUM_Comments_By_Block;
|
||||
truncate staging2.stg_specific_table_fthlg_sum;
|
||||
truncate staging2.stg_process_table_fthlg_sum;
|
||||
|
||||
|
||||
execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* transfer data from generic to specific for fthlg*/
|
||||
|
||||
execute 'insert into staging2.stg_specific_table_fthlg_sum
|
||||
select * from staging1.staging_generic_table a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
select count(*) into err_query from staging2.stg_specific_table_fthlg_sum;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for FTHLG Summary',
|
||||
detail = 'No data in table stg_specific_table_fthlg_sum',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
|
||||
update staging2.stg_specific_table_fthlg_sum set column2 = TRIM (TRAILING FROM column2 );
|
||||
update staging2.stg_specific_table_fthlg_sum set column2 = TRIM (LEADING FROM column2 );
|
||||
--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
|
||||
--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source) ;
|
||||
--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source) ;
|
||||
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified ;
|
||||
/* keyword match in config table*/
|
||||
execute 'update transactional.source_config a set f1_source = replace(f1_source,''_1'','''')
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_fthlg_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_fthlg_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* keyword match in config table*/
|
||||
execute 'update transactional.source_config a set f1_source = replace(f1_source,''_2'','''')
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_fthlg_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_fthlg_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a set row_previous_number=row_number_start-1
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from transactional.source_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* config file last field update as null otherwise it picks up next format row number*/
|
||||
execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Test Manager Comments_2'' and
|
||||
a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*inserting run_time in config*/
|
||||
execute 'update transactional.source_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* tagging block_row_numbers for each block in process table*/
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Model''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Trailer Type''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_1:''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_1''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_1''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition_2:''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Engineer Comments_2''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments_2''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_SUM_Trac_H1_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_SUM_Trac_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
|
||||
err_block:='FTHLG_SUM_Trac_H1_Block';
|
||||
|
||||
insert into staging2.FTHLG_SUM_Trac_H1_Block
|
||||
(
|
||||
tractor_model,
|
||||
tractor_make ,
|
||||
tractor_engine_hp,
|
||||
rated_rpm,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_kg_front,
|
||||
tractor_weight_kg_rear,
|
||||
tractor_weight_kg_total,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_fthlg_sum
|
||||
where block_tag='FTHLG_SUM_Trac_H1'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trac_H1_Block set trx_record =0 where tractor_model = '0';
|
||||
|
||||
update staging2.FTHLG_SUM_Trac_H1_Block set trx_record=0 where block_row_number in (1,2);
|
||||
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Trac_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Trac_H1_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_SUM_Trail_Type_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_SUM_Trail_Type_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='FTHLG_SUM_Trail_Type_Block';
|
||||
|
||||
insert into staging2.FTHLG_SUM_Trail_Type_Block
|
||||
(
|
||||
Trailer_Type,
|
||||
Tire_size_and_inflation_pressure_psi,
|
||||
No_Of_Axle,
|
||||
No_Of_Wheels,
|
||||
Trailer_Gross_Weight_Kg,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm,
|
||||
Tractor_Hitch_Height_from_Ground_mm,
|
||||
Trailer_hitch_Height_above_ground_level_mm,
|
||||
Gradient_Slope_1_Degree,
|
||||
Gradient_Slope_2_degree,
|
||||
Tractor_Hitch_Type,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_fthlg_sum
|
||||
where block_tag='FTHLG_SUM_Trail_Type'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block set trx_record=0 where block_row_number = 1;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block a
|
||||
set trailer_hitch_height_above_ground_level_mm= b.first_value from (SELECT
|
||||
block_row_number,trailer_hitch_height_above_ground_level_mm, value_partition, first_value(trailer_hitch_height_above_ground_level_mm) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
trailer_hitch_height_above_ground_level_mm,
|
||||
sum(case when trailer_hitch_height_above_ground_level_mm is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2
|
||||
ORDER BY block_row_number asc
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block a
|
||||
set tractor_hitch_height_from_ground_mm= b.first_value from (SELECT
|
||||
block_row_number,tractor_hitch_height_from_ground_mm, value_partition, first_value(tractor_hitch_height_from_ground_mm) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
tractor_hitch_height_from_ground_mm,
|
||||
sum(case when tractor_hitch_height_from_ground_mm is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block a
|
||||
set gradient_slope_1_degree= b.first_value from (SELECT
|
||||
block_row_number,gradient_slope_1_degree, value_partition, first_value(gradient_slope_1_degree) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
gradient_slope_1_degree,
|
||||
sum(case when gradient_slope_1_degree is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block a
|
||||
set gradient_slope_2_degree= b.first_value from (SELECT
|
||||
block_row_number,gradient_slope_2_degree, value_partition, first_value(gradient_slope_2_degree) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
gradient_slope_2_degree,
|
||||
sum(case when gradient_slope_2_degree is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block a
|
||||
set tractor_hitch_type= b.first_value from (SELECT
|
||||
block_row_number,tractor_hitch_type, value_partition, first_value(tractor_hitch_type) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
tractor_hitch_type,
|
||||
sum(case when tractor_hitch_type is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Trail_Type_Block where block_row_number >= 2
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.FTHLG_SUM_Trail_Type_Block set trx_record=0
|
||||
where Trailer_Type in ('Performance Test Results');
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Trail_Type_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Trail_Type_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_SUM_Test_Condition_1_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_SUM_Test_Condition_1_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
|
||||
err_block:='FTHLG_SUM_Test_Condition_1_Block';
|
||||
|
||||
insert into staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr,
|
||||
Mileage_Km_Ltr,
|
||||
Average_speed_of_travel_kmph,
|
||||
Total_distance_travelled_km,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
Performance_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Mileage_Km_Ltr_2,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_3,
|
||||
Mileage_Km_Ltr_3,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,
|
||||
column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_1''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text);
|
||||
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
set test_iterationnumber=1;
|
||||
|
||||
|
||||
|
||||
insert into staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr,
|
||||
Mileage_Km_Ltr,
|
||||
Average_speed_of_travel_kmph,
|
||||
Total_distance_travelled_km,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
Performance_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Mileage_Km_Ltr_2,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_3,
|
||||
Mileage_Km_Ltr_3,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column8::text,
|
||||
column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_1''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text);
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
set test_iterationnumber=2
|
||||
where test_iterationnumber is null;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block a
|
||||
set Test_Condition= b.first_value from (SELECT
|
||||
test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber)
|
||||
FROM (
|
||||
SELECT
|
||||
test_iterationnumber,
|
||||
Test_Condition,
|
||||
sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
ORDER BY test_iterationnumber asc
|
||||
) as q) b where a.test_iterationnumber = b.test_iterationnumber;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block set trx_record =0
|
||||
where tractor_model = '0' or fuel_consumption_ltr_hr is NULL;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%';
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
set fuel_consumption_lit_hr_2=left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3),
|
||||
Mileage_Km_Ltr_2 = left(Mileage_Km_Ltr_2,length(Mileage_Km_Ltr_2)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
set fuel_consumption_lit_hr_3=null where fuel_consumption_lit_hr_3 like '%indicates%';
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_1_Block
|
||||
set fuel_consumption_lit_hr_3 = left(fuel_consumption_lit_hr_3,length(fuel_consumption_lit_hr_3)-3),
|
||||
Mileage_Km_Ltr_3 = left(Mileage_Km_Ltr_3,length(Mileage_Km_Ltr_3)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
delete from staging2.FTHLG_SUM_Test_Condition_1_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTHLG_SUM_Test_Condition_1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Test_Condition_1_Block');
|
||||
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_SUM_Test_Condition_2_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_SUM_Test_Condition_2_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='FTHLG_SUM_Test_Condition_2_Block';
|
||||
|
||||
insert into staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr,
|
||||
Mileage_Km_Ltr,
|
||||
Average_speed_of_travel_kmph,
|
||||
Total_distance_travelled_km,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
Performance_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Mileage_Km_Ltr_2,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_3,
|
||||
Mileage_Km_Ltr_3,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_2''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text,
|
||||
a_32 text,a_33 text);
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
set test_iterationnumber=3;
|
||||
|
||||
|
||||
insert into staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Fuel_consumption_Ltr_hr,
|
||||
Mileage_Km_Ltr,
|
||||
Average_speed_of_travel_kmph,
|
||||
Total_distance_travelled_km,
|
||||
Gear_used_on_Straight_Road,
|
||||
Straight_road_RPM_Drop,
|
||||
Gear_used_on_Up_Slope_1,
|
||||
Up_Slope_RPM_Drop_1,
|
||||
Gear_used_on_Up_Slope_2,
|
||||
Up_Slope_RPM_Drop_2,
|
||||
Gear_used_on_Down_Slope,
|
||||
Down_Slope_RPM_Shoot_up,
|
||||
Performance_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Mileage_Km_Ltr_2,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_3,
|
||||
Mileage_Km_Ltr_3,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Range_Gear_Shifting,
|
||||
Speed_Gear_Shifting,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column8::text,column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM staging2.stg_process_table_FTHLG_sum where block_tag=''FTHLG_SUM_Test_Condition_2''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,a_31 text,
|
||||
a_32 text,a_33 text);
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
set test_iterationnumber=4
|
||||
where test_iterationnumber is null;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block a
|
||||
set Test_Condition= b.first_value from (SELECT
|
||||
test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber)
|
||||
FROM (
|
||||
SELECT
|
||||
test_iterationnumber,
|
||||
Test_Condition,
|
||||
sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition
|
||||
FROM staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
ORDER BY test_iterationnumber asc
|
||||
) as q) b where a.test_iterationnumber = b.test_iterationnumber;
|
||||
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block a
|
||||
set Test_Date=(select Test_Date from staging2.FTHLG_SUM_Test_Condition_1_Block b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk=b.file_syspk)
|
||||
where Test_Date='0' and a.file_syspk=__file_syspk;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block a
|
||||
set Test_Date=(select Test_Date from staging2.FTHLG_SUM_Test_Condition_1_Block b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk=b.file_syspk)
|
||||
where Test_Date='0' and a.file_syspk=__file_syspk;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block set trx_record =0
|
||||
where tractor_model = '0' or
|
||||
fuel_consumption_ltr_hr is NULL;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
set fuel_consumption_lit_hr_2=null where fuel_consumption_lit_hr_2 like '%indicates%';
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
set fuel_consumption_lit_hr_2=left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3),
|
||||
Mileage_Km_Ltr_2 = left(Mileage_Km_Ltr_2,length(Mileage_Km_Ltr_2)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
set fuel_consumption_lit_hr_3=null where fuel_consumption_lit_hr_3 like '%indicates%';
|
||||
|
||||
update staging2.FTHLG_SUM_Test_Condition_2_Block
|
||||
set fuel_consumption_lit_hr_3 = left(fuel_consumption_lit_hr_3,length(fuel_consumption_lit_hr_3)-3),
|
||||
Mileage_Km_Ltr_3 = left(Mileage_Km_Ltr_3,length(Mileage_Km_Ltr_3)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
|
||||
delete from staging2.FTHLG_SUM_Test_Condition_2_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTHLG_SUM_Test_Condition_2_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Test_Condition_2_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_SUM_Comments_By_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_SUM_Comments_By_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='FTHLG_SUM_Comments_By_Block';
|
||||
|
||||
|
||||
insert into staging2.FTHLG_SUM_Comments_By_Block (dummy_f) values
|
||||
('dummy');
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_1=
|
||||
(select column3 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Engineer_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_3=
|
||||
(select column3 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Engineer_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_1=
|
||||
(select column3 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Manager_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_3=
|
||||
(select column3 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Manager_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_2=
|
||||
(select column8 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Egnineer_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_engineer_comments_4=
|
||||
(select column8 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Engineer_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_2=
|
||||
(select column8 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Manager_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set test_manager_comments_4=
|
||||
(select column8 from staging2.stg_process_table_fthlg_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTHLG_SUM_Manager_Comments_2''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''';
|
||||
|
||||
|
||||
delete from staging2.FTHLG_SUM_Comments_By_Block where dummy_f is null ;
|
||||
|
||||
execute 'update staging2.FTHLG_SUM_Comments_By_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_SUM_Comments_By_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_fthlg_sum_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
378
onetime/dataloadfunctions/field/FTHLG_TRS_ods.sql
Executable file
378
onetime/dataloadfunctions/field/FTHLG_TRS_ods.sql
Executable file
@@ -0,0 +1,378 @@
|
||||
drop function if exists staging2.fn_FTHLG_TRS_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTHLG_TRS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __test_instance_id int;
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare _error int;
|
||||
declare __test_master_id int;
|
||||
declare __test_tractor_id int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_FTHLG_TRS_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTHLG
|
||||
Sheet Format: FTHLG_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTHLG_TRS_TRX()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location_name,
|
||||
gradient_slope_1_degree,
|
||||
gradient_slope_2_degree,
|
||||
tractor_hitch_type,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test,
|
||||
test_report_date,
|
||||
type_of_road,
|
||||
tractor_hitch_ht_mm,
|
||||
tractor_rwheel_c2h_dist_mm,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
Report_Reference_No test_report_no ,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location test_location_name,
|
||||
Gradient_Slope_1_Degree::numeric,
|
||||
Gradient_Slope_2_Degree::numeric,
|
||||
Tractor_Hitch_Type,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test::date,
|
||||
Report_Date::date test_report_date,
|
||||
Type_of_Road,
|
||||
Tractor_Hitch_Height_from_Ground_mm::numeric tractor_hitch_ht_mm ,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm::numeric tractor_rwheel_c2h_dist_mm,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.FTHLG_TRS_H1_Block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
tractor_engine_hp,
|
||||
fip_type,
|
||||
hour_meter_reading,
|
||||
steering_type,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
egr_yn,
|
||||
brake_type,
|
||||
pto_type,
|
||||
standard_pto_speed_rpm,
|
||||
epto_speed_rpm,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
ballasted_tractor_accessories,
|
||||
mechanical_ballast_rear,
|
||||
water_ballast_rear_75_pct,
|
||||
mechanical_ballast_front_kg,
|
||||
mechanical_ballast_front,
|
||||
total_ballast_weight,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP::numeric,
|
||||
FIP_Type,
|
||||
Hour_Meter_Reading::float,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No egr_yn,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM::numeric,
|
||||
EPTO_Speed_RPM,
|
||||
Tractor_Weight_kg_Front::numeric tractor_weight_front_kg,
|
||||
Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg,
|
||||
Tractor_Weight_kg_Total::numeric tractor_weight_total_kg,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
Water_Ballast_Rear_75 water_ballast_rear_75_pct,
|
||||
Mechanical_Ballast_Front_in_kg::numeric mechanical_ballast_front_kg,
|
||||
Mechanical_Ballast_Front,
|
||||
Total_Ballast_Weight::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.fthlg_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
|
||||
) where file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info a
|
||||
set test_tractor_yn ='Y' where syspk in
|
||||
(select min(syspk) from transactional.test_instance_tractor_info b
|
||||
where b.file_syspk =a.file_syspk)
|
||||
and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_tractor_yn ='N'
|
||||
where test_tractor_yn is null and file_syspk =__file_syspk;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
'front',
|
||||
front_tyre_make tyre_make,
|
||||
front_tyre_size tyre_size,
|
||||
front_tyre_pressure_psi::numeric tyre_pressure_psi
|
||||
from staging2.fthlg_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.tyre_type ='front' and a.file_syspk =__file_syspk;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_sr_no,
|
||||
'rear',
|
||||
rear_tyre_make tyre_make,
|
||||
rear_tyre_size tyre_size,
|
||||
rear_tyre_pressure_psi::numeric tyre_pressure_psi
|
||||
from staging2.fthlg_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.tyre_type ='rear' and a.file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
low_idle_declared,
|
||||
high_idle_declared,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
low_idle low_idle_declared,
|
||||
high_idle high_idle_declared,
|
||||
rated_rpm::numeric,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.fthlg_trs_engine_rpm_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.test_instance_trailer_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
type_of_trailer,
|
||||
no_of_axle,
|
||||
no_of_wheels,
|
||||
trailer_hitch_ht_above_ground_lvl_mm,
|
||||
make_model_of_trailer,
|
||||
trailer_platform_length_mm,
|
||||
trailer_platform_width_mm,
|
||||
trailer_platform_height_mm,
|
||||
tire_size,
|
||||
inflation_pressure_psi,
|
||||
track_width_of_trailer_mm,
|
||||
hzntl_dist_of_hitch_pt_from_trailer_face_mm,
|
||||
tractor_rwc_to_hitch_pt_center_dist_mm,
|
||||
dist_from_tractor_rwc_to_trailer_rwc_mm,
|
||||
dist_from_trailer_front_axle_dist_from_hitch_pt_mm,
|
||||
trailer_empty_weight_kg,
|
||||
trailer_gross_weight_kg,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
Type_Of_Trailer,
|
||||
No_Of_Axle::numeric,
|
||||
No_Of_Wheels::numeric,
|
||||
Trailer_hitch_Height_above_ground_level_mm::numeric trailer_hitch_ht_above_ground_lvl_mm,
|
||||
Make_model_of_trailer,
|
||||
Trailer_platform_length_mm::numeric,
|
||||
Trailer_platform_Width_mm::numeric,
|
||||
Trailer_platform_Height_mm::numeric,
|
||||
Tire_size,
|
||||
Inflation_pressure_psi::numeric,
|
||||
Track_width_of_trailer_mm::numeric,
|
||||
Horizontal_distance_of_hitch_point_from_trailer_front_face_mm::numeric hzntl_dist_of_hitch_pt_from_trailer_face_mm,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm::numeric tractor_rwc_to_hitch_pt_center_dist_mm,
|
||||
Distance_from_Trailer_front_axle_distance_from_hitch_point_mm::numeric dist_from_tractor_rwc_to_trailer_rwc_mm,
|
||||
Distance_from_tractor_rear_wheel_to_tractor_rear_wheel_mm::numeric dist_from_trailer_front_axle_dist_from_hitch_pt_mm,
|
||||
Trailer_empty_weight_Kg::numeric,
|
||||
Trailer_Gross_Weight_Kg::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.fthlg_trs_trailer_block where trx_record=1;
|
||||
|
||||
|
||||
update transactional.test_instance a
|
||||
set report_template_no=b.report_template_no,
|
||||
report_template_rev_no=b.report_template_rev_no,
|
||||
report_template_rev_date =b.report_template_rev_date
|
||||
from staging2.fthlg_trs_trailer_block b where trx_record=1
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='Field';
|
||||
select syspk from transactional.test_instance_tractor_info into __test_tractor_id
|
||||
where file_syspk =__file_syspk and test_tractor_yn ='Y';
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_engine_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tyre_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_trailer_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1)
|
||||
where file_syspk = __file_syspk;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTHLG_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
423
onetime/dataloadfunctions/field/FTHLG_TRS_stg2.sql
Executable file
423
onetime/dataloadfunctions/field/FTHLG_TRS_stg2.sql
Executable file
@@ -0,0 +1,423 @@
|
||||
drop function if exists staging2.fn_fthlg_trs_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_fthlg_trs_block(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare err_query int;
|
||||
declare err_block text;
|
||||
begin
|
||||
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_FTHLG_TRS_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: FTHLG
|
||||
Sheet Format: FTHLG_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTHLG_TRS',259);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
truncate staging2.FTHLG_TRS_H1_INT;
|
||||
truncate staging2.FTHLG_TRS_H1_Block;
|
||||
truncate staging2.FTHLG_TRS_SPEC_Block;
|
||||
truncate staging2.FTHLG_TRS_Engine_RPM_Block;
|
||||
truncate staging2.FTHLG_TRS_Trailer_Block;
|
||||
truncate staging2.stg_specific_table_fthlg_trs;
|
||||
truncate staging2.stg_process_table_fthlg_trs;
|
||||
|
||||
|
||||
execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* transfer data from generic to specific for fthlg*/
|
||||
|
||||
execute 'insert into staging2.stg_specific_table_fthlg_trs
|
||||
select * from staging1.staging_generic_table a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
select count(*) into err_query from staging2.stg_specific_table_fthlg_trs;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for FTHLG Tractor Specifications',
|
||||
detail = 'No data in table stg_specific_table_fthlg_trs',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
/*
|
||||
update staging2.stg_specific_table_fthlg_trs set column2 = TRIM (TRAILING FROM column2 );
|
||||
update staging2.stg_specific_table_fthlg_trs set column2 = TRIM (LEADING FROM column2 );
|
||||
update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified);
|
||||
|
||||
update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
*/
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified;
|
||||
|
||||
/* keyword match in config table*/
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_fthlg_trs b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_fthlg_trs a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update transactional.source_config a set row_previous_number=row_number_start-1
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from transactional.source_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* config file last field update as null otherwise it picks up next format row number*/
|
||||
execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Trailer Details'' and
|
||||
a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*inserting run_time in config*/
|
||||
execute 'update transactional.source_config a
|
||||
set run_time=current_timestamp where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers for each block in process table*/
|
||||
execute 'insert into staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor specifications sheet'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Engine RPM Data:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_fthlg_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_fthlg_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Trailer Details'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
/*inserting data into FTHLG_TRS_H1_INT*/
|
||||
err_block:='FTHLG_TRS_H1_Block';
|
||||
|
||||
insert into staging2.FTHLG_TRS_H1_INT
|
||||
(column2,column3,column4,column5,column6,column7,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,block_row_number from staging2.stg_process_table_fthlg_trs a
|
||||
where block_tag='FTHLG_TRS_H1' order by block_row_number;
|
||||
|
||||
|
||||
|
||||
insert into staging2.FTHLG_TRS_H1_INT(column2,column3)
|
||||
select 'Date of Test',column5
|
||||
from staging2.FTHLG_TRS_H1_INT
|
||||
where block_row_number=1;
|
||||
|
||||
insert into staging2.FTHLG_TRS_H1_INT(column2,column3)
|
||||
select 'Report Date',column7
|
||||
from staging2.FTHLG_TRS_H1_INT
|
||||
where block_row_number=1;
|
||||
|
||||
insert into staging2.FTHLG_TRS_H1_INT(column2,column3)
|
||||
select column5,column6
|
||||
from staging2.FTHLG_TRS_H1_INT
|
||||
where block_row_number in (5,6,8);
|
||||
|
||||
/*inserting data into block -.FTHLG_TRS_H1_Block*/
|
||||
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_TRS_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
|
||||
|
||||
insert into staging2.FTHLG_TRS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Report_Reference_No,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location,
|
||||
Gradient_Slope_1_Degree,
|
||||
Gradient_Slope_2_Degree,
|
||||
Tractor_Hitch_Type,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test,
|
||||
Report_Date,
|
||||
Type_of_Road,
|
||||
Tractor_Hitch_Height_from_Ground_mm,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text]) AS val
|
||||
FROM staging2.FTHLG_TRS_H1_INT
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text);
|
||||
|
||||
|
||||
delete from staging2.FTHLG_TRS_H1_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTHLG_TRS_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_H1_Block');
|
||||
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_TRS_SPEC_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_TRS_SPEC_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='FTHLG_TRS_SPEC_Block';
|
||||
|
||||
insert into staging2.FTHLG_TRS_SPEC_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
Front_Tyre_Make,
|
||||
Front_Tyre_Size,
|
||||
Front_Tyre_Pressure_psi,
|
||||
Rear_Tyre_Make,
|
||||
Rear_Tyre_Size,
|
||||
Rear_Tyre_Pressure_psi ,
|
||||
Tractor_Weight_kg_Front ,
|
||||
Tractor_Weight_kg_Rear ,
|
||||
Tractor_Weight_kg_Total,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear,
|
||||
Mechanical_Ballast_Rear_in_KG ,
|
||||
Water_Ballast_Rear_75,
|
||||
Mechanical_Ballast_Front_in_Kg,
|
||||
Mechanical_Ballast_Front,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_fthlg_trs where block_tag=''FTHLG_TRS_SPEC''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text);
|
||||
|
||||
update staging2.FTHLG_TRS_SPEC_Block set trx_record=0
|
||||
where tractor_make is null and tractor_sr_no is null;
|
||||
|
||||
update staging2.FTHLG_TRS_SPEC_Block set trx_record=0
|
||||
where (tractor_model is null and front_tyre_make is null) or (tractor_model is null and rear_tyre_make is null);
|
||||
|
||||
delete from staging2.FTHLG_TRS_SPEC_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTHLG_TRS_SPEC_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_SPEC_Block');
|
||||
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_TRS_Engine_RPM_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_TRS_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='FTHLG_TRS_Engine_RPM_Block';
|
||||
|
||||
insert into staging2.FTHLG_TRS_Engine_RPM_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_model,
|
||||
Tractor_make,
|
||||
tractor_sr_no,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_fthlg_trs where block_tag=''FTHLG_TRS_Engine_RPM''
|
||||
or (block_tag=''FTHLG_TRS_SPEC'' and block_row_number in (1,2,3))
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text);
|
||||
|
||||
update staging2.FTHLG_TRS_Engine_RPM_Block set trx_record=0
|
||||
where tractor_model is null;
|
||||
|
||||
delete from staging2.FTHLG_TRS_Engine_RPM_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTHLG_TRS_Engine_RPM_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_Engine_RPM_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTHLG_TRS_Trailer_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTHLG_TRS_Trailer_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='FTHLG_TRS_Trailer_Block';
|
||||
|
||||
insert into staging2.FTHLG_TRS_Trailer_Block
|
||||
(
|
||||
dummy_f,
|
||||
Type_Of_Trailer,
|
||||
No_Of_Axle,
|
||||
No_Of_Wheels,
|
||||
Trailer_hitch_Height_above_ground_level_mm,
|
||||
Make_model_of_trailer,
|
||||
Trailer_platform_length_mm,
|
||||
Trailer_platform_Width_mm,
|
||||
Trailer_platform_Height_mm,
|
||||
Tire_size,
|
||||
Inflation_pressure_psi,
|
||||
Track_width_of_trailer_mm,
|
||||
Horizontal_distance_of_hitch_point_from_trailer_front_face_mm,
|
||||
Tractor_Rear_Wheel_Center_to_Hitch_Point_Center_Distance_mm,
|
||||
Distance_from_Trailer_front_axle_distance_from_hitch_point_mm,
|
||||
Distance_from_tractor_rear_wheel_to_tractor_rear_wheel_mm,
|
||||
Trailer_empty_weight_Kg,
|
||||
Trailer_Gross_Weight_Kg
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
|
||||
FROM staging2.stg_process_table_fthlg_trs where block_tag=''FTHLG_TRS_Trailer'' and block_row_number <=17
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
|
||||
,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text);
|
||||
|
||||
|
||||
update staging2.FTHLG_TRS_Trailer_Block set report_template_no=
|
||||
(select column2 from staging2.stg_process_table_fthlg_trs where block_row_number=18
|
||||
and block_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null;
|
||||
|
||||
update staging2.FTHLG_TRS_Trailer_Block set report_template_rev_no=
|
||||
(select column4 from staging2.stg_process_table_fthlg_trs where block_row_number=18
|
||||
and block_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null;
|
||||
|
||||
|
||||
update staging2.FTHLG_TRS_Trailer_Block set report_template_rev_date=
|
||||
(select column6 from staging2.stg_process_table_fthlg_trs where block_row_number=18 and
|
||||
block_tag='FTHLG_TRS_Trailer')where make_model_of_trailer is not null;
|
||||
|
||||
update staging2.FTHLG_TRS_Trailer_Block set trx_record=0
|
||||
where type_of_trailer is null;
|
||||
|
||||
execute 'update staging2.FTHLG_TRS_Trailer_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTHLG_TRS_Trailer_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTHLG_TRS_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
349
onetime/dataloadfunctions/field/FTWET_SUM_ods.sql
Executable file
349
onetime/dataloadfunctions/field/FTWET_SUM_ods.sql
Executable file
@@ -0,0 +1,349 @@
|
||||
drop function if exists staging2.fn_FTWET_SUM_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTWET_SUM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __test_instance_id int;
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare _error int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_FTWET_SUM_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTWET
|
||||
Sheet Format: FTWET_SUM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTWET_SUM_TRX()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_engine_hp,
|
||||
rated_rpm,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
trim('HP' from tractor_engine_hp)::numeric,
|
||||
rated_rpm::numeric,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
tractor_weight_kg_front::numeric,
|
||||
tractor_weight_kg_rear::numeric,
|
||||
tractor_weight_kg_total::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftwet_sum_trac_h1_block where trx_record=1;
|
||||
|
||||
update transactional.field_perf_summary_tractor_info a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=trim(b.tractor_model) and a.file_syspk =b.file_syspk
|
||||
)where a.file_syspk =__file_syspk;
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
implement_type,
|
||||
implement_size,
|
||||
hitch_category,
|
||||
implement_weight,
|
||||
soil_type,
|
||||
soil_moisture_content_pct,
|
||||
soil_bulk_density_g_per_cc,
|
||||
soil_cone_index,
|
||||
field_condition,
|
||||
season,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
make_of_implement,
|
||||
implement_type,
|
||||
implement_size,
|
||||
hitch_category,
|
||||
implement_weight::numeric,
|
||||
soil_type,
|
||||
moisture_content::numeric soil_moisture_content_pct,
|
||||
bulk_density_g_cc::numeric soil_bulk_density_g_per_cc,
|
||||
soil_cone_index::numeric soil_cone_index,
|
||||
field_condition,
|
||||
season,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftwet_sum_implement_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
type_of_cage_wheel,
|
||||
cage_wheel_width_mm,
|
||||
cage_wheel_weight,
|
||||
cage_wheel_inner_and_outer_ring_dia_mm,
|
||||
cage_wheel_center_ring_dia_mm,
|
||||
no_of_angles_on_cage_wheel,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
Type_of_Cage_Wheel,
|
||||
Cage_Wheel_Width_mm::numeric,
|
||||
Cage_wheel_Weight::numeric,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_inner_and_outer_ring_dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm::numeric,
|
||||
No_of_angles_on_cage_wheel::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.FTWET_SUM_Cage_Wheel_Block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.field_perf_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_iteration_number,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight_1st_Pass,
|
||||
Engine_RPM_Drop_on_straight_2nd_Pass,
|
||||
Engine_RPM_Drop_on_straight_3rd_Pass,
|
||||
Engine_RPM_Drop_on_turn_1st_Pass,
|
||||
Engine_RPM_Drop_on_turn_2nd_Pass,
|
||||
Engine_RPM_Drop_on_turn_3rd_Pass,
|
||||
No_of_passes,
|
||||
depth_of_cut_cm,
|
||||
fuel_consumption_lit_per_hr,
|
||||
area_covered_acr_per_hr,
|
||||
fuel_consumption_lit_per_acr,
|
||||
fuel_consumption_var_lit_per_hr,
|
||||
area_covered_var_acr_per_hr,
|
||||
fuel_consumption_var_lit_per_acr,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_perf,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
implement_lifting_per_lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
test_iterationnumber::numeric,
|
||||
Test_Condition,
|
||||
Test_Date::date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set::numeric,
|
||||
PTO_RPM_set::numeric,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH::numeric,
|
||||
Engine_RPM_Drop_on_straight_1st_Pass,
|
||||
Engine_RPM_Drop_on_straight_2nd_Pass,
|
||||
Engine_RPM_Drop_on_straight_3rd_Pass,
|
||||
Engine_RPM_Drop_on_turn_1st_Pass,
|
||||
Engine_RPM_Drop_on_turn_2nd_Pass,
|
||||
Engine_RPM_Drop_on_turn_3rd_Pass,
|
||||
No_of_passes::numeric,
|
||||
Avg_Depth_of_cut_cm depth_of_cut_cm ,
|
||||
Fuel_consumption_lit_hr::numeric fuel_consumption_lit_per_hr,
|
||||
Area_covered_acr_hr::numeric area_covered_acr_per_hr,
|
||||
Fuel_consumption_lit_Acr::numeric fuel_consumption_lit_per_acr,
|
||||
case when fuel_consumption_lit_hr_2 ~ E'^\\d+$' then fuel_consumption_lit_hr_2::numeric else null end as fuel_consumption_var_lit_per_hr ,
|
||||
case when area_covered_acr_hr_2 ~ E'^\\d+$' then area_covered_acr_hr_2::numeric else null end as area_covered_var_acr_per_hr ,
|
||||
case when fuel_consumption_lit_acr_2 ~ E'^\\d+$' then fuel_consumption_lit_acr_2::numeric else null end as fuel_consumption_var_lit_per_acr,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance tractor_braking_perf,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response implement_lifting_per_lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.FTWET_SUM_Test_Condition_Block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_1,
|
||||
test_mgr_comments =b.test_manager_comments_1
|
||||
from staging2.ftwet_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =1;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_engr_comments=b.test_engineer_comments_2,
|
||||
test_mgr_comments =b.test_manager_comments_2
|
||||
from staging2.ftwet_sum_comments_by_block b
|
||||
where a.file_syspk=b.file_syspk and a.test_iteration_number =2;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
|
||||
update transactional.field_perf_summary
|
||||
set engine_rpm_drop_on_straight_1st_pass =replace(engine_rpm_drop_on_straight_1st_pass,' to ','-'),
|
||||
engine_rpm_drop_on_straight_2nd_pass =replace(engine_rpm_drop_on_straight_2nd_pass,' to ','-'),
|
||||
engine_rpm_drop_on_straight_3rd_pass =replace(engine_rpm_drop_on_straight_3rd_pass,' to ','-'),
|
||||
engine_rpm_drop_on_turn_1st_pass=replace(engine_rpm_drop_on_turn_1st_pass,' to ','-'),
|
||||
engine_rpm_drop_on_turn_2nd_pass=replace(engine_rpm_drop_on_turn_2nd_pass,' to ','-'),
|
||||
engine_rpm_drop_on_turn_3rd_pass=replace(engine_rpm_drop_on_turn_3rd_pass,' to ','-'),
|
||||
depth_of_cut_cm=replace(depth_of_cut_cm,' to ','-')
|
||||
where file_mnemonic = 'FTWET';
|
||||
|
||||
UPDATE transactional.field_perf_summary
|
||||
SET
|
||||
--updating RPM drop straight 1st pass:
|
||||
erpmdrop_straight_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 1))::numeric,
|
||||
erpmdrop_straight_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_straight_1st_pass), '-', 2))::numeric end,
|
||||
--updating RPM drop straight 2nd pass:
|
||||
erpmdrop_straight_2ndpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_2nd_pass), '-', 1))::numeric,
|
||||
erpmdrop_straight_2ndpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_2nd_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_straight_2nd_pass), '-', 2))::numeric end,
|
||||
--updating RPM drop straight 3rd pass:
|
||||
erpmdrop_straight_3rdpass_low = trim(split_part(trim(engine_rpm_drop_on_straight_3rd_pass), '-', 1))::numeric,
|
||||
erpmdrop_straight_3rdpass_high = case trim(split_part(trim(engine_rpm_drop_on_straight_3rd_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_straight_3rd_pass), '-', 2))::numeric end,
|
||||
--updating RPM drop turn 1st pass:
|
||||
erpmdrop_turn_1stpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 1))::numeric,
|
||||
erpmdrop_turn_1stpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_turn_1st_pass), '-', 2))::numeric end,
|
||||
--updating RPM drop turn 2nd pass:
|
||||
erpmdrop_turn_2ndpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_2nd_pass), '-', 1))::numeric,
|
||||
erpmdrop_turn_2ndpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_2nd_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_turn_2nd_pass), '-', 2))::numeric end,
|
||||
--updating RPM drop turn 3rd pass:
|
||||
erpmdrop_turn_3rdpass_low = trim(split_part(trim(engine_rpm_drop_on_turn_3rd_pass), '-', 1))::numeric,
|
||||
erpmdrop_turn_3rdpass_high = case trim(split_part(trim(engine_rpm_drop_on_turn_3rd_pass), '-', 2))
|
||||
when '' then null
|
||||
else trim(split_part(trim(engine_rpm_drop_on_turn_3rd_pass), '-', 2))::numeric end,
|
||||
--updating depth of cut:
|
||||
depth_of_cut_cm_low = trim(split_part(trim(depth_of_cut_cm), '-', 1))::numeric,
|
||||
depth_of_cut_cm_high= case trim(split_part(trim(depth_of_cut_cm), '-', 2))
|
||||
when '' then null
|
||||
else trim('cm' from split_part(trim(depth_of_cut_cm), '-', 2))::numeric end
|
||||
where file_mnemonic = 'FTWET';
|
||||
|
||||
|
||||
update transactional.field_perf_summary
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.field_perf_summary_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.field_perf_summary_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary_trailer_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =1 and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.field_perf_summary a
|
||||
set test_instance_tractor_id = (select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.tractor_model=b.tractor_model and a.file_syspk =b.file_syspk
|
||||
)where test_iteration_number =2 and a.file_syspk =__file_syspk;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTWET_SUM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
511
onetime/dataloadfunctions/field/FTWET_SUM_stg2.sql
Executable file
511
onetime/dataloadfunctions/field/FTWET_SUM_stg2.sql
Executable file
@@ -0,0 +1,511 @@
|
||||
drop function if exists staging2.fn_FTWET_SUM_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTWET_SUM_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare err_query int;
|
||||
declare err_block text;
|
||||
|
||||
begin
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_FTWET_SUM_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: FTWET
|
||||
Sheet Format: FTWET_SUM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_ftwet_sum_block(20,1,'FTWET','FTWET_SUM',260);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
truncate staging2.FTWET_SUM_Trac_H1_Block;
|
||||
truncate staging2.FTWET_SUM_Implement_Block;
|
||||
truncate staging2.FTWET_SUM_Cage_Wheel_Block;
|
||||
truncate staging2.FTWET_SUM_Test_Condition_Block;
|
||||
truncate staging2.FTWET_SUM_Comments_By_Block;
|
||||
truncate staging2.stg_specific_table_ftwet_sum;
|
||||
truncate staging2.stg_process_table_ftwet_sum;
|
||||
|
||||
|
||||
execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* transfer data from generic to specific for ftwet*/
|
||||
|
||||
execute 'insert into staging2.stg_specific_table_ftwet_sum
|
||||
select * from staging1.staging_generic_table a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
select count(*) into err_query from staging2.stg_specific_table_ftwet_sum;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for FTWET Summary',
|
||||
detail = 'No data in table stg_specific_table_ftwet_sum',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_ftwet_sum set column2 = TRIM (TRAILING FROM column2 );
|
||||
update staging2.stg_specific_table_ftwet_sum set column2 = TRIM (LEADING FROM column2 );
|
||||
--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified) ;
|
||||
--
|
||||
--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
update transactional.source_config set F1_source=F1_modified;
|
||||
|
||||
|
||||
/* keyword match in config table*/
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_ftwet_sum b
|
||||
where F1_source=column2
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_ftwet_sum a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where F1_source=column2
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null and
|
||||
a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update transactional.source_config a set row_previous_number=row_number_start-1
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* keyword match in config table*/
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from transactional.source_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* config file last field update as null otherwise it picks up next format row number*/
|
||||
execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Test Manager Comments'' and
|
||||
a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*inserting run_time in config*/
|
||||
execute 'update transactional.source_config a
|
||||
set run_time=current_timestamp
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers for each block in process table*/
|
||||
execute 'insert into staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Model'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Make of Implement'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Type of Cage Wheel'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Condition:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_sum
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_sum a
|
||||
join transactional.source_config b
|
||||
on a.row_number >=row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Test Manager Comments'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/*inserting data into block -FTWET_SUM_Trac_H1_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_SUM_Trac_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='FTWET_SUM_Trac_H1_Block';
|
||||
|
||||
insert into staging2.FTWET_SUM_Trac_H1_Block
|
||||
(
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Engine_HP,
|
||||
Rated_RPM,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type,
|
||||
FIP_Type,
|
||||
Steering_Type,
|
||||
Tractor_Weight_kg_Front,
|
||||
Tractor_Weight_kg_Rear,
|
||||
Tractor_Weight_kg_Total,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_FTWET_sum
|
||||
where block_tag='FTWET_SUM_Trac_H1'
|
||||
order by block_row_number;
|
||||
|
||||
delete from staging2.FTWET_SUM_Trac_H1_Block where tractor_model='0';
|
||||
|
||||
update staging2.FTWET_SUM_Trac_H1_Block set trx_record=0 where block_row_number=1;
|
||||
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Trac_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Trac_H1_Block');
|
||||
|
||||
/*inserting data into block -FTWET_SUM_Implement_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_SUM_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
|
||||
err_block:='FTWET_SUM_Implement_Block';
|
||||
|
||||
insert into staging2.FTWET_SUM_Implement_Block
|
||||
(
|
||||
Make_of_Implement,
|
||||
Implement_Type,
|
||||
Implement_Size,
|
||||
Hitch_Category,
|
||||
Implement_Weight,
|
||||
Soil_Type,
|
||||
Moisture_Content ,
|
||||
Bulk_Density_g_cc ,
|
||||
Soil_Cone_index,
|
||||
Field_Condition ,
|
||||
Season,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_FTWET_sum
|
||||
where block_tag='FTWET_SUM_Impement'
|
||||
order by block_row_number;
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
update staging2.FTWET_SUM_Implement_Block set trx_record=0 where block_row_number=1;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Implement_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTWET_SUM_Cage_Wheel_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_SUM_Cage_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='FTWET_SUM_Cage_Wheel_Block';
|
||||
|
||||
insert into staging2.FTWET_SUM_Cage_Wheel_Block
|
||||
(
|
||||
Type_of_Cage_Wheel,
|
||||
Cage_Wheel_Width_mm,
|
||||
Cage_wheel_Weight,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm,
|
||||
Distance_between_RHS_LHS_cage_wheel_Inner_Ring_mm,
|
||||
No_of_angles_on_cage_wheel,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4,column5,column6,column7,column8,block_row_number
|
||||
from staging2.stg_process_table_FTWET_sum
|
||||
where block_tag='FTWET_SUM_Cage_Wheel'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.FTWET_SUM_Cage_Wheel_Block
|
||||
set trx_record=0 where block_row_number in (1,3);
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Cage_Wheel_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Cage_Wheel_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTWET_SUM_Test_Condition_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_SUM_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='FTWET_SUM_Test_Condition_Block';
|
||||
|
||||
insert into staging2.FTWET_SUM_Test_Condition_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight_1st_Pass,
|
||||
Engine_RPM_Drop_on_straight_2nd_Pass,
|
||||
Engine_RPM_Drop_on_straight_3rd_Pass,
|
||||
Engine_RPM_Drop_on_turn_1st_Pass,
|
||||
Engine_RPM_Drop_on_turn_2nd_Pass,
|
||||
Engine_RPM_Drop_on_turn_3rd_Pass,
|
||||
No_of_passes,
|
||||
Avg_Depth_of_cut_cm,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,
|
||||
column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_FTWET_sum where block_tag=''FTWET_SUM_Test_Condition''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text,a_37 text,a_38 text);
|
||||
|
||||
update staging2.FTWET_SUM_Test_Condition_Block
|
||||
set test_iterationnumber=1
|
||||
where test_iterationnumber is null;
|
||||
|
||||
insert into staging2.FTWET_SUM_Test_Condition_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Condition,
|
||||
Test_Date,
|
||||
Tractor_Model,
|
||||
Engine_RPM_set,
|
||||
PTO_RPM_set,
|
||||
Gear_Used,
|
||||
Nominal_Speed_KMPH,
|
||||
Engine_RPM_Drop_on_straight_1st_Pass,
|
||||
Engine_RPM_Drop_on_straight_2nd_Pass,
|
||||
Engine_RPM_Drop_on_straight_3rd_Pass,
|
||||
Engine_RPM_Drop_on_turn_1st_Pass,
|
||||
Engine_RPM_Drop_on_turn_2nd_Pass,
|
||||
Engine_RPM_Drop_on_turn_3rd_Pass,
|
||||
No_of_passes,
|
||||
Avg_Depth_of_cut_cm,
|
||||
Fuel_consumption_lit_hr,
|
||||
Area_covered_acr_hr,
|
||||
Fuel_consumption_lit_Acr,
|
||||
M_M_Performance_in_compared_to_respective_competitor_tractors,
|
||||
Fuel_consumption_lit_hr_2,
|
||||
Area_covered_acr_hr_2,
|
||||
Fuel_consumption_lit_Acr_2,
|
||||
Trail_Observations,
|
||||
Engine_Smoke_on_Load,
|
||||
Engine_acceleration_smoke,
|
||||
Draft_Response,
|
||||
Tractor_Steer_ability,
|
||||
Tractor_braking_performance,
|
||||
Front_Visibility,
|
||||
Implement_Accessibility,
|
||||
Front_Wheel_dragging_at_turning,
|
||||
Front_end_lifting_during_operation,
|
||||
RPM_Recovery_Time,
|
||||
Engine_Vibration,
|
||||
Engine_Sound,
|
||||
Implement_Lifting_Lowering_response,
|
||||
Pulverization_Quality,
|
||||
Pulverization_Index
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column8::text,
|
||||
column9::text,column10::text,column11::text,column12::text]) AS val
|
||||
FROM staging2.stg_process_table_FTWET_sum where block_tag=''FTWET_SUM_Test_Condition''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text
|
||||
,a_21 text,a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text,a_30 text,
|
||||
a_31 text,a_32 text,a_33 text,a_34 text,a_35 text,a_36 text,a_37 text,a_38 text);
|
||||
|
||||
update staging2.FTWET_SUM_Test_Condition_Block
|
||||
set test_iterationnumber=2
|
||||
where test_iterationnumber is null;
|
||||
|
||||
update staging2.FTWET_SUM_Test_Condition_Block a
|
||||
set Test_Condition= b.first_value from (SELECT
|
||||
test_iterationnumber,Test_Condition, value_partition, first_value(Test_Condition) over (partition by value_partition order by test_iterationnumber)
|
||||
FROM (
|
||||
SELECT
|
||||
test_iterationnumber,
|
||||
Test_Condition,
|
||||
sum(case when Test_Condition is null then 0 else 1 end) over (order by test_iterationnumber) as value_partition
|
||||
FROM staging2.FTWET_SUM_Test_Condition_Block
|
||||
ORDER BY test_iterationnumber asc
|
||||
) as q) b where a.test_iterationnumber = b.test_iterationnumber;
|
||||
|
||||
|
||||
delete from staging2.FTWET_SUM_Test_Condition_Block
|
||||
where tractor_model is null or engine_rpm_set = '0';
|
||||
|
||||
update staging2.FTWET_SUM_Test_Condition_Block set fuel_consumption_lit_hr_2=null
|
||||
where lower(fuel_consumption_lit_hr_2) like '%indicates%';
|
||||
|
||||
update staging2.FTWET_SUM_Test_Condition_Block
|
||||
set fuel_consumption_lit_hr_2 = left(fuel_consumption_lit_hr_2,length(fuel_consumption_lit_hr_2)-3),
|
||||
Area_covered_acr_hr_2 = left(Area_covered_acr_hr_2,length(Area_covered_acr_hr_2)-3) ,
|
||||
Fuel_consumption_lit_Acr_2 = left(Fuel_consumption_lit_Acr_2,length(Fuel_consumption_lit_Acr_2)-3)
|
||||
where fuel_consumption_lit_hr_2 notnull;
|
||||
|
||||
|
||||
delete from staging2.FTWET_SUM_Test_Condition_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTWET_SUM_Test_Condition_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Test_Condition_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTWET_SUM_Comments_By_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_SUM_Comments_By_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='FTWET_SUM_Comments_By_Block';
|
||||
|
||||
|
||||
insert into staging2.FTWET_SUM_Comments_By_Block (dummy_f) values ('dummy');
|
||||
|
||||
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Comments_By_Block set test_engineer_comments_1=
|
||||
(select column3 from staging2.stg_process_table_ftwet_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTWET_SUM_Engineer_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Comments_By_Block set test_manager_comments_1=
|
||||
(select column3 from staging2.stg_process_table_ftwet_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTWET_SUM_Manager_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
|
||||
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Comments_By_Block set test_engineer_comments_2=
|
||||
(select column8 from staging2.stg_process_table_ftwet_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTWET_SUM_Engineer_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
|
||||
|
||||
execute 'update staging2.FTWET_SUM_Comments_By_Block set test_manager_comments_2=
|
||||
(select column8 from staging2.stg_process_table_ftwet_sum a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.block_tag=''FTWET_SUM_Manager_Comments_1''
|
||||
and block_row_number=1 ) where dummy_f=''dummy''' ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
delete from staging2.FTWET_SUM_Comments_By_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTWET_SUM_Comments_By_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_SUM_Comments_By_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTWET_SUM_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
375
onetime/dataloadfunctions/field/FTWET_TRS_ods.sql
Executable file
375
onetime/dataloadfunctions/field/FTWET_TRS_ods.sql
Executable file
@@ -0,0 +1,375 @@
|
||||
drop function if exists staging2.fn_FTWET_TRS_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTWET_TRS_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __test_instance_id int;
|
||||
declare __test_instance_tractor_id int;
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare _error int;
|
||||
declare __test_master_id int;
|
||||
declare __test_tractor_id int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_FTWET_TRS_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: FTWET
|
||||
Sheet Format: FTWET_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTWET_TRS_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location_name,
|
||||
soil_moisture_content_pct,
|
||||
soil_bulk_density_g_per_cc,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test,
|
||||
test_report_date,
|
||||
season,
|
||||
type_of_soil,
|
||||
soil_cone_index,
|
||||
field_condition,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
report_reference_no test_report_no,
|
||||
objective_of_test,
|
||||
background_of_test,
|
||||
job_order_no,
|
||||
test_location test_location_name,
|
||||
soil_moisture_content_::numeric soil_moisture_content_pct ,
|
||||
soil_bulk_density_g_cc::numeric soil_bulk_density_g_per_cc,
|
||||
test_engineer,
|
||||
test_operator,
|
||||
date_of_test::date,
|
||||
report_date::date test_report_date,
|
||||
season,
|
||||
type_of_soil,
|
||||
soil_cone_index_kpa::int soil_cone_index,
|
||||
field_condition,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftwet_trs_h1_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_sr_no,
|
||||
tractor_engine_hp,
|
||||
fip_type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
wheel_drive_type,
|
||||
egr_yn,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
tractor_weight_front_kg,
|
||||
tractor_weight_rear_kg,
|
||||
tractor_weight_total_kg,
|
||||
Ballasted_Tractor_Accessories,
|
||||
mechanical_ballast_rear_in_kg,
|
||||
water_ballast_rear_75_pct ,
|
||||
Mechanical_Ballast_Front,
|
||||
mechanical_ballast_front_kg ,
|
||||
Total_Ballast_Weight,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
trim('HP' from Tractor_Engine_HP)::numeric,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading::numeric,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD wheel_drive_type ,
|
||||
EGR_Yes_No egr_yn,
|
||||
Brake_Type ,
|
||||
PTO_Type ,
|
||||
Standard_PTO_Speed_RPM::numeric,
|
||||
EPTO_Speed_RPM::numeric,
|
||||
Tractor_Weight_kg_Front::numeric tractor_weight_front_kg ,
|
||||
Tractor_Weight_kg_Rear::numeric tractor_weight_rear_kg ,
|
||||
Tractor_Weight_kg_Total::numeric tractor_weight_total_kg ,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear_in_KG::numeric mechanical_ballast_rear_in_kg ,
|
||||
Water_Ballast_Rear water_ballast_rear_75_pct ,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg::int mechanical_ballast_front_kg ,
|
||||
Total_Ballast_Weight::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftwet_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when tractor_make like 'Mahindra%' then 'Y' else 'N' end
|
||||
) where file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info a
|
||||
set test_tractor_yn ='Y' where syspk in
|
||||
(select min(syspk) from transactional.test_instance_tractor_info b
|
||||
where b.file_syspk =a.file_syspk )
|
||||
and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_tractor_yn ='N'
|
||||
where test_tractor_yn is null and file_syspk =__file_syspk;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
'front',
|
||||
front_tyre_make tyre_make,
|
||||
front_tyre_size tyre_size,
|
||||
front_tyre_pressure_psi::int tyre_pressure_psi
|
||||
from staging2.ftwet_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.tyre_type ='front' and a.file_syspk =__file_syspk;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_pressure_psi
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
'rear',
|
||||
rear_tyre_make tyre_make,
|
||||
rear_tyre_size tyre_size,
|
||||
rear_tyre_pressure_psi::numeric tyre_pressure_psi
|
||||
from staging2.ftwet_trs_spec_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tyre_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.tyre_type ='rear' and a.file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
low_idle_declared,
|
||||
high_idle_declared,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
low_idle low_idle_declared,
|
||||
high_idle high_idle_declared,
|
||||
rated_rpm::numeric,
|
||||
engine_to_pto_ratio_540_pto,
|
||||
engine_to_pto_ratio_540e_pto,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftwet_trs_engine_rpm_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set test_instance_tractor_id =(select syspk
|
||||
from transactional.test_instance_tractor_info b
|
||||
where a.file_syspk=b.file_syspk and
|
||||
a.tractor_model=b.tractor_model and a.tractor_sr_no=b.tractor_sr_no)
|
||||
where a.file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.test_instance_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
make_of_implement,
|
||||
no_of_disc_blades_bottoms,
|
||||
cutting_width_m,
|
||||
implement_weight_kg,
|
||||
hitch_category,
|
||||
span_for_mounted_implement_mm,
|
||||
mast_height_for_mounted_implement_mm,
|
||||
type_of_cage_wheel_hcw_fcw,
|
||||
Cage_Wheel_Width_mm,
|
||||
cage_wheel_weight_kg,
|
||||
cage_wheel_inner_ring_dia_mm,
|
||||
cage_wheel_outer_ring_dia_mm,
|
||||
cage_wheel_center_ring_dia_mm,
|
||||
dist_btwn_lhs_fcw_to_rhs_fcw_mm,
|
||||
No_of_angles_on_cage_wheel,
|
||||
No_of_days_of_water_logging,
|
||||
Depth_of_water_mm,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
make_of_implement,
|
||||
no_of_bottoms_tyne_disc_blade::numeric no_of_disc_blades_bottoms,
|
||||
cutting_width_m,
|
||||
implement_weight_kg::numeric,
|
||||
hitch_category,
|
||||
span_cm_for_mounted_implement::numeric span_for_mounted_implement_cm ,
|
||||
mast_height_cm_for_mounted_implement::numeric mast_height_for_mounted_implement_cm,
|
||||
Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel type_of_cage_wheel_hcw_fcw ,
|
||||
Cage_Wheel_Width_mm::numeric,
|
||||
Cage_wheel_Weight::numeric cage_wheel_weight_kg,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_inner_ring_dia_mm ,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm::numeric cage_wheel_outer_ring_dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm::numeric cage_wheel_center_ring_dia_mm ,
|
||||
Distance_between_cage_wheel_Ring_mm_For_Full_wheel::int dist_btwn_lhs_fcw_to_rhs_fcw_mm,
|
||||
No_of_angles_on_cage_wheel::numeric,
|
||||
No_of_days_of_water_logging::numeric,
|
||||
Depth_of_water_mm::numeric,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.ftwet_trs_implement_block where trx_record=1;
|
||||
|
||||
|
||||
update transactional.test_instance a
|
||||
set report_template_no=b.report_template_no,
|
||||
report_template_rev_no=b.report_template_rev_no,
|
||||
report_template_rev_date =b.report_template_rev_date
|
||||
from staging2.ftwet_trs_implement_block b where a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='Field';
|
||||
select syspk from transactional.test_instance_tractor_info into __test_tractor_id
|
||||
where file_syspk =__file_syspk and test_tractor_yn ='Y';
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_engine_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tyre_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_trailer_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_file_name =(select a.file_name from staging1.staging_generic_table a where file_syspk = __file_syspk limit 1)
|
||||
where file_syspk = __file_syspk;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_FTWET_TRS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
403
onetime/dataloadfunctions/field/FTWET_TRS_stg2.sql
Executable file
403
onetime/dataloadfunctions/field/FTWET_TRS_stg2.sql
Executable file
@@ -0,0 +1,403 @@
|
||||
/*FTWET_TRS starts*/
|
||||
|
||||
drop function if exists staging2.fn_FTWET_TRS_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_FTWET_TRS_Block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
|
||||
declare __client_id int :=p_client_id;
|
||||
declare __function_id int :=p_function_id;
|
||||
declare __file_mnemonic text :=p_file_mnemonic;
|
||||
declare __file_sheet_mnemonic text :=p_file_sheet_mnemonic;
|
||||
declare __file_syspk int :=p_file_syspk;
|
||||
declare err_state text;
|
||||
declare err_msg text;
|
||||
declare err_detail text;
|
||||
declare err_hint text;
|
||||
declare err_context text;
|
||||
declare err_query int;
|
||||
declare err_block text;
|
||||
|
||||
begin
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_FTWET_TRS_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: FTWET
|
||||
Sheet Format: FTWET_TRS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_fthlg_trs_block(20,1,'FTHLG','FTWET_TRS',260);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
truncate staging2.FTWET_TRS_H1_INT;
|
||||
truncate staging2.FTWET_TRS_H1_Block;
|
||||
truncate staging2.FTWET_TRS_Engine_RPM_Block;
|
||||
truncate staging2.FTWET_TRS_Implement_Block;
|
||||
truncate staging2.ftwet_trs_spec_block;
|
||||
truncate staging2.stg_specific_table_ftwet_trs;
|
||||
truncate staging2.stg_process_table_ftwet_trs;
|
||||
|
||||
|
||||
execute 'delete from fw_core.fw_jobctl_file_sheet_block_run_schedule where file_syspk='||p_file_syspk||' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=null,
|
||||
row_previous_number=null,
|
||||
row_read_end=null,
|
||||
run_time=null
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* transfer data from generic to specific for ftwet*/
|
||||
execute 'insert into staging2.stg_specific_table_ftwet_trs
|
||||
select * from staging1.staging_generic_table a
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
and a.file_syspk='||p_file_syspk||'';
|
||||
|
||||
select count(*) into err_query from staging2.stg_specific_table_ftwet_trs;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for FTWET Tractor Specifications',
|
||||
detail = 'No data in table stg_specific_table_ftwet_trs',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
|
||||
update staging2.stg_specific_table_ftwet_trs set column2 = TRIM (TRAILING FROM column2 );
|
||||
update staging2.stg_specific_table_ftwet_trs set column2 = TRIM (LEADING FROM column2 );
|
||||
--update transactional.source_config set F1_modified = TRIM (TRAILING FROM F1_modified);
|
||||
--update transactional.source_config set F1_modified = TRIM (LEADING FROM F1_modified);
|
||||
--update transactional.source_config set F1_source = TRIM (TRAILING FROM F1_source);
|
||||
--update transactional.source_config set F1_source = TRIM (LEADING FROM F1_source);
|
||||
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified ;
|
||||
|
||||
/* keyword match in config table*/
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_ftwet_trs b
|
||||
where upper(F1_source)=upper(column2)
|
||||
and b.is_rownumber_fetched is null)
|
||||
where a.row_number_start is null
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update staging2.stg_specific_table_ftwet_trs a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)=upper(column2)
|
||||
and b.row_number_start=a.row_number
|
||||
and is_rownumber_fetched is null
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'update transactional.source_config a set row_previous_number=row_number_start-1
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
execute 'update transactional.source_config a
|
||||
set row_read_end= (select b.row_number_start
|
||||
from transactional.source_config b
|
||||
where b.syspk=a.syspk+1 )
|
||||
where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* config file last field update as null otherwise it picks up next format row number*/
|
||||
execute 'update transactional.source_config a set row_read_end = null where f1_modified =''Implement Details''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*inserting run_time in config*/
|
||||
execute 'update transactional.source_config a
|
||||
set run_time=current_timestamp where a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers for each block in process table*/
|
||||
execute 'insert into staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications Sheet'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Tractor Specifications'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Engine RPM Data:'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_ftwet_trs
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_ftwet_trs a
|
||||
join transactional.source_config b
|
||||
on a.row_number >row_number_start
|
||||
and a.column2 <> ''''
|
||||
and (a.row_number< row_read_end or row_read_end is null)
|
||||
and f1_modified=''Implement Details'' and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/*inserting data into FTHLG_TRS_H1_INT*/
|
||||
insert into staging2.FTWET_TRS_H1_INT(column2,column3,column4,column5,column6,column7,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,block_row_number from staging2.stg_process_table_ftwet_trs a
|
||||
where block_tag='FTWET_TRS_H1';
|
||||
|
||||
insert into staging2.FTWET_TRS_H1_INT(column2,column3)
|
||||
select 'Date of Test',column5
|
||||
from staging2.FTWET_TRS_H1_INT
|
||||
where block_row_number=1;
|
||||
|
||||
insert into staging2.FTWET_TRS_H1_INT(column2,column3)
|
||||
select 'Report Date',column7
|
||||
from staging2.FTWET_TRS_H1_INT
|
||||
where block_row_number=1;
|
||||
|
||||
insert into staging2.FTWET_TRS_H1_INT(column2,column3)
|
||||
select column5,column6
|
||||
from staging2.FTWET_TRS_H1_INT where block_row_number between 4 and 7;
|
||||
|
||||
|
||||
/*inserting data into block -.FTWET_TRS_H1_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_TRS_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='FTWET_TRS_H1_Block';
|
||||
|
||||
insert into staging2.FTWET_TRS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Report_Reference_No,
|
||||
Objective_Of_Test,
|
||||
Background_of_Test,
|
||||
Job_Order_No,
|
||||
Test_Location,
|
||||
Soil_Moisture_Content_,
|
||||
Soil_Bulk_Density_g_cc,
|
||||
Test_Engineer,
|
||||
Test_Operator,
|
||||
Date_of_Test,
|
||||
Report_Date,
|
||||
Season,
|
||||
Type_of_Soil,
|
||||
Soil_Cone_Index_kPa,
|
||||
Field_Condition
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text]) AS val
|
||||
FROM staging2.FTWET_TRS_H1_INT
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text,a_10 text,
|
||||
a_11 text,a_12 text,a_13 text,a_14 text,a_15 text);
|
||||
|
||||
|
||||
|
||||
delete from staging2.FTWET_TRS_H1_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTWET_TRS_H1_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_H1_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTWET_TRS_SPEC_Block*/
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_TRS_SPEC_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='FTWET_TRS_SPEC_Block';
|
||||
|
||||
insert into staging2.FTWET_TRS_SPEC_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_Model,
|
||||
Tractor_Make,
|
||||
Tractor_Sr_No,
|
||||
Tractor_Engine_HP,
|
||||
FIP_Type,
|
||||
hour_Meter_Reading,
|
||||
Steering_Type,
|
||||
Transmission_Type,
|
||||
Wheel_Drive_Type_WD,
|
||||
EGR_Yes_No,
|
||||
Brake_Type,
|
||||
PTO_Type,
|
||||
Standard_PTO_Speed_RPM,
|
||||
EPTO_Speed_RPM,
|
||||
Front_Tyre_Make,
|
||||
Front_Tyre_Size,
|
||||
Front_Tyre_Pressure_psi,
|
||||
Rear_Tyre_Make,
|
||||
Rear_Tyre_Size,
|
||||
Rear_Tyre_Pressure_psi ,
|
||||
Tractor_Weight_kg_Front ,
|
||||
Tractor_Weight_kg_Rear ,
|
||||
Tractor_Weight_kg_Total,
|
||||
Ballasted_Tractor_Accessories,
|
||||
Mechanical_Ballast_Rear_in_KG ,
|
||||
Water_Ballast_Rear,
|
||||
Mechanical_Ballast_Front,
|
||||
Mechanical_Ballast_Front_in_Kg,
|
||||
Total_Ballast_Weight
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_ftwet_trs where block_tag=''FTWET_TRS_SPEC''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,
|
||||
a_9 text,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text,a_19 text,a_20 text,a_21 text,
|
||||
a_22 text,a_23 text,a_24 text,a_25 text,a_26 text,a_27 text,a_28 text,a_29 text);
|
||||
|
||||
update staging2.FTWET_TRS_SPEC_Block set trx_record=0
|
||||
where tractor_make is null and tractor_sr_no is null;
|
||||
|
||||
update staging2.FTWET_TRS_SPEC_Block set trx_record=0
|
||||
where (tractor_model is null and front_tyre_make is null) or (tractor_model is null and rear_tyre_make is null);
|
||||
|
||||
|
||||
delete from staging2.FTWET_TRS_SPEC_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTWET_TRS_SPEC_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_SPEC_Block');
|
||||
|
||||
/*inserting data into block -FTWET_TRS_SPEC_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_TRS_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='FTWET_TRS_Engine_RPM_Block';
|
||||
|
||||
insert into staging2.FTWET_TRS_Engine_RPM_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tractor_model,
|
||||
Tractor_make,
|
||||
Low_Idle,
|
||||
High_Idle,
|
||||
Rated_RPM,
|
||||
Engine_to_PTO_Ratio_540_PTO,
|
||||
Engine_to_PTO_Ratio_540E_PTO
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.stg_process_table_ftwet_trs where block_tag=''FTWET_TRS_Engine_RPM''
|
||||
or (block_tag=''FTWET_TRS_SPEC'' and block_row_number in (1,2))
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text);
|
||||
|
||||
update staging2.FTWET_TRS_Engine_RPM_Block set trx_record=0
|
||||
where tractor_model is null;
|
||||
|
||||
delete from staging2.FTWET_TRS_Engine_RPM_Block where dummy_f is null ;
|
||||
execute 'update staging2.FTWET_TRS_Engine_RPM_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_Engine_RPM_Block');
|
||||
|
||||
|
||||
/*inserting data into block -FTWET_TRS_Implement_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'FTWET_TRS_Implement_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
|
||||
err_block:='FTWET_TRS_Implement_Block';
|
||||
|
||||
insert into staging2.FTWET_TRS_Implement_Block
|
||||
(
|
||||
dummy_f,
|
||||
Name_of_Implement,
|
||||
Type_of_Implement,
|
||||
Make_of_Implement,
|
||||
No_of_bottoms_Tyne_Disc_Blade,
|
||||
Cutting_Width_m,
|
||||
Implement_Weight_Kg,
|
||||
Span_cm_For_Mounted_Implement,
|
||||
Hitch_Category,
|
||||
Mast_Height_cm_For_Mounted_Implement,
|
||||
Type_of_Cage_Wheel_Half_Cage_wheel_Full_Cage_Wheel,
|
||||
Cage_Wheel_Width_mm,
|
||||
Cage_wheel_Weight,
|
||||
Cage_Wheel_inner_Outer_Ring_Dia_mm,
|
||||
Cage_Wheel_Center_Ring_Dia_mm,
|
||||
Distance_between_cage_wheel_Ring_mm_For_Full_wheel,
|
||||
No_of_angles_on_cage_wheel,
|
||||
No_of_days_of_water_logging,
|
||||
Depth_of_water_mm
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column3,column4,column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column3::text,column4::text,column5::text,column6::text]) AS val
|
||||
FROM staging2.stg_process_table_ftwet_trs where block_tag=''FTWET_TRS_Implement''
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t ( col text,a_1 text,a_2 text,a_3 text,a_4 text,a_5 text,a_6 text,a_7 text,a_8 text,a_9 text
|
||||
,a_10 text,a_11 text,a_12 text,a_13 text,a_14 text,a_15 text,a_16 text,a_17 text,a_18 text);
|
||||
|
||||
|
||||
update staging2.FTWET_TRS_Implement_Block set report_template_no= (select column2 from staging2.stg_process_table_ftwet_trs where block_row_number=19 and block_tag='FTWET_TRS_Implement');
|
||||
|
||||
|
||||
update staging2.FTWET_TRS_Implement_Block set report_template_rev_no= (select column4 from staging2.stg_process_table_ftwet_trs where block_row_number=19 and block_tag='FTWET_TRS_Implement');
|
||||
|
||||
|
||||
update staging2.FTWET_TRS_Implement_Block set report_template_rev_date= (select column6 from staging2.stg_process_table_ftwet_trs where block_row_number=19 and block_tag='FTWET_TRS_Implement');
|
||||
|
||||
update staging2.FTWET_TRS_Implement_Block set trx_record=0
|
||||
where name_of_implement is null;
|
||||
|
||||
execute 'update staging2.FTWET_TRS_Implement_Block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_syspk='||p_file_syspk||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'FTWET_TRS_Implement_Block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_FTWET_TRS_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
Reference in New Issue
Block a user