sql files
This commit is contained in:
927
onetime/dataloadfunctions/Drawbar/DBOECD_TEST_ods.sql
Executable file
927
onetime/dataloadfunctions/Drawbar/DBOECD_TEST_ods.sql
Executable file
@@ -0,0 +1,927 @@
|
||||
--select transactional.fn_dboecd_test_trx();
|
||||
|
||||
drop function if exists staging2.fn_dboecd_test_trx;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_dboecd_test_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;
|
||||
begin
|
||||
|
||||
/***********************************************************
|
||||
Function Name:fn_dboecd_test_trx
|
||||
Function Desc: This function populates data into trx block
|
||||
File Format: DBOECD
|
||||
Sheet Format: DBOECD_TEST
|
||||
Creation Date: March 27 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_dboecd_test_trx()
|
||||
***************************************************************/
|
||||
SET search_path TO staging2;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
acceptance_criteria,
|
||||
objective_of_test,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
date_of_test
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
test_request_no,
|
||||
date '1899-12-30' + sample_receipt_date::int * interval '1' day as sample_receipt_date ,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
date '1899-12-30' + test_report_date::int * interval '1' day as test_report_date ,
|
||||
no_of_sample,
|
||||
date '1899-12-30' + test_start_date::int* interval '1' day as test_start_date ,
|
||||
date '1899-12-30' + test_end_date::int* interval '1' day as test_end_date ,
|
||||
tractor_sr_no,
|
||||
test_standard_refer,
|
||||
test_location,
|
||||
operator_name,
|
||||
project_group,
|
||||
objective,
|
||||
acceptance_criteria,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
current_date
|
||||
from
|
||||
staging2.dboecd_test_h1_block;
|
||||
|
||||
update transactional.test_instance a
|
||||
set test_condition=b.c2
|
||||
from staging2.dboecd_test_test_condition_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance a
|
||||
set remarks = b.remark
|
||||
from staging2.dboecd_test_drawbar_performance_fuel_consumption_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
select file_syspk into __file_syspk from staging2.dboecd_test_h1_block;
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
low_idle_declared,
|
||||
low_idle_observed,
|
||||
high_idle_declared,
|
||||
high_idle_observed,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,model,
|
||||
low_idle_declared,
|
||||
low_idle_observed::int,
|
||||
high_idle_declared,
|
||||
high_idle_observed::int,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.DBOECD_test_engine_RPM_RPM_block;
|
||||
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set rated_rpm=b.rated_speed::int ,engine_to_pto_ratio_540_pto=b.engine_to_pto_ratio::numeric::int,engine_power_hp = b.engine_power_hp::int,
|
||||
pto_power_hp = b.pto_power_hp::numeric
|
||||
from
|
||||
staging2.dboecd_test_engine_rpm_engine_to_pto_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set engine_cylinder_stroke_mm=b.stroke::int,engine_cylinder_bore_mm=b.bore::numeric,engine_cylinder_no=b.number::int,engine_cylinder_capacity_ltr=b.capacity::int
|
||||
from staging2.dboecd_test_tractor_specifications_cylinders_block b
|
||||
where b.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set engine_type=b."type" ,engine_serial_no=b.serial_no,engine_make=b.make_in_block ,engine_model = b.model_in_block ,rated_rpm=b.rated_speed::int
|
||||
from staging2.dboecd_test_tractor_specifications_engine_details_block b
|
||||
where b.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
wheel_base_mm,
|
||||
tractor_engine_hp,
|
||||
pto_power_hp,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
wheel_base_mm::int,
|
||||
engine_power_hp::int,
|
||||
pto_power_hp::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dboecd_test_engine_rpm_engine_to_pto_block;
|
||||
|
||||
update transactional.test_instance_tractor_info a
|
||||
set
|
||||
steering_type=b.steering_type,
|
||||
transmission_type=clutch_type,
|
||||
transmission_disc_diam=diameter_of_disc_mm
|
||||
from staging2.dboecd_test_transmission_clutch_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
insert into transactional.test_instance_drawbar_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
drawbar_type,
|
||||
required_pull_in_kg,
|
||||
actual_pull_in_kg,
|
||||
required_power_in_hp,
|
||||
actual_power_in_hp,
|
||||
calculated_hitch_height_mm,
|
||||
actual_hitch_height_mm,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
pull_type,
|
||||
required_pull_in_kg::numeric ,
|
||||
actual_pull_in_kg::numeric ,
|
||||
required_power_in_hp::numeric,
|
||||
actual_power_in_hp::numeric ,
|
||||
calculated_hitch_height_mm::numeric,
|
||||
actual_hitch_height_mm::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dboecd_test_engine_rpm_required_pull_block;
|
||||
|
||||
update transactional.test_instance_drawbar_info a
|
||||
set weight_front_kg = front::int ,
|
||||
weight_rear_kg = rear::int ,
|
||||
weight_total_kg = total::int
|
||||
from staging2.dboecd_test_engine_rpm_weight_block b
|
||||
where b.weight_kg='Unballast'
|
||||
and a.drawbar_type='UB'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_drawbar_info a
|
||||
set weight_front_kg = front::int ,
|
||||
weight_rear_kg = rear::int ,
|
||||
weight_total_kg = total::int
|
||||
from staging2.dboecd_test_engine_rpm_weight_block b
|
||||
where b.weight_kg='Ballast'
|
||||
and a.drawbar_type='B'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info a
|
||||
set test_condition=b.test_condition,
|
||||
drawbar_type_info=b.type,
|
||||
height_above_ground_max_mm=b.height_above_ground_max_mm::numeric,
|
||||
height_above_ground_min_mm=b.height_above_ground_min_mm::numeric,
|
||||
position_related_to_pto=b.position_related_to_pto,
|
||||
wheel_base=b.wheel_base
|
||||
from staging2.dboecd_test_transmission_drawbar_block b
|
||||
where a.drawbar_type=b.test_condition
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info set drawbar_type_name='Un-Ballasted' where drawbar_type='UB';
|
||||
update transactional.test_instance_drawbar_info set drawbar_type_name='Ballasted' where drawbar_type='B';
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_number_of_lug,
|
||||
tyre_number_of_no_load_lug_30m,
|
||||
tyre_lug_height,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
dummy_f,
|
||||
tyre_make,
|
||||
size,
|
||||
ply_rating::int,
|
||||
load_carrying_capacity_in_kg,
|
||||
pressure_kg_cm2::numeric,
|
||||
number_of_lug::int,
|
||||
number_of_no_load_lug_30m::int,
|
||||
lug_height::numeric,
|
||||
dynamic_rolling_radius_mm::numeric,
|
||||
wheel_rim_make_size,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.DBOECD_test_engine_RPM_tyre_details_block ;
|
||||
|
||||
insert into transactional.drawbar_perf_results_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
gear_number_and_range,
|
||||
travel_speed_km_per_hr,
|
||||
drawbar_power_kw,
|
||||
drawbar_power_hp,
|
||||
drawbar_pull_kgf,
|
||||
drawbar_pull_kn,
|
||||
engine_speed_min_1,
|
||||
fan_speed_min_1,
|
||||
wheel_slip_pct_front,
|
||||
no_of_load_lugs_front,
|
||||
wheel_slip_pct_rear,
|
||||
fuel_consumption_l_per_h,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_g_per_kwh,
|
||||
fuel_consumption_kwh_per_l,
|
||||
temp_engine_oil_c,
|
||||
temp_trans_oil_c,
|
||||
temp_coolant_c,
|
||||
temp_fuel_in_c,
|
||||
temp_fuel_out_c,
|
||||
atm_conditions_rh_pct,
|
||||
atm_conditions_temp_c,
|
||||
atm_conditions_pressure_kpa,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
c1,
|
||||
c2::numeric,
|
||||
c3::numeric,
|
||||
c4::numeric,
|
||||
c5::int,
|
||||
c6::numeric,
|
||||
c7::int,
|
||||
c8::int,
|
||||
c9::numeric,
|
||||
c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,
|
||||
c13::numeric,
|
||||
c14::numeric,
|
||||
c15::numeric,
|
||||
c16::int,
|
||||
c17::int,
|
||||
c18::int,
|
||||
c19::int,
|
||||
c20::int,
|
||||
c21::numeric,
|
||||
c22::numeric,
|
||||
c23::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dboecd_test_drawbar_performance_selected_summary_block;
|
||||
|
||||
insert into transactional.drawbar_perf_oecd_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
test_condition ,
|
||||
gear_number_and_range,
|
||||
travel_speed_km_per_hr,
|
||||
drawbar_power_kw,
|
||||
drawbar_power_hp,
|
||||
drawbar_pull_kgf,
|
||||
drawbar_pull_kn,
|
||||
engine_speed_min_1,
|
||||
fan_speed_min_1,
|
||||
wheel_slip_pct_front,
|
||||
no_of_load_lugs_front,
|
||||
wheel_slip_pct_rear,
|
||||
fuel_consumption_l_per_h,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_g_per_kwh,
|
||||
fuel_consumption_kwh_per_l,
|
||||
temp_engine_oil_c,
|
||||
temp_trans_oil_c,
|
||||
temp_coolant_c,
|
||||
temp_fuel_in_c,
|
||||
temp_fuel_out_c,
|
||||
atm_conditions_rh_pct,
|
||||
atm_conditions_temp_c,
|
||||
atm_conditions_pressure_kpa,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
c1_1,
|
||||
c2_1,
|
||||
c1,
|
||||
c2::numeric,
|
||||
c3::numeric,
|
||||
c4::numeric,
|
||||
c5::int,
|
||||
c6::numeric,
|
||||
c7::int,
|
||||
c8::int,
|
||||
c9::numeric,
|
||||
c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,
|
||||
c13::numeric,
|
||||
c14::numeric,
|
||||
c15::numeric,
|
||||
c16::int,
|
||||
c17::int,
|
||||
c18::int,
|
||||
c19::int,
|
||||
c20::int,
|
||||
c21::numeric,
|
||||
c22::numeric,
|
||||
c23::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dboecd_test_drawbar_performance_fuel_consumption_block;
|
||||
|
||||
|
||||
insert into transactional.drawbar_perf_results
|
||||
( client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
gear_number_and_range,
|
||||
travel_speed_km_per_hr,
|
||||
drawbar_power_kw,
|
||||
drawbar_power_hp,
|
||||
drawbar_pull_kgf,
|
||||
drawbar_pull_kn,
|
||||
engine_speed_min_1,
|
||||
fan_speed_min_1,
|
||||
wheel_slip_pct_front,
|
||||
no_of_load_lugs_front,
|
||||
wheel_slip_pct_rear,
|
||||
fuel_consumption_l_per_h,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_g_per_kwh,
|
||||
fuel_consumption_kwh_per_l,
|
||||
temp_engine_oil_c,
|
||||
temp_trans_oil_c,
|
||||
temp_coolant_c,
|
||||
temp_fuel_in_c,
|
||||
temp_fuel_out_c,
|
||||
atm_conditions_rh_pct,
|
||||
atm_conditions_temp_c,
|
||||
atm_conditions_pressure_kpa,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
c1,
|
||||
c2::numeric,
|
||||
c3::numeric,
|
||||
c4::numeric,
|
||||
c5::int,
|
||||
c6::numeric,
|
||||
c7::int,
|
||||
c8::int,
|
||||
c9::numeric,
|
||||
c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,
|
||||
c13::numeric,
|
||||
c14::numeric,
|
||||
c15::numeric,
|
||||
c16::int,
|
||||
c17::int,
|
||||
c18::int,
|
||||
c19::int,
|
||||
c20::int,
|
||||
c21::numeric,
|
||||
c22::numeric,
|
||||
c23::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dboecd_test_drawbar_performance_gear_performance_block;
|
||||
|
||||
|
||||
insert into transactional.test_instance_equipment_info
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
instrument_name,
|
||||
instrument_serial_no,
|
||||
calibration_due_date,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic )
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
s_no::int,
|
||||
instruments,
|
||||
instruments_no,
|
||||
date '1899-12-30' + cali_due_date::int * interval '1' day as cali_due_date,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.DBOECD_test_test_equipment_used_block;
|
||||
|
||||
insert into transactional.test_instance_measurement_uncertainty
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
load_cell,
|
||||
rpm_meter,
|
||||
speed,
|
||||
fuel_flow_meter,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
load_cell,
|
||||
rpm_meter,
|
||||
speed,
|
||||
fuel_flow_meter,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dboecd_test_measurement_uncertainty_block;
|
||||
|
||||
insert into transactional.test_instance_tractor_info_misc
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
capacity_of_fuel_tank_ltr,
|
||||
make_type_and_model_of_injection_pump,
|
||||
manufacturers_production_setting,
|
||||
make_type_and_model_of_injectors,
|
||||
make_type_and_model_of_magneto_coil_and_distributor,
|
||||
make_type_and_model_of_carburetor,
|
||||
ignition_or_injection_timing,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
regexp_replace(capacity_of_fuel_tank_lit,'[^0-9]', '', 'g')::int,
|
||||
make_type_and_model_of_injection_pump,
|
||||
manufacturer_production_setting,
|
||||
make_type_and_model_of_injectors,
|
||||
make_type_and_model_of_magneto_coil_and_distributor,
|
||||
make_type_and_model_of_carburetor,
|
||||
ignition_or_injection_timing_manual_or_automatic,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dboecd_test_tractor_specifications_fuel_and_injection_block;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set aircleaner_make_model=b.make_and_model
|
||||
from staging2.dboecd_test_tractor_specifications_cleaner_block b
|
||||
where b.cleaner_type='Air cleaner'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set aircleaner_type=b.type
|
||||
from staging2.dboecd_test_tractor_specifications_cleaner_block b
|
||||
where cleaner_type='Air cleaner'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set precleaner_make_model=b.make_and_model
|
||||
from staging2.dboecd_test_tractor_specifications_cleaner_block b
|
||||
where cleaner_type='Precleaner (if fitted)'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set precleaner_type=b.type
|
||||
from staging2.dboecd_test_tractor_specifications_cleaner_block b
|
||||
where cleaner_type='Precleaner (if fitted)'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update staging2.dboecd_test_transmission_speed_chart_block a
|
||||
set tyre_condition=b.descr
|
||||
from staging2.dboecd_test_transmission_speed_chart_desc_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
insert into transactional.test_instance_gear_speed_chart
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
forward_reverse,
|
||||
gear,
|
||||
speed_kmph,
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
'forward',
|
||||
gear,
|
||||
cast(coalesce(nullif(forward,''),'0') as numeric),
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dboecd_test_transmission_speed_chart_block;
|
||||
|
||||
|
||||
insert into transactional.test_instance_gear_speed_chart
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
forward_reverse,
|
||||
gear,
|
||||
speed_kmph,
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
'reverse',
|
||||
gear,
|
||||
cast(coalesce(nullif(reverse,''),'0') as numeric),
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dboecd_test_transmission_speed_chart_block;
|
||||
|
||||
|
||||
|
||||
insert into transactional.Test_instance_wheels_info
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
steered_driving_wheel,
|
||||
location_of_driving_wheel,
|
||||
make_of_tyres,
|
||||
wheel_types,
|
||||
wheel_size,
|
||||
maximum_permissible_load_kg,
|
||||
ply_rating,
|
||||
track_width_max_mm,
|
||||
track_width_min_mm,
|
||||
inflation_pressure_kg_per_cm2,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
dummy_f,
|
||||
location_of_driving_wheel,
|
||||
make_of_tyres,
|
||||
types,
|
||||
size,
|
||||
maximum_permissible_load_kg::int,
|
||||
ply_rating::int,
|
||||
track_width_max_mm::int,
|
||||
track_width_min_mm::int,
|
||||
inflation_pressure_kg_cm2::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dboecd_test_transmission_wheels_block;
|
||||
|
||||
|
||||
insert into transactional.Test_instance_fuel_lubricant_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
trade_name,
|
||||
fuel_lubricant_type,
|
||||
octane_per_cetane_number,
|
||||
viscocity,
|
||||
density_at_15c,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
trade_name,
|
||||
type,
|
||||
octane_cetane_number::numeric,
|
||||
viscosity,
|
||||
density_at_15c,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dboecd_test_transmission_fuel_lubricant_block ;
|
||||
|
||||
|
||||
insert into transactional.drawbar_perf_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_parameter ,
|
||||
acceptance_criteria ,
|
||||
observation ,
|
||||
remarks,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
parameter,
|
||||
acceptance_criteria ,
|
||||
observations,
|
||||
remarks,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dboecd_test_remarks_block;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_by=b.prepared_by,
|
||||
--report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_template_rev_no=b.revision_no,
|
||||
report_template_rev_Date=b.rev3,
|
||||
report_template_no=b.rev1,
|
||||
report_title=b.comments
|
||||
from staging2.dboecd_test_remarks_footer_block b
|
||||
where a.file_syspk=b.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_drawbar_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.drawbar_perf_results_summary
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_results
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_observations
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_oecd_results
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_equipment_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_measurement_uncertainty
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info_misc
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_gear_speed_chart
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_wheels_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_fuel_lubricant_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_observations
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_results_summary
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_oecd_results
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.drawbar_perf_results
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
|
||||
update transactional.test_instance_engine_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_drawbar_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tyre_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_equipment_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_measurement_uncertainty
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info_misc
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_gear_speed_chart
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_wheels_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_fuel_lubricant_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
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_dboecd_test_trx', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
1472
onetime/dataloadfunctions/Drawbar/DBOECD_TEST_stg2.sql
Executable file
1472
onetime/dataloadfunctions/Drawbar/DBOECD_TEST_stg2.sql
Executable file
File diff suppressed because it is too large
Load Diff
862
onetime/dataloadfunctions/Drawbar/DBSTD_TEST_ods.sql
Executable file
862
onetime/dataloadfunctions/Drawbar/DBSTD_TEST_ods.sql
Executable file
@@ -0,0 +1,862 @@
|
||||
drop function if exists staging2.fn_dbstd_test_trx;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_dbstd_test_trx(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
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 __test_instance_tractor_id int;
|
||||
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;
|
||||
begin
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_dbstd_test_trx
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: DBSTD
|
||||
Sheet Format: DBSTD_TEST
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging.fn_dbstd_test_trx()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='Drawbar';
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
acceptance_criteria,
|
||||
objective_of_test,
|
||||
date_of_test,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
test_request_no,
|
||||
date '1899-12-30' + sample_receipt_date::numeric * interval '1' day as sample_receipt_date ,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
date '1899-12-30' + test_report_date::numeric * interval '1' day as test_report_date ,
|
||||
no_of_sample,
|
||||
date '1899-12-30' + test_start_date::numeric* interval '1' day as test_start_date ,
|
||||
date '1899-12-30' + test_end_date::numeric* interval '1' day as test_end_date ,
|
||||
tractor_sr_no,
|
||||
test_standard_refer,
|
||||
test_location,
|
||||
operator_name,
|
||||
project_group,
|
||||
objective,
|
||||
acceptance_criteria,
|
||||
current_date,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_h1_block;
|
||||
|
||||
update transactional.test_instance a
|
||||
set test_condition=b.c2
|
||||
from staging2.dbstd_test_test_condition_block b
|
||||
where a.file_syspk=b.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;
|
||||
|
||||
|
||||
/* ODS */
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(client_id,function_id,file_syspk,tractor_model,tractor_make,low_idle_declared,low_idle_observed,high_idle_declared,high_idle_observed,file_mnemonic,
|
||||
file_sheet_mnemonic)
|
||||
select client_id,function_id,file_syspk,make,model,low_idle_declared,low_idle_observed::numeric,high_idle_declared,high_idle_observed::numeric,file_mnemonic,file_sheet_mnemonic
|
||||
from staging2.DBSTD_test_engine_RPM_RPM_block;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set engine_to_pto_ratio_540_pto=b.engine_to_pto_ratio::numeric,engine_power_hp = b.engine_power_hp::numeric,
|
||||
pto_power_hp = b.pto_power_hp::numeric
|
||||
from
|
||||
staging2.dbstd_test_engine_rpm_engine_to_pto_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set engine_cylinder_stroke_mm=b.stroke::numeric,engine_cylinder_bore_mm=b.bore::numeric,engine_cylinder_no=b.number::numeric,
|
||||
engine_cylinder_capacity_ltr=regexp_replace(b.capacity,'[^0-9]', '', 'g')::int
|
||||
from staging2.dbstd_test_tractor_specifications_cylinders_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_engine_info a
|
||||
set engine_serial_no=serial_no,engine_type=type,rated_rpm=rated_speed::numeric,engine_make=b.make_in_block ,engine_model = b.model_in_block
|
||||
from staging2.dbstd_test_tractor_specifications_engine_details_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
/*ODS */
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
wheel_base_mm,
|
||||
tractor_engine_hp,
|
||||
pto_power_hp,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
wheel_base_mm::numeric,
|
||||
engine_power_hp::numeric,
|
||||
pto_power_hp::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from dbstd_test_engine_rpm_engine_to_pto_block;
|
||||
|
||||
update transactional.test_instance_tractor_info a
|
||||
set
|
||||
steering_type=b.steering_type,
|
||||
transmission_type=clutch_type,
|
||||
transmission_disc_diam=diameter_of_disc_mm
|
||||
from staging2.dbstd_test_transmission_clutch_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
/*ODS */
|
||||
insert into transactional.test_instance_drawbar_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
drawbar_type,
|
||||
required_pull_in_kg,
|
||||
actual_pull_in_kg,
|
||||
required_power_in_hp,
|
||||
actual_power_in_hp,
|
||||
calculated_hitch_height_mm,
|
||||
actual_hitch_height_mm,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
pull_type,
|
||||
required_pull_in_kg::numeric ,
|
||||
actual_pull_in_kg::numeric ,
|
||||
required_power_in_hp::numeric,
|
||||
actual_power_in_hp::numeric ,
|
||||
calculated_hitch_height_mm::numeric,
|
||||
actual_hitch_height_mm::numeric ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_engine_rpm_required_pull_block;
|
||||
|
||||
update transactional.test_instance_drawbar_info a
|
||||
set weight_front_kg = front::numeric ,
|
||||
weight_rear_kg = rear::numeric ,
|
||||
weight_total_kg = total::numeric
|
||||
from staging2.dbstd_test_engine_rpm_weight_block b
|
||||
where b.weight_kg='Unballast'
|
||||
and a.drawbar_type='UB'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_drawbar_info a
|
||||
set weight_front_kg = front::numeric ,
|
||||
weight_rear_kg = rear::numeric ,
|
||||
weight_total_kg = total::numeric
|
||||
from staging2.dbstd_test_engine_rpm_weight_block b
|
||||
where b.weight_kg='Ballast'
|
||||
and a.drawbar_type='B'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info a
|
||||
set test_condition=b.test_condition,
|
||||
drawbar_type_info=b.type,
|
||||
height_above_ground_max_mm=b.height_above_ground_max_mm::numeric,
|
||||
height_above_ground_min_mm=b.height_above_ground_min_mm::numeric,
|
||||
position_related_to_pto=b.position_related_to_pto,
|
||||
wheel_base=b.wheel_base
|
||||
from staging2.dbstd_test_transmission_drawbar_block b
|
||||
where a.drawbar_type=b.test_condition
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info set drawbar_type_name='UnBallasted' where drawbar_type='UB';
|
||||
update transactional.test_instance_drawbar_info set drawbar_type_name='Ballasted' where drawbar_type='B';
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_number_of_lug,
|
||||
tyre_number_of_no_load_lug_30m,
|
||||
tyre_lug_height,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
dummy_f,
|
||||
tyre_make,
|
||||
size,
|
||||
ply_rating::numeric,
|
||||
load_carrying_capacity_in_kg,
|
||||
pressure_kg_cm2::numeric,
|
||||
number_of_lug::numeric,
|
||||
number_of_no_load_lug_30m::numeric,
|
||||
lug_height::numeric,
|
||||
dynamic_rolling_radius_mm::numeric,
|
||||
wheel_rim_make_size ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.DBSTD_test_engine_RPM_tyre_details_block ;
|
||||
|
||||
/* ODS */
|
||||
|
||||
insert into transactional.drawbar_perf_results_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
gear_number_and_range,
|
||||
travel_speed_km_per_hr,
|
||||
drawbar_power_kw,
|
||||
drawbar_power_hp,
|
||||
drawbar_pull_kgf,
|
||||
drawbar_pull_kn,
|
||||
engine_speed_min_1,
|
||||
fan_speed_min_1,
|
||||
wheel_slip_pct_front,
|
||||
no_of_load_lugs_front,
|
||||
wheel_slip_pct_rear,
|
||||
fuel_consumption_l_per_h,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_g_per_kwh,
|
||||
fuel_consumption_kwh_per_l,
|
||||
temp_engine_oil_c,
|
||||
temp_trans_oil_c,
|
||||
temp_coolant_c,
|
||||
temp_fuel_in_c,
|
||||
temp_fuel_out_c,
|
||||
atm_conditions_rh_pct,
|
||||
atm_conditions_temp_c,
|
||||
atm_conditions_pressure_kpa,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
c1,
|
||||
c2::numeric,
|
||||
c3::numeric,
|
||||
c4::numeric,
|
||||
c5::numeric,
|
||||
c6::numeric,
|
||||
c7::numeric,
|
||||
c8::numeric,
|
||||
c9::numeric,
|
||||
c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,
|
||||
c13::numeric,
|
||||
c14::numeric,
|
||||
c15::numeric,
|
||||
c16::numeric,
|
||||
c17::numeric,
|
||||
c18::numeric,
|
||||
c19::numeric,
|
||||
c20::numeric,
|
||||
c21::numeric,
|
||||
c22::numeric,
|
||||
c23::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dbstd_test_drawbar_performance_selected_summary_block;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.drawbar_perf_results
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
gear_number_and_range,
|
||||
travel_speed_km_per_hr,
|
||||
drawbar_power_kw,
|
||||
drawbar_power_hp,
|
||||
drawbar_pull_kgf,
|
||||
drawbar_pull_kn,
|
||||
engine_speed_min_1,
|
||||
fan_speed_min_1,
|
||||
wheel_slip_pct_front,
|
||||
no_of_load_lugs_front,
|
||||
wheel_slip_pct_rear,
|
||||
fuel_consumption_l_per_h,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_g_per_kwh,
|
||||
fuel_consumption_kwh_per_l,
|
||||
temp_engine_oil_c,
|
||||
temp_trans_oil_c,
|
||||
temp_coolant_c,
|
||||
temp_fuel_in_c,
|
||||
temp_fuel_out_c,
|
||||
atm_conditions_rh_pct,
|
||||
atm_conditions_temp_c,
|
||||
atm_conditions_pressure_kpa,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
c1,
|
||||
c2::numeric,
|
||||
c3::numeric,
|
||||
c4::numeric,
|
||||
c5::numeric,
|
||||
c6::numeric,
|
||||
c7::numeric,
|
||||
c8::numeric,
|
||||
c9::numeric,
|
||||
c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,
|
||||
c13::numeric,
|
||||
c14::numeric,
|
||||
c15::numeric,
|
||||
c16::numeric,
|
||||
c17::numeric,
|
||||
c18::numeric,
|
||||
c19::numeric,
|
||||
c20::numeric,
|
||||
c21::numeric,
|
||||
c22::numeric,
|
||||
c23::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dbstd_test_drawbar_performance_gear_performance_block;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.test_instance_equipment_info
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,instrument_name,instrument_serial_no,calibration_due_date,file_mnemonic,
|
||||
file_sheet_mnemonic)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
s_no::numeric,
|
||||
instruments,
|
||||
instruments_no,
|
||||
date '1899-12-30' + cali_due_date::numeric * interval '1' day as cali_due_date ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.DBSTD_test_test_equipment_used_block;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.test_instance_measurement_uncertainty
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
load_cell,
|
||||
rpm_meter,
|
||||
speed,
|
||||
fuel_flow_meter,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
load_cell,
|
||||
rpm_meter,
|
||||
speed,
|
||||
fuel_flow_meter ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_measurement_uncertainty_block;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.test_instance_tractor_info_misc
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
capacity_of_fuel_tank_ltr,
|
||||
make_type_and_model_of_injection_pump,
|
||||
manufacturers_production_setting,
|
||||
make_type_and_model_of_injectors,
|
||||
make_type_and_model_of_magneto_coil_and_distributor,
|
||||
make_type_and_model_of_carburetor,
|
||||
ignition_or_injection_timing,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
regexp_replace(capacity_of_fuel_tank_lit,'[^0-9]', '', 'g')::numeric,
|
||||
make_type_and_model_of_injection_pump,
|
||||
manufacturer_production_setting,
|
||||
make_type_and_model_of_injectors,
|
||||
make_type_and_model_of_magneto_coil_and_distributor,
|
||||
make_type_and_model_of_carburetor,
|
||||
ignition_or_injection_timing_manual_or_automatic,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_tractor_specifications_fuel_and_injection_block;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set aircleaner_make_model=b.make_and_model
|
||||
from staging2.dbstd_test_tractor_specifications_cleaner_block b
|
||||
where b.cleaner_type='Air cleaner'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set aircleaner_type=b.type
|
||||
from staging2.dbstd_test_tractor_specifications_cleaner_block b
|
||||
where cleaner_type='Air cleaner'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set precleaner_make_model=b.make_and_model
|
||||
from staging2.dbstd_test_tractor_specifications_cleaner_block b
|
||||
where cleaner_type='Precleaner (if fitted)'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info_misc a
|
||||
set precleaner_type=b.type
|
||||
from staging2.dbstd_test_tractor_specifications_cleaner_block b
|
||||
where cleaner_type='Precleaner (if fitted)'
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
update staging2.dbstd_test_transmission_speed_chart_block a
|
||||
set tyre_condition=b.descr
|
||||
from staging2.dbstd_test_transmission_speed_chart_desc_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
/* ODS */
|
||||
|
||||
insert into transactional.test_instance_gear_speed_chart
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
forward_reverse,
|
||||
gear,
|
||||
speed_kmph,
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
'forward',
|
||||
gear,
|
||||
cast(coalesce(nullif(forward,''),'0') as numeric),
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_transmission_speed_chart_block;
|
||||
|
||||
/* ODs */
|
||||
insert into transactional.test_instance_gear_speed_chart
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
forward_reverse,
|
||||
gear,
|
||||
speed_kmph,
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
'reverse',
|
||||
gear,
|
||||
cast(coalesce(nullif(reverse,''),'0') as numeric),
|
||||
tyre_condition,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_transmission_speed_chart_block;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.Test_instance_wheels_info
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
steered_driving_wheel,
|
||||
location_of_driving_wheel,
|
||||
make_of_tyres,
|
||||
wheel_types,
|
||||
wheel_size,
|
||||
maximum_permissible_load_kg,
|
||||
ply_rating,
|
||||
track_width_max_mm,
|
||||
track_width_min_mm,
|
||||
inflation_pressure_kg_per_cm2,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
dummy_f,
|
||||
location_of_driving_wheel,
|
||||
make_of_tyres,
|
||||
types,
|
||||
size,
|
||||
regexp_replace(maximum_permissible_load_kg,'[^0-9]', '', 'g')::int,
|
||||
regexp_replace(ply_rating,'[^0-9]', '', 'g')::int,
|
||||
track_width_max_mm::numeric,
|
||||
track_width_min_mm::numeric,
|
||||
inflation_pressure_kg_cm2::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dbstd_test_transmission_wheels_block;
|
||||
|
||||
update staging2.dbstd_test_transmission_wheels_block a
|
||||
set location_of_driving_wheel=(select location_of_driving_wheel from
|
||||
staging2.dbstd_test_transmission_wheels_block b where location_of_driving_wheel is not null)
|
||||
where location_of_driving_wheel is null;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.Test_instance_fuel_lubricant_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
trade_name,
|
||||
fuel_lubricant_type,
|
||||
octane_per_cetane_number,
|
||||
viscocity,
|
||||
density_at_15c,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
trade_name,
|
||||
type,
|
||||
octane_cetane_number::numeric,
|
||||
viscosity,
|
||||
density_at_15c,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from
|
||||
staging2.dbstd_test_transmission_fuel_lubricant_block ;
|
||||
|
||||
/* ODS */
|
||||
insert into transactional.drawbar_perf_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_parameter ,
|
||||
acceptance_criteria ,
|
||||
observation ,
|
||||
remarks ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
parameter,
|
||||
acceptance_criteria ,
|
||||
observations,
|
||||
remarks ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.dbstd_test_remarks_block;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_template_rev_no=b.revision_no,
|
||||
report_template_rev_Date=b.rev3,
|
||||
report_template_no=b.rev1,
|
||||
report_title=b.comments,
|
||||
test_master_id = __test_master_id
|
||||
from staging2.dbstd_test_remarks_footer_block b
|
||||
where a.file_syspk=b.file_syspk;
|
||||
|
||||
select file_syspk into __file_syspk from staging2.dbstd_test_h1_block;
|
||||
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;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_template_rev_no=b.revision_no,
|
||||
report_template_rev_Date=b.rev3,
|
||||
report_template_no=b.rev1,
|
||||
report_title=b.comments,
|
||||
test_tractor_id = __test_instance_tractor_id,
|
||||
test_master_id = __test_master_id
|
||||
from staging2.dbstd_test_remarks_footer_block b
|
||||
where a.file_syspk=b.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_drawbar_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.drawbar_perf_results_summary
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_results
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_equipment_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_measurement_uncertainty
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info_misc
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_gear_speed_chart
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_wheels_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_fuel_lubricant_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_observations
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.drawbar_perf_observations
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_results_summary
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.drawbar_perf_results
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_engine_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_drawbar_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tyre_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_equipment_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_measurement_uncertainty
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info_misc
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_gear_speed_chart
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_wheels_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.Test_instance_fuel_lubricant_info
|
||||
set test_instance_tractor_id=__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
err_context := '';
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_DBSTD_test_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
return err_context;
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
err_state = returned_sqlstate,
|
||||
err_msg = message_text,
|
||||
err_detail = pg_exception_detail,
|
||||
err_hint = pg_exception_hint,
|
||||
err_context = pg_exception_context;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_DBSTD_test_block', err_state, err_msg, err_detail, err_hint, err_context,'error');
|
||||
return err_context;
|
||||
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
1358
onetime/dataloadfunctions/Drawbar/DBSTD_TEST_stg2.sql
Executable file
1358
onetime/dataloadfunctions/Drawbar/DBSTD_TEST_stg2.sql
Executable file
File diff suppressed because it is too large
Load Diff
459
onetime/dataloadfunctions/IHT/IHTBT30_BT30_ODS.sql
Executable file
459
onetime/dataloadfunctions/IHT/IHTBT30_BT30_ODS.sql
Executable file
@@ -0,0 +1,459 @@
|
||||
drop function if exists staging2.fn_IHTBT30_BT30_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_BT30_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTBT30_BT30_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHT
|
||||
Sheet Format: IHTBT30_BT30
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTBT30_BT30_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
test_condition,
|
||||
test_standard_desc,
|
||||
test_standard_id,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
observations
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
sample_receipt_date::date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date::date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date::date,
|
||||
Test_End_Date::date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Ref,
|
||||
test_location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
condition,
|
||||
test_standard,
|
||||
test_standard_id::numeric,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
observations
|
||||
from
|
||||
staging2.IHTBT30_BT30_H1_block where trx_record =1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTBT30_BT30_footer_block b
|
||||
where a.file_sheet_mnemonic='IHTBT30_BT30' and trx_record =1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_use_type,
|
||||
tyre_pressure_kg_per_cm2
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
tyre_use_type,
|
||||
pressure_kg_cm2::numeric
|
||||
from staging2.IHTBT30_BT30_tyre_details_block where trx_record =1;
|
||||
|
||||
|
||||
insert into transactional.test_instance_drawbar_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
weight_front_kg,
|
||||
weight_rear_kg,
|
||||
weight_total_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
test_condition,
|
||||
front::numeric ,
|
||||
rear::numeric ,
|
||||
total::numeric
|
||||
from staging2.IHTBT30_BT30_weight_block where trx_record =1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_platform
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
platform
|
||||
from staging2.IHTBT30_BT30_h1_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;
|
||||
|
||||
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT30_BT30_test_res_1_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT30_BT30_test_res_2_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT30_BT30_test_res_3_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT30_BT30_test_res_4_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_condition
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
date_of_test,
|
||||
time_of_test,
|
||||
location_name,
|
||||
test_mode,
|
||||
wind_velocity_kmph,
|
||||
ambient_temp_c,
|
||||
humidity_rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
condition,
|
||||
date::date,
|
||||
time,
|
||||
location,
|
||||
mode,
|
||||
wind_velocity_km_hr,
|
||||
ambient_temperature_c::numeric ,
|
||||
humidity_rh::numeric
|
||||
from staging2.IHTBT30_BT30_test_condition_block where trx_record =1;
|
||||
|
||||
update transactional.iht_brake_perf_test_results a
|
||||
set brake_perf_test_condition_id=(select syspk
|
||||
from transactional.iht_brake_perf_test_condition b
|
||||
where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk)
|
||||
where a.file_syspk =__file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.iht_brake_perf_test_condition
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.iht_brake_perf_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTBT30_BT30_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
908
onetime/dataloadfunctions/IHT/IHTBT30_BT30_STG2.sql
Executable file
908
onetime/dataloadfunctions/IHT/IHTBT30_BT30_STG2.sql
Executable file
@@ -0,0 +1,908 @@
|
||||
drop function if exists staging2.fn_IHTBT30_BT30_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTBT30_BT30_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_IHTBT30_BT30_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHT
|
||||
Sheet Format: IHTBT30_BT30
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTBT30_BT30_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTBT30_BT30_block(1,2,'IHT','IHTBT30_BT30',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTBT30_BT30_H1_INT;
|
||||
truncate table staging2.IHTBT30_BT30_H1_block;
|
||||
truncate table staging2.IHTBT30_BT30_Weight_Tyre_Int;
|
||||
truncate table staging2.IHTBT30_BT30_Weight_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Tyre_Details_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Test_Res_1_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Test_Res_2_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Test_Res_3_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Test_Res_4_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Test_Condition_Block;
|
||||
truncate table staging2.IHTBT30_BT30_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTBT30_BT30;
|
||||
truncate table staging2.stg_process_table_IHTBT30_BT30;
|
||||
|
||||
|
||||
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 IHT */
|
||||
execute 'insert into staging2.stg_specific_table_IHTBT30_BT30
|
||||
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_IHTBT30_BT30;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHTBT30',
|
||||
detail = 'No data in table stg_specific_table_IHTBT30_BT30',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTBT30_BT30
|
||||
set column10='Objective' where lower(column10) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTBT30_BT30
|
||||
set column10='Acceptance criteria' where lower(column10) like 'acceptance criteria%';
|
||||
|
||||
|
||||
update staging2.stg_specific_table_IHTBT30_BT30
|
||||
set column10='Condition' where lower(column10) like 'condition%';
|
||||
|
||||
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_IHTBT30_BT30 b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTBT30_BT30 a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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 Request No''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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=''Un-Ballast cold''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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=''Ballast cold''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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=''Fade Performance''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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=''Recovery Performance''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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=''Weight (kg)''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT30_BT30
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT30_BT30 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=''Prepared by''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column5 into __model from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTBT30_BT30_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTBT30_BT30_H1_BLOCK';
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select a.column3,column5 from staging2.stg_process_table_IHTBT30_BT30 a where block_tag='IHTBT30_BT30_H1'
|
||||
and block_row_number <=9;
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select a.column7,column9 from staging2.stg_process_table_IHTBT30_BT30 a where block_tag='IHTBT30_BT30_H1'
|
||||
and block_row_number <=9;
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Objective',column10
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where column10='Objective'
|
||||
and block_tag='IHTBT30_BT30_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column8
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_H1' and block_row_number=11;
|
||||
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Condition',column10
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where column10='Condition'
|
||||
and block_tag='IHTBT30_BT30_H1'
|
||||
);
|
||||
|
||||
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Test std',column4
|
||||
from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where block_row_number=11
|
||||
and block_tag='IHTBT30_BT30_H1';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Test std Id',column3
|
||||
from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where block_row_number=11
|
||||
and block_tag='IHTBT30_BT30_H1';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Test Standard ref',split_part(column3,':',2)
|
||||
from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where block_row_number=10
|
||||
and block_tag='IHTBT30_BT30_H1';
|
||||
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_INT (c1,c2)
|
||||
select 'Observations',column3
|
||||
from staging2.stg_process_table_IHTBT30_BT30
|
||||
where block_tag='IHTBT30_BT30_Weight_Tyre'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where column3='Remarks & Observations'
|
||||
and block_tag='IHTBT30_BT30_Weight_Tyre'
|
||||
);
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
Test_Location,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Domestic_Export,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Platform,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
condition,
|
||||
Test_Standard,
|
||||
Test_Standard_id,
|
||||
Test_Standard_ref,
|
||||
Remarks,
|
||||
Observations
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTBT30_BT30_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
update staging2.IHTBT30_BT30_H1_Block
|
||||
set Sample_Receipt_Date=case
|
||||
when Sample_Receipt_Date like '%-%' then Sample_Receipt_Date::timestamptz
|
||||
else date '1899-12-30' + Sample_Receipt_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
update staging2.IHTBT30_BT30_H1_Block
|
||||
set Test_Report_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
update staging2.IHTBT30_BT30_H1_Block
|
||||
set Test_Start_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
update staging2.IHTBT30_BT30_H1_Block
|
||||
set Test_End_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
delete from staging2.IHTBT30_BT30_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTBT30_BT30_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_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,'IHTBT30_BT30_H1_BLOCK');
|
||||
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Weight_Tyre_Int
|
||||
(
|
||||
column3,column4,column5,column6,column7,column8,column9,
|
||||
column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,column8,
|
||||
column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_Weight_Tyre'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Weight_Tyre_Int set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Weight_Tyre_Int 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||'''';
|
||||
|
||||
|
||||
/*block starts - IHTBT30_BT30_Weight_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTBT30_BT30_Weight_Block';
|
||||
insert into staging2.IHTBT30_BT30_Weight_Block
|
||||
(
|
||||
dummy_f,
|
||||
test_condition,
|
||||
Front,
|
||||
Rear,
|
||||
Total
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column7::text]) AS val
|
||||
FROM staging2.IHTBT30_BT30_Weight_Tyre_Int where column5 is not null and column7 is not null and block_row_number<>1
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text);
|
||||
|
||||
|
||||
delete from staging2.IHTBT30_BT30_Weight_Block where dummy_f is null ;
|
||||
update staging2.IHTBT30_BT30_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Weight_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,'IHTBT30_BT30_Weight_Block');
|
||||
|
||||
/*block starts - IHTBT30_BT30_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTBT30_BT30_Tyre_Details_Block';
|
||||
insert into staging2.IHTBT30_BT30_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Pressure_kg_cm2,
|
||||
tyre_use_type,
|
||||
Tyre_Make,
|
||||
tyre_size,
|
||||
ply_rating
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column10,column11}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column10::text,column11::text]) AS val
|
||||
FROM staging2.IHTBT30_BT30_Weight_Tyre_Int where column11 is not null or column10 is not null
|
||||
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);
|
||||
|
||||
|
||||
|
||||
delete from staging2.IHTBT30_BT30_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTBT30_BT30_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Tyre_Details_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,'IHTBT30_BT30_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT30_BT30_Test_Res_1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Test_Res_1_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTBT30_BT30_Test_Res_1_Block';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Test_Res_1_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_Test_Res_1'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_1_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_1_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_1_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_1_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_1_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_1_Block set trx_record =0 where block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_1_Block set trx_record =0
|
||||
where column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_1_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Test_Res_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,'IHTBT30_BT30_Test_Res_1_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT30_BT30_Test_Res_2_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Test_Res_2_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTBT30_BT30_Test_Res_2_Block';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Test_Res_2_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_Test_Res_2'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_2_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_2_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
select
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_2_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_2_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_2_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_2_Block set trx_record =0 where block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_2_Block set trx_record =0
|
||||
where column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_2_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Test_Res_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,'IHTBT30_BT30_Test_Res_2_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT30_BT30_Test_Res_3_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Test_Res_3_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTBT30_BT30_Test_Res_3_Block';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Test_Res_3_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_Test_Res_3'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_3_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_3_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_3_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_3_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_3_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_3_Block set trx_record =0 where block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_3_Block set trx_record =0
|
||||
where column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_3_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Test_Res_3_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,'IHTBT30_BT30_Test_Res_3_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT30_BT30_Test_Res_4_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Test_Res_4_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='IHTBT30_BT30_Test_Res_4_Block';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Test_Res_4_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT30_BT30 a
|
||||
where block_tag='IHTBT30_BT30_Test_Res_4'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_4_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_4_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_4_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_4_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT30_BT30_Test_Res_4_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_4_Block set trx_record =0 where block_row_number in (1,2,3,4,15);
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_4_Block set trx_record =0
|
||||
where column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Res_4_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Test_Res_4_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,'IHTBT30_BT30_Test_Res_4_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT30_BT30_Test_Condition_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='IHTBT30_BT30_Test_Condition_Block';
|
||||
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Test_Condition_Block (condition)
|
||||
select column2 from staging2.IHTBT30_BT30_Test_Res_1_Block
|
||||
where block_row_number=2
|
||||
union
|
||||
select column2 from staging2.IHTBT30_BT30_Test_Res_2_Block
|
||||
where block_row_number=2
|
||||
union
|
||||
select column2 from staging2.IHTBT30_BT30_Test_Res_3_Block
|
||||
where block_row_number=2
|
||||
union
|
||||
select column2 from staging2.IHTBT30_BT30_Test_Res_4_Block
|
||||
where block_row_number=2;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT30_BT30_Test_Res_1_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT30_BT30_Test_Res_1_Block b
|
||||
where b.block_row_number =3 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT30_BT30_Test_Res_2_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT30_BT30_Test_Res_2_Block b
|
||||
where b.block_row_number =3 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT30_BT30_Test_Res_3_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT30_BT30_Test_Res_3_Block b
|
||||
where b.block_row_number =3 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT30_BT30_Test_Res_4_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT30_BT30_Test_Res_4_Block b
|
||||
where b.block_row_number=3 and condition=b.column2;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block a
|
||||
set date= case
|
||||
when date like '%-%' then date::timestamptz
|
||||
else date '1899-12-30' + date::int * interval '1' day
|
||||
end ;
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Test_Condition_Block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_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,'IHTBT30_BT30_Test_Condition_Block');
|
||||
|
||||
/*block starts - IHTBT30_BT30_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT30_BT30_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9);
|
||||
err_block:='IHTBT30_BT30_Footer_block';
|
||||
|
||||
insert into staging2.IHTBT30_BT30_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set prepared_by=( select column6 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set reviewed_by=( select column6 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set approved_by=( select column6 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and lower(column3)='Approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set rev2=( select column7 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set rev3=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set replaces=( select column11 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set revision_no=( select column11 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set prepared_date=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set reviewed_date=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block a
|
||||
set approved_date=( select column10 from staging2.stg_process_table_IHTBT30_BT30 b
|
||||
where b.block_tag='IHTBT30_BT30_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT30_BT30_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTBT30_BT30_Footer_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,'IHTBT30_BT30_Footer_block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTBT30_BT30_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
460
onetime/dataloadfunctions/IHT/IHTBT50_BT50_ODS.sql
Executable file
460
onetime/dataloadfunctions/IHT/IHTBT50_BT50_ODS.sql
Executable file
@@ -0,0 +1,460 @@
|
||||
drop function if exists staging2.fn_IHTBT50_BT50_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_BT50_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTBT50_BT50_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHT
|
||||
Sheet Format: IHTBT50_BT50
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTBT50_BT50_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
test_condition,
|
||||
test_standard_desc,
|
||||
test_standard_id,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
observations
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
sample_receipt_date::date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date::date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date::date,
|
||||
Test_End_Date::date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Ref,
|
||||
test_location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
condition,
|
||||
test_standard,
|
||||
test_standard_id::numeric,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
observations
|
||||
from
|
||||
staging2.IHTBT50_BT50_H1_block where trx_record =1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTBT50_BT50_footer_block b
|
||||
where a.file_sheet_mnemonic='IHTBT50_BT50' and trx_record =1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_use_type,
|
||||
tyre_pressure_kg_per_cm2
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
tyre_use_type,
|
||||
pressure_kg_cm2::numeric
|
||||
from staging2.IHTBT50_BT50_tyre_details_block where trx_record =1;
|
||||
|
||||
|
||||
insert into transactional.test_instance_drawbar_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
weight_front_kg,
|
||||
weight_rear_kg,
|
||||
weight_total_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
test_condition,
|
||||
front::numeric ,
|
||||
rear::numeric ,
|
||||
total::numeric
|
||||
from staging2.IHTBT50_BT50_weight_block where trx_record =1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_platform
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
platform
|
||||
from staging2.IHTBT50_BT50_h1_block where trx_record =1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when lower(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;
|
||||
|
||||
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT50_BT50_test_res_1_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT50_BT50_test_res_2_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT50_BT50_test_res_3_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column10
|
||||
from staging2.IHTBT50_BT50_test_res_4_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_condition
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
date_of_test,
|
||||
time_of_test,
|
||||
location_name,
|
||||
test_mode,
|
||||
wind_velocity_kmph,
|
||||
ambient_temp_c,
|
||||
humidity_rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
condition,
|
||||
date::date,
|
||||
time,
|
||||
location,
|
||||
mode,
|
||||
wind_velocity_km_hr,
|
||||
ambient_temperature_c::numeric ,
|
||||
humidity_rh::numeric
|
||||
from staging2.IHTBT50_BT50_test_condition_block where trx_record =1;
|
||||
|
||||
update transactional.iht_brake_perf_test_results a
|
||||
set brake_perf_test_condition_id=(select syspk
|
||||
from transactional.iht_brake_perf_test_condition b
|
||||
where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk)
|
||||
where a.file_syspk=__file_syspk;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.iht_brake_perf_test_condition
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.iht_brake_perf_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTBT50_BT50_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
908
onetime/dataloadfunctions/IHT/IHTBT50_BT50_STG2.sql
Executable file
908
onetime/dataloadfunctions/IHT/IHTBT50_BT50_STG2.sql
Executable file
@@ -0,0 +1,908 @@
|
||||
drop function if exists staging2.fn_IHTBT50_BT50_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTBT50_BT50_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_IHTBT50_BT50_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHT
|
||||
Sheet Format: IHTBT50_BT50
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTBT50_BT50_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTBT50_BT50_block(1,2,'IHT','IHTBT50_BT50',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTBT50_BT50_H1_INT;
|
||||
truncate table staging2.IHTBT50_BT50_H1_block;
|
||||
truncate table staging2.IHTBT50_BT50_Weight_Tyre_Int;
|
||||
truncate table staging2.IHTBT50_BT50_Weight_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Tyre_Details_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Test_Res_1_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Test_Res_2_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Test_Res_3_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Test_Res_4_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Test_Condition_Block;
|
||||
truncate table staging2.IHTBT50_BT50_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTBT50_BT50;
|
||||
truncate table staging2.stg_process_table_IHTBT50_BT50;
|
||||
|
||||
|
||||
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 IHT */
|
||||
execute 'insert into staging2.stg_specific_table_IHTBT50_BT50
|
||||
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_IHTBT50_BT50;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHTBT50',
|
||||
detail = 'No data in table stg_specific_table_IHTBT50_BT50',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTBT50_BT50
|
||||
set column10='Objective' where lower(column10) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTBT50_BT50
|
||||
set column10='Acceptance criteria' where lower(column10) like 'acceptance criteria%';
|
||||
|
||||
|
||||
update staging2.stg_specific_table_IHTBT50_BT50
|
||||
set column10='Condition' where lower(column10) like 'condition%';
|
||||
|
||||
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_IHTBT50_BT50 b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTBT50_BT50 a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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 Request No''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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=''Un-Ballast cold''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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=''Ballast cold''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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=''Fade Performance''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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=''Recovery Performance''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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=''Weight (kg)''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTBT50_BT50
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTBT50_BT50 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=''Prepared by''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column5 into __model from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTBT50_BT50_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTBT50_BT50_H1_BLOCK';
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select a.column3,column5 from staging2.stg_process_table_IHTBT50_BT50 a where block_tag='IHTBT50_BT50_H1'
|
||||
and block_row_number <=9;
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select a.column7,column9 from staging2.stg_process_table_IHTBT50_BT50 a where block_tag='IHTBT50_BT50_H1'
|
||||
and block_row_number <=9;
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Objective',column10
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where column10='Objective'
|
||||
and block_tag='IHTBT50_BT50_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column8
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_H1' and block_row_number=11;
|
||||
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Condition',column10
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where column10='Condition'
|
||||
and block_tag='IHTBT50_BT50_H1'
|
||||
);
|
||||
|
||||
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Test std',column4
|
||||
from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where block_row_number=11
|
||||
and block_tag='IHTBT50_BT50_H1';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Test std Id',column3
|
||||
from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where block_row_number=11
|
||||
and block_tag='IHTBT50_BT50_H1';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Test Standard ref',split_part(column3,':',2)
|
||||
from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where block_row_number=10
|
||||
and block_tag='IHTBT50_BT50_H1';
|
||||
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_INT (c1,c2)
|
||||
select 'Observations',column3
|
||||
from staging2.stg_process_table_IHTBT50_BT50
|
||||
where block_tag='IHTBT50_BT50_Weight_Tyre'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where column3='Remarks & Observations'
|
||||
and block_tag='IHTBT50_BT50_Weight_Tyre'
|
||||
);
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
Test_Location,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Domestic_Export,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Platform,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
condition,
|
||||
Test_Standard,
|
||||
Test_Standard_id,
|
||||
Test_Standard_ref,
|
||||
Remarks,
|
||||
Observations
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTBT50_BT50_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
update staging2.IHTBT50_BT50_H1_Block
|
||||
set Sample_Receipt_Date=case
|
||||
when Sample_Receipt_Date like '%-%' then Sample_Receipt_Date::timestamptz
|
||||
else date '1899-12-30' + Sample_Receipt_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
update staging2.IHTBT50_BT50_H1_Block
|
||||
set Test_Report_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
update staging2.IHTBT50_BT50_H1_Block
|
||||
set Test_Start_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
update staging2.IHTBT50_BT50_H1_Block
|
||||
set Test_End_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
delete from staging2.IHTBT50_BT50_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTBT50_BT50_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_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,'IHTBT50_BT50_H1_BLOCK');
|
||||
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Weight_Tyre_Int
|
||||
(
|
||||
column3,column4,column5,column6,column7,column8,column9,
|
||||
column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,column8,
|
||||
column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_Weight_Tyre'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Weight_Tyre_Int set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Weight_Tyre_Int 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||'''';
|
||||
|
||||
|
||||
/*block starts - IHTBT50_BT50_Weight_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTBT50_BT50_Weight_Block';
|
||||
insert into staging2.IHTBT50_BT50_Weight_Block
|
||||
(
|
||||
dummy_f,
|
||||
test_condition,
|
||||
Front,
|
||||
Rear,
|
||||
Total
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column7::text]) AS val
|
||||
FROM staging2.IHTBT50_BT50_Weight_Tyre_Int where column5 is not null and column7 is not null and block_row_number<>1
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text);
|
||||
|
||||
|
||||
delete from staging2.IHTBT50_BT50_Weight_Block where dummy_f is null ;
|
||||
update staging2.IHTBT50_BT50_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Weight_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,'IHTBT50_BT50_Weight_Block');
|
||||
|
||||
/*block starts - IHTBT50_BT50_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTBT50_BT50_Tyre_Details_Block';
|
||||
insert into staging2.IHTBT50_BT50_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Pressure_kg_cm2,
|
||||
tyre_use_type,
|
||||
Tyre_Make,
|
||||
tyre_size,
|
||||
ply_rating
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column10,column11}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column10::text,column11::text]) AS val
|
||||
FROM staging2.IHTBT50_BT50_Weight_Tyre_Int where column11 is not null or column10 is not null
|
||||
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);
|
||||
|
||||
|
||||
|
||||
delete from staging2.IHTBT50_BT50_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTBT50_BT50_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Tyre_Details_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,'IHTBT50_BT50_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT50_BT50_Test_Res_1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Test_Res_1_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTBT50_BT50_Test_Res_1_Block';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Test_Res_1_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_Test_Res_1'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_1_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_1_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_1_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_1_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_1_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_1_Block set trx_record =0 where block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_1_Block set trx_record =0 where
|
||||
column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_1_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Test_Res_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,'IHTBT50_BT50_Test_Res_1_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT50_BT50_Test_Res_2_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Test_Res_2_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTBT50_BT50_Test_Res_2_Block';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Test_Res_2_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_Test_Res_2'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_2_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_2_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
select
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_2_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_2_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_2_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_2_Block set trx_record =0 where block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_2_Block set trx_record =0 where
|
||||
column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_2_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Test_Res_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,'IHTBT50_BT50_Test_Res_2_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT50_BT50_Test_Res_3_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Test_Res_3_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTBT50_BT50_Test_Res_3_Block';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Test_Res_3_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_Test_Res_3'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_3_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_3_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_3_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_3_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_3_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_3_Block set trx_record =0 where block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_3_Block set trx_record =0 where
|
||||
column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_3_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Test_Res_3_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,'IHTBT50_BT50_Test_Res_3_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT50_BT50_Test_Res_4_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Test_Res_4_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='IHTBT50_BT50_Test_Res_4_Block';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Test_Res_4_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_IHTBT50_BT50 a
|
||||
where block_tag='IHTBT50_BT50_Test_Res_4'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_4_Block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_4_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number,column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_4_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_4_Block a
|
||||
set column10= b.first_value from (SELECT
|
||||
block_row_number,column10, value_partition, first_value(column10) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column10,
|
||||
sum(case when column10 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTBT50_BT50_Test_Res_4_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number=b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_4_Block set trx_record =0 where block_row_number in (1,2,3,4,15);
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_4_Block set trx_record =0 where
|
||||
column4 is null and column5 is null;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Res_4_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Test_Res_4_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,'IHTBT50_BT50_Test_Res_4_Block');
|
||||
|
||||
|
||||
/*block starts - IHTBT50_BT50_Test_Condition_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Test_Condition_Block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='IHTBT50_BT50_Test_Condition_Block';
|
||||
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Test_Condition_Block (condition)
|
||||
select column2 from staging2.IHTBT50_BT50_Test_Res_1_Block
|
||||
where block_row_number=2
|
||||
union
|
||||
select column2 from staging2.IHTBT50_BT50_Test_Res_2_Block
|
||||
where block_row_number=2
|
||||
union
|
||||
select column2 from staging2.IHTBT50_BT50_Test_Res_3_Block
|
||||
where block_row_number=2
|
||||
union
|
||||
select column2 from staging2.IHTBT50_BT50_Test_Res_4_Block
|
||||
where block_row_number=2;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT50_BT50_Test_Res_1_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT50_BT50_Test_Res_1_Block b
|
||||
where b.block_row_number =3 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT50_BT50_Test_Res_2_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT50_BT50_Test_Res_2_Block b
|
||||
where b.block_row_number =3 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT50_BT50_Test_Res_3_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT50_BT50_Test_Res_3_Block b
|
||||
where b.block_row_number =3 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set date=b.column4,
|
||||
location=b.column7,
|
||||
--time=b.column9,
|
||||
mode=b.column10
|
||||
from staging2.IHTBT50_BT50_Test_Res_4_Block b
|
||||
where b.block_row_number =2 and condition=b.column2;
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block
|
||||
set Wind_Velocity_Km_hr=b.column5,
|
||||
Ambient_Temperature_C=b.column7,
|
||||
Humidity_RH=b.column9
|
||||
from staging2.IHTBT50_BT50_Test_Res_4_Block b
|
||||
where b.block_row_number=3 and condition=b.column2;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block a
|
||||
set date= case
|
||||
when date like '%-%' then date::timestamptz
|
||||
else date '1899-12-30' + date::int * interval '1' day
|
||||
end ;
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Test_Condition_Block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_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,'IHTBT50_BT50_Test_Condition_Block');
|
||||
|
||||
/*block starts - IHTBT50_BT50_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTBT50_BT50_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9);
|
||||
err_block:='IHTBT50_BT50_Footer_block';
|
||||
|
||||
insert into staging2.IHTBT50_BT50_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set prepared_by=( select column6 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set reviewed_by=( select column6 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set approved_by=( select column6 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and lower(column3)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set rev2=( select column7 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set rev3=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set replaces=( select column11 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set revision_no=( select column11 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set prepared_date=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set reviewed_date=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block a
|
||||
set approved_date=( select column10 from staging2.stg_process_table_IHTBT50_BT50 b
|
||||
where b.block_tag='IHTBT50_BT50_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTBT50_BT50_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTBT50_BT50_Footer_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,'IHTBT50_BT50_Footer_block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTBT50_BT50_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
539
onetime/dataloadfunctions/IHT/IHTBTD_BTD_ODS.sql
Executable file
539
onetime/dataloadfunctions/IHT/IHTBTD_BTD_ODS.sql
Executable file
@@ -0,0 +1,539 @@
|
||||
drop function if exists staging2.fn_IHTBTD_BTD_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTBTD_BTD_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTBTD_BTD_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHT
|
||||
Sheet Format: IHTBTD_BTD
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTBTD_BTD_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
test_condition,
|
||||
test_standard_desc,
|
||||
test_standard_id,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
observations
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
to_date(sample_receipt_date,'DD-MM-YYYY'),
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
to_date(Test_Report_Date,'DD-MM-YYYY'),
|
||||
No_of_Sample,
|
||||
to_date(Test_Start_Date,'DD-MM-YYYY'),
|
||||
to_date(Test_End_Date, 'DD-MM-YYYY'),
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
test_location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
condition,
|
||||
test_standard,
|
||||
test_standard_id::numeric,
|
||||
test_standard_ref
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
observations
|
||||
from
|
||||
staging2.IHTBTD_BTD_H1_block where trx_record =1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTBTD_BTD_footer_block b
|
||||
where a.file_sheet_mnemonic='IHTBTD_BTD' and trx_record =1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_use_type,
|
||||
tyre_pressure_kg_per_cm2
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
tyre_use_type,
|
||||
pressure_kg_cm2::numeric
|
||||
from staging2.IHTBTD_BTD_tyre_details_block where trx_record =1;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_drawbar_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
weight_front_kg,
|
||||
weight_rear_kg,
|
||||
weight_total_kg,
|
||||
status
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
test_condition,
|
||||
front::numeric ,
|
||||
rear::numeric ,
|
||||
total::numeric ,
|
||||
status
|
||||
from staging2.IHTBTD_BTD_weight_block where trx_record =1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_platform
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
platform
|
||||
from staging2.IHTBTD_BTD_h1_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;
|
||||
|
||||
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column11
|
||||
from staging2.IHTBTD_BTD_test_res_1_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column11
|
||||
from staging2.IHTBTD_BTD_test_res_2_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column11
|
||||
from staging2.IHTBTD_BTD_test_res_3_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column11
|
||||
from staging2.IHTBTD_BTD_test_res_4_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column11
|
||||
from staging2.IHTBTD_BTD_test_res_5_block where trx_record =1;
|
||||
|
||||
|
||||
insert into transactional.iht_brake_perf_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
srl_no,
|
||||
trigger_speed_km_per_h,
|
||||
brake_control_input_force_kg,
|
||||
required_corrected_stopping_distance_m,
|
||||
actual_stopping_distance_m,
|
||||
deceleration_m_s2_v2_2s,
|
||||
observation,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9,
|
||||
column13
|
||||
from staging2.IHTBTD_BTD_test_res_6_block where trx_record =1;
|
||||
|
||||
insert into transactional.iht_brake_perf_test_condition
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
date_of_test,
|
||||
time_of_test,
|
||||
location_name,
|
||||
test_mode,
|
||||
wind_velocity_kmph,
|
||||
ambient_temp_c,
|
||||
humidity_rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
condition,
|
||||
date::date,
|
||||
time,
|
||||
location,
|
||||
mode,
|
||||
wind_velocity_km_hr,
|
||||
ambient_temperature_c::numeric ,
|
||||
humidity_rh::numeric
|
||||
from staging2.ihtbtd_btd_test_condition_block where trx_record =1;
|
||||
|
||||
update transactional.iht_brake_perf_test_results a
|
||||
set brake_perf_test_condition_id=(select syspk
|
||||
from transactional.iht_brake_perf_test_condition b
|
||||
where a.test_mode =b.test_mode and a.test_condition=b.test_condition and a.file_syspk=b.file_syspk)
|
||||
where a.file_syspk=__file_syspk;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.iht_brake_perf_test_condition
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.iht_brake_perf_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTBTD_BTD_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
1098
onetime/dataloadfunctions/IHT/IHTBTD_BTD_STG2.sql
Executable file
1098
onetime/dataloadfunctions/IHT/IHTBTD_BTD_STG2.sql
Executable file
File diff suppressed because it is too large
Load Diff
336
onetime/dataloadfunctions/IHT/IHT_CGM_ODS.sql
Executable file
336
onetime/dataloadfunctions/IHT/IHT_CGM_ODS.sql
Executable file
@@ -0,0 +1,336 @@
|
||||
drop function if exists staging2.fn_IHTCGM_CGM_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_CGM_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTCGM_CGM_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTCGM
|
||||
Sheet Format: IHTCGM_CGM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTCGM_CGM_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
acceptance_criteria,
|
||||
remarks
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date,
|
||||
No_of_Sample,
|
||||
date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date,
|
||||
date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks
|
||||
from staging2.IHTCGM_CGM_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTCGM_CGM_footer_block b
|
||||
where a.file_sheet_mnemonic ='IHTCGM_CGM' and trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_static_rolling_radius_mm,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
load_carrying_capacity,
|
||||
Pressure_kg_cm2::numeric ,
|
||||
Dynamic_rolling_radius::numeric ,
|
||||
Static_rolling_radius::numeric ,
|
||||
wheel_rim_make_size
|
||||
from staging2.IHTCGM_CGM_tyre_details_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
wheel_base_mm,
|
||||
rear_track_width_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
wheel_base::numeric ,
|
||||
rear_track_width::numeric
|
||||
from staging2.IHTCGM_CGM_wheel_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;
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_weight_reaction
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
total_weight_kg,
|
||||
front_reaction_kg,
|
||||
rear_reaction_kg,
|
||||
left_reaction_fl_rl_kg,
|
||||
right_reaction_fr_rr_kg,
|
||||
front_left_reaction_kg,
|
||||
front_right_reactionkg,
|
||||
rear_left_reaction_kg,
|
||||
rear_right_reactionkg,
|
||||
distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg::numeric,
|
||||
Front_Reaction_kg::numeric ,
|
||||
Rear_Reaction_kg::numeric ,
|
||||
Left_Reaction_FL_RL_kg::numeric ,
|
||||
Right_reaction_FR_RR_kg::numeric ,
|
||||
Front_Left_Reaction_kg::numeric ,
|
||||
Front_Right_Reaction_kg::numeric ,
|
||||
Rear_Left_Reaction_kg::numeric ,
|
||||
Rear_Right_Reaction_kg::numeric ,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1::numeric
|
||||
from staging2.IHTCGM_CGM_weight_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.IHT_cgm_lifting_angle_load_details
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
angle,
|
||||
value_in_tan,
|
||||
diff_of_tan_value,
|
||||
load_kn,
|
||||
load_kg,
|
||||
diff_in_load_kg,
|
||||
vertical_co_ordinate_z_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3::numeric,
|
||||
column4::numeric ,
|
||||
column5::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric,
|
||||
column10::numeric
|
||||
from staging2.IHTCGM_cgm_lifting_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_cgm_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
horizontal_distance_from_rac_x_mm,
|
||||
lateral_co_ordinate_in_horizontal_plane_y_mm,
|
||||
vertical_co_ordinate_z_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
determination_of_horizontal_distance_from_rac_x::numeric ,
|
||||
determination_of_lateral_coordinate_in_horizontal_plane_y::numeric ,
|
||||
determination_of_vertical_coordinate_z::numeric
|
||||
from staging2.IHTCGM_cgm_results_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_weight_reaction
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_cgm_lifting_angle_load_details
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_cgm_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTCGM_CGM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
565
onetime/dataloadfunctions/IHT/IHT_CGM_STG2.sql
Executable file
565
onetime/dataloadfunctions/IHT/IHT_CGM_STG2.sql
Executable file
@@ -0,0 +1,565 @@
|
||||
drop function if exists staging2.fn_IHTCGM_CGM_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTCGM_CGM_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_IHTCGM_CGM_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHTCGM
|
||||
Sheet Format: IHTCGM_CGM
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTCGM_CGM_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTCGM_CGM_block(1,2,'IHTCGM','IHTCGM_CGM',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTCGM_CGM_H1_Int;
|
||||
truncate table staging2.IHTCGM_CGM_H1_block;
|
||||
truncate table staging2.IHTCGM_CGM_Weight_Tyre_Int;
|
||||
truncate table staging2.IHTCGM_CGM_Weight_Block;
|
||||
truncate table staging2.IHTCGM_CGM_Wheel_Block;
|
||||
truncate table staging2.IHTCGM_CGM_Tyre_Details_Block;
|
||||
truncate table staging2.IHTCGM_CGM_Lifting_Block;
|
||||
truncate table staging2.IHTCGM_CGM_Results_Block;
|
||||
truncate table staging2.IHTCGM_CGM_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTCGM_CGM;
|
||||
truncate table staging2.stg_process_table_IHTCGM_CGM;
|
||||
|
||||
|
||||
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 IHTCGM */
|
||||
execute 'insert into staging2.stg_specific_table_IHTCGM_CGM
|
||||
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_IHTCGM_CGM;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHT CGM',
|
||||
detail = 'No data in table stg_specific_table_IHTCGM_CGM',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTCGM_CGM
|
||||
set column15='Objective' where lower(column15) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTCGM_CGM
|
||||
set column15='Acceptance criteria' where lower(column15) like 'acceptance criteria%';
|
||||
|
||||
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_IHTCGM_CGM b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTCGM_CGM a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTCGM_CGM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTCGM_CGM 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 Request no.''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTCGM_CGM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTCGM_CGM 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=''Weight Reaction''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTCGM_CGM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTCGM_CGM 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=''Lifting Angle & Load''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTCGM_CGM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTCGM_CGM 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=''Prepared by''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column6 into __model from staging2.stg_process_table_IHTCGM_CGM a
|
||||
where block_tag='IHTCGM_CGM_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTCGM_CGM_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTCGM_CGM_H1_BLOCK';
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_INT (c1,c2)
|
||||
select a.column3,column6 from staging2.stg_process_table_IHTCGM_CGM a where block_tag='IHTCGM_CGM_H1';
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_INT (c1,c2)
|
||||
select a.column9,column12 from staging2.stg_process_table_IHTCGM_CGM a where block_tag='IHTCGM_CGM_H1';
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_INT (c1,c2)
|
||||
select 'Objective',column15
|
||||
from staging2.stg_process_table_IHTCGM_CGM a
|
||||
where block_tag='IHTCGM_CGM_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTCGM_CGM a
|
||||
where column15='Objective'
|
||||
and block_tag='IHTCGM_CGM_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column15
|
||||
from staging2.stg_process_table_IHTCGM_CGM a
|
||||
where block_tag='IHTCGM_CGM_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTCGM_CGM a
|
||||
where column15='Acceptance criteria'
|
||||
and block_tag='IHTCGM_CGM_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_INT (c1,c2)
|
||||
select split_part(column3,':',1),split_part(column3,':',2)
|
||||
from staging2.stg_process_table_IHTCGM_CGM
|
||||
where block_tag='IHTCGM_CGM_Lifting' and block_row_number=15;
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_INT (c1,c2)
|
||||
select 'Test Purpose',column10
|
||||
from staging2.stg_process_table_IHTCGM_CGM a
|
||||
where block_tag='IHTCGM_CGM_H1' and column3='Test Purpose';
|
||||
|
||||
update staging2.IHTCGM_CGM_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTCGM_CGM_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTCGM_CGM_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
|
||||
delete from staging2.IHTCGM_CGM_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTCGM_CGM_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_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,'IHTCGM_CGM_H1_BLOCK');
|
||||
|
||||
|
||||
insert into staging2.IHTCGM_CGM_Weight_Tyre_Int
|
||||
(
|
||||
column3,column6,column10,column11,column13,column15,column17,column19,
|
||||
column20,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column6,column10,column11,column13,column15,column17,column19,
|
||||
column20,block_row_number
|
||||
from staging2.stg_process_table_IHTCGM_CGM a
|
||||
where block_tag='IHTCGM_CGM_Weight_Tyre'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTCGM_CGM_Weight_Tyre_Int set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_Weight_Tyre_Int 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.IHTCGM_CGM_Weight_Tyre_Int set trx_record = 0 where block_row_number=3;
|
||||
|
||||
/*block starts - IHTCGM_CGM_Weight_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTCGM_CGM_Weight_Block';
|
||||
|
||||
insert into staging2.IHTCGM_CGM_Weight_Block
|
||||
(
|
||||
dummy_f,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg,
|
||||
Front_Reaction_kg,
|
||||
Rear_Reaction_kg,
|
||||
Left_Reaction_FL_RL_kg,
|
||||
Right_reaction_FR_RR_kg,
|
||||
Front_Left_Reaction_kg,
|
||||
Front_Right_Reaction_kg,
|
||||
Rear_Left_Reaction_kg,
|
||||
Rear_Right_Reaction_kg,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column6::text]) AS val
|
||||
FROM staging2.IHTCGM_CGM_Weight_Tyre_Int where trx_record=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);
|
||||
|
||||
delete from staging2.IHTCGM_CGM_Weight_Block where dummy_f is null ;
|
||||
update staging2.IHTCGM_CGM_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_Weight_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,'IHTCGM_CGM_Weight_Block');
|
||||
|
||||
/*block starts - IHTCGM_CGM_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTCGM_CGM_Tyre_Details_Block';
|
||||
insert into staging2.IHTCGM_CGM_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating,
|
||||
Load_Carrying_Capacity,
|
||||
Pressure_kg_cm2,
|
||||
Dynamic_rolling_radius,
|
||||
Static_rolling_radius,
|
||||
Wheel_rim_Make_size
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column15,column19}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column15::text,column19::text]) AS val
|
||||
FROM staging2.IHTCGM_CGM_Weight_Tyre_Int where block_row_number between 3 and 11
|
||||
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);
|
||||
|
||||
delete from staging2.IHTCGM_CGM_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTCGM_CGM_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_Tyre_Details_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,'IHTCGM_CGM_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTCGM_CGM_Wheel_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTCGM_CGM_Wheel_Block';
|
||||
insert into staging2.IHTCGM_CGM_Wheel_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTCGM_CGM_Wheel_Block
|
||||
set Wheel_Base=(select column13 from
|
||||
staging2.IHTCGM_CGM_Weight_Tyre_Int
|
||||
where block_row_number=1 and column10='Wheel Base in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Wheel_Block
|
||||
set Rear_Track_Width=(select column20 from
|
||||
staging2.IHTCGM_CGM_Weight_Tyre_Int
|
||||
where block_row_number=1 and column17='Rear Track Width in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTCGM_CGM_Wheel_Block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_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,'IHTCGM_CGM_Wheel_Block');
|
||||
|
||||
/*block starts - IHTCGM_CGM_Lifting_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_Lifting_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTCGM_CGM_Lifting_Block';
|
||||
|
||||
insert into staging2.IHTCGM_CGM_Lifting_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,block_row_number
|
||||
from staging2.stg_process_table_IHTCGM_CGM a
|
||||
where block_tag='IHTCGM_CGM_Lifting'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
update staging2.IHTCGM_CGM_Lifting_Block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_Lifting_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.IHTCGM_CGM_Lifting_Block set trx_record =0 where block_row_number not in (3,4,5,6,7,8,9);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTCGM_CGM_Lifting_Block');
|
||||
|
||||
|
||||
/*block starts - IHTCGM_CGM_Results_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_Results_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTCGM_CGM_Results_Block';
|
||||
insert into staging2.IHTCGM_CGM_Results_Block (dummy_f) values('dummy');
|
||||
|
||||
update staging2.IHTCGM_CGM_Results_Block
|
||||
set Determination_of_Horizontal_Distance_from_RAC_X=
|
||||
(select column10 from staging2.IHTCGM_CGM_Lifting_Block
|
||||
where block_row_number=12) where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Results_Block
|
||||
set Determination_of_Lateral_CoOrdinate_in_Horizontal_Plane_Y=
|
||||
(select column10 from staging2.IHTCGM_CGM_Lifting_Block
|
||||
where block_row_number=13) where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Results_Block
|
||||
set Determination_of_Vertical_CoOrdinate_Z=
|
||||
(select column10 from staging2.IHTCGM_CGM_Lifting_Block
|
||||
where block_row_number=14) where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTCGM_CGM_Results_Block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_Results_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,'IHTCGM_CGM_Results_Block');
|
||||
|
||||
|
||||
/*block starts - IHTCGM_CGM_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTCGM_CGM_Footer_block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block='IHTCGM_CGM_Footer_block';
|
||||
insert into staging2.IHTCGM_CGM_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set prepared_by=( select column7 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set reviewed_by=( select column7 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set approved_by=( select column7 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and lower(column3)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set rev2=( select column9 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set rev3=( select column18 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set replaces=( select column19 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set revision_no=( select column19 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set prepared_date=( select column16 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set reviewed_date=( select column16 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block a
|
||||
set approved_date=( select column16 from staging2.stg_process_table_IHTCGM_CGM b
|
||||
where b.block_tag='IHTCGM_CGM_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTCGM_CGM_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTCGM_CGM_Footer_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,'IHTCGM_CGM_Footer_block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTCGM_CGM_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
434
onetime/dataloadfunctions/IHT/IHT_EMT_ODS.sql
Executable file
434
onetime/dataloadfunctions/IHT/IHT_EMT_ODS.sql
Executable file
@@ -0,0 +1,434 @@
|
||||
drop function if exists staging2.fn_IHTEMT_EMT_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_EMT_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTEMT_EMT_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTEMT
|
||||
Sheet Format: IHTEMT_EMT
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTEMT_EMT_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
test_purpose
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date,
|
||||
No_of_Sample,
|
||||
date '1899-12-30' + Test_Start_Date ::int * interval '1' day as Test_Start_Date,
|
||||
date '1899-12-30' + Test_End_Date ::int * interval '1' day as Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
from staging2.IHTEMT_EMT_H1_block where trx_record =1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTEMT_EMT_footer_block b
|
||||
where a.file_sheet_mnemonic ='IHTEMT_EMT' and trx_record =1;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_static_rolling_radius_mm,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
load_carrying_capacity,
|
||||
Pressure_kg_cm2::numeric ,
|
||||
Dynamic_rolling_radius::numeric ,
|
||||
Static_rolling_radius::numeric ,
|
||||
wheel_rim_make_size
|
||||
from staging2.IHTEMT_EMT_tyre_details_block where trx_record =1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
wheel_base_mm,
|
||||
turning_circle_diameter_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
wheel_base::numeric ,
|
||||
tcd::numeric
|
||||
from staging2.IHTEMT_EMT_wheel_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;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_weight_reaction
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
total_weight_kg,
|
||||
front_reaction_kg,
|
||||
rear_reaction_kg,
|
||||
left_reaction_fl_rl_kg,
|
||||
right_reaction_fr_rr_kg,
|
||||
front_left_reaction_kg,
|
||||
front_right_reactionkg,
|
||||
rear_left_reaction_kg,
|
||||
rear_right_reactionkg,
|
||||
distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg::numeric,
|
||||
Front_Reaction_kg::numeric ,
|
||||
Rear_Reaction_kg::numeric ,
|
||||
Left_Reaction_FL_RL_kg::numeric ,
|
||||
Right_reaction_FR_RR_kg::numeric ,
|
||||
Front_Left_Reaction_kg::numeric ,
|
||||
Front_Right_Reaction_kg::numeric ,
|
||||
Rear_Left_Reaction_kg::numeric ,
|
||||
Rear_Right_Reaction_kg::numeric ,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1::numeric
|
||||
from staging2.IHTEMT_EMT_weight_block where trx_record =1;
|
||||
|
||||
|
||||
insert into transactional.IHT_steering_effort
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_speed_kmph,
|
||||
max_angle_lh,
|
||||
max_angle_rh,
|
||||
max_effort_lh,
|
||||
max_effort_rh
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column8::numeric
|
||||
from staging2.IHTEMT_emt_steering_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_pedal_effort
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
parameters,
|
||||
efforts_kg,
|
||||
travel_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric ,
|
||||
column4::numeric
|
||||
from staging2.IHTEMT_emt_pedal_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_gear_effort
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
parameters,
|
||||
efforts_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column5,
|
||||
column8::numeric
|
||||
from staging2.IHTEMT_emt_pedal_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_brake_pedal_effort
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
pedal_effort_kg,
|
||||
pedal_travel_lh_mm,
|
||||
pedal_travel_rh_mm,
|
||||
pedal_travel_latched_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2::numeric,
|
||||
column3::numeric,
|
||||
column4::numeric ,
|
||||
column5::numeric,
|
||||
column6::numeric
|
||||
from staging2.IHTEMT_emt_brake_pedal_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_clutch_pedal_effort
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
pedal_effort_kg,
|
||||
pedal_travel_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric
|
||||
from staging2.IHTEMT_emt_brake_pedal_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_weight_reaction
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_brake_pedal_effort
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_pedal_effort
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_steering_effort
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_gear_effort
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_clutch_pedal_effort
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTEMT_EMT_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
91
onetime/dataloadfunctions/IHT/IHT_EMT_STD_ODS.sql
Executable file
91
onetime/dataloadfunctions/IHT/IHT_EMT_STD_ODS.sql
Executable file
@@ -0,0 +1,91 @@
|
||||
|
||||
drop function if exists staging2.fn_IHTEMT_STD_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_STD_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTEMT_STD_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTEMT
|
||||
Sheet Format: IHTEMT_STD
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTEMT_STD_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.iht_steering_effort_raw_data
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
time_sec,
|
||||
steering_anglel,
|
||||
effort_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
time_s::numeric,
|
||||
steering_angle ::numeric,
|
||||
effort ::numeric
|
||||
from staging2.IHTEMT_STD_RAW_Data_Block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTEMT_STD_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
149
onetime/dataloadfunctions/IHT/IHT_EMT_STD_STG2.sql
Executable file
149
onetime/dataloadfunctions/IHT/IHT_EMT_STD_STG2.sql
Executable file
@@ -0,0 +1,149 @@
|
||||
drop function if exists staging2.fn_IHTEMT_STD_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_STD_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_IHTEMT_STD_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHTEMT
|
||||
Sheet Format: IHTEMT_STD
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTEMT_STD_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTEMT_STD_block(1,2,'IHTEMT','IHTEMT_STD',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTEMT_STD_RAW_Data_Block;
|
||||
truncate table staging2.stg_specific_table_IHTEMT_STD;
|
||||
truncate table staging2.stg_process_table_IHTEMT_STD;
|
||||
|
||||
|
||||
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 IHTEMT */
|
||||
execute 'insert into staging2.stg_specific_table_IHTEMT_STD
|
||||
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_IHTEMT_STD;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHTEMT STD',
|
||||
detail = 'No data in table stg_specific_table_IHTEMT_STD',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
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_IHTEMT_STD b
|
||||
where upper(F1_modified)=upper(column1)
|
||||
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_IHTEMT_STD a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column1)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Steering effort RAW data''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_STD
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_STD 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=''Steering effort RAW data''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/*block starts - IHTEMT_STD_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_STD_RAW_Data_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
|
||||
err_block:='IHTEMT_STD_RAW_Data_Block';
|
||||
insert into staging2.IHTEMT_STD_RAW_Data_Block (Time_s,Steering_Angle,Effort,block_row_number)
|
||||
select a.column1,column2,column3,block_row_number from staging2.stg_process_table_IHTEMT_STD a
|
||||
where block_tag='IHTEMT_STD_RAW_Data';
|
||||
|
||||
|
||||
execute 'update staging2.IHTEMT_STD_RAW_Data_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.IHTEMT_STD_RAW_Data_Block set trx_record =0 where block_row_number in (1,2,3);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_STD_RAW_Data_Block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTEMT_STD_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
615
onetime/dataloadfunctions/IHT/IHT_EMT_STG2.sql
Executable file
615
onetime/dataloadfunctions/IHT/IHT_EMT_STG2.sql
Executable file
@@ -0,0 +1,615 @@
|
||||
drop function if exists staging2.fn_IHTEMT_EMT_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTEMT_EMT_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_IHTEMT_EMT_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHTEMT
|
||||
Sheet Format: IHTEMT_EMT
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTEMT_EMT_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTEMT_EMT_block(1,2,'IHTEMT','IHTEMT_EMT',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTEMT_EMT_H1_INT;
|
||||
truncate table staging2.IHTEMT_EMT_H1_block;
|
||||
truncate table staging2.IHTEMT_EMT_Weight_Tyre_Int;
|
||||
truncate table staging2.IHTEMT_EMT_Weight_Block;
|
||||
truncate table staging2.IHTEMT_EMT_Wheel_Block;
|
||||
truncate table staging2.IHTEMT_EMT_Tyre_Details_Block;
|
||||
truncate table staging2.IHTEMT_EMT_Steering_Block;
|
||||
truncate table staging2.IHTEMT_EMT_Pedal_Block;
|
||||
truncate table staging2.IHTEMT_EMT_Brake_Pedal_Block;
|
||||
truncate table staging2.IHTEMT_EMT_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTEMT_EMT;
|
||||
truncate table staging2.stg_process_table_IHTEMT_EMT;
|
||||
|
||||
|
||||
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 IHTEMT */
|
||||
execute 'insert into staging2.stg_specific_table_IHTEMT_EMT
|
||||
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_IHTEMT_EMT;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHTEMT EMT',
|
||||
detail = 'No data in table stg_specific_table_IHTEMT_EMT',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTEMT_EMT
|
||||
set column14='Objective' where lower(column14) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTEMT_EMT
|
||||
set column14='Acceptance criteria' where lower(column14) like 'acceptance criteria%';
|
||||
|
||||
|
||||
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_IHTEMT_EMT b
|
||||
where upper(F1_modified)=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_IHTEMT_EMT a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_EMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_EMT 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 Request no.''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_EMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_EMT 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=''Weight Reaction''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_EMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_EMT 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=''Steering effort''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_EMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_EMT 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=''Pedal Effort''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_EMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_EMT 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=''Brake Pedal Effort''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTEMT_EMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTEMT_EMT 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=''Prepared by''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model and make*/
|
||||
select column5 into __make from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_H1' and trim(column2)='Tractor Model';
|
||||
|
||||
|
||||
select column5 into __model from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_H1' and trim(column2)='Tractor Model';
|
||||
|
||||
/*block starts - IHTEMT_EMT_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTEMT_EMT_H1_BLOCK';
|
||||
insert into staging2.IHTEMT_EMT_H1_INT (c1,c2)
|
||||
select a.column2,column5 from staging2.stg_process_table_IHTEMT_EMT a where block_tag='IHTEMT_EMT_H1';
|
||||
|
||||
insert into staging2.IHTEMT_EMT_H1_INT (c1,c2)
|
||||
select a.column8,column11 from staging2.stg_process_table_IHTEMT_EMT a where block_tag='IHTEMT_EMT_H1';
|
||||
|
||||
insert into staging2.IHTEMT_EMT_H1_INT (c1,c2)
|
||||
select 'Objective',column14
|
||||
from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTEMT_EMT a
|
||||
where column14='Objective'
|
||||
and block_tag='IHTEMT_EMT_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTEMT_EMT_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column14
|
||||
from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTEMT_EMT a
|
||||
where column14='Acceptance criteria'
|
||||
and block_tag='IHTEMT_EMT_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTEMT_EMT_H1_INT (c1,c2)
|
||||
select split_part(column2,':',1),split_part(column2,':',2)
|
||||
from staging2.stg_process_table_IHTEMT_EMT
|
||||
where block_tag='IHTEMT_EMT_Footer' and block_row_number=1;
|
||||
|
||||
insert into staging2.IHTEMT_EMT_H1_INT (c1,c2)
|
||||
select 'Test Purpose',column9
|
||||
from staging2.stg_process_table_IHTEMT_EMT
|
||||
where block_tag='IHTEMT_EMT_Weight_Tyre' and column2='Test Purpose';
|
||||
|
||||
|
||||
update staging2.IHTEMT_EMT_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTEMT_EMT_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTEMT_EMT_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
|
||||
delete from staging2.IHTEMT_EMT_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTEMT_EMT_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_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,'IHTEMT_EMT_H1_BLOCK');
|
||||
|
||||
|
||||
insert into staging2.IHTEMT_EMT_Weight_Tyre_Int
|
||||
(
|
||||
column2,column5,column9,column10,column12,column14,column16,column18,
|
||||
column19,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column5,column9,column10,column12,column14,column16,column18,
|
||||
column19,block_row_number
|
||||
from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_Weight_Tyre'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTEMT_EMT_Weight_Tyre_Int set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Weight_Tyre_Int 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||'''';
|
||||
|
||||
|
||||
/*block starts - IHTEMT_EMT_Weight_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTEMT_EMT_Weight_Block';
|
||||
|
||||
insert into staging2.IHTEMT_EMT_Weight_Block
|
||||
(
|
||||
dummy_f,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg,
|
||||
Front_Reaction_kg,
|
||||
Rear_Reaction_kg,
|
||||
Left_Reaction_FL_RL_kg,
|
||||
Right_reaction_FR_RR_kg,
|
||||
Front_Left_Reaction_kg,
|
||||
Front_Right_Reaction_kg,
|
||||
Rear_Left_Reaction_kg,
|
||||
Rear_Right_Reaction_kg,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text]) AS val
|
||||
FROM staging2.IHTEMT_EMT_Weight_Tyre_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);
|
||||
|
||||
|
||||
delete from staging2.IHTEMT_EMT_Weight_Block where dummy_f is null ;
|
||||
update staging2.IHTEMT_EMT_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Weight_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,'IHTEMT_EMT_Weight_Block');
|
||||
|
||||
/*block starts - IHTEMT_EMT_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTEMT_EMT_Tyre_Details_Block';
|
||||
|
||||
insert into staging2.IHTEMT_EMT_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating,
|
||||
Load_Carrying_Capacity,
|
||||
Pressure_kg_cm2,
|
||||
Dynamic_rolling_radius,
|
||||
Static_rolling_radius,
|
||||
Wheel_rim_Make_size
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column14,column18}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column14::text,column18::text]) AS val
|
||||
FROM staging2.IHTEMT_EMT_Weight_Tyre_Int where block_row_number between 3 and 11
|
||||
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,a_9 text);
|
||||
|
||||
delete from staging2.IHTEMT_EMT_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTEMT_EMT_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Tyre_Details_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,'IHTEMT_EMT_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTEMT_EMT_Wheel_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTEMT_EMT_Wheel_Block';
|
||||
insert into staging2.IHTEMT_EMT_Wheel_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTEMT_EMT_Wheel_Block
|
||||
set Wheel_Base=(select column12 from
|
||||
staging2.IHTEMT_EMT_Weight_Tyre_Int
|
||||
where block_row_number=1 and column9='Wheel Base in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Wheel_Block
|
||||
set TCD=(select replace(column19,'mm','') from
|
||||
staging2.IHTEMT_EMT_Weight_Tyre_Int
|
||||
where block_row_number=1 and column16='TCD in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTEMT_EMT_Wheel_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_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,'IHTEMT_EMT_Wheel_Block');
|
||||
|
||||
/*block starts - IHTEMT_EMT_Steering_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Steering_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTEMT_EMT_Steering_Block';
|
||||
|
||||
insert into staging2.IHTEMT_EMT_Steering_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,
|
||||
column8,block_row_number
|
||||
from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_Steering'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTEMT_EMT_Steering_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Steering_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.IHTEMT_EMT_Steering_Block set trx_record =0 where block_row_number in (1,2,3);
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Steering_Block');
|
||||
|
||||
|
||||
/*block starts - IHTEMT_EMT_Pedal_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Pedal_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTEMT_EMT_Pedal_Block';
|
||||
insert into staging2.IHTEMT_EMT_Pedal_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,
|
||||
column8,block_row_number
|
||||
from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_Pedal'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTEMT_EMT_Pedal_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Pedal_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.IHTEMT_EMT_Pedal_Block set trx_record =0 where block_row_number in (1,2);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Pedal_Block');
|
||||
|
||||
/*block starts - IHTEMT_EMT_Brake_Pedal_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Brake_Pedal_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='IHTEMT_EMT_Brake_Pedal_Block';
|
||||
insert into staging2.IHTEMT_EMT_Brake_Pedal_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTEMT_EMT a
|
||||
where block_tag='IHTEMT_EMT_Brake_Pedal'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
update staging2.IHTEMT_EMT_Brake_Pedal_Block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Brake_Pedal_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.IHTEMT_EMT_Brake_Pedal_Block set trx_record =0 where block_row_number in (1,2,3,14);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTEMT_EMT_Brake_Pedal_Block');
|
||||
|
||||
/*block starts - IHTEMT_EMT_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTEMT_EMT_Footer_block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='IHTEMT_EMT_Footer_block';
|
||||
insert into staging2.IHTEMT_EMT_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set prepared_by=( select column6 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and lower(column2)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set reviewed_by=( select column6 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and lower(column2)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set approved_by=( select column6 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and lower(column2)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set comments=( select column2 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set rev1=( select column2 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set rev2=( select column8 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set rev3=( select column17 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set replaces=( select column18 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set revision_no=( select column18 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set prepared_date=( select column15 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set reviewed_date=( select column15 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block a
|
||||
set approved_date=( select column15 from staging2.stg_process_table_IHTEMT_EMT b
|
||||
where b.block_tag='IHTEMT_EMT_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTEMT_EMT_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTEMT_EMT_Footer_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,'IHTEMT_EMT_Footer_block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTEMT_EMT_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
433
onetime/dataloadfunctions/IHT/IHT_HAM_ODS.sql
Executable file
433
onetime/dataloadfunctions/IHT/IHT_HAM_ODS.sql
Executable file
@@ -0,0 +1,433 @@
|
||||
drop function if exists staging2.fn_IHTHAM_HAM_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_HAM_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTHAM_HAM_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTHAM
|
||||
Sheet Format: IHTHAM_HAM
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTHAM_HAM_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
acceptance_criteria,
|
||||
test_condition,
|
||||
remarks
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date::date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date::date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date::date,
|
||||
Test_End_Date::date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Acceptance_criteria,
|
||||
Objective,
|
||||
condition,
|
||||
Remarks
|
||||
from
|
||||
staging2.IHTHAM_HAM_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTHAM_HAM_footer_block b
|
||||
where a.file_sheet_mnemonic='IHTHAM_HAM' and trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_number_of_lug,
|
||||
tyre_number_of_no_load_lug_30m,
|
||||
tyre_lug_height,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating::numeric ,
|
||||
Load_Carrying_Capacity,
|
||||
pressure_kg_cm2::numeric ,
|
||||
No_of_lug::numeric,
|
||||
Number_of_no_load_lug_30m::numeric,
|
||||
Lug_Height::numeric,
|
||||
Dynamic_rolling_radius::numeric ,
|
||||
Wheel_rim_Make_size
|
||||
from staging2.IHTHAM_HAM_tyre_details_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model
|
||||
from
|
||||
staging2.IHTHAM_HAM_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when lower(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;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
low_idle_declared,
|
||||
low_idle_observed,
|
||||
high_idle_declared,
|
||||
high_idle_observed,
|
||||
rated_rpm,
|
||||
rated_rpm_observed,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
low_idle_declared,
|
||||
low_idle_observed::numeric,
|
||||
high_idle_declared,
|
||||
high_idle_observed::numeric,
|
||||
rated_rpm_declared::numeric,
|
||||
rated_rpm_observed::numeric,
|
||||
engine_to_pto_ratio
|
||||
from staging2.IHTHAM_HAM_engine_rpm_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_weight_reaction
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
front_reaction_kg,
|
||||
rear_reaction_kg,
|
||||
total_weight_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
test_condition,
|
||||
Front_weight::numeric,
|
||||
Rear_weight::numeric,
|
||||
Total_weight::numeric
|
||||
from staging2.IHTHAM_HAM_weight_block where trx_record=1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_atmospheric_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
ambient_temp_c,
|
||||
humidity_pct,
|
||||
wind_velocity_kmph,
|
||||
date_of_test,
|
||||
start_time,
|
||||
end_time
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Ambient_temp_C::numeric ,
|
||||
humidity::numeric ,
|
||||
wind_velocity,
|
||||
date::date,
|
||||
start_time::time,
|
||||
end_time::time
|
||||
from staging2.IHTHAM_HAM_atmos_cond_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_drawbar_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
required_pull_in_kg,
|
||||
required_power_in_hp,
|
||||
actual_pull_in_kg,
|
||||
actual_power_in_hp,
|
||||
calculated_hitch_height_mm,
|
||||
actual_hitch_height_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
test_condition,
|
||||
Required_pull_in_kg::numeric ,
|
||||
Required_Power_in_hp::numeric ,
|
||||
Actual_pull_in_kg::numeric ,
|
||||
actual_power_in_hp::numeric ,
|
||||
Calculated_hitch_heigh_mm::numeric ,
|
||||
Actual_hitch_height_mm::numeric
|
||||
from staging2.IHTHAM_ham_drawbar_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_hot_air_mapping_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
gear,
|
||||
load_kg,
|
||||
speed_kmph,
|
||||
speed_rpm,
|
||||
ambient_measured_temp_c,
|
||||
head_measured_temp_c,
|
||||
head_roa_c,
|
||||
chest_measured_temp_c,
|
||||
chest_roa_c,
|
||||
rh_leg_measured_temp_c,
|
||||
rh_leg_roa_c,
|
||||
lh_leg_measured_temp_c,
|
||||
lh_leg_roa_c,
|
||||
rh_hand_measured_temp_c,
|
||||
rh_hand_roa_c,
|
||||
lh_hand_measured_temp_c,
|
||||
lh_hand_roa_c,
|
||||
time_of_test,
|
||||
towards_main_security_gate_yn,
|
||||
time_diff_h_min
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column10::numeric ,
|
||||
column11::numeric ,
|
||||
column12::numeric ,
|
||||
column13::numeric ,
|
||||
column14::numeric ,
|
||||
column15::numeric ,
|
||||
column16::numeric ,
|
||||
column17::numeric ,
|
||||
column18::numeric ,
|
||||
column19::numeric ,
|
||||
column20::numeric ,
|
||||
column21::numeric ,
|
||||
column22::time ,column23 ,column24::time
|
||||
from staging2.IHTHAM_ham_results_block ihrb where trx_record=1 order by block_row_number;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_weight_reaction
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_atmospheric_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_drawbar_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_hot_air_mapping_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTHAM_HAM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
855
onetime/dataloadfunctions/IHT/IHT_HAM_STG2.sql
Executable file
855
onetime/dataloadfunctions/IHT/IHT_HAM_STG2.sql
Executable file
@@ -0,0 +1,855 @@
|
||||
drop function if exists staging2.fn_IHTHAM_HAM_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTHAM_HAM_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_IHTHAM_HAM_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHT
|
||||
Sheet Format: IHTHAM_HAM
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTHAM_HAM_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTHAM_HAM_block(1,2,'IHT','IHTHAM_HAM',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTHAM_HAM_H1_Int;
|
||||
truncate table staging2.IHTHAM_HAM_H1_block;
|
||||
truncate table staging2.IHTHAM_HAM_Tyre_Details_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int;
|
||||
truncate table staging2.IHTHAM_HAM_Engine_RPM_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Tractor_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Weight_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Drawbar_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Atmos_Cond_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Results_Block;
|
||||
truncate table staging2.IHTHAM_HAM_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTHAM_HAM;
|
||||
truncate table staging2.stg_process_table_IHTHAM_HAM;
|
||||
|
||||
|
||||
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 IHT */
|
||||
execute 'insert into staging2.stg_specific_table_IHTHAM_HAM
|
||||
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_IHTHAM_HAM;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHT HAM',
|
||||
detail = 'No data in table stg_specific_table_IHTHAM_HAM',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTHAM_HAM set column15='Objective'
|
||||
where lower(column15) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTHAM_HAM set column15='Acceptance criteria'
|
||||
where lower(column15) like 'acceptance criteria%';
|
||||
|
||||
|
||||
|
||||
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_IHTHAM_HAM b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTHAM_HAM a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTHAM_HAM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHAM_HAM 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 Request no.''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHAM_HAM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHAM_HAM 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)''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHAM_HAM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHAM_HAM 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=''Atmospheric condition''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHAM_HAM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHAM_HAM 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=''Gear''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHAM_HAM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHAM_HAM 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=''Prepared By''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column6 into __model from staging2.stg_process_table_IHTHAM_HAM a
|
||||
where block_tag='IHTHAM_HAM_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTHAM_HAM_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTHAM_HAM_H1_BLOCK';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_INT (c1,c2)
|
||||
select a.column3,column6 from staging2.stg_process_table_IHTHAM_HAM a where block_tag='IHTHAM_HAM_H1';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_INT (c1,c2)
|
||||
select a.column9,column12 from staging2.stg_process_table_IHTHAM_HAM a where block_tag='IHTHAM_HAM_H1';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_INT (c1,c2)
|
||||
select 'Objective',column15
|
||||
from staging2.stg_process_table_IHTHAM_HAM a
|
||||
where block_tag='IHTHAM_HAM_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTHAM_HAM a
|
||||
where column15='Objective'
|
||||
and block_tag='IHTHAM_HAM_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column15
|
||||
from staging2.stg_process_table_IHTHAM_HAM a
|
||||
where block_tag='IHTHAM_HAM_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTHAM_HAM a
|
||||
where column15='Acceptance criteria'
|
||||
and block_tag='IHTHAM_HAM_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_INT (c1,c2)
|
||||
select split_part(column3,':',1),split_part(column3,':',2)
|
||||
from staging2.stg_process_table_IHTHAM_HAM
|
||||
where block_tag='IHTHAM_HAM_Results' and block_row_number=49;
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_INT (c1,c2)
|
||||
select column3,column4
|
||||
from staging2.stg_process_table_IHTHAM_HAM
|
||||
where block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number=4;
|
||||
|
||||
update staging2.IHTHAM_HAM_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Test_standard_refer,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
condition
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTHAM_HAM_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
update staging2.IHTHAM_HAM_H1_Block
|
||||
set Sample_Receipt_Date=case
|
||||
when Sample_Receipt_Date like '%-%' then Sample_Receipt_Date::timestamptz
|
||||
else date '1899-12-30' + Sample_Receipt_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
update staging2.IHTHAM_HAM_H1_Block
|
||||
set Test_Report_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
update staging2.IHTHAM_HAM_H1_Block
|
||||
set Test_Start_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
update staging2.IHTHAM_HAM_H1_Block
|
||||
set Test_End_Date=case
|
||||
when Test_Report_Date like '%-%' then Test_Report_Date::timestamptz
|
||||
else date '1899-12-30' + Test_Report_Date::int * interval '1' day
|
||||
end;
|
||||
|
||||
|
||||
delete from staging2.IHTHAM_HAM_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTHAM_HAM_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_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,'IHTHAM_HAM_H1_BLOCK');
|
||||
|
||||
insert into staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
(
|
||||
column3,column4,column5,column6,column8,column9 ,
|
||||
column10,column11,column12,column13,
|
||||
column14,column15,column16,column17,
|
||||
column18,column19,column20,column21 ,
|
||||
column22,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column8,column9,
|
||||
column10,column11,column12,column13,
|
||||
column14,column15,column16,column17,
|
||||
column18,column19,column20,column21 ,
|
||||
column22,block_row_number
|
||||
from staging2.stg_process_table_IHTHAM_HAM a
|
||||
where block_tag='IHTHAM_HAM_Engine_Tyre_Weight'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int 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||'''';
|
||||
|
||||
/*block starts - IHTHAM_HAM_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTHAM_HAM_Tyre_Details_Block';
|
||||
insert into staging2.IHTHAM_HAM_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating,
|
||||
Load_Carrying_Capacity,
|
||||
pressure_kg_cm2,
|
||||
No_of_lug,
|
||||
Number_of_no_load_lug_30m,
|
||||
Lug_Height,
|
||||
Dynamic_rolling_radius,
|
||||
Wheel_rim_Make_size
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column15,column20}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column15::text,column20::text]) AS val
|
||||
FROM staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int where block_row_number between 4 and 14
|
||||
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,a_9 text,a_10 text,a_11 text);
|
||||
|
||||
|
||||
|
||||
delete from staging2.IHTHAM_HAM_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTHAM_HAM_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Tyre_Details_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,'IHTHAM_HAM_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTHAM_HAM_Engine_RPM_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTHAM_HAM_Engine_RPM_Block';
|
||||
insert into staging2.IHTHAM_HAM_Engine_RPM_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set low_idle_declared=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=2 and column3='Low Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set low_idle_observed=(select column8 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=2 and column3='Low Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set high_idle_declared=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=3 and column10='High Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set high_idle_observed=(select column8 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=3 and column3='High Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set rated_rpm_declared=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=4 and column3='Rated RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set rated_rpm_observed=(select column8 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=4 and column3='Rated RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block
|
||||
set Engine_to_PTO_Ratio=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=5 and column3='Engine to PTO Ratio')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Engine_RPM_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_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,'IHTHAM_HAM_Engine_RPM_Block');
|
||||
|
||||
|
||||
/*block starts -IHTHAM_HAM_Drawbar_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Drawbar_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTHAM_HAM_Drawbar_Block';
|
||||
|
||||
|
||||
insert into staging2.IHTHAM_HAM_Drawbar_Block(test_condition)
|
||||
select distinct column6 from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number between 9 and 14;
|
||||
|
||||
insert into staging2.IHTHAM_HAM_Drawbar_Block(test_condition)
|
||||
select distinct column8 from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number between 9 and 14;
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Required_pull_in_kg = (select column7
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='UB' and block_row_number =9);
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Required_Power_in_hp = (select column7
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='UB' and block_row_number =10);
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Actual_pull_in_kg = (select column7
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='UB' and block_row_number =11);
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set actual_power_in_hp = (select column7
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='UB' and block_row_number =12);
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Calculated_hitch_heigh_mm = (select column7
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='UB' and block_row_number =13);
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Actual_hitch_height_mm = (select column7
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='UB' and block_row_number =14);
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Required_pull_in_kg = (select column9
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='B' and block_row_number =9);
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Required_Power_in_hp = (select column9
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='B' and block_row_number =10);
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Actual_pull_in_kg = (select column9
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='B' and block_row_number =11);
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set actual_power_in_hp = (select column9
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='B' and block_row_number =12);
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Calculated_hitch_heigh_mm = (select column9
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='B' and block_row_number =13);
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block
|
||||
set Actual_hitch_height_mm = (select column9
|
||||
from staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where test_condition='B' and block_row_number =14);
|
||||
|
||||
update staging2.IHTHAM_HAM_Drawbar_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Drawbar_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,'IHTHAM_HAM_Drawbar_Block');
|
||||
|
||||
|
||||
|
||||
/*block starts - IHTHAM_HAM_Tractor_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Tractor_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTHAM_HAM_Tractor_Block';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_Tractor_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTHAM_HAM_Tractor_Block
|
||||
set Wheel_Base_mm=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=5 and column3='Wheel Base (mm)')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Tractor_Block
|
||||
set Engine_Power_hp=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=6 and column3='Engine Power hp')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Tractor_Block
|
||||
set PTO_Power_hp=(select column6 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=7 and column3='PTO Power hp')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Tractor_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Tractor_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,'IHTHAM_HAM_Tractor_Block');
|
||||
|
||||
/*block starts -IHTHAM_HAM_Weight_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTHAM_HAM_Weight_Block';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_Weight_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set test_condition=(select column10 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=2 )
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set test_condition=(select column10 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set Front_weight=(select column13 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=2 and column14='Unballast')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set Front_weight=(select column13 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=3 and column14='Ballast')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set Rear_weight=(select column17 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=2 and column14='Unballast')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set Rear_weight=(select column17 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=3 and column14='Ballast')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set Total_weight=(select column21 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=2 and column14='Unballast')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block
|
||||
set Total_weight=(select column21 from
|
||||
staging2.IHTHAM_HAM_Engine_Tyre_Weight_Int
|
||||
where block_row_number=3 and column14='Ballast')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Weight_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,'IHTHAM_HAM_Weight_Block');
|
||||
|
||||
|
||||
/*block starts - IHTHAM_HAM_Atmos_Cond_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Atmos_Cond_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='IHTHAM_HAM_Atmos_Cond_Block';
|
||||
insert into staging2.IHTHAM_HAM_Atmos_Cond_Block
|
||||
(
|
||||
dummy_f,
|
||||
Ambient_temp_C,
|
||||
humidity,
|
||||
wind_velocity
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text]) AS val
|
||||
FROM staging2.stg_process_table_ihtham_ham
|
||||
where block_tag=''IHTHAM_HAM_Atmos_Cond'' and block_row_number in (1,2,3)
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
update staging2.IHTHAM_HAM_Atmos_Cond_Block
|
||||
set date=
|
||||
(select date '1899-12-30' + column8::int * interval '1' day
|
||||
FROM staging2.stg_process_table_ihtham_ham
|
||||
where column7='Date' and block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number =1);
|
||||
|
||||
update staging2.IHTHAM_HAM_Atmos_Cond_Block
|
||||
set start_time=
|
||||
(select to_char(to_timestamp((column8::numeric)* 60),'HH12:MI')
|
||||
FROM staging2.stg_process_table_ihtham_ham
|
||||
where column7='Start Time' and block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number=2);
|
||||
|
||||
update staging2.IHTHAM_HAM_Atmos_Cond_Block
|
||||
set end_time=
|
||||
(select to_char(to_timestamp((column8::numeric)* 60),'HH12:MI')
|
||||
FROM staging2.stg_process_table_ihtham_ham
|
||||
where column7='End time' and block_tag='IHTHAM_HAM_Atmos_Cond' and block_row_number=3);
|
||||
|
||||
|
||||
|
||||
delete from staging2.IHTHAM_HAM_Atmos_Cond_Block where dummy_f is null ;
|
||||
update staging2.IHTHAM_HAM_Atmos_Cond_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Atmos_Cond_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,'IHTHAM_HAM_Atmos_Cond_Block');
|
||||
|
||||
|
||||
/*block starts - IHTHAM_HAM_Results_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Results_Block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='IHTHAM_HAM_Results_Block';
|
||||
insert into staging2.IHTHAM_HAM_Results_Block
|
||||
(
|
||||
column3,column4,column5,column6,
|
||||
column7,column8,column9,
|
||||
column10,column11,column12,
|
||||
column13,column14,column15,
|
||||
column16,column17,column18,
|
||||
column19,column20,column21,
|
||||
column22,column23,column24,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,
|
||||
column7,column8,column9,
|
||||
column10,column11,column12,
|
||||
column13,column14,column15,
|
||||
column16,column17,column18,
|
||||
column19,column20,column21,
|
||||
column22,column23,column24,block_row_number
|
||||
from staging2.stg_process_table_IHTHAM_HAM a
|
||||
where block_tag='IHTHAM_HAM_Results'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Results_Block
|
||||
set trx_record =0 where block_row_number in (1,2,49,50,51);
|
||||
|
||||
update staging2.ihtham_ham_results_block a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.ihtham_ham_results_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTHAM_HAM_Results_Block
|
||||
set column22= to_char((column22::numeric) * '24 hours'::interval,'HH12:MIPM')
|
||||
where trx_record=1;
|
||||
|
||||
--select to_char((3.4722222222222654E-3) * '24 hours'::interval,'HH12:MI')
|
||||
|
||||
--select to_timestamp(cast('3.4722222222222654E-3' as real));
|
||||
|
||||
update staging2.IHTHAM_HAM_Results_Block
|
||||
set column24= to_char((cast(column24 as real)) * '24 hours'::interval,'HH24:MI')
|
||||
where trx_record=1;
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Results_Block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Results_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,'IHTHAM_HAM_Results_Block');
|
||||
|
||||
/*block starts - IHTHAM_HAM_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHAM_HAM_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9);
|
||||
err_block:='IHTHAM_HAM_Footer_block';
|
||||
|
||||
insert into staging2.IHTHAM_HAM_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set prepared_by=( select column7 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set reviewed_by=( select column7 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set approved_by=( select column7 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and lower(column3)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set rev2=( select column9 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set rev3=( select column18 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set replaces=( select column23 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set revision_no=( select column23 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set prepared_date=( select column19 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set reviewed_date=( select column19 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block a
|
||||
set approved_date=( select column19 from staging2.stg_process_table_IHTHAM_HAM b
|
||||
where b.block_tag='IHTHAM_HAM_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHAM_HAM_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTHAM_HAM_Footer_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,'IHTHAM_HAM_Footer_block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTHAM_HAM_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
|
||||
306
onetime/dataloadfunctions/IHT/IHT_HLS_ODS.sql
Executable file
306
onetime/dataloadfunctions/IHT/IHT_HLS_ODS.sql
Executable file
@@ -0,0 +1,306 @@
|
||||
drop function if exists staging2.fn_IHTHLS_HLS_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTHLS_HLS_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_instance_tractor_id int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTHLS_HLS_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTHLS
|
||||
Sheet Format: IHTHLS_HLS
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTHLS_HLS_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
test_purpose
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date,
|
||||
No_of_Sample,
|
||||
to_date(Test_Start_Date,'DD-MM-YYYY'),
|
||||
to_date(Test_End_Date, 'DD-MM-YYYY'),
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
from staging2.IHTHLS_HLS_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTHLS_HLS_footer_block b
|
||||
where a.file_sheet_mnemonic ='IHTHLS_HLS' and trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_static_rolling_radius_mm,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
load_carrying_capacity,
|
||||
Pressure_kg_cm2::numeric ,
|
||||
Dynamic_rolling_radius::numeric ,
|
||||
Static_rolling_radius::numeric ,
|
||||
wheel_rim_make_size
|
||||
from staging2.IHTHLS_HLS_tyre_details_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
wheel_base_mm,
|
||||
rear_track_width_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
wheel_base::numeric ,
|
||||
rear_track_width::numeric
|
||||
from staging2.IHTHLS_hls_wheel_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;
|
||||
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_weight_reaction
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
total_weight_kg,
|
||||
front_reaction_kg,
|
||||
rear_reaction_kg,
|
||||
left_reaction_fl_rl_kg,
|
||||
right_reaction_fr_rr_kg,
|
||||
front_left_reaction_kg,
|
||||
front_right_reactionkg,
|
||||
rear_left_reaction_kg,
|
||||
rear_right_reactionkg,
|
||||
distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg::numeric,
|
||||
Front_Reaction_kg::numeric ,
|
||||
Rear_Reaction_kg::numeric ,
|
||||
Left_Reaction_FL_RL_kg::numeric ,
|
||||
Right_reaction_FR_RR_kg::numeric ,
|
||||
Front_Left_Reaction_kg::numeric ,
|
||||
Front_Right_Reaction_kg::numeric ,
|
||||
Rear_Left_Reaction_kg::numeric ,
|
||||
Rear_Right_Reaction_kg::numeric ,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1::numeric
|
||||
from staging2.IHTHLS_hls_weight_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.IHT_hyd_lift_sensitivity
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tpl_load,
|
||||
engine_rpm_type,
|
||||
lifting_time_sec,
|
||||
lowering_time_sec
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
TPL_load,
|
||||
Engine_RPM,
|
||||
Lifting_time_Sec::numeric ,
|
||||
Lowering_time_Sec::numeric
|
||||
from staging2.IHTHLS_hls_numeric_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_weight_reaction
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_hyd_lift_sensitivity
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTHLS_HLS_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
571
onetime/dataloadfunctions/IHT/IHT_HLS_STG2.sql
Executable file
571
onetime/dataloadfunctions/IHT/IHT_HLS_STG2.sql
Executable file
@@ -0,0 +1,571 @@
|
||||
drop function if exists staging2.fn_IHTHLS_HLS_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTHLS_HLS_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_IHTHLS_HLS_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHTHLS
|
||||
Sheet Format: IHTHLS_HLS
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTHLS_HLS_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTHLS_HLS_block(1,2,'IHTHLS','IHTHLS_HLS',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTHLS_HLS_H1_Int;
|
||||
truncate table staging2.IHTHLS_HLS_H1_block;
|
||||
truncate table staging2.IHTHLS_HLS_Weight_Tyre_Int;
|
||||
truncate table staging2.IHTHLS_HLS_Weight_Block;
|
||||
truncate table staging2.IHTHLS_HLS_Wheel_Block;
|
||||
truncate table staging2.IHTHLS_HLS_Numeric_Int;
|
||||
truncate table staging2.IHTHLS_HLS_Numeric_Block;
|
||||
truncate table staging2.IHTHLS_HLS_Tyre_Details_Block;
|
||||
truncate table staging2.IHTHLS_HLS_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTHLS_HLS;
|
||||
truncate table staging2.stg_process_table_IHTHLS_HLS;
|
||||
|
||||
|
||||
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 IHTHLS */
|
||||
execute 'insert into staging2.stg_specific_table_IHTHLS_HLS
|
||||
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_IHTHLS_HLS;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHTHLS ',
|
||||
detail = 'No data in table stg_specific_table_IHTHLS_HLS',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTHLS_HLS
|
||||
set column15='Objective' where lower(column15) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTHLS_HLS
|
||||
set column15='Acceptance criteria' where lower(column15) like 'acceptance criteria%';
|
||||
|
||||
|
||||
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_IHTHLS_HLS b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTHLS_HLS a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTHLS_HLS
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHLS_HLS 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 Request no.''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHLS_HLS
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHLS_HLS 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=''Weight Reaction''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHLS_HLS
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHLS_HLS 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=''Numerical data''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTHLS_HLS
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTHLS_HLS 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=''Prepared By''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column6 into __model from staging2.stg_process_table_IHTHLS_HLS a
|
||||
where block_tag='IHTHLS_HLS_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTHLS_HLS_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHLS_HLS_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTHLS_HLS_H1_BLOCK';
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_INT (c1,c2)
|
||||
select a.column3,column6 from staging2.stg_process_table_IHTHLS_HLS a where block_tag='IHTHLS_HLS_H1';
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_INT (c1,c2)
|
||||
select a.column9,column12 from staging2.stg_process_table_IHTHLS_HLS a where block_tag='IHTHLS_HLS_H1';
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_INT (c1,c2)
|
||||
select 'Objective',column15
|
||||
from staging2.stg_process_table_IHTHLS_HLS a
|
||||
where block_tag='IHTHLS_HLS_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTHLS_HLS a
|
||||
where column15='Objective'
|
||||
and block_tag='IHTHLS_HLS_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column15
|
||||
from staging2.stg_process_table_IHTHLS_HLS a
|
||||
where block_tag='IHTHLS_HLS_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTHLS_HLS a
|
||||
where column15='Acceptance criteria'
|
||||
and block_tag='IHTHLS_HLS_H1'
|
||||
);
|
||||
|
||||
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_INT (c1,c2)
|
||||
select split_part(column3,':',1),split_part(column3,':',2)
|
||||
from staging2.stg_process_table_IHTHLS_HLS
|
||||
where block_tag='IHTHLS_HLS_Numeric' and block_row_number=6;
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_INT (c1,c2)
|
||||
select 'Test Purpose',column10
|
||||
from staging2.stg_process_table_IHTHLS_HLS a
|
||||
where block_tag='IHTHLS_HLS_Weight_Tyre' and column3='Test Purpose';
|
||||
|
||||
|
||||
update staging2.IHTHLS_HLS_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTHLS_HLS_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTHLS_HLS_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
|
||||
delete from staging2.IHTHLS_HLS_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTHLS_HLS_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_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,'IHTHLS_HLS_H1_Block');
|
||||
|
||||
|
||||
insert into staging2.IHTHLS_HLS_Weight_Tyre_Int
|
||||
(
|
||||
column3,column6,column10,column13,column15,column17,column19,
|
||||
column20,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column6,column10,column13,column15,column17,column19,
|
||||
column20,block_row_number
|
||||
from staging2.stg_process_table_IHTHLS_HLS a
|
||||
where block_tag='IHTHLS_HLS_Weight_Tyre'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTHLS_HLS_Weight_Tyre_Int set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_Weight_Tyre_Int 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||'''';
|
||||
|
||||
|
||||
/*block starts - IHTHLS_HLS_Weight_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHLS_HLS_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTHLS_HLS_Weight_Block';
|
||||
insert into staging2.IHTHLS_HLS_Weight_Block
|
||||
(
|
||||
dummy_f,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg,
|
||||
Front_Reaction_kg,
|
||||
Rear_Reaction_kg,
|
||||
Left_Reaction_FL_RL_kg,
|
||||
Right_reaction_FR_RR_kg,
|
||||
Front_Left_Reaction_kg,
|
||||
Front_Right_Reaction_kg,
|
||||
Rear_Left_Reaction_kg,
|
||||
Rear_Right_Reaction_kg,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column6::text]) AS val
|
||||
FROM staging2.IHTHLS_HLS_Weight_Tyre_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);
|
||||
|
||||
delete from staging2.IHTHLS_HLS_Weight_Block where dummy_f is null ;
|
||||
update staging2.IHTHLS_HLS_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_Weight_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,'IHTHLS_HLS_Weight_Block');
|
||||
|
||||
/*block starts - IHTHLS_HLS_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHLS_HLS_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTHLS_HLS_Tyre_Details_Block';
|
||||
insert into staging2.IHTHLS_HLS_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating,
|
||||
Load_Carrying_Capacity,
|
||||
Pressure_kg_cm2,
|
||||
Dynamic_rolling_radius,
|
||||
Static_rolling_radius,
|
||||
Wheel_rim_Make_size
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column15,column19}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column15::text,column19::text]) AS val
|
||||
FROM staging2.IHTHLS_HLS_Weight_Tyre_Int where block_row_number between 3 and 11
|
||||
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,a_9 text);
|
||||
|
||||
delete from staging2.IHTHLS_HLS_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTHLS_HLS_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_Tyre_Details_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,'IHTHLS_HLS_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTHLS_HLS_Wheel_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHLS_HLS_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTHLS_HLS_Wheel_Block';
|
||||
insert into staging2.IHTHLS_HLS_Wheel_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTHLS_HLS_Wheel_Block
|
||||
set Wheel_Base=(select column13 from
|
||||
staging2.IHTHLS_HLS_Weight_Tyre_Int
|
||||
where block_row_number=1 and column10='Wheel Base in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Wheel_Block
|
||||
set Rear_Track_Width=(select column20 from
|
||||
staging2.IHTHLS_HLS_Weight_Tyre_Int
|
||||
where block_row_number=1 and column17='Rear Track Width in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHLS_HLS_Wheel_Block set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_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,'IHTHLS_HLS_Wheel_Block');
|
||||
|
||||
|
||||
/* insert IHTHLS_HLS_Numeric_Int*/
|
||||
|
||||
insert into staging2.IHTHLS_HLS_Numeric_Int
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
from staging2.stg_process_table_IHTHLS_HLS a
|
||||
where block_tag='IHTHLS_HLS_Numeric'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTHLS_HLS_Numeric_Int set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_Numeric_Int 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.IHTHLS_HLS_Numeric_Int set trx_record =0 where block_row_number in (1,6);
|
||||
|
||||
|
||||
/*block starts - IHTHLS_HLS_Numeric_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHLS_HLS_Numeric_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTHLS_HLS_Numeric_Block';
|
||||
insert into staging2.IHTHLS_HLS_Numeric_Block
|
||||
(
|
||||
dummy_f,
|
||||
TPL_load,
|
||||
Engine_RPM,
|
||||
Lifting_time_Sec,
|
||||
Lowering_time_Sec
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column8::text]) AS val
|
||||
FROM staging2.IHTHLS_HLS_Numeric_Int
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text,a_4 text);
|
||||
|
||||
update staging2.IHTHLS_hls_numeric_block a
|
||||
set TPL_load= b.first_value from (SELECT
|
||||
block_row_number,TPL_load, value_partition, first_value(TPL_load) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
TPL_load,
|
||||
sum(case when TPL_load is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTHLS_hls_numeric_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b;
|
||||
|
||||
delete from staging2.IHTHLS_HLS_Numeric_Block where dummy_f is null;
|
||||
update staging2.IHTHLS_HLS_Numeric_Block set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_Numeric_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,'IHTHLS_HLS_Numeric_Block');
|
||||
|
||||
/*block starts - IHTHLS_HLS_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTHLS_HLS_Footer_block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTHLS_HLS_Footer_block';
|
||||
insert into staging2.IHTHLS_HLS_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set prepared_by=( select column7 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set reviewed_by=( select column7 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set approved_by=( select column7 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and lower(column3)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set rev2=( select column9 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set rev3=( select column18 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set replaces=( select column19 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set revision_no=( select column19 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set prepared_date=( select column16 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set reviewed_date=( select column16 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block a
|
||||
set approved_date=( select column16 from staging2.stg_process_table_IHTHLS_HLS b
|
||||
where b.block_tag='IHTHLS_HLS_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTHLS_HLS_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTHLS_HLS_Footer_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,'IHTHLS_HLS_Footer_block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTHLS_HLS_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
603
onetime/dataloadfunctions/IHT/IHT_NST_ODS.sql
Executable file
603
onetime/dataloadfunctions/IHT/IHT_NST_ODS.sql
Executable file
@@ -0,0 +1,603 @@
|
||||
drop function if exists staging2.fn_IHTNST_NST_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_NST_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_IHTNST_NST_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTNST
|
||||
Sheet Format: IHTNST_NST
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTNST_NST_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
test_condition,
|
||||
test_purpose
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date,
|
||||
No_of_Sample,
|
||||
date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date,
|
||||
date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_facility,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
condition,
|
||||
Test_Purpose
|
||||
from
|
||||
staging2.IHTNST_NST_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTNST_nst_footer_block b
|
||||
where a.file_sheet_mnemonic='IHTNST_NST' and trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_wheel_rim_make_and_size
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric ,
|
||||
load_carrying_capacity,
|
||||
wheel_rim_make_size
|
||||
from staging2.IHTNST_nst_tyre_details_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
low_idle_declared,
|
||||
low_idle_observed,
|
||||
high_idle_declared,
|
||||
high_idle_observed,
|
||||
rated_rpm,
|
||||
rated_rpm_observed,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
low_idle_declared,
|
||||
low_idle_observed::numeric,
|
||||
high_idle_declared,
|
||||
high_idle_observed::numeric,
|
||||
rated_rpm_declared::numeric,
|
||||
rated_rpm_observed::numeric,
|
||||
engine_to_pto_ratio
|
||||
from staging2.IHTNST_nst_engine_rpm_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
weight_reactions_front_kg,
|
||||
tractor_weight_front_observed_kg,
|
||||
tractor_weight_front_remark,
|
||||
weight_reactions_rear_kg,
|
||||
tractor_weight_rear_observed_kg,
|
||||
tractor_weight_rear_remark,
|
||||
tractor_weight_total_kg,
|
||||
tractor_weight_total_observed_kg,
|
||||
tractor_weight_total_remark
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
front_weight_declared::numeric ,
|
||||
front_weight_observed::numeric,
|
||||
front_weight_remark,
|
||||
rear_weight_declared::numeric,
|
||||
rear_weight_observed::numeric,
|
||||
rear_weight_remark,
|
||||
total_weight_declared::numeric,
|
||||
total_weight_observed::numeric,
|
||||
total_weight_remark
|
||||
from staging2.IHTNST_nst_weight_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;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_atmospheric_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
ambient_temp_c,
|
||||
humidity_pct,
|
||||
pressure_kpa,
|
||||
background_noise_dba,
|
||||
wind_velocity_kmph
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
ambient_temp_c::numeric,
|
||||
humidity::numeric,
|
||||
pressure_kpa::numeric,
|
||||
background_noise::numeric,
|
||||
wind_velocity
|
||||
from staging2.IHTNST_nst_atmos_cond_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_noise_measurement_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_type,
|
||||
test_mode,
|
||||
gear,
|
||||
noise_level_1_db_a,
|
||||
noise_level_2_db_a,
|
||||
noise_level_3_db_a
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column1,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric
|
||||
from staging2.IHTNST_nst_stand_noise_block where trx_record=1;
|
||||
|
||||
update transactional.IHT_noise_measurement_results
|
||||
set test_condition = (select column4
|
||||
from staging2.IHTNST_nst_stand_noise_block
|
||||
where block_row_number=3) where file_syspk = __file_syspk;
|
||||
|
||||
insert into transactional.IHT_noise_measurement_test
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
from transactional.IHT_noise_measurement_results where test_type='BY STANDER’S NOISE';
|
||||
|
||||
update transactional.IHT_noise_measurement_test
|
||||
set acceptance_criteria=b.acceptance_criteria,
|
||||
remarks =b.remarks
|
||||
from staging2.IHTNST_nst_stand_noise_block b
|
||||
where b.column1 ='BY STANDER’S NOISE' and test_type='BY STANDER’S NOISE' and trx_record=1;
|
||||
|
||||
insert into transactional.IHT_noise_measurement_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_type,
|
||||
test_mode,
|
||||
gear,
|
||||
noise_level_1_db_a,
|
||||
noise_level_2_db_a,
|
||||
noise_level_3_db_a
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column1,
|
||||
column2,
|
||||
column3,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric
|
||||
from staging2.IHTNST_nst_stand_noise_block where trx_record=1;
|
||||
|
||||
update transactional.IHT_noise_measurement_results
|
||||
set test_condition = (select column7
|
||||
from staging2.IHTNST_nst_stand_noise_block
|
||||
where block_row_number=3) where test_condition is null;
|
||||
|
||||
insert into transactional.IHT_noise_measurement_test
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
from transactional.IHT_noise_measurement_results where test_type='BY STANDER’S NOISE';
|
||||
|
||||
update transactional.IHT_noise_measurement_test
|
||||
set acceptance_criteria=b.acceptance_criteria,
|
||||
remarks =b.remarks
|
||||
from staging2.IHTNST_nst_stand_noise_block b
|
||||
where b.column1 ='BY STANDER’S NOISE' and test_type='BY STANDER’S NOISE' and trx_record=1;
|
||||
|
||||
insert into transactional.IHT_noise_measurement_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_type,
|
||||
test_mode,
|
||||
gear,
|
||||
load_kg,
|
||||
speed_kmph,
|
||||
speed_rpm,
|
||||
noise_level_1_db_a,
|
||||
noise_level_2_db_a,
|
||||
noise_level_3_db_a
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column1,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric
|
||||
from staging2.IHTNST_nst_oel_noise_block where trx_record=1;
|
||||
|
||||
update transactional.IHT_noise_measurement_test
|
||||
set acceptance_criteria=b.acceptance_criteria,
|
||||
remarks =b.remarks
|
||||
from staging2.IHTNST_nst_oel_noise_block b
|
||||
where b.column1 ='OEL Noise without Load' and test_type='OEL Noise without Load';
|
||||
|
||||
insert into transactional.IHT_noise_measurement_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_type,
|
||||
test_mode,
|
||||
gear,
|
||||
load_kg,
|
||||
speed_kmph,
|
||||
speed_rpm,
|
||||
noise_level_1_db_a,
|
||||
noise_level_2_db_a,
|
||||
noise_level_3_db_a
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column1,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric
|
||||
from staging2.IHTNST_nst_oel_noise_load_block where trx_record=1;
|
||||
|
||||
update transactional.IHT_noise_measurement_test
|
||||
set acceptance_criteria=b.acceptance_criteria,
|
||||
remarks =b.remarks
|
||||
from staging2.IHTNST_nst_oel_noise_load_block b
|
||||
where b.column1 ='OEL Noise with Load' and test_type='OEL Noise with Load';
|
||||
|
||||
insert into transactional.IHT_noise_measurement_test
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
from transactional.IHT_noise_measurement_results where test_type ='OEL Noise without Load' ;
|
||||
|
||||
insert into transactional.IHT_noise_measurement_test
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
test_mode
|
||||
from transactional.IHT_noise_measurement_results where test_type ='OEL Noise with Load';
|
||||
|
||||
delete from transactional.IHT_noise_measurement_test a
|
||||
using transactional.IHT_noise_measurement_test b
|
||||
where (a.syspk < b.syspk and
|
||||
a.test_condition is not null and
|
||||
a.test_condition =b.test_condition and
|
||||
a.test_mode =b.test_mode and a.test_type=b.test_type) or
|
||||
(a.syspk < b.syspk and a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type);
|
||||
|
||||
update transactional.IHT_noise_measurement_results a
|
||||
set noise_measurement_id =(select syspk
|
||||
from transactional.IHT_noise_measurement_test b
|
||||
where (a.test_condition =b.test_condition and a.test_condition is not null and
|
||||
a.test_mode =b.test_mode and a.test_type=b.test_type) or
|
||||
(a.test_condition is null and a.test_mode =b.test_mode and a.test_type=b.test_type));
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_atmospheric_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_noise_measurement_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_noise_measurement_test
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTNST_NST_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
917
onetime/dataloadfunctions/IHT/IHT_NST_STG2.sql
Executable file
917
onetime/dataloadfunctions/IHT/IHT_NST_STG2.sql
Executable file
@@ -0,0 +1,917 @@
|
||||
drop function if exists staging2.fn_IHTNST_NST_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTNST_NST_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_IHTNST_NST_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHTNST
|
||||
Sheet Format: IHTNST_NST
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTNST_NST_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTNST_NST_block(1,2,'IHTNST','IHTNST_NST',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTNST_NST_H1_Int;
|
||||
truncate table staging2.IHTNST_NST_H1_block;
|
||||
truncate table staging2.IHTNST_NST_Tyre_Details_Block;
|
||||
truncate table staging2.IHTNST_NST_Engine_RPM_Atmos_Int;
|
||||
truncate table staging2.IHTNST_NST_Engine_RPM_Block;
|
||||
truncate table staging2.IHTNST_NST_Weight_Block;
|
||||
truncate table staging2.IHTNST_NST_Atmos_Cond_Block;
|
||||
truncate table staging2.IHTNST_NST_STAND_Noise_Block;
|
||||
truncate table staging2.IHTNST_NST_OEL_Noise_Block;
|
||||
truncate table staging2.IHTNST_NST_OEL_Noise_Load_Block;
|
||||
truncate table staging2.IHTNST_NST_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTNST_NST;
|
||||
truncate table staging2.stg_process_table_IHTNST_NST;
|
||||
|
||||
|
||||
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 IHTNST */
|
||||
execute 'insert into staging2.stg_specific_table_IHTNST_NST
|
||||
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_IHTNST_NST;
|
||||
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHT NST',
|
||||
detail = 'No data in table stg_specific_table_IHTNST_NST',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTNST_NST set column8='Objective' where lower(column8) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTNST_NST set column8='Condition' where lower(column8) like 'condition%';
|
||||
|
||||
update staging2.stg_specific_table_IHTNST_NST set column3='Remarks' where lower(column3) like 'remarks%';
|
||||
|
||||
update staging2.stg_specific_table_IHTNST_NST set column7='Acceptance Criteria'
|
||||
where lower(column7) like 'acceptance criteria%';
|
||||
|
||||
|
||||
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_IHTNST_NST b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTNST_NST a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Prepared by''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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 Request No''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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=''Tyre Details''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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=''BY STANDER’S NOISE''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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=''OEL Noise without Load''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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=''OEL Noise with Load''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTNST_NST
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTNST_NST 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=''Prepared by''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column4 into __model from staging2.stg_process_table_IHTNST_nst a
|
||||
where block_tag='IHTNST_NST_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTNST_NST_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTNST_NST_H1_BLOCK';
|
||||
insert into staging2.IHTNST_NST_H1_INT (c1,c2)
|
||||
select a.column3,column4 from staging2.stg_process_table_IHTNST_NST a where block_tag='IHTNST_NST_H1';
|
||||
|
||||
insert into staging2.IHTNST_NST_H1_INT (c1,c2)
|
||||
select a.column6,column7 from staging2.stg_process_table_IHTNST_NST a where block_tag='IHTNST_NST_H1';
|
||||
|
||||
insert into staging2.IHTNST_NST_H1_INT (c1,c2)
|
||||
select 'Objective',column8
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where column8='Objective'
|
||||
and block_tag='IHTNST_NST_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTNST_NST_H1_INT (c1,c2)
|
||||
select 'Condition',column8
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_Tyre_Details'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where column8='Condition'
|
||||
and block_tag='IHTNST_NST_Tyre_Details'
|
||||
);
|
||||
|
||||
insert into staging2.IHTNST_NST_H1_INT (c1,c2)
|
||||
select 'Test Purpose',column6
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where column3='Test Purpose' and block_tag ='IHTNST_NST_Engine_RPM_Atmos';
|
||||
|
||||
|
||||
update staging2.IHTNST_NST_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTNST_NST_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Facility,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Test_standard_refer,
|
||||
Objective,
|
||||
condition,
|
||||
Test_Purpose
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTNST_NST_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
|
||||
delete from staging2.IHTNST_NST_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTNST_NST_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_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,'IHTNST_NST_H1_BLOCK');
|
||||
|
||||
/*block starts - IHTNST_NST_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTNST_NST_Tyre_Details_Block';
|
||||
|
||||
insert into staging2.IHTNST_NST_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating,
|
||||
Load_Carrying_Capacity,
|
||||
Wheel_rim_Make_size
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column4,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column4::text,column6::text]) AS val
|
||||
FROM staging2.stg_process_table_IHTNST_NST where block_tag=''IHTNST_NST_Tyre_Details''
|
||||
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);
|
||||
|
||||
update staging2.IHTNST_NST_Tyre_Details_Block
|
||||
set ply_rating =replace(ply_rating,' Ply','');
|
||||
|
||||
delete from staging2.IHTNST_NST_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTNST_NST_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_Tyre_Details_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,'IHTNST_NST_Tyre_Details_Block');
|
||||
|
||||
|
||||
/* inserting Engine_RPM_Atmos_INT */
|
||||
|
||||
insert into staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_Engine_RPM_Atmos'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column8=(select column6 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=9) where block_row_number=5;
|
||||
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column6 = null where block_row_number=9;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column9=(select column7 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=9) where block_row_number=5;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column7=null where block_row_number=9;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column8=(select column8 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=9)where block_row_number=6;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column8 =null where block_row_number=9;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column9=(select column9 from staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=9)where block_row_number=6;
|
||||
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
set column9 =null where block_row_number=9;
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Atmos_Int set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_Engine_RPM_Atmos_Int 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||'''';
|
||||
|
||||
/*block starts - IHTNST_NST_Engine_RPM_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_Engine_RPM_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTNST_NST_Engine_RPM_Block';
|
||||
insert into staging2.IHTNST_NST_Engine_RPM_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set low_idle_declared=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=2 and column3='Low Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set low_idle_observed=(select column6 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=2 and column3='Low Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set high_idle_declared=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=3 and column3='High IdleRPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set high_idle_observed=(select column6 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=3 and column3='High IdleRPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set rated_rpm_declared=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=4 and column3='Rated RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set rated_rpm_observed=(select column6 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=4 and column3='Rated RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set Engine_to_PTO_Ratio=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=9 and column3='Engine to PTO Ratio')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set low_idle_remark= (select column7
|
||||
FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=2 and column3='Low Idle RPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block
|
||||
set high_idle_remark= (select column7
|
||||
FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=3 and column3='High IdleRPM')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTNST_NST_Engine_RPM_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_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,'IHTNST_NST_Engine_RPM_Block');
|
||||
|
||||
/*block starts -IHTNST_NST_Weight_Block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTNST_NST_Weight_Block';
|
||||
insert into staging2.IHTNST_NST_Weight_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set Front_weight_declared=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=6 and column3='Front')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set Front_weight_observed=(select column6 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=6 and column3='Front')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set Rear_weight_declared=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=7 and column3='Rear')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set Rear_weight_observed=(select column6 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=7 and column3='Rear')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set Total_weight_declared=(select column4 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=8 and column3='Total')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set Total_weight_observed=(select column6 from
|
||||
staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=8 and column3='Total')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set front_weight_remark= (select column7
|
||||
FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=6 and column3='Front')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set rear_weight_remark= (select column7
|
||||
FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=7 and column3='Rear')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block
|
||||
set total_weight_remark= (select column7
|
||||
FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int
|
||||
where block_row_number=8 and column3='Total')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTNST_NST_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_Weight_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,'IHTNST_NST_Weight_Block');
|
||||
|
||||
|
||||
/*block starts - IHTNST_NST_Atmos_Cond_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_Atmos_Cond_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTNST_NST_Atmos_Cond_Block';
|
||||
insert into staging2.IHTNST_NST_Atmos_Cond_Block
|
||||
(
|
||||
dummy_f,
|
||||
Ambient_temp_C,
|
||||
humidity,
|
||||
Pressure_kPa,
|
||||
Background_Noise,
|
||||
wind_velocity
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column9}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column9::text]) AS val
|
||||
FROM staging2.IHTNST_NST_Engine_RPM_Atmos_Int where block_row_number between 2 and 6
|
||||
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);
|
||||
|
||||
delete from staging2.IHTNST_NST_Atmos_Cond_Block where dummy_f is null ;
|
||||
update staging2.IHTNST_NST_Atmos_Cond_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_Atmos_Cond_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,'IHTNST_NST_Atmos_Cond_Block');
|
||||
|
||||
|
||||
/*block starts - IHTNST_NST_STAND_Noise_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_STAND_Noise_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='IHTNST_NST_STAND_Noise_Block';
|
||||
insert into staging2.IHTNST_NST_STAND_Noise_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_STAND_Noise'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block
|
||||
set column2=column3 where column4 is null and block_row_number in (2,6);
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block
|
||||
set column1=column3 where column4 is null and block_row_number =1;
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block a
|
||||
set column1= b.first_value from (SELECT
|
||||
block_row_number, column1, value_partition, first_value(column1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column1,
|
||||
sum(case when column1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTNST_NST_STAND_Noise_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTNST_NST_STAND_Noise_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block
|
||||
set trx_record=0 where block_row_number <>5;
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block
|
||||
set remarks=(select column3
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_STAND_Noise' and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where lower(column3)='remarks'
|
||||
and block_tag='IHTNST_NST_STAND_Noise'
|
||||
));
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block
|
||||
set acceptance_criteria=(select column7
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_STAND_Noise' and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where lower(column7)='acceptance criteria'
|
||||
and block_tag='IHTNST_NST_STAND_Noise'
|
||||
));
|
||||
|
||||
update staging2.IHTNST_NST_STAND_Noise_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_STAND_Noise_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,'IHTNST_NST_STAND_Noise_Block');
|
||||
|
||||
|
||||
/*block starts - IHTNST_NST_OEL_Noise_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_OEL_Noise_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='IHTNST_NST_OEL_Noise_Block';
|
||||
insert into staging2.IHTNST_NST_OEL_Noise_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_OEL_Noise'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block
|
||||
set column2=column3 where column4 is null and block_row_number in (2,8,14);
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block
|
||||
set column1=column3 where column4 is null and block_row_number =1;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block a
|
||||
set column1= b.first_value from (SELECT
|
||||
block_row_number, column1, value_partition, first_value(column1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column1,
|
||||
sum(case when column1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTNST_NST_OEL_Noise_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTNST_NST_OEL_Noise_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block
|
||||
set trx_record=0 where block_row_number in (1,2,3,4,8,9,10,14,15,16,17,18);
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block
|
||||
set remarks=(select column3
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_OEL_Noise' and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where lower(column3)='remarks'
|
||||
and block_tag='IHTNST_NST_OEL_Noise'
|
||||
));
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block
|
||||
set acceptance_criteria=(select column7
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_OEL_Noise' and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where lower(column7)='acceptance criteria'
|
||||
and block_tag='IHTNST_NST_OEL_Noise'
|
||||
));
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_OEL_Noise_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,'IHTNST_NST_OEL_Noise_Block');
|
||||
|
||||
/*block starts - IHTNST_NST_OEL_Noise_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_OEL_Noise_Load_Block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='IHTNST_NST_OEL_Noise_Load_Block';
|
||||
insert into staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_OEL_Noise_Load'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
set column2=column3 where column4 is null and block_row_number in (2,5,11);
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
set column1=column3 where column4 is null and block_row_number =1;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block a
|
||||
set column1= b.first_value from (SELECT
|
||||
block_row_number, column1, value_partition, first_value(column1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column1,
|
||||
sum(case when column1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
set trx_record=0 where block_row_number not in (8,9,10,14,15,16);
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
set remarks=(select column3
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_OEL_Noise_Load' and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where lower(column3)='remarks'
|
||||
and block_tag='IHTNST_NST_OEL_Noise_Load'
|
||||
));
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block
|
||||
set acceptance_criteria=(select column7
|
||||
from staging2.stg_process_table_IHTNST_NST a
|
||||
where block_tag='IHTNST_NST_OEL_Noise_Load' and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTNST_NST a
|
||||
where lower(column7)='acceptance criteria'
|
||||
and block_tag='IHTNST_NST_OEL_Noise_Load'
|
||||
));
|
||||
|
||||
update staging2.IHTNST_NST_OEL_Noise_Load_Block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_OEL_Noise_Load_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,'IHTNST_NST_OEL_Noise_Load_Block');
|
||||
|
||||
|
||||
|
||||
/*block starts - IHTNST_NST_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTNST_NST_Footer_block',__file_mnemonic,__file_sheet_mnemonic,9);
|
||||
err_block:='IHTNST_NST_Footer_block';
|
||||
|
||||
insert into staging2.IHTNST_NST_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set prepared_by=( select column4 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set reviewed_by=( select column4 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set approved_by=( select column4 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and lower(column3)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set rev2=( select column5 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set rev3=( select column8 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set replaces=( select column9 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set revision_no=( select column9 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set prepared_date=( select column8 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set reviewed_date=( select column8 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block a
|
||||
set approved_date=( select column8 from staging2.stg_process_table_IHTNST_NST b
|
||||
where b.block_tag='IHTNST_NST_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTNST_NST_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTNST_NST_Footer_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,'IHTNST_NST_Footer_block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTNST_NST_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
379
onetime/dataloadfunctions/IHT/IHT_SLL_ODS.sql
Executable file
379
onetime/dataloadfunctions/IHT/IHT_SLL_ODS.sql
Executable file
@@ -0,0 +1,379 @@
|
||||
drop function if exists staging2.fn_IHTSLL_SLL_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_SLL_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_IHTSLL_SLL_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: IHTSLL
|
||||
Sheet Format: IHTSLL_SLL
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTSLL_SLL_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
job_order_no,
|
||||
sample_receipt_date,
|
||||
test_report_no,
|
||||
generation,
|
||||
customer_name,
|
||||
test_engineer,
|
||||
test_report_date,
|
||||
no_of_sample,
|
||||
test_start_date,
|
||||
test_end_date,
|
||||
tractor_sr_no,
|
||||
test_standard_ref,
|
||||
test_location_name,
|
||||
test_operator,
|
||||
project_group,
|
||||
objective_of_test,
|
||||
acceptance_criteria,
|
||||
remarks,
|
||||
test_purpose
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Test_Request_no,
|
||||
date '1899-12-30' + sample_receipt_date::int * interval '1' day as Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
date '1899-12-30' + Test_Report_Date::int * interval '1' day as Test_Report_Date,
|
||||
No_of_Sample,
|
||||
date '1899-12-30' + Test_Start_Date::int * interval '1' day as Test_Start_Date,
|
||||
date '1899-12-30' + Test_End_Date::int * interval '1' day as Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
from staging2.IHTSLL_SLL_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set
|
||||
report_prepared_date=to_date(b.prepared_date,'DD-MM-YYYY'),
|
||||
report_reviewed_date=to_date(b.reviewed_date,'DD-MM-YYYY'),
|
||||
report_approved_date=to_date(b.approved_date,'DD-MM-YYYY'),
|
||||
report_prepared_by=b.prepared_by,
|
||||
report_reviewed_by=b.reviewed_by,
|
||||
report_approved_by=b.approved_by,
|
||||
report_template_replaces=b.replaces,
|
||||
report_title=b.comments,
|
||||
report_template_no=b.rev1,
|
||||
report_template_rev_date=b.rev2,
|
||||
report_template_rev_no= b.rev3
|
||||
from staging2.IHTSLL_SLL_footer_block b
|
||||
where a.file_sheet_mnemonic ='IHTSLL_SLL' and trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tyre_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tyre_type,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
tyre_ply_rating,
|
||||
tyre_load_carrying_capacity,
|
||||
tyre_pressure_kg_per_cm2,
|
||||
tyre_static_rolling_radius_mm,
|
||||
tyre_dynamic_rolling_radius_mm,
|
||||
tyre_wheel_rim_make_and_size
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
tyre_details,
|
||||
tyre_make,
|
||||
tyre_size,
|
||||
ply_rating::numeric,
|
||||
load_carrying_capacity,
|
||||
Pressure_kg_cm2::numeric ,
|
||||
Dynamic_rolling_radius::numeric ,
|
||||
Static_rolling_radius::numeric ,
|
||||
wheel_rim_make_size
|
||||
from staging2.IHTSLL_SLL_tyre_details_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
wheel_base_mm,
|
||||
rear_track_width_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
wheel_base::numeric ,
|
||||
rear_track_width::numeric
|
||||
from staging2.IHTSLL_SLL_wheel_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when lower(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;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.test_instance_weight_reaction
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
total_weight_kg,
|
||||
front_reaction_kg,
|
||||
rear_reaction_kg,
|
||||
left_reaction_fl_rl_kg,
|
||||
right_reaction_fr_rr_kg,
|
||||
front_left_reaction_kg,
|
||||
front_right_reactionkg,
|
||||
rear_left_reaction_kg,
|
||||
rear_right_reactionkg,
|
||||
distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg::numeric,
|
||||
Front_Reaction_kg::numeric ,
|
||||
Rear_Reaction_kg::numeric ,
|
||||
Left_Reaction_FL_RL_kg::numeric ,
|
||||
Right_reaction_FR_RR_kg::numeric ,
|
||||
Front_Left_Reaction_kg::numeric ,
|
||||
Front_Right_Reaction_kg::numeric ,
|
||||
Rear_Left_Reaction_kg::numeric ,
|
||||
Rear_Right_Reaction_kg::numeric ,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1::numeric
|
||||
from staging2.IHTSLL_SLL_weight_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.IHT_gear_max_speed
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
gear,
|
||||
low_1000_rpm,
|
||||
rated_2300_rpm,
|
||||
specification,
|
||||
high_2500_rpm,
|
||||
actual_speed_pct,
|
||||
diff_in_speed_kmph
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric ,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric
|
||||
from staging2.IHTSLL_sll_forward_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_gear_max_speed
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
gear,
|
||||
low_1000_rpm,
|
||||
rated_2300_rpm,
|
||||
specification,
|
||||
high_2500_rpm,
|
||||
actual_speed_pct,
|
||||
diff_in_speed_kmph
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric ,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric
|
||||
from staging2.IHTSLL_sll_reverse_block where trx_record=1;
|
||||
|
||||
insert into transactional.IHT_speed_lead_lag_measurement
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
gear,
|
||||
engine_rpm,
|
||||
wheel_drive_type,
|
||||
no_of_revolution_front,
|
||||
ratio,
|
||||
lead_lag_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,
|
||||
column4::numeric ,
|
||||
column5,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8
|
||||
from staging2.IHTSLL_sll_lead_lag_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='In House';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_weight_reaction
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_gear_max_speed
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.IHT_speed_lead_lag_measurement
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_IHTSLL_SLL_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
670
onetime/dataloadfunctions/IHT/IHT_SLL_STG2.sql
Executable file
670
onetime/dataloadfunctions/IHT/IHT_SLL_STG2.sql
Executable file
@@ -0,0 +1,670 @@
|
||||
drop function if exists staging2.fn_IHTSLL_SLL_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_IHTSLL_SLL_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_IHTSLL_SLL_block
|
||||
Function Desc: This function populates data into staging 2 block
|
||||
File Format: IHTSLL
|
||||
Sheet Format: IHTSLL_SLL
|
||||
Creation Date: March 25 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_IHTSLL_SLL_block(p_client_id,p_function_id, p_file_mnemonic,
|
||||
p_file_sheet_mnemonic, p_file_syspk)
|
||||
Function call ex: select staging2.fn_IHTSLL_SLL_block(1,2,'IHTSLL','IHTSLL_SLL',456)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* to process multiple files - re-runnability*/
|
||||
|
||||
truncate table staging2.IHTSLL_SLL_H1_Int;
|
||||
truncate table staging2.IHTSLL_SLL_H1_block;
|
||||
truncate table staging2.IHTSLL_SLL_Weight_Tyre_Int;
|
||||
truncate table staging2.IHTSLL_SLL_Weight_Block;
|
||||
truncate table staging2.IHTSLL_SLL_Wheel_Block;
|
||||
truncate table staging2.IHTSLL_SLL_Tyre_Details_Block;
|
||||
truncate table staging2.IHTSLL_SLL_Forward_Block;
|
||||
truncate table staging2.IHTSLL_SLL_Reverse_Block;
|
||||
truncate table staging2.IHTSLL_SLL_Lead_Lag_Block;
|
||||
truncate table staging2.IHTSLL_SLL_Footer_Block;
|
||||
truncate table staging2.stg_specific_table_IHTSLL_SLL;
|
||||
truncate table staging2.stg_process_table_IHTSLL_SLL;
|
||||
|
||||
|
||||
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 IHTSLL */
|
||||
execute 'insert into staging2.stg_specific_table_IHTSLL_SLL
|
||||
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_IHTSLL_SLL;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for IHTSLL',
|
||||
detail = 'No data in table stg_specific_table_IHTSLL_SLL',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_IHTSLL_SLL
|
||||
set column15='Objective' where lower(column15) like 'objective%';
|
||||
|
||||
update staging2.stg_specific_table_IHTSLL_SLL
|
||||
set column15='Acceptance criteria' where lower(column15) like 'acceptance criteria%';
|
||||
|
||||
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_IHTSLL_SLL b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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_IHTSLL_SLL a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_modified)=upper(column3)
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Remarks:''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
execute 'insert into staging2.stg_process_table_IHTSLL_SLL
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTSLL_SLL 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 Request No''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTSLL_SLL
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTSLL_SLL 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=''Weight Reaction''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTSLL_SLL
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTSLL_SLL 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=''K2-4WD HST EACH GEAR MAX SPEED - FORWARD''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTSLL_SLL
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTSLL_SLL 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=''K2- 4WD HST EACH GEAR MAX SPEED REVERSE''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTSLL_SLL
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTSLL_SLL 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=''Lead / Lag Measurement on K2 4WD HST''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_IHTSLL_SLL
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_IHTSLL_SLL 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=''Prepared by''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/*selecting tractor model*/
|
||||
select column6 into __model from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_H1' and trim(column3)='Tractor Model';
|
||||
|
||||
/*block starts - IHTSLL_SLL_H1_BLOCK */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_H1_BLOCK',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='IHTSLL_SLL_H1_BLOCK';
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_INT (c1,c2)
|
||||
select a.column3,column6 from staging2.stg_process_table_IHTSLL_SLL a where block_tag='IHTSLL_SLL_H1';
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_INT (c1,c2)
|
||||
select a.column9,column12 from staging2.stg_process_table_IHTSLL_SLL a where block_tag='IHTSLL_SLL_H1';
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_INT (c1,c2)
|
||||
select 'Objective',column15
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTSLL_SLL a
|
||||
where column15='Objective'
|
||||
and block_tag='IHTSLL_SLL_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_INT (c1,c2)
|
||||
select 'Acceptance criteria',column15
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_H1'
|
||||
and row_number=
|
||||
(
|
||||
select row_number+1 from
|
||||
staging2.stg_process_table_IHTSLL_SLL a
|
||||
where column15='Acceptance criteria'
|
||||
and block_tag='IHTSLL_SLL_H1'
|
||||
);
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_INT (c1,c2)
|
||||
select split_part(column3,':',1),split_part(column3,':',2)
|
||||
from staging2.stg_process_table_IHTSLL_SLL
|
||||
where block_tag='IHTSLL_SLL_Lead_Lag' and block_row_number=10;
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_INT (c1,c2)
|
||||
select 'Test Purpose',column10
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where column3='Test Purpose' and block_tag='IHTSLL_SLL_Weight_Tyre';
|
||||
|
||||
update staging2.IHTSLL_SLL_H1_Int set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_H1_Int 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||'''';
|
||||
|
||||
insert into staging2.IHTSLL_SLL_H1_Block
|
||||
(
|
||||
dummy_f,
|
||||
Test_Request_no,
|
||||
Sample_Receipt_Date,
|
||||
Test_report_No,
|
||||
Tractor_Model,
|
||||
Generation,
|
||||
Customer_Name,
|
||||
Test_Engineer,
|
||||
Test_Report_Date,
|
||||
No_of_Sample,
|
||||
Test_Start_Date,
|
||||
Test_End_Date,
|
||||
Tractor_Sr_No,
|
||||
Test_Standard_Refer,
|
||||
Test_Location,
|
||||
Operator_Name,
|
||||
Project_Group,
|
||||
Objective,
|
||||
Acceptance_Criteria,
|
||||
Remarks,
|
||||
Test_Purpose
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{c2}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[c2::text]) AS val
|
||||
FROM staging2.IHTSLL_SLL_H1_INT
|
||||
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,
|
||||
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);
|
||||
|
||||
|
||||
delete from staging2.IHTSLL_SLL_H1_Block where dummy_f is null ;
|
||||
update staging2.IHTSLL_SLL_H1_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_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,'IHTSLL_SLL_H1_BLOCK');
|
||||
|
||||
|
||||
insert into staging2.IHTSLL_SLL_Weight_Tyre_Int
|
||||
(
|
||||
column3,column6,column10,column11,column13,column15,column17,column19,
|
||||
column20,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column6,column10,column11,column13,column15,column17,column19,
|
||||
column20,block_row_number
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_Weight_Tyre'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTSLL_SLL_Weight_Tyre_Int set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Weight_Tyre_Int 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||'''';
|
||||
|
||||
|
||||
/*block starts - IHTSLL_SLL_Weight_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Weight_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='IHTSLL_SLL_Weight_Block';
|
||||
insert into staging2.IHTSLL_SLL_Weight_Block
|
||||
(
|
||||
dummy_f,
|
||||
Weight_Reaction,
|
||||
Total_Weight_kg,
|
||||
Front_Reaction_kg,
|
||||
Rear_Reaction_kg,
|
||||
Left_Reaction_FL_RL_kg,
|
||||
Right_reaction_FR_RR_kg,
|
||||
Front_Left_Reaction_kg,
|
||||
Front_Right_Reaction_kg,
|
||||
Rear_Left_Reaction_kg,
|
||||
Rear_Right_Reaction_kg,
|
||||
Distance_of_lifting_point_from_rear_axle_mm_d1
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column6::text]) AS val
|
||||
FROM staging2.IHTSLL_SLL_Weight_Tyre_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);
|
||||
|
||||
delete from staging2.IHTSLL_SLL_Weight_Block where dummy_f is null ;
|
||||
update staging2.IHTSLL_SLL_Weight_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Weight_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,'IHTSLL_SLL_Weight_Block');
|
||||
|
||||
/*block starts - IHTSLL_SLL_Tyre_Details_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Tyre_Details_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='IHTSLL_SLL_Tyre_Details_Block';
|
||||
insert into staging2.IHTSLL_SLL_Tyre_Details_Block
|
||||
(
|
||||
dummy_f,
|
||||
Tyre_Details,
|
||||
Tyre_Make,
|
||||
Tyre_size,
|
||||
Ply_Rating,
|
||||
Load_Carrying_Capacity,
|
||||
Pressure_kg_cm2,
|
||||
Dynamic_rolling_radius,
|
||||
Static_rolling_radius,
|
||||
Wheel_rim_Make_size
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column15,column19}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column15::text,column19::text]) AS val
|
||||
FROM staging2.IHTSLL_SLL_Weight_Tyre_Int where block_row_number between 3 and 11
|
||||
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,a_9 text);
|
||||
|
||||
delete from staging2.IHTSLL_SLL_Tyre_Details_Block where dummy_f is null ;
|
||||
update staging2.IHTSLL_SLL_Tyre_Details_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Tyre_Details_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,'IHTSLL_SLL_Tyre_Details_Block');
|
||||
|
||||
|
||||
/*block starts - IHTSLL_SLL_Wheel_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='IHTSLL_SLL_Wheel_Block';
|
||||
insert into staging2.IHTSLL_SLL_Wheel_Block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTSLL_SLL_Wheel_Block
|
||||
set Wheel_Base=(select column13 from
|
||||
staging2.IHTSLL_SLL_Weight_Tyre_Int
|
||||
where block_row_number=1 and column10='Wheel Base in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Wheel_Block
|
||||
set Rear_Track_Width=(select column20 from
|
||||
staging2.IHTSLL_SLL_Weight_Tyre_Int
|
||||
where block_row_number=1 and column17='Rear Track Width in mm')
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.IHTSLL_SLL_Wheel_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_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,'IHTSLL_SLL_Wheel_Block');
|
||||
|
||||
/*block starts - IHTSLL_SLL_Forward_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Forward_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='IHTSLL_SLL_Forward_Block';
|
||||
|
||||
insert into staging2.IHTSLL_SLL_Forward_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_Forward'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTSLL_SLL_Forward_Block
|
||||
set column2=(select split_part(column3,'-',3)
|
||||
from staging2.IHTSLL_SLL_Forward_Block where block_row_number =1);
|
||||
|
||||
delete from staging2.IHTSLL_SLL_Forward_Block where column3 is null;
|
||||
|
||||
|
||||
update staging2.IHTSLL_SLL_Forward_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Forward_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.IHTSLL_SLL_Forward_Block set trx_record =0 where block_row_number in (1,2);
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Forward_Block');
|
||||
|
||||
/*block starts - IHTSLL_SLL_Reverse_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Reverse_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
|
||||
err_block:='IHTSLL_SLL_Reverse_Block';
|
||||
|
||||
insert into staging2.IHTSLL_SLL_Reverse_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_Reverse'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.IHTSLL_sll_reverse_block
|
||||
set column2=(select split_part(column3,' ',8)
|
||||
from staging2.IHTSLL_sll_reverse_block where block_row_number =1);
|
||||
|
||||
delete from staging2.IHTSLL_sll_reverse_block where column3 is null;
|
||||
|
||||
update staging2.IHTSLL_SLL_Reverse_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Reverse_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.IHTSLL_SLL_Reverse_Block set trx_record =0 where block_row_number in (1,2);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Reverse_Block');
|
||||
|
||||
/*block starts - IHTSLL_SLL_Lead_Lag_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Lead_Lag_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block='IHTSLL_SLL_Lead_Lag_Block';
|
||||
insert into staging2.IHTSLL_SLL_Lead_Lag_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
from staging2.stg_process_table_IHTSLL_SLL a
|
||||
where block_tag='IHTSLL_SLL_Lead_Lag'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTSLL_SLL_Lead_Lag_Block a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTSLL_SLL_Lead_Lag_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTSLL_SLL_Lead_Lag_Block a
|
||||
set column4= b.first_value from (SELECT
|
||||
block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column4,
|
||||
sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTSLL_SLL_Lead_Lag_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTSLL_SLL_Lead_Lag_Block a
|
||||
set column7= b.first_value from (SELECT
|
||||
block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column7,
|
||||
sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTSLL_SLL_Lead_Lag_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.IHTSLL_SLL_Lead_Lag_Block a
|
||||
set column8= b.first_value from (SELECT
|
||||
block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column8,
|
||||
sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.IHTSLL_SLL_Lead_Lag_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.IHTSLL_SLL_Lead_Lag_Block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Lead_Lag_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.IHTSLL_SLL_Lead_Lag_Block set trx_record =0 where block_row_number in (1,2,3);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'IHTSLL_SLL_Lead_Lag_Block');
|
||||
|
||||
/*block starts - IHTSLL_SLL_Footer_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'IHTSLL_SLL_Footer_block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='IHTSLL_SLL_Footer_block';
|
||||
insert into staging2.IHTSLL_SLL_Footer_block(dummy_f) values ('dummy');
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set prepared_by=( select column7 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and lower(column3)='prepared by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set reviewed_by=( select column7 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and lower(column3)='reviewed by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set approved_by=( select column7 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and lower(column3)='approved by' )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set comments=( select column3 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=5 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set rev1=( select column3 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set rev2=( select column9 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set rev3=( select column18 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=6 )
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set replaces=( select column19 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set revision_no=( select column19 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set prepared_date=( select column16 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=1)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set reviewed_date=( select column16 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=2)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block a
|
||||
set approved_date=( select column16 from staging2.stg_process_table_IHTSLL_SLL b
|
||||
where b.block_tag='IHTSLL_SLL_Footer'
|
||||
and block_row_number=3)
|
||||
where dummy_F='dummy';
|
||||
|
||||
update staging2.IHTSLL_SLL_Footer_block set model=__model;
|
||||
execute 'update staging2.IHTSLL_SLL_Footer_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,'IHTSLL_SLL_Footer_block');
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_IHTSLL_SLL_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
1183
onetime/dataloadfunctions/ODS_Load/fn_fw_ods_load.sql
Executable file
1183
onetime/dataloadfunctions/ODS_Load/fn_fw_ods_load.sql
Executable file
File diff suppressed because it is too large
Load Diff
261
onetime/dataloadfunctions/PTO/PTO_GVG_ods.sql
Executable file
261
onetime/dataloadfunctions/PTO/PTO_GVG_ods.sql
Executable file
@@ -0,0 +1,261 @@
|
||||
drop function if exists staging2.fn_PTO_GVG_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_PTO_GVG_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
declare __make text;
|
||||
declare __model text;
|
||||
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 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;
|
||||
begin
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_PTOBEN_GVG_TRX
|
||||
Function Desc: This function populates data into ODS blocks
|
||||
File Format: PTOBEN
|
||||
Sheet Format: PTOBEN_GVG
|
||||
Creation Date: April 27 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_PTO_GVG_TRX(907)
|
||||
***************************************************************/
|
||||
select tractor_model into __model from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='PTO';
|
||||
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic ,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
case when __file_sheet_mnemonic = 'PTOBEN_GVG' then 'PTOBEN_GVG'
|
||||
else 'PTOSTD_GVG'
|
||||
end,
|
||||
make,
|
||||
model
|
||||
from staging2.ptoben_prf_tractor_specs_block where trx_record=1;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
insert into transactional.PTO_Perf_Governing_Graph
|
||||
(client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
test_type,
|
||||
engine_speed_rpm,
|
||||
torque_kg_m,
|
||||
power_hp,
|
||||
sfc_gm_per_hp_hr,
|
||||
fuelling_mm3_per_stroke_per_cyl,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
test_condition ,
|
||||
c1,
|
||||
c2::numeric,
|
||||
c3::numeric,
|
||||
c4::numeric,
|
||||
c5::numeric,
|
||||
c6::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
union
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
test_condition ,
|
||||
c7_1,
|
||||
c7::numeric,
|
||||
c8::numeric,
|
||||
c9::numeric,
|
||||
c10::numeric,
|
||||
c11::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
and (c7 is not null and c8 is not null and c9 is not null and c10 is not null and c11 is not null)
|
||||
union
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
test_condition ,
|
||||
c12_1,
|
||||
c12::numeric,
|
||||
c13::numeric,
|
||||
c14::numeric,
|
||||
c15::numeric,
|
||||
c16::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
and (c12 is not null and c13 is not null and c14 is not null and c15 is not null and c16 is not null)
|
||||
union
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
make,
|
||||
model,
|
||||
test_condition ,
|
||||
c17_1,
|
||||
c17::numeric,
|
||||
c18::numeric,
|
||||
c19::numeric,
|
||||
c20::numeric,
|
||||
c21::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
and (c17 is not null and c18 is not null and c19 is not null and c20 is not null and c21 is not null)
|
||||
union
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
model,
|
||||
make,
|
||||
test_condition ,
|
||||
c22_1,
|
||||
c22::numeric,
|
||||
c23::numeric,
|
||||
c24::numeric,
|
||||
c25::numeric,
|
||||
c26::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
and (c22 is not null and c23 is not null and c24 is not null and c25 is not null and c26 is not null)
|
||||
union
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
model,
|
||||
make,
|
||||
test_condition ,
|
||||
c27_1,
|
||||
c27::numeric,
|
||||
c28::numeric,
|
||||
c29::numeric,
|
||||
c30::numeric,
|
||||
c31::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
and (c27 is not null and c28 is not null and c29 is not null and c30 is not null and c32 is not null)
|
||||
union
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
model,
|
||||
make,
|
||||
test_condition ,
|
||||
c32_1,
|
||||
c32::numeric,
|
||||
c33::numeric,
|
||||
c34::numeric,
|
||||
c35::numeric,
|
||||
c36::numeric,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic
|
||||
from staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
where trx_record=1
|
||||
and (c32 is not null and c33 is not null and c34 is not null and c35 is not null and c36 is not null);
|
||||
|
||||
update transactional.PTO_Perf_Governing_Graph set test_mode = 'Normal Mode' where file_sheet_mnemonic = 'PTOBEN_GVGN' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Perf_Governing_Graph set test_mode = 'Boost Mode' where file_sheet_mnemonic = 'PTOBEN_GVGB' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Perf_Governing_Graph set test_mode = 'Eco Mode' where file_sheet_mnemonic = 'PTOBEN_GVGE' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Perf_Governing_Graph set test_mode = 'Standard Mode' where file_sheet_mnemonic = 'PTOSTD_GVG' and file_syspk = __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;
|
||||
|
||||
|
||||
update transactional.PTO_Perf_Governing_Graph
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_tractor_id = __test_instance_tractor_id,
|
||||
test_master_id = __test_master_id
|
||||
where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
|
||||
update transactional.test_instance a
|
||||
set (test_location_name,test_engineer,date_of_test) = (select place,test_engineer,TO_DATE(test_date, 'DD/MM/YYYY') from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed')
|
||||
where file_syspk = __file_syspk;
|
||||
|
||||
UPDATE transactional.pto_perf_governing_graph a set test_mode = CASE WHEN a.test_condition like '%Normal%' THEN 'Normal'
|
||||
WHEN a.test_condition like '%Eco%' THEN 'Eco'
|
||||
WHEN a.test_condition like '%Boost%' THEN 'Boost'
|
||||
WHEN a.test_condition like '%Standard%' THEN 'Standard'
|
||||
ELSE NULL
|
||||
end;
|
||||
|
||||
err_context := '';
|
||||
perform fw_core.fn_insert_db_error( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_GVG_trx', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
return err_context;
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
err_state = returned_sqlstate,
|
||||
err_msg = message_text,
|
||||
err_detail = pg_exception_detail,
|
||||
err_hint = pg_exception_hint,
|
||||
err_context = pg_exception_context;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_GVG_trx', err_state, err_msg, err_detail, err_hint, err_context,'error');
|
||||
return err_context;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
383
onetime/dataloadfunctions/PTO/PTO_GVG_stg2.sql
Executable file
383
onetime/dataloadfunctions/PTO/PTO_GVG_stg2.sql
Executable file
@@ -0,0 +1,383 @@
|
||||
drop function if exists staging2.fn_PTO_GVG_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_PTO_GVG_block(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
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_PTOBEN_GVG_block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: PTOBEN
|
||||
Sheet Format: PTOBEN_GVG
|
||||
Creation Date: April 27 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_PTO_GVG_block(1,1,'PTOBEN','PTOBEN_GVG',944)
|
||||
***************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.stg_specific_table_PTOBEN_GVG;
|
||||
truncate table staging2.stg_process_table_PTOBEN_GVG;
|
||||
truncate table staging2.PTOBEN_GVG_performance_governing_trails_block;
|
||||
|
||||
|
||||
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 PTOBEN */
|
||||
execute 'insert into staging2.stg_specific_table_PTOBEN_GVG
|
||||
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_PTOBEN_GVG;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for pto',
|
||||
detail = 'No data in table stg_specific_table_PTOBEN_PRF',
|
||||
errcode = 'PTO',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_PTOBEN_GVG set column3 = TRIM (TRAILING FROM column3 );
|
||||
update staging2.stg_specific_table_PTOBEN_GVG set column3 = TRIM (LEADING FROM column3 );
|
||||
|
||||
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=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);
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_PTOBEN_GVG b
|
||||
where trim(upper(F1_modified))=trim(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||'''';
|
||||
|
||||
/* keyword match in config table*/
|
||||
execute 'update staging2.stg_specific_table_PTOBEN_GVG a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where trim(upper(F1_modified))=trim(upper(column3))
|
||||
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||'''';
|
||||
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Graphs - for Example''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
|
||||
execute 'insert into staging2.stg_process_table_PTOBEN_GVG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_PTOBEN_GVG 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=''Data Inputs''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_PTOBEN_GVG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_PTOBEN_GVG 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=''Graphs - for Example''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
select column5 into __make from staging2.stg_process_table_PTOBEN_PRF a
|
||||
where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=7 ;
|
||||
|
||||
select column5 into __model from staging2.stg_process_table_PTOBEN_PRF a
|
||||
where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=9;
|
||||
|
||||
|
||||
/* block PTOBEN_GVG_performance_governing_trails_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'PTOBEN_GVG_performance_governing_trails_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
|
||||
err_block := 'PTOBEN_GVG_performance_governing_trails_block';
|
||||
|
||||
insert into staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
(
|
||||
c2,
|
||||
c3,
|
||||
c4,
|
||||
c5,
|
||||
c6,
|
||||
c7,
|
||||
c8,
|
||||
c9,
|
||||
c10,
|
||||
c11,
|
||||
c12,
|
||||
c13,
|
||||
c14,
|
||||
c15,
|
||||
c16,
|
||||
c17,
|
||||
c18,
|
||||
c19,
|
||||
c20,
|
||||
c21,
|
||||
c22,
|
||||
c23,
|
||||
c24,
|
||||
c25,
|
||||
c26,
|
||||
c27,
|
||||
c28,
|
||||
c29,
|
||||
c30,
|
||||
c31,
|
||||
c32,
|
||||
c33,
|
||||
c34,
|
||||
c35,
|
||||
c36,
|
||||
block_row_number
|
||||
)
|
||||
|
||||
select column2,
|
||||
column3,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9,
|
||||
column10,
|
||||
column11,
|
||||
column12,
|
||||
column13,
|
||||
column14,
|
||||
column15,
|
||||
column16,
|
||||
column17,
|
||||
column18,
|
||||
column19,
|
||||
column20,
|
||||
column21,
|
||||
column22,
|
||||
column23,
|
||||
column24,
|
||||
column25,
|
||||
column26,
|
||||
column27,
|
||||
column28,
|
||||
column29,
|
||||
column30,
|
||||
column31,
|
||||
column32,
|
||||
column33,
|
||||
column34,
|
||||
column35,
|
||||
column36,
|
||||
block_row_number
|
||||
from staging2.stg_process_table_PTOBEN_GVG a
|
||||
where block_tag='PTOBEN_GVG_data_inputs';
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set test_condition=c2
|
||||
where block_row_number=2;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c2=null
|
||||
where block_row_number=2;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set test_condition= b.first_value from (SELECT
|
||||
block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
test_condition,
|
||||
sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c1=c2 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c1= b.first_value from (SELECT
|
||||
block_row_number, c1, value_partition, first_value(c1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c1,
|
||||
sum(case when c1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c7_1=c7 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c7_1= b.first_value from (SELECT
|
||||
block_row_number, c7_1, value_partition, first_value(c7_1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c7_1,
|
||||
sum(case when c7_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c12_1=c12 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c12_1= b.first_value from (SELECT
|
||||
block_row_number, c12_1, value_partition, first_value(c12_1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c12_1,
|
||||
sum(case when c12_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c17_1=c17 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c17_1= b.first_value from (SELECT
|
||||
block_row_number, c17_1, value_partition, first_value(c17_1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c17_1,
|
||||
sum(case when c17_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c22_1=c22 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c22_1= b.first_value from (SELECT
|
||||
block_row_number, c22_1, value_partition, first_value(c22_1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c22_1,
|
||||
sum(case when c22_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c27_1=c27 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c27_1= b.first_value from (SELECT
|
||||
block_row_number, c27_1, value_partition, first_value(c27_1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c27_1,
|
||||
sum(case when c27_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set c32_1=c32 where block_row_number=5;
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block a
|
||||
set c32_1= b.first_value from (SELECT
|
||||
block_row_number, c32_1, value_partition, first_value(c32_1) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
c32_1,
|
||||
sum(case when c32_1 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block
|
||||
set trx_record=0 where block_row_number in (1,2,3,4,5);
|
||||
|
||||
execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set client_id='||p_client_id||'';
|
||||
execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set function_id='||p_function_id||'';
|
||||
execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set file_mnemonic='''||p_file_mnemonic||'''';
|
||||
execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
execute 'update staging2.PTOBEN_GVG_performance_governing_trails_block set file_syspk='||p_file_syspk||'';
|
||||
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block set make=__make;
|
||||
update staging2.PTOBEN_GVG_performance_governing_trails_block set model=__model;
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_GVG_performance_governing_trails_block');
|
||||
|
||||
err_context := '';
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_GVG_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
return err_context;
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
err_state = returned_sqlstate,
|
||||
err_msg = message_text,
|
||||
err_detail = pg_exception_detail,
|
||||
err_hint = pg_exception_hint,
|
||||
err_context = pg_exception_context;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_GVG_block', err_state, err_msg, err_detail, err_hint, err_context,'error');
|
||||
return err_context;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
133
onetime/dataloadfunctions/PTO/PTO_MPM_ods.sql
Executable file
133
onetime/dataloadfunctions/PTO/PTO_MPM_ods.sql
Executable file
@@ -0,0 +1,133 @@
|
||||
drop function if exists staging2.fn_PTO_MPM_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_PTO_MPM_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
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;
|
||||
begin
|
||||
|
||||
/***********************************************************
|
||||
Function Name:fn_PTOBEN_MPM_TRX
|
||||
Function Desc: This function populates data into ODS blocks
|
||||
File Format: PTOBEN
|
||||
Sheet Format: PTOBEN_MPM
|
||||
Creation Date: April 27 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_PTO_MPM_TRX(907)
|
||||
***************************************************************/
|
||||
|
||||
select tractor_model into __model from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='PTO';
|
||||
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic ,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
case when __file_sheet_mnemonic = 'PTOBEN_MPM' then 'PTOBEN_MPM'
|
||||
else 'PTOSTD_MPM'
|
||||
end,
|
||||
make,
|
||||
model
|
||||
from staging2.ptoben_prf_tractor_specs_block where trx_record=1;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
|
||||
insert into transactional.PTO_Multipoint_Mapping
|
||||
(
|
||||
client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,
|
||||
tractor_make ,tractor_model ,
|
||||
test_condition,
|
||||
engine_speed_rpm,
|
||||
engine_load_pct,
|
||||
sfc_gm_per_hp_hr,
|
||||
fuel_consumption_ltr_per_hr
|
||||
)
|
||||
|
||||
select client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,make,model,test_condition,
|
||||
c2::numeric,c3::numeric,c4::numeric,c5::numeric
|
||||
from staging2.PTOBEN_MPM_performance_boost_natural_block
|
||||
where trx_record=1 ;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
update transactional.PTO_Multipoint_Mapping set test_mode = 'Normal Mode' where file_sheet_mnemonic = 'PTOBEN_MPMN' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Multipoint_Mapping set test_mode = 'Boost Mode' where file_sheet_mnemonic = 'PTOBEN_MPMB' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Multipoint_Mapping set test_mode = 'Eco Mode' where file_sheet_mnemonic = 'PTOBEN_MPME' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Multipoint_Mapping set test_mode = 'Standard Mode' where file_sheet_mnemonic = 'PTOSTD_MPM' and file_syspk = __file_syspk;
|
||||
|
||||
|
||||
update transactional.PTO_Multipoint_Mapping
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_tractor_id = __test_instance_tractor_id,
|
||||
test_master_id = __test_master_id
|
||||
where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
|
||||
update transactional.test_instance a
|
||||
set (test_location_name,test_engineer,date_of_test) = (select place,test_engineer,TO_DATE(test_date, 'DD/MM/YYYY') from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed')
|
||||
where file_syspk = __file_syspk;
|
||||
|
||||
UPDATE transactional.pto_multipoint_mapping a set test_mode = CASE WHEN a.test_condition like '%Normal%' THEN 'Normal'
|
||||
WHEN a.test_condition like '%Eco%' THEN 'Eco'
|
||||
WHEN a.test_condition like '%Boost%' THEN 'Boost'
|
||||
WHEN a.test_condition like '%Standard%' THEN 'Standard'
|
||||
ELSE NULL
|
||||
end;
|
||||
|
||||
err_context := '';
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_MPM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
return err_context;
|
||||
|
||||
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
err_state = returned_sqlstate,
|
||||
err_msg = message_text,
|
||||
err_detail = pg_exception_detail,
|
||||
err_hint = pg_exception_hint,
|
||||
err_context = pg_exception_context;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_MPM_TRX', err_state, err_msg, err_detail, err_hint, err_context,'error');
|
||||
return err_context;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
195
onetime/dataloadfunctions/PTO/PTO_MPM_stg2.sql
Executable file
195
onetime/dataloadfunctions/PTO/PTO_MPM_stg2.sql
Executable file
@@ -0,0 +1,195 @@
|
||||
drop function if exists staging2.fn_PTO_MPM_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_PTO_MPM_block(p_client_id int,p_function_id int, p_file_mnemonic text,p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
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_PTOBEN_MPM_block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: PTOBEN
|
||||
Sheet Format: PTOBEN_MPMB
|
||||
Creation Date: April 26 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_PTO_MPM_block(1,1,'PTOBEN','PTOBEN_MPM',944)
|
||||
***************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.stg_specific_table_PTOBEN_MPM;
|
||||
truncate table staging2.stg_process_table_PTOBEN_MPM;
|
||||
truncate table staging2.PTOBEN_MPM_performance_boost_natural_block;
|
||||
|
||||
|
||||
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 PTOBST */
|
||||
execute 'insert into staging2.stg_specific_table_PTOBEN_MPM
|
||||
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_PTOBEN_MPM;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for pto',
|
||||
detail = 'No data in table stg_specific_table_PTOBEN_PRF',
|
||||
errcode = 'PTO',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_PTOBEN_MPM set column3 = TRIM (TRAILING FROM column3 );
|
||||
update staging2.stg_specific_table_PTOBEN_MPM set column3 = TRIM (LEADING FROM column3 );
|
||||
|
||||
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_PTOBEN_MPM b
|
||||
where trim(upper(F1_modified))=trim(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*/
|
||||
execute 'update staging2.stg_specific_table_PTOBEN_MPM a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where trim(upper(F1_modified))=trim(upper(column3))
|
||||
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||'''';
|
||||
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''Performance - Boost Mode @ Natural Ambient''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
/* tagging block_row_numbers*/
|
||||
|
||||
execute 'insert into staging2.stg_process_table_PTOBEN_MPM
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_PTOBEN_MPM 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=''Data Inputs''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
select column5 into __make from staging2.stg_process_table_PTOBEN_PRF a
|
||||
where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=7 ;
|
||||
|
||||
select column5 into __model from staging2.stg_process_table_PTOBEN_PRF a
|
||||
where block_tag='PTOBEN_PRF_Key_Performance_Parameters' and block_row_number=9;
|
||||
|
||||
/* block - PTOBEN_MPM_performance_boost_natural_block*/
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'PTOBEN_MPM_performance_boost_natural_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block :='PTOBEN_MPM_performance_boost_natural_block';
|
||||
insert into staging2.PTOBEN_MPM_performance_boost_natural_block
|
||||
(
|
||||
c2,
|
||||
c3,
|
||||
c4,
|
||||
c5,
|
||||
block_row_number
|
||||
)
|
||||
select column2,column3,column4 ,column5,block_row_number from staging2.stg_process_table_PTOBEN_MPM
|
||||
where block_tag='PTOBEN_MPM_data_inputs';
|
||||
|
||||
|
||||
update staging2.PTOBEN_MPM_performance_boost_natural_block
|
||||
set test_condition=c2
|
||||
where block_row_number=2;
|
||||
|
||||
update staging2.PTOBEN_MPM_performance_boost_natural_block
|
||||
set c2=null
|
||||
where block_row_number=2;
|
||||
|
||||
|
||||
update staging2.PTOBEN_MPM_performance_boost_natural_block a
|
||||
set test_condition= b.first_value from (SELECT
|
||||
block_row_number, test_condition, value_partition, first_value(test_condition) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
test_condition,
|
||||
sum(case when test_condition is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.PTOBEN_MPM_performance_boost_natural_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
|
||||
update staging2.PTOBEN_MPM_performance_boost_natural_block
|
||||
set trx_record=0
|
||||
where block_row_number in (1,2,3);
|
||||
|
||||
execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set client_id='||p_client_id||'';
|
||||
execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set function_id='||p_function_id||'';
|
||||
execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set file_mnemonic='''||p_file_mnemonic||'''';
|
||||
execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
execute 'update staging2.PTOBEN_MPM_performance_boost_natural_block set file_syspk='||p_file_syspk||'';
|
||||
|
||||
update staging2.PTOBEN_MPM_performance_boost_natural_block set make=__make;
|
||||
update staging2.PTOBEN_MPM_performance_boost_natural_block set model=__model;
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'PTOBEN_MPM_performance_boost_natural_block');
|
||||
err_context := '';
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_PTO_MPM_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
return err_context;
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
err_state = returned_sqlstate,
|
||||
err_msg = message_text,
|
||||
err_detail = pg_exception_detail,
|
||||
err_hint = pg_exception_hint,
|
||||
err_context = pg_exception_context;
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,err_block,'stg2', 'fn_PTO_MPM_block', err_state, err_msg, err_detail, err_hint, err_context,'error');
|
||||
return err_context;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
691
onetime/dataloadfunctions/PTO/PTO_PRF_ods.sql
Executable file
691
onetime/dataloadfunctions/PTO/PTO_PRF_ods.sql
Executable file
@@ -0,0 +1,691 @@
|
||||
drop function if exists staging2.fn_PTO_PRF_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_PTO_PRF_TRX(p_client_id int,p_function_id int, p_file_mnemonic text,
|
||||
p_file_sheet_mnemonic text, p_file_syspk int)
|
||||
RETURNS text AS $$
|
||||
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;
|
||||
begin
|
||||
|
||||
/***********************************************************
|
||||
Function Name:fn_PTO_PNA_TRX
|
||||
Function Desc: This function populates data into ODS blocks
|
||||
File Format: PTOBST
|
||||
Sheet Format: PTOBST_PNA
|
||||
Creation Date: April 27 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_PTO_PRF_TRX(907)
|
||||
***************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='PTO';
|
||||
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_sr_no,
|
||||
test_standard_ref
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_serial_number,
|
||||
test_standard
|
||||
from staging2.ptoben_prf_tractor_specs_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_sr_no
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_serial_number
|
||||
from staging2.ptoben_prf_tractor_specs_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance a
|
||||
set (test_location_name,test_engineer,date_of_test) = (select place,test_engineer,TO_DATE(test_date, 'DD/MM/YYYY') from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed')
|
||||
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;
|
||||
|
||||
update transactional.test_instance_tractor_info a
|
||||
set (gear_ratio) = (select engine_to_pto_ratio::numeric from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where file_syspk = __file_syspk and test_condition='observed')
|
||||
where file_syspk = __file_syspk;
|
||||
|
||||
|
||||
insert into transactional.PTO_Key_Perf_Parameters
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
tractor_serial_number,
|
||||
tractor_emission,
|
||||
test_standard,
|
||||
pto_gear_ratio,
|
||||
specific_gravity_of_fuel_kg_per_m3,
|
||||
pto_power_declared_hp,
|
||||
pto_power_declared_kw,
|
||||
pto_sfc_declared_gm_per_hp_hr,
|
||||
pto_sfc_declared_kg_per_kw_hr,
|
||||
pct_of_backup_torque_declared,
|
||||
max_equ_crankshaft_torque_declared_nm,
|
||||
equ_crankshaft_torque_at_max_power_declared_nm,
|
||||
engine_speed_at_max_equ_crankshaft_torque_declared_rpm,
|
||||
rated_engine_speed_declared_rpm,
|
||||
max_torque_engine_speed_declared_rpm,
|
||||
engine_high_idle_speed_declared_rpm,
|
||||
engine_low_idle_speed_declared_rpm,
|
||||
engine_oil_temp_at_na_declared_c,
|
||||
coolant_temp_at_na_declared_c,
|
||||
engine_oil_temp_at_ha_declared_c,
|
||||
coolant_temp_at_ha_declared_c,
|
||||
ambient_pressure_declared_bar,
|
||||
ambient_pressure_declared_mm_of_hg,
|
||||
back_pressure_declared_bar,
|
||||
back_pressure_declared_mm_of_hg,
|
||||
engine_oil_pressure_declared_bar,
|
||||
exhaust_temp_declared_c,
|
||||
relative_humidity_declared_pct,
|
||||
coolant_water_pct_of_total_coolant_capacity_declared,
|
||||
test_engineer,test_bed,location_name,total_run_hrs,test_date,tooled_up,
|
||||
created_by
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
tractor_serial_number,
|
||||
tractor_emmission,
|
||||
test_standard,
|
||||
engine_to_pto_ratio::numeric,
|
||||
specific_gravity_of_fuel::numeric,
|
||||
pto_power_hp,
|
||||
pto_power_kw,
|
||||
pto_sfc_gm_hp,
|
||||
pto_sfc_kw_hp,
|
||||
pct_of_backup_torque,
|
||||
maximum_equ_crankshaft_torque_nm,
|
||||
equ_crankshaft_torque_maximum_power_nm,
|
||||
engine_speed_at_maximum_equivalent_crankshaft_torque_rpm,
|
||||
rated_engine_speed,
|
||||
max_torque_engine_speed,
|
||||
engine_high_idle_speed,
|
||||
engine_low_idle_speed,
|
||||
engine_oil_temp_na,
|
||||
coolant_temp_na,
|
||||
engine_oil_temp_ha,
|
||||
coolant_temp_ha,
|
||||
ambient_pressure_bar,
|
||||
ambient_pressure_mm_of_hg,
|
||||
back_pressure_bar,
|
||||
back_pressure_mm_of_hg,
|
||||
engine_oil_pressure_bar,
|
||||
exhaust_temperature_c,
|
||||
relative_humidity_pct,
|
||||
coolant_water_pct,
|
||||
test_engineer,test_bed,place,total_run_hrs::int,
|
||||
TO_DATE(test_date, 'DD/MM/YYYY') ,
|
||||
tooled_up,
|
||||
'Compegence'
|
||||
from staging2.ptoben_prf_key_performance_parameters_block
|
||||
where trx_record=1 and test_condition ='declared';
|
||||
|
||||
|
||||
update transactional.PTO_Key_Perf_Parameters a
|
||||
set (pto_power_observed_hp,pto_power_observed_kw,pto_sfc_observed_gm_per_hp_hr,pto_sfc_observed_kg_per_kw_hr,
|
||||
pct_of_backup_torque_observed,max_equ_crankshaft_torque_observed_nm,equ_crankshaft_torque_at_max_power_observed_nm,
|
||||
engine_speed_at_max_equ_crankshaft_torque_observed_rpm,rated_engine_speed_observed_rpm
|
||||
,max_torque_engine_speed_observed_rpm,engine_high_idle_speed_observed_rpm,engine_low_idle_speed_observed_rpm,
|
||||
engine_oil_temp_at_na_observed_c,coolant_temp_at_na_observed_c,engine_oil_temp_at_ha_observed_c,coolant_temp_at_ha_observed_c,
|
||||
ambient_pressure_observed_bar,ambient_pressure_observed_mm_of_hg,back_pressure_observed_bar,back_pressure_observed_mm_of_hg,
|
||||
engine_oil_pressure_observed_bar,exhaust_temp_observed_c,relative_humidity_observed_pct,coolant_water_pct_of_total_coolant_capacity_observed)
|
||||
= (select pto_power_hp::numeric,
|
||||
pto_power_kw::numeric,
|
||||
pto_sfc_gm_hp::numeric,
|
||||
pto_sfc_kw_hp::numeric,
|
||||
pct_of_backup_torque::numeric,
|
||||
maximum_equ_crankshaft_torque_nm::numeric,
|
||||
equ_crankshaft_torque_maximum_power_nm::numeric,
|
||||
engine_speed_at_maximum_equivalent_crankshaft_torque_rpm::numeric,
|
||||
rated_engine_speed::numeric,
|
||||
max_torque_engine_speed::numeric,
|
||||
engine_high_idle_speed::numeric,
|
||||
engine_low_idle_speed::numeric,
|
||||
engine_oil_temp_na::numeric,
|
||||
coolant_temp_na::numeric,
|
||||
engine_oil_temp_ha::numeric,
|
||||
coolant_temp_ha::numeric,
|
||||
ambient_pressure_bar::numeric,
|
||||
ambient_pressure_mm_of_hg::numeric,
|
||||
back_pressure_bar::numeric,
|
||||
back_pressure_mm_of_hg::numeric,
|
||||
engine_oil_pressure_bar::numeric,
|
||||
exhaust_temperature_c::numeric,
|
||||
relative_humidity_pct::numeric,
|
||||
coolant_water_pct::numeric from staging2.PTOBEN_PRF_Key_Performance_Parameters_block where test_condition='observed') where file_syspk = __file_syspk;
|
||||
|
||||
update transactional.PTO_Key_Perf_Parameters set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Key_Perf_Parameters set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Key_Perf_Parameters set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Key_Perf_Parameters set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk;
|
||||
|
||||
|
||||
/* block */
|
||||
insert into transactional.PTO_Perf_Results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
pto_test_type,
|
||||
serial_number,
|
||||
speed_engine_rpm,
|
||||
speed_pto_rpm,
|
||||
brake_torque_n_m,
|
||||
brake_torque_kg_m,
|
||||
power_kw,
|
||||
power_hp,
|
||||
eq_cblock_row_number_torque_nm,
|
||||
fuel_consumption_kg_per_hr,
|
||||
fuel_consumption_gm_per_hp_hr,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_mm3_per_str_per_cyl,
|
||||
sp_energy_kwh_per_ltr,
|
||||
temperatures_fuel_c,
|
||||
temperatures_ambient_c,
|
||||
temperatures_air_intake_c,
|
||||
temperatures_water_outlet_c,
|
||||
temperatures_exhaust_c,
|
||||
temperatures_engine_oil_c,
|
||||
pressure_ambient_bar,
|
||||
pressure_ambient_mm_of_hg,
|
||||
pressure_exhaust_bar,
|
||||
pressure_exhaust_mm_of_hg,
|
||||
pressure_lub_oil_bar,
|
||||
pressure_lub_oil_mm_of_hg,
|
||||
rh_pct
|
||||
)
|
||||
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
test_condition,
|
||||
c2,
|
||||
c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric,
|
||||
c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric,
|
||||
c26::numeric,c27::numeric,c28::numeric
|
||||
from staging2.ptoben_prf_varying_speed_natural_ambient_block
|
||||
where trx_record=1;
|
||||
|
||||
/* block */
|
||||
insert into transactional.PTO_Perf_Results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
pto_test_type,
|
||||
serial_number,
|
||||
speed_engine_rpm,
|
||||
speed_pto_rpm,
|
||||
brake_torque_n_m,
|
||||
brake_torque_kg_m,
|
||||
power_kw,
|
||||
power_hp,
|
||||
eq_cblock_row_number_torque_nm,
|
||||
fuel_consumption_kg_per_hr,
|
||||
fuel_consumption_gm_per_hp_hr,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_mm3_per_str_per_cyl,
|
||||
sp_energy_kwh_per_ltr,
|
||||
temperatures_fuel_c,
|
||||
temperatures_ambient_c,
|
||||
temperatures_air_intake_c,
|
||||
temperatures_water_outlet_c,
|
||||
temperatures_exhaust_c,
|
||||
temperatures_engine_oil_c,
|
||||
pressure_ambient_bar,
|
||||
pressure_ambient_mm_of_hg,
|
||||
pressure_exhaust_bar,
|
||||
pressure_exhaust_mm_of_hg,
|
||||
pressure_lub_oil_bar,
|
||||
pressure_lub_oil_mm_of_hg,
|
||||
rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
test_condition,
|
||||
c2,
|
||||
c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric,
|
||||
c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric,
|
||||
c26::numeric,c27::numeric,c28::numeric
|
||||
from staging2.ptoben_prf_2hrs_max_power_natural_ambient_block
|
||||
where trx_record=1;
|
||||
|
||||
update transactional.PTO_Perf_Results set average_yn = CASE WHEN serial_number = 'Avg' THEN 'Y'
|
||||
end where
|
||||
pto_test_type = '2Hrs Max Power Test @ Natural Ambient';
|
||||
|
||||
/* block */
|
||||
insert into transactional.PTO_Perf_Results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
pto_test_type,
|
||||
pto_test_sub_type,
|
||||
serial_number,
|
||||
speed_engine_rpm,
|
||||
speed_pto_rpm,
|
||||
brake_torque_n_m,
|
||||
brake_torque_kg_m,
|
||||
power_kw,
|
||||
power_hp,
|
||||
eq_cblock_row_number_torque_nm,
|
||||
fuel_consumption_kg_per_hr,
|
||||
fuel_consumption_gm_per_hp_hr,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_mm3_per_str_per_cyl,
|
||||
sp_energy_kwh_per_ltr,
|
||||
temperatures_fuel_c,
|
||||
temperatures_ambient_c,
|
||||
temperatures_air_intake_c,
|
||||
temperatures_water_outlet_c,
|
||||
temperatures_exhaust_c,
|
||||
temperatures_engine_oil_c,
|
||||
pressure_ambient_bar,
|
||||
pressure_ambient_mm_of_hg,
|
||||
pressure_exhaust_bar,
|
||||
pressure_exhaust_mm_of_hg,
|
||||
pressure_lub_oil_bar,
|
||||
pressure_lub_oil_mm_of_hg,
|
||||
rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
test_condition,
|
||||
c3,
|
||||
c2,
|
||||
c1::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric,
|
||||
c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric,
|
||||
c26::numeric,c27::numeric,c28::numeric
|
||||
from staging2.ptoben_prf_varying_load_rated_rpm_block
|
||||
where trx_record=1;
|
||||
|
||||
/* block */
|
||||
insert into transactional.PTO_Perf_Results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
pto_test_type,
|
||||
pto_test_sub_type,
|
||||
serial_number,
|
||||
speed_engine_rpm,
|
||||
speed_pto_rpm,
|
||||
brake_torque_n_m,
|
||||
brake_torque_kg_m,
|
||||
power_kw,
|
||||
power_hp,
|
||||
eq_cblock_row_number_torque_nm,
|
||||
fuel_consumption_kg_per_hr,
|
||||
fuel_consumption_gm_per_hp_hr,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_mm3_per_str_per_cyl,
|
||||
sp_energy_kwh_per_ltr,
|
||||
temperatures_fuel_c,
|
||||
temperatures_ambient_c,
|
||||
temperatures_air_intake_c,
|
||||
temperatures_water_outlet_c,
|
||||
temperatures_exhaust_c,
|
||||
temperatures_engine_oil_c,
|
||||
pressure_ambient_bar,
|
||||
pressure_ambient_mm_of_hg,
|
||||
pressure_exhaust_bar,
|
||||
pressure_exhaust_mm_of_hg,
|
||||
pressure_lub_oil_bar,
|
||||
pressure_lub_oil_mm_of_hg,
|
||||
rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
test_condition,
|
||||
c3,
|
||||
c2,
|
||||
c1::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric,
|
||||
c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric,
|
||||
c26::numeric,c27::numeric,c28::numeric
|
||||
from staging2.ptoben_prf_varying_load_std_pto_block
|
||||
where trx_record=1;
|
||||
|
||||
/* block */
|
||||
insert into transactional.PTO_Perf_Results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
pto_test_type,
|
||||
serial_number,
|
||||
speed_engine_rpm,
|
||||
speed_pto_rpm,
|
||||
brake_torque_n_m,
|
||||
brake_torque_kg_m,
|
||||
power_kw,
|
||||
power_hp,
|
||||
eq_cblock_row_number_torque_nm,
|
||||
fuel_consumption_kg_per_hr,
|
||||
fuel_consumption_gm_per_hp_hr,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_mm3_per_str_per_cyl,
|
||||
sp_energy_kwh_per_ltr,
|
||||
temperatures_fuel_c,
|
||||
temperatures_ambient_c,
|
||||
temperatures_air_intake_c,
|
||||
temperatures_water_outlet_c,
|
||||
temperatures_exhaust_c,
|
||||
temperatures_engine_oil_c,
|
||||
pressure_ambient_bar,
|
||||
pressure_ambient_mm_of_hg,
|
||||
pressure_exhaust_bar,
|
||||
pressure_exhaust_mm_of_hg,
|
||||
pressure_lub_oil_bar,
|
||||
pressure_lub_oil_mm_of_hg,
|
||||
rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
test_condition,
|
||||
c2,
|
||||
c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric,
|
||||
c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric,
|
||||
c26::numeric,c27::numeric,c28::numeric
|
||||
from staging2.ptoben_prf_varying_speed_test_high_ambient_block
|
||||
where trx_record=1;
|
||||
|
||||
insert into transactional.PTO_Perf_Results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_model,
|
||||
tractor_make,
|
||||
pto_test_type,
|
||||
serial_number,
|
||||
speed_engine_rpm,
|
||||
speed_pto_rpm,
|
||||
brake_torque_n_m,
|
||||
brake_torque_kg_m,
|
||||
power_kw,
|
||||
power_hp,
|
||||
eq_cblock_row_number_torque_nm,
|
||||
fuel_consumption_kg_per_hr,
|
||||
fuel_consumption_gm_per_hp_hr,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_mm3_per_str_per_cyl,
|
||||
sp_energy_kwh_per_ltr,
|
||||
temperatures_fuel_c,
|
||||
temperatures_ambient_c,
|
||||
temperatures_air_intake_c,
|
||||
temperatures_water_outlet_c,
|
||||
temperatures_exhaust_c,
|
||||
temperatures_engine_oil_c,
|
||||
pressure_ambient_bar,
|
||||
pressure_ambient_mm_of_hg,
|
||||
pressure_exhaust_bar,
|
||||
pressure_exhaust_mm_of_hg,
|
||||
pressure_lub_oil_bar,
|
||||
pressure_lub_oil_mm_of_hg,
|
||||
rh_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
model,
|
||||
make,
|
||||
test_condition,
|
||||
c2,
|
||||
c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,
|
||||
c11::numeric,
|
||||
c12::numeric,c13::numeric,c14::numeric,c15::numeric,c16::numeric,c17::numeric,c18::numeric,
|
||||
c19::numeric,c20::numeric,c21::numeric,c22::numeric,c23::numeric,c24::numeric,c25::numeric,
|
||||
c26::numeric,c27::numeric,c28::numeric
|
||||
from staging2.ptoben_prf_2hrs_max_power_test_high_ambient_block
|
||||
where trx_record=1;
|
||||
|
||||
update transactional.PTO_Perf_Results set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Perf_Results set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Perf_Results set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk;
|
||||
update transactional.PTO_Perf_Results set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk;
|
||||
|
||||
update transactional.PTO_Perf_Results set average_yn = CASE WHEN serial_number = 'Avg' THEN 'Y'
|
||||
end where
|
||||
pto_test_type = '2Hrs Max Power Test @ High Ambient';
|
||||
|
||||
/* block */
|
||||
insert into transactional.pto_smoke_test
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
engine_speed_rpm,
|
||||
pto_speed_rpm ,
|
||||
torque_100_pct ,
|
||||
torque_80_pct ,
|
||||
smoke_fsn_100_pct ,
|
||||
smoke_fsn_80_pct
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
c2::numeric,c3::numeric,c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric
|
||||
from staging2.ptoben_prf_smoke_test_block ppstb
|
||||
where trx_record=1 ;
|
||||
|
||||
update transactional.pto_smoke_test set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk;
|
||||
update transactional.pto_smoke_test set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk;
|
||||
update transactional.pto_smoke_test set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk;
|
||||
update transactional.pto_smoke_test set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk;
|
||||
|
||||
|
||||
insert into transactional.pto_engine_oil_consumption
|
||||
(
|
||||
client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
oil_consumption_gm_per_hr,
|
||||
oil_consumption_pct_of_fuel_consumption
|
||||
)
|
||||
select client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,make,model,
|
||||
c2::numeric,c3::numeric,c5::numeric
|
||||
from staging2.ptoben_prf_engine_oil_consumption_block ppeocb
|
||||
where trx_record=1;
|
||||
|
||||
update transactional.pto_engine_oil_consumption set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk;
|
||||
update transactional.pto_engine_oil_consumption set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk;
|
||||
update transactional.pto_engine_oil_consumption set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk;
|
||||
update transactional.pto_engine_oil_consumption set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk;
|
||||
|
||||
update transactional.test_instance set test_mode = 'Normal' where file_sheet_mnemonic = 'PTOBEN_PRFN' and file_syspk = __file_syspk;
|
||||
update transactional.test_instance set test_mode = 'Boost' where file_sheet_mnemonic = 'PTOBEN_PRFB' and file_syspk = __file_syspk;
|
||||
update transactional.test_instance set test_mode = 'Eco' where file_sheet_mnemonic = 'PTOBEN_PRFE' and file_syspk = __file_syspk;
|
||||
update transactional.test_instance set test_mode = 'Standard' where file_sheet_mnemonic = 'PTOSTD_PRF' and file_syspk = __file_syspk;
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_tractor_id = __test_instance_tractor_id,
|
||||
test_master_id = __test_master_id
|
||||
where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
|
||||
update transactional.PTO_Key_Perf_Parameters
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id
|
||||
where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id
|
||||
where file_syspk=__file_syspk and file_sheet_mnemonic =__file_sheet_mnemonic;
|
||||
|
||||
update transactional.PTO_Perf_Results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.pto_engine_oil_consumption
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.pto_smoke_test
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
err_context := '';
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_PRF_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
return err_context;
|
||||
|
||||
EXCEPTION when OTHERS then
|
||||
|
||||
GET STACKED DIAGNOSTICS
|
||||
err_state = returned_sqlstate,
|
||||
err_msg = message_text,
|
||||
err_detail = pg_exception_detail,
|
||||
err_hint = pg_exception_hint,
|
||||
err_context = pg_exception_context;
|
||||
|
||||
perform fw_core.fn_insert_db_error (__client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'trx', 'fn_PTO_PRF_TRX', err_state, err_msg, err_detail, err_hint, err_context,'error');
|
||||
return err_context;
|
||||
end
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
||||
|
||||
1113
onetime/dataloadfunctions/PTO/PTO_PRF_stg2.sql
Executable file
1113
onetime/dataloadfunctions/PTO/PTO_PRF_stg2.sql
Executable file
File diff suppressed because it is too large
Load Diff
251
onetime/dataloadfunctions/budni/BUDNI_ARC_ODS.sql
Executable file
251
onetime/dataloadfunctions/budni/BUDNI_ARC_ODS.sql
Executable file
@@ -0,0 +1,251 @@
|
||||
drop function if exists staging2.fn_BUDNI_ARC_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_ARC_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_ARC_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_ARC
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_ARC_TRX()
|
||||
***************************************************************/
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
ballast_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
FIP_type,
|
||||
steering_type,
|
||||
Ballast_Condition
|
||||
from staging2.BUDNI_ARC_Spec_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when lower(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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
type_of_road
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
type_of_track
|
||||
from
|
||||
staging2.BUDNI_ARC_Spec_H1_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio engine_to_pto_ratio_540_pto
|
||||
from staging2.BUDNI_ARC_Spec_H1_block where trx_record=1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.budni_air_cleaner_perf_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
atm_condtion_temperature_c,
|
||||
atm_condition_pressure_kpa,
|
||||
atm_condition_relative_humidity_pct,
|
||||
atm_condtion_mass_of_oil_before_test,
|
||||
position_of_tractor,
|
||||
loss_of_oil_g,
|
||||
oil_pull_over_pct,
|
||||
engine_oil_pressure
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Temperature_C,
|
||||
Pressure_kPa,
|
||||
Relative_humidity::numeric,
|
||||
Mass_of_oil_before_test::numeric,
|
||||
Position_of_tractor,
|
||||
Loss_of_oil::numeric,
|
||||
Oil_pull_Over::numeric,
|
||||
Engine_oil_pressure
|
||||
from staging2.budni_arc_perf_atmos_meas_test_block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
sequence_number,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3::int,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9
|
||||
from staging2.BUDNI_ARC_test_obs_summary_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_air_cleaner_perf_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_ARC_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
282
onetime/dataloadfunctions/budni/BUDNI_ARC_STG2.sql
Executable file
282
onetime/dataloadfunctions/budni/BUDNI_ARC_STG2.sql
Executable file
@@ -0,0 +1,282 @@
|
||||
drop function if exists staging2.fn_BUDNI_ARC_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_ARC_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_BUDNI_ARC_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format:BUDNI
|
||||
Sheet Format: BUDNI_ARC
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_FTDRY_SUM_Block (20,1,'BUDNI','BUDNI_ARC',273);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
truncate staging2.BUDNI_ARC_Spec_H1_Block;
|
||||
truncate staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block;
|
||||
truncate staging2.BUDNI_ARC_Test_Obs_Summary_Block;
|
||||
truncate staging2.stg_specific_table_BUDNI_ARC;
|
||||
truncate staging2.stg_process_table_BUDNI_ARC;
|
||||
|
||||
|
||||
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 BUDNI*/
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_ARC
|
||||
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_BUDNI_ARC;
|
||||
|
||||
if err_query=0 then
|
||||
err_context :='data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni ARC',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_ARC',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic or data exists in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified;
|
||||
|
||||
|
||||
/* 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_BUDNI_ARC b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_BUDNI_ARC a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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 =''AIR CLEANER OIL PULL OVER TEST Observations Summary''
|
||||
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_BUDNI_ARC
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_ARC 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 Tractor Specifiactions''
|
||||
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_BUDNI_ARC
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_ARC 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=''Atmospheric conditions:''
|
||||
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_BUDNI_ARC
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_ARC 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=''AIR CLEANER OIL PULL OVER TEST Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_ARC a
|
||||
where block_tag='BUDNI_ARC_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_ARC a
|
||||
where block_tag='BUDNI_ARC_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_ARC_Spec_H1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_ARC_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_ARC_Spec_H1_Block';
|
||||
|
||||
insert into staging2.BUDNI_ARC_Spec_H1_block
|
||||
(
|
||||
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_ARC where block_tag='BUDNI_ARC_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_ARC_Spec_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||'''';
|
||||
|
||||
|
||||
update staging2.BUDNI_ARC_Spec_H1_block a
|
||||
set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6,
|
||||
Test_Engine_Set_RPM=column7,Type_of_track=column8
|
||||
from staging2.stg_process_table_BUDNI_ARC b
|
||||
where b.block_tag='BUDNI_ARC_Spec_H1'
|
||||
and b.block_row_number=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_ARC_Spec_H1_Block');
|
||||
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_ARC_Perf_Atmos_Meas_Test_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_ARC_Perf_Atmos_Meas_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
|
||||
err_block:='BUDNI_ARC_Perf_Atmos_Meas_Test_Block';
|
||||
|
||||
insert into staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block
|
||||
(
|
||||
Position_of_tractor,
|
||||
Loss_of_oil,
|
||||
Oil_pull_Over,
|
||||
Engine_oil_pressure,
|
||||
block_row_number
|
||||
)
|
||||
select
|
||||
column3,column6,column7,column8,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_ARC a
|
||||
where block_tag ='BUDNI_ARC_Perf_Atmos_Meas_Test' and block_row_number in (5,6,7,8,9)
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_ARC_Perf_Atmos_Meas_Test_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.BUDNI_ARC_Perf_Atmos_Meas_Test_Block a
|
||||
set
|
||||
Temperature_C=column3,
|
||||
Pressure_kPa=column4 ,
|
||||
Relative_humidity=column5,
|
||||
Mass_of_oil_before_test=column6
|
||||
from staging2.stg_process_table_BUDNI_ARC b
|
||||
where b.block_tag ='BUDNI_ARC_Perf_Atmos_Meas_Test'
|
||||
and b.block_row_number =3
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_ARC_Perf_Atmos_Meas_Test_Block');
|
||||
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_ARC_Test_Obs_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_ARC_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
|
||||
err_block:='BUDNI_ARC_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_ARC_Test_Obs_Summary_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_ARC a
|
||||
where block_tag='BUDNI_ARC_Test_Obs_Summary' and block_row_number in (1,2,3)
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_ARC_Test_Obs_Summary_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in(1,2);
|
||||
|
||||
|
||||
update staging2.BUDNI_ARC_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_ARC_Test_Obs_Summary_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,'BUDNI_ARC_Test_Obs_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_ARC_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
505
onetime/dataloadfunctions/budni/BUDNI_BRK_ODS.sql
Executable file
505
onetime/dataloadfunctions/budni/BUDNI_BRK_ODS.sql
Executable file
@@ -0,0 +1,505 @@
|
||||
drop function if exists staging2.fn_BUDNI_BRK_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_BRK_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_BRK_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_BRK
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_BRK_TRX()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
brake_type,
|
||||
brake_free_play_lh,
|
||||
brake_free_play_rh,
|
||||
unballasted_max_speed_kmph,
|
||||
road_ballasted_max_speed_kmph
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::numeric tractor_engine_hp,
|
||||
Type_of_brake,
|
||||
brake_free_play_lh::numeric ,
|
||||
brake_free_play_rh::numeric ,
|
||||
maximum_attainable_speed_kmph_unballasted::numeric ,
|
||||
maximum_attainable_speed_kmph_ballasted::numeric
|
||||
from staging2.BUDNI_BRK_Spec_H1_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;
|
||||
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
type_of_road
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
type_of_track
|
||||
from
|
||||
staging2.BUDNI_BRK_Spec_H1_block where trx_record =1;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int
|
||||
from staging2.BUDNI_BRK_Spec_H1_block where trx_record =1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.budni_brake_perf_service_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
braking_device_control_force_n,
|
||||
mean_deceleration_msec2,
|
||||
stopping_dist_m
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
Braking_device_control_force_N::numeric ,
|
||||
Mean_deceleration_m_sec2::numeric ,
|
||||
Stopping_distance_m ::numeric
|
||||
from staging2.budni_brk_service_cold_ballasted_25kmph_block where trx_record =1;
|
||||
|
||||
insert into transactional.budni_brake_perf_service_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
braking_device_control_force_n,
|
||||
mean_deceleration_msec2,
|
||||
stopping_dist_m
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
Braking_device_control_force_N::numeric ,
|
||||
Mean_deceleration_m_sec2::numeric ,
|
||||
Stopping_distance_m ::numeric
|
||||
from staging2.budni_brk_service_cold_ballasted_maximum_block where trx_record =1;
|
||||
|
||||
insert into transactional.budni_brake_perf_service_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
braking_device_control_force_n,
|
||||
mean_deceleration_msec2,
|
||||
stopping_dist_m
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
Braking_device_control_force_N::numeric ,
|
||||
Mean_deceleration_m_sec2::numeric ,
|
||||
Stopping_distance_m ::numeric
|
||||
from staging2.budni_brk_service_cold_standard_25kmph_block where trx_record =1;
|
||||
|
||||
insert into transactional.budni_brake_perf_service_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
braking_device_control_force_n,
|
||||
mean_deceleration_msec2,
|
||||
stopping_dist_m
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
Braking_device_control_force_N::numeric ,
|
||||
Mean_deceleration_m_sec2::numeric ,
|
||||
Stopping_distance_m ::numeric
|
||||
from staging2.budni_brk_service_cold_standard_maximum_block where trx_record =1;
|
||||
|
||||
|
||||
insert into transactional.budni_brake_perf_service_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
braking_device_control_force_n,
|
||||
mean_deceleration_msec2,
|
||||
stopping_dist_m
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
Braking_device_control_force_N::numeric ,
|
||||
Mean_deceleration_m_sec2::numeric ,
|
||||
Stopping_distance_m ::numeric
|
||||
from staging2.budni_brk_service_fade_standard_maximum_block where trx_record =1;
|
||||
|
||||
insert into transactional.budni_brake_perf_service_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
braking_device_control_force_n,
|
||||
mean_deceleration_msec2,
|
||||
stopping_dist_m
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
brake_test_type,
|
||||
brake_test_name,
|
||||
speed_condition,
|
||||
ballast_condition,
|
||||
Braking_device_control_force_N::numeric ,
|
||||
Mean_deceleration_m_sec2::numeric ,
|
||||
Stopping_distance_m ::numeric
|
||||
from staging2.budni_brk_service_fade_ballasted_25kmph_block;
|
||||
|
||||
|
||||
|
||||
update transactional.budni_brake_perf_service_brake_test_results
|
||||
set max_dev_of_tractor_from_its_org_course_m =column3,
|
||||
abnormal_vibration=column5,
|
||||
the_brakes_were_heated_by =column7
|
||||
from staging2.budni_brk_other_observations_Block where trx_record =1;
|
||||
|
||||
insert into transactional.budni_brake_perf_parking_brake_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
particulars
|
||||
from staging2.budni_brk_parking_barke_test_block where trx_record =1;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set braking_device_control_force_n_facing_up = (
|
||||
select Braking_device_control_force::numeric
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing up' and particulars='18 percent slope' and a.file_syspk=__file_syspk)
|
||||
where test_condition='18 percent slope' and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set braking_device_control_force_n_facing_down = (
|
||||
select Braking_device_control_force::numeric
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing Down' and particulars='18 percent slope' and a.file_syspk=__file_syspk)
|
||||
where test_condition='18 percent slope' and a.file_syspk =__file_syspk ;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set efficacy_of_parking_brake_facing_down = (
|
||||
select Efficacy_of_parking_brake
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing Down' and particulars='18 percent slope' and a.file_syspk=__file_syspk)
|
||||
where test_condition='18 percent slope' and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set efficacy_of_parking_brake_facing_up = (
|
||||
select Efficacy_of_parking_brake
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing up' and particulars='18 percent slope' and a.file_syspk=__file_syspk)
|
||||
where test_condition='18 percent slope' and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set braking_device_control_force_n_facing_up = (
|
||||
select Braking_device_control_force::numeric
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing up' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk)
|
||||
where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set braking_device_control_force_n_facing_down = (
|
||||
select Braking_device_control_force::numeric
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing Down' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk)
|
||||
where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set efficacy_of_parking_brake_facing_down = (
|
||||
select Efficacy_of_parking_brake
|
||||
from staging2.budni_brk_parking_barke_test_block b
|
||||
where facing='Facing Down' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk)
|
||||
where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk ;
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results a
|
||||
set efficacy_of_parking_brake_facing_up = (
|
||||
select Efficacy_of_parking_brake
|
||||
from staging2.budni_brk_parking_barke_test_block
|
||||
where facing='Facing up' and particulars='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk=__file_syspk)
|
||||
where test_condition='12 percent slope with trailer of 2.55 tonnes.' and a.file_syspk =__file_syspk;
|
||||
|
||||
delete from transactional.budni_brake_perf_parking_brake_test_results a
|
||||
using transactional.budni_brake_perf_parking_brake_test_results b
|
||||
where a.syspk < b.syspk and a.test_condition =b.test_condition and a.file_syspk =b.file_syspk;
|
||||
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8
|
||||
from staging2.BUDNI_BRK_test_obs_summary_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_brake_perf_parking_brake_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_brake_perf_service_brake_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_BRK_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
715
onetime/dataloadfunctions/budni/BUDNI_BRK_STG2.sql
Executable file
715
onetime/dataloadfunctions/budni/BUDNI_BRK_STG2.sql
Executable file
@@ -0,0 +1,715 @@
|
||||
drop function if exists staging2.fn_BUDNI_BRK_Block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_BRK_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;
|
||||
DECLARE __characteristic_1 text;
|
||||
|
||||
begin
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_BUDNI_BRK_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_BRK
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_BRK_Block(20,1,'BUDNI','BUDNI_BRK',273);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
truncate table staging2.BUDNI_BRK_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_BRK_Service_Barke_Test_Int;
|
||||
truncate table staging2.budni_brk_service_cold_ballasted_maximum_block;
|
||||
truncate table staging2.budni_brk_service_cold_standard_25kmph_block;
|
||||
truncate table staging2.budni_brk_service_cold_standard_maximum_block;
|
||||
truncate table staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block;
|
||||
truncate table staging2.BUDNI_BRK_service_fade_standard_maximum_Block;
|
||||
truncate table staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block;
|
||||
truncate table staging2.BUDNI_BRK_other_observations_Block;
|
||||
truncate table staging2.BUDNI_BRK_Parking_Barke_Test_Int;
|
||||
truncate table staging2.BUDNI_BRK_Parking_Barke_Test_Block;
|
||||
truncate table staging2.BUDNI_BRK_Test_Obs_Summary_Block;
|
||||
truncate table staging2.stg_specific_table_BUDNI_BRK;
|
||||
truncate table staging2.stg_process_table_BUDNI_BRK;
|
||||
|
||||
|
||||
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 BUDNI*/
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_BRK
|
||||
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_BUDNI_BRK;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni BRK',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_BRK',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
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_BUDNI_BRK b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_BUDNI_BRK a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)=upper(column3)
|
||||
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 =''Brake Performance Test Observations Summary''
|
||||
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_BUDNI_BRK
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_BRK 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 Tractor Specifiactions''
|
||||
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_BUDNI_BRK
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_BRK 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=''1) Service Barke Testing''
|
||||
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_BUDNI_BRK
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_BRK 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=''2) Parking Brake Test''
|
||||
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_BUDNI_BRK
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_BRK 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=''Brake Performance Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_BRK a
|
||||
where block_tag='BUDNI_BRK_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_BRK a
|
||||
where block_tag='BUDNI_BRK_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_Spec_H1_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_BRK_Spec_H1_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_Spec_H1_block
|
||||
(
|
||||
make,model,tractor_HP,rated_rpm,Type_of_brake ,
|
||||
Type_of_track,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_BRK where block_tag='BUDNI_BRK_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_BRK_Spec_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||'''';
|
||||
|
||||
|
||||
update staging2.BUDNI_BRK_Spec_H1_block a
|
||||
set brake_free_play_lh=column3,brake_free_play_rh=column4,
|
||||
maximum_attainable_speed_kmph_unballasted=column5,
|
||||
maximum_attainable_speed_kmph_ballasted=column6
|
||||
from staging2.stg_process_table_BUDNI_BRK b
|
||||
where b.block_tag='BUDNI_BRK_Spec_H1'
|
||||
and b.block_row_number=6
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_Spec_H1_block');
|
||||
|
||||
insert into staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
(
|
||||
column3,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9,
|
||||
block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_BRK a
|
||||
where block_tag ='BUDNI_BRK_Service_Barke_Test'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column2=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
where block_row_number=1) where block_row_number=3;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column3=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
where block_row_number=2) where block_row_number=3;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column3=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
where block_row_number=3)where block_row_number=10;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column5=(select column5 from staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
where block_row_number=18)where block_row_number=17;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column3=(select column3 from staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
where block_row_number=17)where block_row_number=22;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column3=null where block_row_number =1;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column3=null where block_row_number =2;
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
set column5 =null where block_row_number=18;
|
||||
|
||||
|
||||
update staging2.BUDNI_BRK_Service_Barke_Test_Int a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.budni_brk_service_barke_test_int set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_BRK_Service_Barke_Test_int 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||'''';
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_service_cold_standard_maximum_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_service_cold_standard_maximum_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_BRK_service_cold_standard_maximum_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_service_cold_standard_maximum_Block
|
||||
(
|
||||
dummy_f,
|
||||
Braking_device_control_force_N,
|
||||
Mean_deceleration_m_sec2,
|
||||
Stopping_distance_m
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (4,5,6)
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_standard_maximum_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_service_cold_standard_maximum_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_service_cold_standard_maximum_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.BUDNI_BRK_service_cold_standard_maximum_Block a
|
||||
set brake_test_type =column2,
|
||||
brake_test_name =column3,
|
||||
speed_condition =column5
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=3 and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_standard_maximum_Block a
|
||||
set ballast_condition =column3
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=4 and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_standard_maximum_Block');
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_service_cold_ballasted_maximum_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_service_cold_ballasted_maximum_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='BUDNI_BRK_service_cold_ballasted_maximum_Block';
|
||||
insert into staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block
|
||||
(
|
||||
dummy_f,
|
||||
Braking_device_control_force_N,
|
||||
Mean_deceleration_m_sec2,
|
||||
Stopping_distance_m
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (7,8,9)
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_service_cold_ballasted_maximum_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.BUDNI_BRK_service_cold_ballasted_maximum_Block a
|
||||
set brake_test_type =column2,
|
||||
brake_test_name =column3,
|
||||
speed_condition =column5
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=3 and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_ballasted_maximum_Block a
|
||||
set ballast_condition =column3
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=7 and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_ballasted_maximum_Block');
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_service_cold_standard_25kmph_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_service_cold_standard_25kmph_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='BUDNI_BRK_service_cold_standard_25kmph_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_service_cold_standard_25kmph_Block
|
||||
(
|
||||
dummy_f,
|
||||
Braking_device_control_force_N,
|
||||
Mean_deceleration_m_sec2,
|
||||
Stopping_distance_m
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (11,12,13)
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_standard_25kmph_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_service_cold_standard_25kmph_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_service_cold_standard_25kmph_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.BUDNI_BRK_service_cold_standard_25kmph_Block a
|
||||
set brake_test_type =column2,
|
||||
brake_test_name =column3,
|
||||
speed_condition =column5
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=10 and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_standard_25kmph_Block a
|
||||
set ballast_condition =column3
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=11 and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_standard_25kmph_Block');
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_service_cold_ballasted_25kmph_Block*/
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_service_cold_ballasted_25kmph_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='BUDNI_BRK_service_cold_ballasted_25kmph_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block
|
||||
(
|
||||
dummy_f,
|
||||
Braking_device_control_force_N,
|
||||
Mean_deceleration_m_sec2,
|
||||
Stopping_distance_m
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (14,15,16)
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_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.BUDNI_BRK_service_cold_ballasted_25kmph_Block a
|
||||
set brake_test_type =column2,
|
||||
brake_test_name =column3,
|
||||
speed_condition =column5
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=10 and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_BRK_service_cold_ballasted_25kmph_Block a
|
||||
set ballast_condition =column3
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=14 and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_cold_ballasted_25kmph_Block');
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_service_fade_standard_maximum_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_service_fade_standard_maximum_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='BUDNI_BRK_service_fade_standard_maximum_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_service_fade_standard_maximum_Block
|
||||
(
|
||||
dummy_f,
|
||||
Braking_device_control_force_N,
|
||||
Mean_deceleration_m_sec2,
|
||||
Stopping_distance_m
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (19,20,21)
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
update staging2.BUDNI_BRK_service_fade_standard_maximum_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_service_fade_standard_maximum_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_service_fade_standard_maximum_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.BUDNI_BRK_service_fade_standard_maximum_Block a
|
||||
set brake_test_type =column2,
|
||||
brake_test_name =column3,
|
||||
speed_condition =column5
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=17 and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_BRK_service_fade_standard_maximum_Block a
|
||||
set ballast_condition =column3
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=19 and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_fade_standard_maximum_Block');
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_service_fade_ballasted_25kmph_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_service_fade_ballasted_25kmph_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='BUDNI_BRK_service_fade_ballasted_25kmph_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block
|
||||
(
|
||||
dummy_f,
|
||||
Braking_device_control_force_N,
|
||||
Mean_deceleration_m_sec2,
|
||||
Stopping_distance_m
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Service_Barke_Test_Int where block_row_number in (23,24,25)
|
||||
ORDER BY generate_series(1,15),2'
|
||||
) t (col text,a_1 text,a_2 text,a_3 text);
|
||||
|
||||
update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_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.BUDNI_BRK_service_fade_ballasted_25kmph_Block a
|
||||
set brake_test_type =column2,
|
||||
brake_test_name =column3,
|
||||
speed_condition =column5
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=22 and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_BRK_service_fade_ballasted_25kmph_Block a
|
||||
set ballast_condition =column3
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int b
|
||||
where b.block_row_number=23 and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_service_fade_ballasted_25kmph_Block');
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_other_observations_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_other_observations_Block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='BUDNI_BRK_other_observations_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_other_observations_Block
|
||||
(
|
||||
column3,
|
||||
column5,
|
||||
column7,
|
||||
block_row_number
|
||||
)
|
||||
select
|
||||
column3,
|
||||
column5,
|
||||
column7,
|
||||
block_row_number
|
||||
from staging2.BUDNI_BRK_Service_Barke_Test_Int
|
||||
where block_row_number in (26,27,28) order by block_row_number;
|
||||
|
||||
update staging2.BUDNI_BRK_other_observations_Block
|
||||
set trx_record=0 where block_row_number in (26,27);
|
||||
|
||||
update staging2.BUDNI_BRK_other_observations_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_BRK_other_observations_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 trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_other_observations_Block');
|
||||
|
||||
|
||||
insert into staging2.BUDNI_BRK_Parking_Barke_Test_Int
|
||||
(
|
||||
column3,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
block_row_number
|
||||
)
|
||||
select
|
||||
column3,column5,column6,column7,column8,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_BRK a
|
||||
where block_tag ='BUDNI_BRK_Parking_Brake_Test'
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Int
|
||||
set column6=column5 where block_row_number=2;
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Int
|
||||
set column8=column7 where block_row_number=2;
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Int
|
||||
set column6=column5 where block_row_number=5;
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Int
|
||||
set column8=column7 where block_row_number=5;
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Int set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_BRK_Parking_Barke_Test_Int 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||'''';
|
||||
|
||||
|
||||
/* blocks data loading start -BUDNI_BRK_Parking_Barke_Test_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_Parking_Barke_Test_Block',__file_mnemonic,__file_sheet_mnemonic,9);
|
||||
err_block:='BUDNI_BRK_Parking_Barke_Test_Block';
|
||||
insert into staging2.BUDNI_BRK_Parking_Barke_Test_Block
|
||||
(
|
||||
dummy_f,
|
||||
particulars,
|
||||
facing,
|
||||
Braking_device_control_force,
|
||||
Efficacy_of_parking_brake
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_BRK_Parking_Barke_Test_Int where block_row_number <> 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);
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Block set trx_record=0 where particulars is null;
|
||||
|
||||
update staging2.BUDNI_BRK_Parking_Barke_Test_Block set make=__make,model=__model;
|
||||
delete from staging2.BUDNI_BRK_Parking_Barke_Test_Block where dummy_f is null;
|
||||
execute 'update staging2.BUDNI_BRK_Parking_Barke_Test_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 trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_Parking_Barke_Test_Block');
|
||||
|
||||
/* blocks data loading start - BUDNI_BRK_Test_Obs_Summary_Block */
|
||||
|
||||
perform trx.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_BRK_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,10);
|
||||
err_block:='BUDNI_BRK_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_BRK_Test_Obs_Summary_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_BRK a
|
||||
where block_tag='BUDNI_BRK_Test_Obs_Summary' and block_row_number <=7
|
||||
order by block_row_number;
|
||||
|
||||
select column3 into __characteristic_1 from staging2.BUDNI_BRK_Test_Obs_Summary_Block
|
||||
where block_row_number=3;
|
||||
|
||||
update staging2.BUDNI_BRK_Test_Obs_Summary_Block set
|
||||
column3=concat(__characteristic_1,'-',column3) where block_row_number in (4,5);
|
||||
|
||||
|
||||
update staging2.BUDNI_BRK_Test_Obs_Summary_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in(1,2,3);
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_BRK_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_BRK_Test_Obs_Summary_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 trx.fn_jobctl_block_end(__file_syspk,'BUDNI_BRK_Test_Obs_Summary_Block');
|
||||
|
||||
perform trx.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_BRK_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
207
onetime/dataloadfunctions/budni/BUDNI_DBP_ODS.sql
Executable file
207
onetime/dataloadfunctions/budni/BUDNI_DBP_ODS.sql
Executable file
@@ -0,0 +1,207 @@
|
||||
drop function if exists staging2.fn_BUDNI_DBP_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_DBP_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_DBP_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_DBP
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_DBP_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
configuration,
|
||||
Transmission_type,
|
||||
Wheel_Drive_Type,
|
||||
Steering_type,
|
||||
hitch_height_mm,
|
||||
Ballast_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
column3,
|
||||
column4,
|
||||
column7,
|
||||
column8,
|
||||
column9,
|
||||
column11,
|
||||
column13::int,
|
||||
column14
|
||||
from staging2.BUDNI_DBP_Spec_H1_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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
type_of_road
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
column3,
|
||||
column4,
|
||||
column15
|
||||
from staging2.BUDNI_DBP_Spec_H1_Block where trx_record =1 ;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
Rated_RPM,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
column3,
|
||||
column4,
|
||||
column6::int,
|
||||
column12
|
||||
from staging2.BUDNI_DBP_Spec_H1_Block where trx_record =1 ;
|
||||
|
||||
|
||||
insert into transactional.budni_drawbar_perf_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condtion,
|
||||
gear_used,
|
||||
travel_speed_km_per_hr,
|
||||
drawbar_power_kw,
|
||||
drawbar_pull_kn,
|
||||
engine_speed_rpm,
|
||||
wheel_slippage_pct ,
|
||||
fuel_consumption_kg_per_kwh,
|
||||
fuel_consumption_ltr_per_hr ,
|
||||
specific_energy_kwh_per_ltr,
|
||||
atmosp_conditions_temp_c,
|
||||
atmosp_conditions_pressure_kpa,
|
||||
atmosp_conditions_rh_pct,
|
||||
temp_fuel_c,
|
||||
temp_trans_oil_c,
|
||||
temp_coolant_c,
|
||||
temp_engine_oil_c
|
||||
)
|
||||
select
|
||||
client_id,function_id,file_syspk,file_mnemonic,file_sheet_mnemonic,make,model,
|
||||
column2,column3,column4::float,column5::float,column6::float,column7::float,
|
||||
column8::float,column9::float,column10::float,column11::float,column12,column13,
|
||||
column14,column15,column16,column17,column18
|
||||
from staging2.BUDNI_DBP_Drawbar_Perf_Block where trx_record = 1;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_drawbar_perf_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_DBP_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
257
onetime/dataloadfunctions/budni/BUDNI_DBP_STG2.sql
Executable file
257
onetime/dataloadfunctions/budni/BUDNI_DBP_STG2.sql
Executable file
@@ -0,0 +1,257 @@
|
||||
drop function if exists staging2.fn_BUDNI_DBP_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_DBP_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_BUDNI_DBP_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_DBP
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_DBP_Block(20,1,'BUDNI','BUDNI_DBP',261);
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.BUDNI_DBP_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_DBP_Drawbar_Perf_Block;
|
||||
truncate table staging2.stg_specific_table_budni_dbp;
|
||||
truncate table staging2.stg_process_table_budni_dbp;
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_budni_dbp
|
||||
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_budni_dbp;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni DBP',
|
||||
detail = 'No data in table stg_specific_table_budni_dbp',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
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_budni_dbp b
|
||||
where upper(F1_source)=upper(column3)
|
||||
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_budni_dbp a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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 =''Tractor Drawbar Performance Report.''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
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_budni_dbp
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_dbp 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 Tractor Specifiactions''
|
||||
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_budni_dbp
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_dbp 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 Drawbar Performance Report.''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_budni_dbp a
|
||||
where block_tag='BUDNI_DBP_Spec_H1' and block_row_number=2;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_budni_dbp a
|
||||
where block_tag='BUDNI_DBP_Spec_H1' and block_row_number=2;
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_DBP_Spec_H1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_DBP_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_DBP_Spec_H1_Block';
|
||||
|
||||
insert into staging2.BUDNI_DBP_Spec_H1_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,column13,
|
||||
column14,column15,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,column8,column9,column10,
|
||||
column11,column12,column13,column14,column15,block_row_number
|
||||
from staging2.stg_process_table_budni_dbp
|
||||
where block_tag='BUDNI_DBP_Spec_H1';
|
||||
|
||||
|
||||
update staging2.BUDNI_DBP_Spec_H1_Block
|
||||
set trx_record=0 where block_row_number in
|
||||
(select distinct first_value(b.block_row_number)
|
||||
over (partition by b.column2 order by b.syspk) from staging2.BUDNI_DBP_Spec_H1_Block b);
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_DBP_Spec_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,'BUDNI_DBP_Spec_H1_Block');
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_DBP_Spec_H1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_DBP_Drawbar_Perf_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_DBP_Drawbar_Perf_Block';
|
||||
|
||||
insert into staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,column13,
|
||||
column14,column15,column16,column17,column18,column19,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,column13,column14,
|
||||
column15,column16,column17,column18,column19,block_row_number
|
||||
from staging2.stg_process_table_budni_dbp a
|
||||
where block_tag='BUDNI_DBP_Drawbar_Perf'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_DBP_Drawbar_Perf_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_DBP_Drawbar_Perf_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.BUDNI_DBP_Drawbar_Perf_Block
|
||||
set column2= column3 where column3 like 'i%';
|
||||
|
||||
update staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
set column3=null
|
||||
where column3 like 'i%';
|
||||
|
||||
update staging2.BUDNI_DBP_Drawbar_Perf_Block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_DBP_Drawbar_Perf_Block
|
||||
set trx_record=0 where column4 is null or
|
||||
block_row_number in
|
||||
(select distinct first_value(b.block_row_number)
|
||||
over (partition by b.column2 order by b.syspk) from staging2.BUDNI_DBP_Drawbar_Perf_Block b);
|
||||
|
||||
delete from staging2.BUDNI_DBP_Drawbar_Perf_Block a
|
||||
using staging2.BUDNI_DBP_Drawbar_Perf_Block b
|
||||
where a.column2 like 'iV%' and b.column2 like 'iV%'
|
||||
and a.column2 =b.column2 and a.syspk>=b.syspk + 2;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_DBP_Drawbar_Perf_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_DBP_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
402
onetime/dataloadfunctions/budni/BUDNI_FLD_ODS.sql
Executable file
402
onetime/dataloadfunctions/budni/BUDNI_FLD_ODS.sql
Executable file
@@ -0,0 +1,402 @@
|
||||
drop function if exists staging2.fn_budni_fld_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_budni_fld_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_FLD_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_FLD
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_FLD_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
ballast_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
FIP_type,
|
||||
steering_type,
|
||||
Ballast_Condition
|
||||
from staging2.budni_fld_Spec_H1_block where trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model
|
||||
from
|
||||
staging2.budni_fld_Spec_H1_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;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio engine_to_pto_ratio_540_pto
|
||||
from staging2.budni_fld_Spec_H1_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
name_of_implement,
|
||||
make_of_implement,
|
||||
type_of_implement,
|
||||
no_of_disc_blades_bottoms,
|
||||
type_of_disc_blades_bottoms,
|
||||
size_of_bottoms_blades_mm,
|
||||
size_of_bottoms_blades2_mm,
|
||||
size_of_bottoms_blades3_mm,
|
||||
spacing_of_bottoms_flanges_mm,
|
||||
span_for_mounted_implement_mm,
|
||||
mast_height_for_mounted_implement_mm,
|
||||
length_mm,
|
||||
width_mm,
|
||||
height_mm,
|
||||
gross_mass_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
items,
|
||||
Make,
|
||||
type,
|
||||
No_of_Disc_blades,
|
||||
Type_of_Disc_blades,
|
||||
Size_of_bottoms_blades_1_mm::numeric,
|
||||
Size_of_bottoms_blades_2_mm::numeric,
|
||||
Size_of_bottoms_blades_3_mm::numeric,
|
||||
Spacing_of_bottoms_flanges_mm::numeric,
|
||||
Lower_hitch_point_span_mm::numeric,
|
||||
Mast_height_mm,
|
||||
Overall_dimensions_mm_length::numeric,
|
||||
Overall_dimensions_mm_Width::numeric,
|
||||
Overall_dimensions_mm_Height::numeric,
|
||||
Gross_mass_kg::numeric
|
||||
from staging2.BUDNI_FLD_Impl_Test_Block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
insert into transactional.test_instance_implement_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
name_of_implement,
|
||||
type_of_implement,
|
||||
cage_wheel_dia_mm,
|
||||
cage_wheel_width_mm,
|
||||
no_and_types_of_lugs,
|
||||
size_of_angle_section_mm,
|
||||
size_of_angle_section2_mm,
|
||||
size_of_angle_section3_mm,
|
||||
length_of_lugs_mm,
|
||||
spacing_of_lugs_mm,
|
||||
cage_wheel_weight_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
Items,
|
||||
type,
|
||||
Dia_mm::numeric,
|
||||
Width_mm::numeric,
|
||||
No_and_types_of_lugs,
|
||||
Size_of_angle_section_1_mm::numeric,
|
||||
Size_of_angle_section_2_mm::numeric,
|
||||
Size_of_angle_section_3_mm::numeric,
|
||||
Length_of_lugs_mm::numeric,
|
||||
Spacing_of_lugs_mm::numeric,
|
||||
Weight_of_each_cage_wheels_kg::numeric
|
||||
from staging2.BUDNI_FLD_Cage_Wheel_Block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
insert into transactional.budni_field_perf_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
operation_type,
|
||||
type_of_soil,
|
||||
avg_soil_moisture_pct_,
|
||||
bulk_density_of_soil_g_per_cc,
|
||||
cone_index_kgf_per_sq_cm,
|
||||
gear_used,
|
||||
avg_speed_of_operation_kmph,
|
||||
avg_wheel_slip_pct,
|
||||
avg_depth_of_cut_cm,
|
||||
avg_working_width_cm,
|
||||
area_covered_ha_per_hr,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_ltr_per_ha,
|
||||
avg_draft_of_implement_kn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
Parameter_operation,
|
||||
Type_of_soil,
|
||||
Av_soil_moisture_Av_depth_of_standing_water_cm,
|
||||
Bulk_density_of_soil_g_cc,
|
||||
Cone_index_kgf_sq_cm_Puddling_index,
|
||||
Gear_used,
|
||||
Av_speed_of_operation_kmph,
|
||||
Av_wheel_slip_Av_Travel_reduction,
|
||||
Av_depth_of_cut_cm_Av_Depth_of_puddle_cm,
|
||||
Av_working_width_cm,
|
||||
Area_covered_ha_h,
|
||||
Fuel_consumption_l_h,
|
||||
Fuel_consumption_l_ha,
|
||||
Av_draft_of_implement_kN
|
||||
from staging2.BUDNI_FLD_Sum_Perf_Test_Block where parameter_operation <> 'Puddling' and trx_record=1;
|
||||
|
||||
insert into transactional.budni_field_perf_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
operation_type,
|
||||
type_of_soil,
|
||||
avg_depth_of_standing_water_cm ,
|
||||
bulk_density_of_soil_g_per_cc,
|
||||
puddling_index_pct,
|
||||
gear_used,
|
||||
avg_speed_of_operation_kmph,
|
||||
avg_travel_reduction_pct,
|
||||
avg_depth_of_puddle_cm,
|
||||
avg_working_width_cm,
|
||||
area_covered_ha_per_hr,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_ltr_per_ha,
|
||||
avg_draft_of_implement_kn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
Parameter_operation,
|
||||
Type_of_soil,
|
||||
Av_soil_moisture_Av_depth_of_standing_water_cm,
|
||||
Bulk_density_of_soil_g_cc,
|
||||
Cone_index_kgf_sq_cm_Puddling_index,
|
||||
Gear_used,
|
||||
Av_speed_of_operation_kmph,
|
||||
Av_wheel_slip_Av_Travel_reduction,
|
||||
Av_depth_of_cut_cm_Av_Depth_of_puddle_cm,
|
||||
Av_working_width_cm,
|
||||
Area_covered_ha_h,
|
||||
Fuel_consumption_l_h,
|
||||
Fuel_consumption_l_ha,
|
||||
Av_draft_of_implement_kN
|
||||
from staging2.BUDNI_FLD_Sum_Perf_Test_Block where parameter_operation ='Puddling' and trx_record=1;
|
||||
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9
|
||||
from staging2.budni_fld_test_obs_summary_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_implement_info
|
||||
set test_instance_id=__test_instance_id
|
||||
--tractor_model =__model,
|
||||
--tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_field_perf_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_budni_fld_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
586
onetime/dataloadfunctions/budni/BUDNI_FLD_STG2.sql
Executable file
586
onetime/dataloadfunctions/budni/BUDNI_FLD_STG2.sql
Executable file
@@ -0,0 +1,586 @@
|
||||
drop function if exists staging2.fn_BUDNI_FLD_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_FLD_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_BUDNI_FLD_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_FLD
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_FLD_Block(20,1,'BUDNI','BUDNI_FLD',261)
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
|
||||
truncate table staging2.BUDNI_FLD_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_FLD_Impl_Test_Int;
|
||||
truncate table staging2.BUDNI_FLD_Impl_Test_Block;
|
||||
truncate table staging2.BUDNI_FLD_Cage_Wheel_Block;
|
||||
truncate table staging2.BUDNI_FLD_Sum_Perf_Test_Int;
|
||||
truncate table staging2.BUDNI_FLD_Sum_Perf_Test_Block;
|
||||
truncate table staging2.BUDNI_FLD_Test_Obs_Summary_Block;
|
||||
truncate table staging2.stg_specific_table_BUDNI_FLD;
|
||||
truncate table staging2.stg_process_table_BUDNI_FLD;
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_FLD
|
||||
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_BUDNI_FLD;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni FLD',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_FLD',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
|
||||
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_BUDNI_FLD b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_BUDNI_FLD a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)=upper(column3)
|
||||
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||'''';
|
||||
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
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 =''Field Performance Test Observations Summary''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
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_BUDNI_FLD
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_FLD 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 Tractor Specifiactions''
|
||||
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_BUDNI_FLD
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_FLD 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=''BRIEF SPECIFICATION OF IMPLEMENTS USED DURING FIELD TEST''
|
||||
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_BUDNI_FLD
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_FLD 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=''SUMMARY OF FIELD PERFORMANCE TEST''
|
||||
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_BUDNI_FLD
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_FLD 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=''Field Performance Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_FLD a
|
||||
where block_tag='BUDNI_FLD_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_FLD a
|
||||
where block_tag='BUDNI_FLD_Spec_H1' and block_row_number=3;
|
||||
|
||||
/* blocks data loading start - BUDNI_FLD_Spec_H1_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_FLD_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_FLD_Spec_H1_block';
|
||||
|
||||
insert into staging2.BUDNI_FLD_Spec_H1_block
|
||||
(
|
||||
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_FLD where block_tag='BUDNI_FLD_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_FLD_Spec_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||'''';
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Spec_H1_block a
|
||||
set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6,
|
||||
Test_Engine_Set_RPM=column7
|
||||
from staging2.stg_process_table_BUDNI_FLD b
|
||||
where b.block_tag='BUDNI_FLD_Spec_H1'
|
||||
and b.block_row_number=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_FLD_Spec_H1_block');
|
||||
|
||||
|
||||
insert into staging2.BUDNI_FLD_Impl_Test_Int
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_FLD a
|
||||
where block_tag ='BUDNI_FLD_Impl_Test' and block_row_number <> 1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Impl_Test_Int a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13 ;
|
||||
|
||||
update staging2.BUDNI_FLD_Impl_Test_Int a
|
||||
set column4= b.first_value from (SELECT
|
||||
block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column4,
|
||||
sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13 ;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Impl_Test_Int a
|
||||
set column5= b.first_value from (SELECT
|
||||
block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column5,
|
||||
sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13 ;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Impl_Test_Int a
|
||||
set column6= b.first_value from (SELECT
|
||||
block_row_number, column6, value_partition, first_value(column6) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column6,
|
||||
sum(case when column6 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number and a.block_row_number <> 13;
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Impl_Test_Int a
|
||||
set column7= b.first_value from (SELECT
|
||||
block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column7,
|
||||
sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Impl_Test_Int a
|
||||
set column8= b.first_value from (SELECT
|
||||
block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column8,
|
||||
sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_FLD_Impl_Test_Int 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||'''';
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_FLD_Impl_Test_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_FLD_Impl_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_FLD_Impl_Test_Block';
|
||||
|
||||
insert into staging2.BUDNI_FLD_Impl_Test_Block
|
||||
(
|
||||
dummy_f,
|
||||
items,
|
||||
Make,
|
||||
type,
|
||||
No_of_Disc_blades,
|
||||
Type_of_Disc_blades,
|
||||
Size_of_bottoms_blades_1_mm,
|
||||
Size_of_bottoms_blades_2_mm,
|
||||
Size_of_bottoms_blades_3_mm,
|
||||
Spacing_of_bottoms_flanges_mm,
|
||||
Lower_hitch_point_span_mm,
|
||||
Mast_height_mm,
|
||||
Overall_dimensions_mm,
|
||||
Overall_dimensions_mm_length,
|
||||
Overall_dimensions_mm_Width,
|
||||
Overall_dimensions_mm_Height,
|
||||
Gross_mass_kg
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text]) AS val
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int where trx_record=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);
|
||||
|
||||
|
||||
delete from staging2.BUDNI_FLD_Impl_Test_Block where dummy_f is null;
|
||||
|
||||
execute 'update staging2.BUDNI_FLD_Impl_Test_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,'BUDNI_FLD_Impl_Test_Block');
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_FLD_Cage_Wheel_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_FLD_Cage_Wheel_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='BUDNI_FLD_Cage_Wheel_Block';
|
||||
|
||||
insert into staging2.BUDNI_FLD_Cage_Wheel_Block
|
||||
(
|
||||
dummy_f,
|
||||
Items,
|
||||
type,
|
||||
Dia_mm,
|
||||
Width_mm,
|
||||
No_and_types_of_lugs,
|
||||
Size_of_angle_section_1_mm,
|
||||
Size_of_angle_section_2_mm,
|
||||
Size_of_angle_section_3_mm,
|
||||
Length_of_lugs_mm,
|
||||
Spacing_of_lugs_mm,
|
||||
Weight_of_each_cage_wheels_kg
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column9}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column9::text]) AS val
|
||||
FROM staging2.BUDNI_FLD_Impl_Test_Int where trx_record=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);
|
||||
|
||||
delete from staging2.BUDNI_FLD_Cage_Wheel_Block where dummy_f is null;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_FLD_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,'BUDNI_FLD_Cage_Wheel_Block');
|
||||
|
||||
|
||||
|
||||
insert into staging2.BUDNI_FLD_Sum_Perf_Test_Int
|
||||
(
|
||||
column3,column4,column5,column6,column7,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_FLD a
|
||||
where block_tag ='BUDNI_FLD_Sum_Perf_Test' and block_row_number <> 1
|
||||
order by block_row_number,column3 ;
|
||||
|
||||
update staging2.BUDNI_FLD_Sum_Perf_Test_Int set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_FLD_Sum_Perf_Test_Int 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||'''';
|
||||
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_FLD_Sum_Perf_Test_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_FLD_Sum_Perf_Test_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='BUDNI_FLD_Sum_Perf_Test_Block';
|
||||
|
||||
insert into staging2.BUDNI_FLD_Sum_Perf_Test_Block
|
||||
(
|
||||
dummy_f,
|
||||
Parameter_operation,
|
||||
Type_of_soil,
|
||||
Av_soil_moisture_Av_depth_of_standing_water_cm,
|
||||
Bulk_density_of_soil_g_cc,
|
||||
Cone_index_kgf_sq_cm_Puddling_index,
|
||||
Gear_used,
|
||||
Av_speed_of_operation_kmph,
|
||||
Av_wheel_slip_Av_Travel_reduction,
|
||||
Av_depth_of_cut_cm_Av_Depth_of_puddle_cm,
|
||||
Av_working_width_cm,
|
||||
Area_covered_ha_h,
|
||||
Fuel_consumption,
|
||||
Fuel_consumption_l_h,
|
||||
Fuel_consumption_l_ha,
|
||||
Av_draft_of_implement_kN
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column5,column6,column7}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column5::text,column6::text,column7::text]) AS val
|
||||
FROM staging2.BUDNI_FLD_Sum_Perf_Test_Int where trx_record=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);
|
||||
|
||||
|
||||
|
||||
delete from staging2.BUDNI_FLD_Sum_Perf_Test_Block where dummy_f is null;
|
||||
|
||||
update staging2.BUDNI_FLD_Sum_Perf_Test_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_FLD_Sum_Perf_Test_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,'BUDNI_FLD_Sum_Perf_Test_Block');
|
||||
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_FLD_Test_Obs_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_FLD_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='BUDNI_FLD_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_FLD a
|
||||
where block_tag='BUDNI_FLD_Test_Obs_Summary' and block_row_number <=6;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
set trx_record=0
|
||||
where block_row_number in (1,2);
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block a
|
||||
set column4= b.first_value from (SELECT
|
||||
block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column4,
|
||||
sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block a
|
||||
set column5= b.first_value from (SELECT
|
||||
block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column5,
|
||||
sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block a
|
||||
set column6= b.first_value from (SELECT
|
||||
block_row_number, column6, value_partition, first_value(column6) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column6,
|
||||
sum(case when column6 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block a
|
||||
set column7= b.first_value from (SELECT
|
||||
block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column7,
|
||||
sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block a
|
||||
set column8= b.first_value from (SELECT
|
||||
block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column8,
|
||||
sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block a
|
||||
set column9= b.first_value from (SELECT
|
||||
block_row_number, column9, value_partition, first_value(column9) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column9,
|
||||
sum(case when column9 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_FLD_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_FLD_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_FLD_Test_Obs_Summary_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,'BUDNI_FLD_Test_Obs_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_FLD_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
364
onetime/dataloadfunctions/budni/BUDNI_HDL_ODS.sql
Executable file
364
onetime/dataloadfunctions/budni/BUDNI_HDL_ODS.sql
Executable file
@@ -0,0 +1,364 @@
|
||||
drop function if exists staging2.fn_BUDNI_HDL_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_HDL_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_instance_tractor_id int;
|
||||
begin
|
||||
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_HDL_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_HDL
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_HDL_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
steering_type
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int,
|
||||
steering_type
|
||||
from staging2.BUDNI_HDL_Spec_H1_block;
|
||||
|
||||
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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model
|
||||
from
|
||||
staging2.BUDNI_HDL_Spec_H1_block;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
rated_rpm::int
|
||||
from staging2.BUDNI_HDL_Spec_H1_block;
|
||||
|
||||
insert into transactional.test_instance_tractor_info_misc
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
hydraulic_type,
|
||||
pump_speed_at_rated_engine_speed_rpm,
|
||||
oil,
|
||||
lift_rod_type_lh,
|
||||
lift_rod_type_rh,
|
||||
lift_rod_length_lh,
|
||||
lift_rod_length_rh,
|
||||
lower_link_length_lh,
|
||||
lower_link_length_rh,
|
||||
pump_hp
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
hydraulic_type,
|
||||
Pump_speed_at_rated_engine_speed_rpm::numeric,
|
||||
Oil,
|
||||
Lift_Rod_type_LH,
|
||||
Lift_Rod_type_RH,
|
||||
Lift_Rod_Length_LH::numeric,
|
||||
Lift_Rod_Length_RH::numeric,
|
||||
Lower_link_Length_LH::numeric,
|
||||
Lower_link_Length_RH::numeric,
|
||||
Pump_HP::numeric
|
||||
from staging2.BUDNI_HDL_Spec_H1_block;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.budni_hydraulic_power_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
pump_dlvry_rate_at_min_pressure_engine_speed_l_per_min,
|
||||
max_hydraulic_power_kw,
|
||||
pump_dlvry_rate_at_max_hydraulic_power_lmin,
|
||||
pressure_at_max_hydraulic_power_mpa,
|
||||
sustained_pressure_of_the_open_relief_valve_mpa,
|
||||
tapping_point_relief_valve_test,
|
||||
tapping_point_pump_perf_test,
|
||||
tapping_point_temperature_of_hydraulic_fluid_c
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
Pump_delivery_rate_at_min_pressure_and_rated_engine::numeric,
|
||||
Maximum_hydraulic_power_kW::numeric,
|
||||
Pump_delivery_rate_at_maximum_hydraulic_power_l_min::numeric,
|
||||
Pressure_at_maximum_hydraulic_power_MPa::numeric,
|
||||
Sustained_pressure_of_the_open_relief_valve_MPa::numeric,
|
||||
tapping_point_relief_valve_test,
|
||||
tapping_point_Pump_performance_test,
|
||||
tapping_point_Temperature_of_hydraulic_fluid_C
|
||||
from staging2.budni_hdl_power_test_block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
insert into transactional.budni_hydraulic_maint_of_lift_load_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
force_applied_at_the_frame_kn,
|
||||
temp_of_hydraulic_fluid_at_the_start_of_test_c,
|
||||
elapsed_time_min,
|
||||
cumulative_drop_in_height_of_lift_mm
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
Force_applied_at_the_frame_kN::numeric,
|
||||
Temperature_of_hydraulic_fluid_at_the_start_of_test_C,
|
||||
Elapsed_time_minute::numeric,
|
||||
Cumulative_drop_in_height_of_lift_mm::numeric
|
||||
from staging2.budni_hdl_maintenance_of_lift_load_block;
|
||||
|
||||
/*block */
|
||||
insert into transactional.budni_hydraulic_lifting_capacity_test_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
test_condition,
|
||||
height_of_lower_hitch_pt_above_ground_in_down_position_mm,
|
||||
vertical_move_ment_with_lifting_forces_mm,
|
||||
max_force_exerted_through_full_range_kn,
|
||||
corresponding_pressure_mpa,
|
||||
moment_about_rear_axle_kn_m,
|
||||
max_tilt_angle_of_mast_from_vertical_degrees
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
column5,
|
||||
column6::numeric,
|
||||
column7::numeric,
|
||||
column8::numeric,
|
||||
column9::numeric,
|
||||
column10::numeric,
|
||||
column11::numeric
|
||||
from staging2.budni_hdl_Lifting_Capacity_Test_Block
|
||||
where trx_record=1;
|
||||
|
||||
|
||||
/* block */
|
||||
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,column4,column7,column8,column10,column11,column12
|
||||
from staging2.budni_hdl_test_obs_summary_block
|
||||
where trx_record=1
|
||||
;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info_misc
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_hydraulic_maint_of_lift_load_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_hydraulic_power_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_hydraulic_lifting_capacity_test_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_HDL_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
547
onetime/dataloadfunctions/budni/BUDNI_HDL_STG2.sql
Executable file
547
onetime/dataloadfunctions/budni/BUDNI_HDL_STG2.sql
Executable file
@@ -0,0 +1,547 @@
|
||||
drop function if exists staging2.fn_budni_hdl_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_budni_hdl_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;
|
||||
DECLARE __characteristic_A text;
|
||||
begin
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_budni_hdl_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_HDL
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_HDL_Block(20,1,'BUDNI','BUDNI_HDL',261);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.stg_specific_table_budni_hdl;
|
||||
truncate table staging2.stg_process_table_budni_hdl;
|
||||
truncate table staging2.budni_hdl_Spec_H1_Block;
|
||||
truncate table staging2.budni_hdl_power_test_Block;
|
||||
truncate table staging2.budni_hdl_Lifting_Capacity_Test_Block;
|
||||
truncate table staging2.budni_hdl_Maintenance_of_lift_load_int;
|
||||
truncate table staging2.budni_hdl_Maintenance_of_lift_load_Block;
|
||||
truncate table staging2.budni_hdl_Test_Obs_Summary_Block;
|
||||
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_budni_hdl
|
||||
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_budni_hdl;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni_HDL',
|
||||
detail = 'No data in table stg_specific_table_budni_hdl',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
|
||||
|
||||
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_budni_hdl b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_budni_hdl a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
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 =''Power Lift and Hydraulic Pump Performance Test Observations Summary''
|
||||
and 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 '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||'''';
|
||||
|
||||
|
||||
execute 'insert into staging2.stg_process_table_budni_hdl
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_hdl 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 Tractor Specifiactions''
|
||||
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_budni_hdl
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_hdl 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=''A) Hydraulic power test:''
|
||||
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_budni_hdl
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_hdl 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=''Tapping Point''
|
||||
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_budni_hdl
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_hdl 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=''C) Maintenance of lift load:''
|
||||
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_budni_hdl
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_hdl 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=''Power Lift and Hydraulic Pump Performance Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_budni_hdl a
|
||||
where block_tag='BUDNI_HDL_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_budni_hdl a
|
||||
where block_tag='BUDNI_HDL_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
|
||||
/* blocks data loading start - budni_hdl_Spec_H1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_HDL_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_HDL_Spec_H1_block';
|
||||
insert into staging2.budni_hdl_Spec_H1_Block
|
||||
(
|
||||
make,
|
||||
model,
|
||||
tractor_HP,
|
||||
rated_rpm,
|
||||
hydraulic_type,
|
||||
Pump_speed_at_rated_engine_speed_rpm,
|
||||
Steering_Type,
|
||||
Oil,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,column8,column9,column10,block_row_number
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag='BUDNI_HDL_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.budni_hdl_Spec_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||'''';
|
||||
|
||||
|
||||
|
||||
update staging2.BUDNI_HDL_Spec_H1_block a
|
||||
set Lift_Rod_type_LH =column3,
|
||||
Lift_Rod_type_RH= column4,
|
||||
Lift_Rod_Length_LH=column5,
|
||||
Lift_Rod_Length_RH=column6,
|
||||
Lower_link_Length_LH=column7,
|
||||
Lower_link_Length_RH=column8,
|
||||
Pump_HP=column9
|
||||
from staging2.stg_process_table_budni_hdl b
|
||||
where b.block_tag='BUDNI_HDL_Spec_H1'
|
||||
and b.block_row_number=6
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_HDL_Spec_H1_block');
|
||||
|
||||
|
||||
/* blocks data loading - budni_hdl_power_test_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'budni_hdl_power_test_block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='budni_hdl_power_test_block';
|
||||
insert into staging2.budni_hdl_power_test_block (dummy_f) values('dummy');
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set Pump_delivery_rate_at_min_pressure_and_rated_engine= (select column3
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set Maximum_hydraulic_power_kW= (select column5
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set Pump_delivery_rate_at_maximum_hydraulic_power_l_min= (select column7
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set Pressure_at_maximum_hydraulic_power_MPa= (select column9
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set Sustained_pressure_of_the_open_relief_valve_MPa= (select column11
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Power_Test' and block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set tapping_point_relief_valve_test = (select column4
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Lifting_Capacity_Test' and block_row_number=2)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set tapping_point_Pump_performance_test= (select column4
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Lifting_Capacity_Test' and block_row_number=3)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.budni_hdl_power_test_block
|
||||
set tapping_point_Temperature_of_hydraulic_fluid_C= (select column4
|
||||
from staging2.stg_process_table_budni_hdl
|
||||
where block_tag ='BUDNI_HDL_Lifting_Capacity_Test' and block_row_number=4)
|
||||
where dummy_f='dummy';
|
||||
|
||||
|
||||
update staging2.BUDNI_HDL_Power_Test_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_HDL_Power_Test_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.BUDNI_HDL_Power_Test_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_power_test_block');
|
||||
|
||||
/* blocks data loading - budni_hdl_Lifting_Capacity_Test_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'budni_hdl_Lifting_Capacity_Test_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='budni_hdl_Lifting_Capacity_Test_Block';
|
||||
insert into staging2.budni_hdl_Lifting_Capacity_Test_Block
|
||||
(
|
||||
column5,column6,column7,
|
||||
column8,column9,column10,column11,block_row_number
|
||||
)
|
||||
select
|
||||
column5,column6,column7,
|
||||
column8,column9,column10,column11,block_row_number
|
||||
from staging2.stg_process_table_budni_hdl a
|
||||
where block_tag='BUDNI_HDL_Lifting_Capacity_Test';
|
||||
|
||||
|
||||
update staging2.budni_hdl_Lifting_Capacity_Test_Block set make=__make,model=__model;
|
||||
execute 'update staging2.budni_hdl_Lifting_Capacity_Test_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.budni_hdl_Lifting_Capacity_Test_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2);
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_Lifting_Capacity_Test_Block');
|
||||
|
||||
|
||||
|
||||
insert into staging2.budni_hdl_Maintenance_of_lift_load_int
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_budni_hdl a
|
||||
where block_tag='BUDNI_HDL_Maintenance_Of_Lift_Load';
|
||||
|
||||
update staging2.budni_hdl_Maintenance_of_lift_load_int
|
||||
set trx_record=0 where
|
||||
block_row_number=1;
|
||||
|
||||
|
||||
|
||||
/* blocks data loading - PTOBST_RPT_PTO_performance_report_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'budni_hdl_Maintenance_of_lift_load_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='budni_hdl_Maintenance_of_lift_load_Block';
|
||||
insert into staging2.budni_hdl_Maintenance_of_lift_load_Block
|
||||
(
|
||||
dummy_f,
|
||||
Elapsed_time_minute,
|
||||
Cumulative_drop_in_height_of_lift_mm
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column7,column8,column9,column10,column11,column12}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column7::text,column8::text,column9::text,
|
||||
column10::text,column11::text,column12::text]) AS val
|
||||
FROM staging2.budni_hdl_Maintenance_of_lift_load_int where block_row_number in (2,3)
|
||||
ORDER BY generate_series(1,15),block_row_number,2'
|
||||
) t (col text,a_1 text,a_2 text);
|
||||
|
||||
|
||||
|
||||
update staging2.budni_hdl_Maintenance_of_lift_load_block
|
||||
set Force_applied_at_the_frame_kN =(select column5
|
||||
from staging2.budni_hdl_Maintenance_of_lift_load_int
|
||||
where column3 ='Force applied at the frame, (kN)')
|
||||
where Force_applied_at_the_frame_kN is null;
|
||||
|
||||
update staging2.budni_hdl_Maintenance_of_lift_load_block
|
||||
set Temperature_of_hydraulic_fluid_at_the_start_of_test_C =(select column5
|
||||
from staging2.budni_hdl_Maintenance_of_lift_load_int
|
||||
where column3 ='Temperature of hydraulic fluid at the start of test, (â °C)')
|
||||
where Temperature_of_hydraulic_fluid_at_the_start_of_test_C is null;
|
||||
|
||||
|
||||
delete from staging2.budni_hdl_Maintenance_of_lift_load_block where dummy_f is null;
|
||||
update staging2.budni_hdl_Maintenance_of_lift_load_block set make=__make,model=__model;
|
||||
execute 'update staging2.budni_hdl_Maintenance_of_lift_load_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,'budni_hdl_Maintenance_of_lift_load_Block');
|
||||
|
||||
|
||||
/* blocks data loading - budni_hdl_Test_Obs_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'budni_hdl_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='budni_hdl_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_budni_hdl a
|
||||
where block_tag='BUDNI_HDL_Test_Obs_Summary' and block_row_number not in (8,9);
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column4= b.first_value from (SELECT
|
||||
block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column4,
|
||||
sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column5= b.first_value from (SELECT
|
||||
block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column5,
|
||||
sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column7= b.first_value from (SELECT
|
||||
block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column7,
|
||||
sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column8= b.first_value from (SELECT
|
||||
block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column8,
|
||||
sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column11= b.first_value from (SELECT
|
||||
block_row_number, column11, value_partition, first_value(column11) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column11,
|
||||
sum(case when column11 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block a
|
||||
set column12= b.first_value from (SELECT
|
||||
block_row_number, column12, value_partition, first_value(column12) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column12,
|
||||
sum(case when column12 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
|
||||
|
||||
select column4 into __characteristic_A
|
||||
from staging2.budni_hdl_Test_Obs_Summary_Block where block_row_number=3;
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block
|
||||
set column4=concat(column4,'. ',__characteristic_A,' -',column5) where trx_record =1;
|
||||
|
||||
|
||||
|
||||
update staging2.budni_hdl_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.budni_hdl_Test_Obs_Summary_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.budni_hdl_Test_Obs_Summary_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2,3);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'budni_hdl_Test_Obs_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_budni_hdl_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
259
onetime/dataloadfunctions/budni/BUDNI_HLG_ODS.sql
Executable file
259
onetime/dataloadfunctions/budni/BUDNI_HLG_ODS.sql
Executable file
@@ -0,0 +1,259 @@
|
||||
drop function if exists staging2.fn_budni_hlg_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_budni_hlg_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_HLG_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_HLG
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_HLG_TRX()
|
||||
***************************************************************/
|
||||
|
||||
/*select file_syspk into __file_syspk from staging2.BUDNI_HLG_Spec_H1_block; */
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
ballast_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
FIP_type,
|
||||
steering_type,
|
||||
Ballast_Condition
|
||||
from staging2.budni_hlg_Spec_H1_block;
|
||||
|
||||
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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
type_of_road
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
type_of_track
|
||||
from
|
||||
staging2.budni_hlg_Spec_H1_block;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio engine_to_pto_ratio_540_pto
|
||||
from staging2.budni_hlg_Spec_H1_block;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.budni_haulage_perf_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
trailer_type,
|
||||
gross_mass_of_trailer_tonne,
|
||||
height_of_trailer_hitch_above_ground_level_mm,
|
||||
gear_used_negotiating_slopes_up_to_8pct,
|
||||
avg_travel_speed_kmph,
|
||||
avg_fuel_consumption_ltr_per_hr,
|
||||
avg_fuel_consumption_ml_per_km_per_tonne,
|
||||
avg_dist_traveled_per_litre_of_fuel_consumption_km,
|
||||
effectiveness_of_brakes,
|
||||
maneuverability_of_tractor_trailer_combination
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
type_of_trailer,
|
||||
Gross_mass_of_trailer_tonne::numeric,
|
||||
Height_of_trailer_hitch_above_ground_level_mm::numeric,
|
||||
Gear_used_during_the_test_for_negotiating_slopes_up_to_8,
|
||||
Average_travel_speed_kmph,
|
||||
l_h,
|
||||
ml_km_tonne,
|
||||
Average_distance_traveled_per_litre_of_fuel_consumption_km,
|
||||
Effectiveness_of_brakes,
|
||||
Maneuverability_of_tractor_trailer_combination
|
||||
from staging2.BUDNI_HLG_Perf_Test_block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
sequence_number ,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3::numeric ,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9
|
||||
from staging2.budni_hlg_test_obs_summary_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
|
||||
update transactional.budni_haulage_perf_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_budni_hlg_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
407
onetime/dataloadfunctions/budni/BUDNI_HLG_STG2.sql
Executable file
407
onetime/dataloadfunctions/budni/BUDNI_HLG_STG2.sql
Executable file
@@ -0,0 +1,407 @@
|
||||
drop function if exists staging2.fn_BUDNI_HLG_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_HLG_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;
|
||||
DECLARE __characteristic_1 text;
|
||||
DECLARE __characteristic_2 text;
|
||||
DECLARE __characteristic_3 text;
|
||||
begin
|
||||
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_BUDNI_HLG_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_HLG
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_HLG_Block(20,1,'BUDNI','BUDNI_HLG',261);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.BUDNI_HLG_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_HLG_Perf_Test_int;
|
||||
truncate table staging2.BUDNI_HLG_Perf_Test_block;
|
||||
truncate table staging2.BUDNI_HLG_Test_Obs_Summary_Block;
|
||||
truncate table staging2.stg_specific_table_BUDNI_HLG;
|
||||
truncate table staging2.stg_process_table_BUDNI_HLG;
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_HLG
|
||||
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_BUDNI_HLG;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni HLG',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_HLG',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified;
|
||||
|
||||
|
||||
/* reverese update in process table for match*/
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_BUDNI_HLG b
|
||||
where trim(upper(F1_source))= trim(upper(column3))
|
||||
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||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
execute 'update staging2.stg_specific_table_BUDNI_HLG a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where trim(upper(F1_source))= trim(upper(column3))
|
||||
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||'''';
|
||||
|
||||
|
||||
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 =''Haulage Performance Test Observations Summary''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
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_BUDNI_HLG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_HLG 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 Tractor Specifiactions''
|
||||
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_BUDNI_HLG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_HLG 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=''Haulage performance Test''
|
||||
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_BUDNI_HLG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_HLG 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=''Haulage Performance Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_HLG a
|
||||
where block_tag='BUDNI_HLG_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_HLG a
|
||||
where block_tag='BUDNI_HLG_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_HLG_Spec_H1_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_HLG_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_HLG_Spec_H1_block';
|
||||
insert into staging2.BUDNI_HLG_Spec_H1_block
|
||||
(
|
||||
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_HLG where block_tag='BUDNI_HLG_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_HLG_Spec_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||'''';
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Spec_H1_block a
|
||||
set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6,
|
||||
Test_Engine_Set_RPM=column7,Type_of_track=column8
|
||||
from staging2.stg_process_table_BUDNI_HLG b
|
||||
where b.block_tag='BUDNI_HLG_Spec_H1'
|
||||
and b.block_row_number=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_HLG_Spec_H1_block');
|
||||
|
||||
insert into staging2.BUDNI_HLG_Perf_Test_int
|
||||
(
|
||||
column3,column6,column8,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column6,column8,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_HLG a
|
||||
where block_tag ='BUDNI_HLG_Perf_Test'
|
||||
order by block_row_number,column3;
|
||||
|
||||
update staging2.BUDNI_HLG_Perf_Test_int set trx_record=0 where block_row_number =1;
|
||||
|
||||
update staging2.BUDNI_HLG_Perf_Test_int set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_HLG_Perf_Test_int 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||'''';
|
||||
|
||||
/* blocks data loading - BUDNI_HLG_perf_test_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_HLG_perf_test_block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
|
||||
err_block:='BUDNI_HLG_perf_test_block';
|
||||
|
||||
insert into staging2.BUDNI_HLG_perf_test_block
|
||||
(
|
||||
dummy_f,
|
||||
type_of_trailer,
|
||||
Gross_mass_of_trailer_tonne,
|
||||
Height_of_trailer_hitch_above_ground_level_mm,
|
||||
Gear_used_during_the_test_for_negotiating_slopes_up_to_8,
|
||||
Average_travel_speed_kmph,
|
||||
Average_fuel_consumption,
|
||||
l_h,
|
||||
ml_km_tonne,
|
||||
Average_distance_traveled_per_litre_of_fuel_consumption_km,
|
||||
General_observations,
|
||||
Effectiveness_of_brakes,
|
||||
Maneuverability_of_tractor_trailer_combination
|
||||
)
|
||||
SELECT *
|
||||
FROM crosstab(
|
||||
'SELECT unnest(''{column6,column8}''::text[]) AS col
|
||||
, row_number() OVER ()
|
||||
, unnest(ARRAY[column6::text,column8::text]) AS val
|
||||
FROM staging2.BUDNI_HLG_Perf_Test_int where trx_record=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);
|
||||
|
||||
delete from staging2.BUDNI_HLG_Perf_Test_block where dummy_f is null;
|
||||
update staging2.BUDNI_HLG_Perf_Test_block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_HLG_Perf_Test_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,'BUDNI_HLG_perf_test_block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_HLG_Test_Obs_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_HLG_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
|
||||
err_block:='BUDNI_HLG_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_HLG a
|
||||
where block_tag='BUDNI_HLG_Test_Obs_Summary' and block_row_number <=11
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block a
|
||||
set column5= b.first_value from (SELECT
|
||||
block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column5,
|
||||
sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
|
||||
|
||||
--update staging2.BUDNI_HLG_Test_Obs_Summary_Block a
|
||||
--set column7= b.first_value from (SELECT
|
||||
-- block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number)
|
||||
--FROM (
|
||||
-- SELECT
|
||||
-- block_row_number,
|
||||
-- column7,
|
||||
-- sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
-- FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
-- ORDER BY block_row_number ASC
|
||||
--) as q) b where a.block_row_number = b.block_row_number ;
|
||||
--
|
||||
--
|
||||
--update staging2.BUDNI_HLG_Test_Obs_Summary_Block a
|
||||
--set column8= b.first_value from (SELECT
|
||||
-- block_row_number, column8, value_partition, first_value(column8) over (partition by value_partition order by block_row_number)
|
||||
--FROM (
|
||||
-- SELECT
|
||||
-- block_row_number,
|
||||
-- column8,
|
||||
-- sum(case when column8 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
-- FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
-- ORDER BY block_row_number ASC
|
||||
--) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
|
||||
--update staging2.BUDNI_HLG_Test_Obs_Summary_Block a
|
||||
--set column9= b.first_value from (SELECT
|
||||
-- block_row_number, column9, value_partition, first_value(column9) over (partition by value_partition order by block_row_number)
|
||||
--FROM (
|
||||
-- SELECT
|
||||
-- block_row_number,
|
||||
-- column9,
|
||||
-- sum(case when column9 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
-- FROM staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
-- ORDER BY block_row_number ASC
|
||||
--) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in
|
||||
(select distinct first_value(b.block_row_number)
|
||||
over (partition by b.column3 order by b.syspk) from staging2.BUDNI_HLG_Test_Obs_Summary_Block b);
|
||||
|
||||
|
||||
|
||||
select column4 into __characteristic_1 from staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
where block_row_number=3;
|
||||
|
||||
|
||||
select column4 into __characteristic_2 from staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
where block_row_number=6;
|
||||
|
||||
|
||||
select column4 into __characteristic_3 from staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
where block_row_number=9;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set column4=concat(__characteristic_1,'-',column4) where block_row_number=4;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set column4=concat(__characteristic_1,'-',column4) where block_row_number=5;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set column4=concat(__characteristic_2,'-',column4) where block_row_number=7;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set column4=concat(__characteristic_2,'-',column4) where block_row_number=8;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set column4=concat(__characteristic_3,'-',column4) where block_row_number=10;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block
|
||||
set column4=concat(__characteristic_3,'-',column4) where block_row_number=11;
|
||||
|
||||
|
||||
update staging2.BUDNI_HLG_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_HLG_Test_Obs_Summary_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,'BUDNI_HLG_Test_Obs_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_HLG_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
202
onetime/dataloadfunctions/budni/BUDNI_LCG_ODS.sql
Executable file
202
onetime/dataloadfunctions/budni/BUDNI_LCG_ODS.sql
Executable file
@@ -0,0 +1,202 @@
|
||||
drop function if exists staging2.fn_BUDNI_LCG_TRX ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_LCG_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_LCG_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_LCG
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_LCG_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
wheel_base_mm,
|
||||
wheel_track_mm,
|
||||
overall_height_mm,
|
||||
ballast_condition,
|
||||
weight_reactions_front_kg,
|
||||
weight_reactions_rear_kg
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
Tractor_HP::int tractor_engine_hp,
|
||||
configuration,
|
||||
Transmission_type,
|
||||
Wheel_Drive_type,
|
||||
Wheel_Base::int wheel_base_mm,
|
||||
wheel_track::int wheel_track_mm,
|
||||
overall_height::int,
|
||||
Ballast_Condition,
|
||||
Tractor_Weight_reactions_Front::int weight_reactions_front_kg ,
|
||||
Tractor_Weight_reactions_Rear::int weight_reactions_rear_kg
|
||||
from staging2.BUDNI_LCG_Spec_H1_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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model
|
||||
from staging2.BUDNI_LCG_Spec_H1_Block where trx_record =1 ;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
Rated_RPM
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
rated_rpm::int
|
||||
from staging2.BUDNI_LCG_Spec_H1_Block where trx_record =1 ;
|
||||
|
||||
|
||||
insert into transactional.budni_centre_of_gravity_location
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
condition,
|
||||
particulars,
|
||||
coordinates
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk ,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
column3,
|
||||
column6,
|
||||
column8
|
||||
from staging2.budni_lcg_gravity_test_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_centre_of_gravity_location
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_LCG_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
238
onetime/dataloadfunctions/budni/BUDNI_LCG_STG2.sql
Executable file
238
onetime/dataloadfunctions/budni/BUDNI_LCG_STG2.sql
Executable file
@@ -0,0 +1,238 @@
|
||||
drop function if exists staging2.fn_BUDNI_LCG_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_LCG_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_BUDNI_LCG_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format:BUDNI_LCG
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_LCG_Block(20,1,'BUDNI','BUDNI_LCG',261);
|
||||
************************************************************************************/
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.BUDNI_LCG_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_LCG_Gravity_Test_Block;
|
||||
truncate table staging2.stg_specific_table_BUDNI_LCG;
|
||||
truncate table staging2.stg_process_table_BUDNI_LCG;
|
||||
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_LCG
|
||||
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_BUDNI_LCG;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni LCG',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_LCG',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
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_BUDNI_LCG b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_BUDNI_LCG a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
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 =''Location of centre of Gravity Test''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
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_BUDNI_LCG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_LCG 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 Tractor Specifiactions''
|
||||
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_BUDNI_LCG
|
||||
select a.* , RANK () OVER ( ORDER BY row_number),b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_LCG 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=''Location of centre of Gravity Test''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_LCG a
|
||||
where block_tag='BUDNI_LCG_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_LCG a
|
||||
where block_tag='BUDNI_LCG_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_LCG_Spec_H1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_LCG_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_LCG_Spec_H1_Block';
|
||||
insert into staging2.BUDNI_LCG_Spec_H1_Block
|
||||
(
|
||||
make,model,Tractor_HP, Rated_RPM,configuration,Transmission_type,
|
||||
Wheel_Drive_type,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_LCG
|
||||
where block_tag='BUDNI_LCG_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_LCG_Spec_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||'''';
|
||||
|
||||
update staging2.BUDNI_LCG_Spec_H1_block a
|
||||
set Wheel_Base=column3,
|
||||
Wheel_track =column4,
|
||||
Overall_height =column5,
|
||||
Ballast_Condition =column6,
|
||||
Tractor_Weight_reactions_Front =column7,
|
||||
Tractor_Weight_reactions_Rear =column8
|
||||
from staging2.stg_process_table_budni_lcg b
|
||||
where b.block_tag='BUDNI_LCG_Spec_H1'
|
||||
and b.block_row_number=6
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_LCG_Spec_H1_Block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_LCG_Gravity_Test_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_LCG_Gravity_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_LCG_Gravity_Test_Block';
|
||||
|
||||
insert into staging2.BUDNI_LCG_Gravity_Test_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_LCG a
|
||||
where block_tag='BUDNI_LCG_Gravity_Test' and block_row_number <=5
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_LCG_Gravity_Test_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_LCG_Gravity_Test_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.BUDNI_LCG_Gravity_Test_Block a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_LCG_Gravity_Test_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.BUDNI_LCG_Gravity_Test_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_LCG_Gravity_Test_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_LCG_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
351
onetime/dataloadfunctions/budni/BUDNI_NMT_ODS.sql
Executable file
351
onetime/dataloadfunctions/budni/BUDNI_NMT_ODS.sql
Executable file
@@ -0,0 +1,351 @@
|
||||
drop function if exists staging2.fn_BUDNI_NMT_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_NMT_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_NMT_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_NMT
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_NMT_TRX()
|
||||
***************************************************************/
|
||||
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
ballast_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
FIP_type,
|
||||
steering_type,
|
||||
Ballast_Condition
|
||||
from staging2.BUDNI_NMT_Spec_H1_block;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
type_of_road
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
type_of_track
|
||||
from
|
||||
staging2.BUDNI_NMT_Spec_H1_block;
|
||||
|
||||
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;
|
||||
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio engine_to_pto_ratio_540_pto
|
||||
from staging2.BUDNI_NMT_Spec_H1_block;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.budni_noise_atmospheric_conditions
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
noise_position,
|
||||
background_noise_level_dba,
|
||||
temperature_c,
|
||||
pressure_kpa,
|
||||
relative_humidity_pct,
|
||||
wind_velocity_ms
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric,
|
||||
column6::numeric,
|
||||
column7::numeric
|
||||
from staging2.BUDNI_NMT_Atmos_Cond_1_Block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
/*block */
|
||||
insert into transactional.budni_noise_measurement_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
noise_position,
|
||||
gear,
|
||||
travel_speed_km_per_hr,
|
||||
noise_level_db_a
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3,
|
||||
column6,
|
||||
column8::numeric
|
||||
from staging2.BUDNI_NMT_Meas_Results_1_Block
|
||||
where trx_record=1;
|
||||
|
||||
insert into transactional.budni_noise_atmospheric_conditions
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
noise_position,
|
||||
background_noise_level_dba,
|
||||
temperature_c,
|
||||
pressure_kpa,
|
||||
relative_humidity_pct,
|
||||
wind_velocity_ms
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3::numeric,
|
||||
column4::numeric,
|
||||
column5::numeric ,
|
||||
column6::numeric,
|
||||
column7::numeric
|
||||
from staging2.BUDNI_NMT_Atmos_Cond_2_Block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
|
||||
/*block */
|
||||
insert into transactional.budni_noise_measurement_results
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
noise_position,
|
||||
gear,
|
||||
drawbar_pull_max_noise_kn,
|
||||
travel_speed_km_per_hr,
|
||||
noise_level_db_a
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3,
|
||||
column4,
|
||||
column6,
|
||||
column8::int
|
||||
from staging2.BUDNI_NMT_Meas_Results_2_Block
|
||||
where trx_record=1;
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
sequence_number,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3::numeric,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9
|
||||
from staging2.budni_nmt_test_obs_summary_block where trx_record=1;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_noise_atmospheric_conditions
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_noise_measurement_results
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_NMT_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
469
onetime/dataloadfunctions/budni/BUDNI_NMT_STG2.sql
Executable file
469
onetime/dataloadfunctions/budni/BUDNI_NMT_STG2.sql
Executable file
@@ -0,0 +1,469 @@
|
||||
drop function if exists staging2.fn_BUDNI_NMT_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_NMT_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
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_BUDNI_NMT_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format:BUDNI_NMT
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_NMT_Block(20,1,'BUDNI','BUDNI_NMT',261);
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.BUDNI_NMT_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_NMT_noise_at_bystander_position_block;
|
||||
truncate table staging2.BUDNI_NMT_Atmos_Cond_1_Block;
|
||||
truncate table staging2.BUDNI_NMT_Meas_Results_1_Block;
|
||||
truncate table staging2.BUDNI_NMT_noise_at_operator_ear_level_block;
|
||||
truncate table staging2.BUDNI_NMT_Atmos_Cond_2_Block;
|
||||
truncate table staging2.BUDNI_NMT_Meas_Results_2_Block;
|
||||
truncate table staging2.BUDNI_NMT_Test_Obs_Summary_Block;
|
||||
truncate table staging2.stg_specific_table_BUDNI_NMT;
|
||||
truncate table staging2.stg_process_table_BUDNI_NMT;
|
||||
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_NMT
|
||||
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_BUDNI_NMT;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for budni nmt',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_NMT',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified;
|
||||
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_BUDNI_NMT b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_BUDNI_NMT a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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||'''';
|
||||
|
||||
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 =''Noise Measurement Test Observations Summary''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
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_BUDNI_NMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_NMT 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 Tractor Specifiactions''
|
||||
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_BUDNI_NMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_NMT 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=''Noise at bystander’s position: Noise Measurement Test''
|
||||
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_BUDNI_NMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_NMT 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=''Noise at operator’s ear level: Noise Measurement Test''
|
||||
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_BUDNI_NMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_NMT 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=''Noise Measurement Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_NMT a
|
||||
where block_tag='BUDNI_NMT_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_NMT a
|
||||
where block_tag='BUDNI_NMT_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_NMT_Spec_H1_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_NMT_Spec_H1_block';
|
||||
|
||||
insert into staging2.BUDNI_NMT_Spec_H1_block
|
||||
(
|
||||
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_NMT where block_tag='BUDNI_NMT_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_NMT_Spec_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||'''';
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_Spec_H1_block a
|
||||
set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6,
|
||||
Test_Engine_Set_RPM=column7,Type_of_track=column8
|
||||
from staging2.stg_process_table_BUDNI_NMT b
|
||||
where b.block_tag='BUDNI_NMT_Spec_H1'
|
||||
and b.block_row_number=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Spec_H1_Block');
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_NMT_noise_at_bystander_position_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_noise_at_bystander_position_block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_NMT_noise_at_bystander_position_block';
|
||||
insert into staging2.BUDNI_NMT_noise_at_bystander_position_block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_NMT a
|
||||
where block_tag ='BUDNI_NMT_Noise_at_bystander_position';
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_noise_at_bystander_position_block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_noise_at_bystander_position_block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_NMT_noise_at_bystander_position_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.BUDNI_NMT_noise_at_bystander_position_Block
|
||||
set trx_record=0 where block_row_number in(1,2);
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_noise_at_bystander_position_block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_noise_at_bystander_position_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,'BUDNI_NMT_noise_at_bystander_position_block');
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_NMT_Atmos_Cond_1_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Atmos_Cond_1_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='BUDNI_NMT_Atmos_Cond_1_Block';
|
||||
insert into staging2.BUDNI_NMT_Atmos_Cond_1_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.BUDNI_NMT_noise_at_bystander_position_block a
|
||||
where block_row_number <=4;
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_Atmos_Cond_1_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_Atmos_Cond_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||'''';
|
||||
|
||||
update staging2.BUDNI_NMT_Atmos_Cond_1_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2,3);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Atmos_Cond_1_Block ');
|
||||
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_NMT_Meas_Results_1_Block */
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Meas_Results_1_Block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='BUDNI_NMT_Meas_Results_1_Block';
|
||||
insert into staging2.BUDNI_NMT_Meas_Results_1_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
from staging2.BUDNI_NMT_noise_at_bystander_position_block a
|
||||
where block_row_number>4;
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_Meas_Results_1_Block
|
||||
set trx_record=0 where
|
||||
block_row_number=5;
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_Meas_Results_1_Block
|
||||
set column3=column4 where column3 is null ;
|
||||
|
||||
update staging2.BUDNI_NMT_Meas_Results_1_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_Meas_Results_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,'BUDNI_NMT_Meas_Results_1_Block ');
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_NMT_Noise_at_operator_ear_level_block */
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Noise_at_operator_ear_level_block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='BUDNI_NMT_Noise_at_operator_ear_level_block';
|
||||
|
||||
insert into staging2.BUDNI_NMT_Noise_at_operator_ear_level_block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_NMT a
|
||||
where block_tag ='BUDNI_NMT_Noise_at_operator_ear_level';
|
||||
|
||||
update staging2.BUDNI_NMT_Noise_at_operator_ear_level_block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_Noise_at_operator_ear_level_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.BUDNI_NMT_Noise_at_operator_ear_level_block
|
||||
set column2=column3 where block_row_number=1;
|
||||
|
||||
|
||||
update staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_NMT_Noise_at_operator_ear_level_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Noise_at_operator_ear_level_block');
|
||||
|
||||
/* blocks data loading -BUDNI_NMT_Atmos_Cond_2_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Atmos_Cond_2_Block',__file_mnemonic,__file_sheet_mnemonic,6);
|
||||
err_block:='BUDNI_NMT_Atmos_Cond_2_Block';
|
||||
insert into staging2.BUDNI_NMT_Atmos_Cond_2_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
from staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a
|
||||
where block_row_number<=4;
|
||||
|
||||
update staging2.BUDNI_NMT_Atmos_Cond_2_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_Atmos_Cond_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||'''';
|
||||
|
||||
update staging2.BUDNI_NMT_Atmos_Cond_2_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2,3);
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_NMT_Atmos_Cond_2_Block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_NMT_Meas_Results_2_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Meas_Results_2_Block',__file_mnemonic,__file_sheet_mnemonic,7);
|
||||
err_block:='BUDNI_NMT_Meas_Results_2_Block';
|
||||
insert into staging2.BUDNI_NMT_Meas_Results_2_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,block_row_number
|
||||
from staging2.BUDNI_NMT_Noise_at_operator_ear_level_block a
|
||||
where block_row_number>4;
|
||||
|
||||
update staging2.BUDNI_NMT_Meas_Results_2_Block
|
||||
set trx_record=0 where
|
||||
block_row_number =5;
|
||||
|
||||
update BUDNI_NMT_Meas_Results_2_Block set column3=column4 where column3 is null;
|
||||
|
||||
update staging2.BUDNI_NMT_Meas_Results_2_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_Meas_Results_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,'BUDNI_NMT_Meas_Results_2_Block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_NMT_Test_Obs_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_NMT_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,8);
|
||||
err_block:='BUDNI_NMT_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_NMT_Test_Obs_Summary_Block
|
||||
(
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column2,column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_NMT a
|
||||
where block_tag='BUDNI_NMT_Test_Obs_Summary' and block_row_number in (1,2,3,4);
|
||||
|
||||
update staging2.BUDNI_NMT_Test_Obs_Summary_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in (1,2);
|
||||
|
||||
update staging2.BUDNI_NMT_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_NMT_Test_Obs_Summary_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,'BUDNI_NMT_Test_Obs_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_NMT_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
315
onetime/dataloadfunctions/budni/BUDNI_PTO_ODS.sql
Executable file
315
onetime/dataloadfunctions/budni/BUDNI_PTO_ODS.sql
Executable file
@@ -0,0 +1,315 @@
|
||||
drop function if exists staging2.fn_BUDNI_PTO_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_PTO_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_PTO_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_PTO
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_PTO_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
fip_type,
|
||||
steering_type,
|
||||
transmission_type,
|
||||
wheel_drive_type
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int,
|
||||
configuration,FIP_type,steering_type,transmission_type,wheel_drive_type
|
||||
from staging2.BUDNI_PTO_Spec_H1_block;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when lower(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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
date_of_test
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
date
|
||||
from
|
||||
staging2.BUDNI_PTO_Spec_H1_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio
|
||||
from staging2.BUDNI_PTO_Spec_H1_block where trx_record=1;
|
||||
|
||||
|
||||
/*block */
|
||||
|
||||
insert into transactional.budni_pto_perf_results_summary
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
pto_category,
|
||||
pto_sub_category ,
|
||||
power_kw,
|
||||
speed_rpm_pto ,
|
||||
speed_rpm_engine ,
|
||||
fuel_consumption_ltr_per_hr,
|
||||
fuel_consumption_kg_per_hr,
|
||||
specific_kg_per_kwh,
|
||||
specific_energy_kwhl
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column2,
|
||||
column3,
|
||||
column4::numeric,column5::numeric,column6::numeric,column7::numeric,column8::numeric,
|
||||
column9::numeric,column10::numeric
|
||||
from staging2.BUDNI_PTO_Perf_Report_block where trx_record=1
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
/*block */
|
||||
insert into transactional.budni_pto_perf_results_details
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
ambient_type,
|
||||
no_load_max_engine_speed_rpm,
|
||||
equi_crankshaft_torque_at_max_power_nm,
|
||||
max_equi_crankshaft_torque_nm,
|
||||
engine_speed_at_max_equi_crankshaft_torque_rpm,
|
||||
backup_torque,
|
||||
pct_smoke_level_max_light_absorption_coef_per_mtr,
|
||||
range_of_atm_conditions_temp_c,
|
||||
range_of_atm_conditions_pressure_kpa,
|
||||
range_of_atm_conditions_rel_humidity_pct
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,
|
||||
column4::int,
|
||||
column5::numeric,
|
||||
column6::numeric,column7::int,column8::numeric,
|
||||
column9::numeric,column10,column11,column12
|
||||
from staging2.BUDNI_PTO_MMTKeyword1_block
|
||||
where trx_record=1;
|
||||
|
||||
|
||||
/* block */
|
||||
|
||||
insert into transactional.budni_pto_perf_results_details
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
ambient_type,
|
||||
max_temp_engine_oil_c,
|
||||
max_temp_coolant_water_c,
|
||||
max_temp_fuel_c,
|
||||
max_temp_air_intake_c,
|
||||
max_temp_exhaust_gas_c,
|
||||
pressure_at_max_power_intake_air_kpa,
|
||||
pressure_at_max_power_exhst_gas_bfr_turbo_charger_kpa,
|
||||
consumptions_lub_oil_gkwh,
|
||||
consumptions_coolant_water_pct_of_total_coolant_capacity
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3,
|
||||
column4::numeric,column5::numeric,column6::numeric,column7::numeric,column8::numeric,column9,
|
||||
column10,column11::numeric,column12::numeric
|
||||
from staging2.BUDNI_PTO_MMTKeyword2_block
|
||||
where trx_record=1 and column3='Natural Ambient';
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
srl_no,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,column3,column4,column7,column8,column10,column11,column12
|
||||
from staging2.BUDNI_PTO_Summary_block
|
||||
where block_row_number in (3,4) and trx_record=1
|
||||
;
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_pto_perf_results_summary
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
update transactional.budni_pto_perf_results_details
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_PTO_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
363
onetime/dataloadfunctions/budni/BUDNI_PTO_STG2.sql
Executable file
363
onetime/dataloadfunctions/budni/BUDNI_PTO_STG2.sql
Executable file
@@ -0,0 +1,363 @@
|
||||
drop function if exists staging2.fn_BUDNI_PTO_block;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_PTO_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
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_BUDNI_PTO_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format:BUDNI_PTO
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_PTO_Block(20,1,'BUDNI','BUDNI_PTO',261);
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.stg_specific_table_BUDNI_PTO;
|
||||
truncate table staging2.stg_process_table_BUDNI_PTO;
|
||||
truncate table staging2.BUDNI_PTO_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_PTO_Perf_Report_block;
|
||||
truncate table staging2.BUDNI_PTO_MMTKeyword1_Block;
|
||||
truncate table staging2.BUDNI_PTO_MMTKeyword2_Block;
|
||||
truncate table staging2.BUDNI_PTO_Summary_Block;
|
||||
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_budni_pto
|
||||
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_budni_pto;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni PTO',
|
||||
detail = 'No data in table stg_specific_table_budni_pto',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
/* trimming data */
|
||||
update staging2.stg_specific_table_budni_pto set column3 = TRIM (TRAILING FROM column3 );
|
||||
update staging2.stg_specific_table_budni_pto set column3 = TRIM (LEADING FROM column3 );
|
||||
|
||||
update transactional.source_config set F1_source=F1_modified ;
|
||||
|
||||
/* keyword match */
|
||||
execute 'update transactional.source_config a
|
||||
set row_number_start=(select min(b.row_number)
|
||||
from staging2.stg_specific_table_budni_pto b
|
||||
where trim(upper(F1_modified))=trim(upper(column3))
|
||||
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 */
|
||||
execute 'update staging2.stg_specific_table_budni_pto a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where trim(upper(F1_modified))=trim(upper(column3))
|
||||
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||'''';
|
||||
|
||||
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 and file_mnemonic='''||p_file_mnemonic||''' and file_sheet_mnemonic='''||p_file_sheet_mnemonic||''' )
|
||||
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 ,run_time=current_timestamp
|
||||
where f1_modified =''PTO Performance Test Observations Summary''
|
||||
and 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_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_pto 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 Tractor Specifiactions''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_pto 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=''PTO Performance Report''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_budni_pto 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=''MMTKeyword1''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag from staging2.stg_specific_table_budni_pto 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=''MMTKeyword2''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
execute 'insert into staging2.stg_process_table_budni_pto
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_budni_pto 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=''PTO Performance Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_budni_pto a
|
||||
where block_tag='BUDNI_PTO_Spec_H1' and block_row_number=3 ;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_budni_pto a
|
||||
where block_tag='BUDNI_PTO_Spec_H1' and block_row_number=3;
|
||||
|
||||
/* blocks data loading start - BUDNI_PTO_Spec_H1_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_PTO_Spec_H1_block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_PTO_Spec_H1_block';
|
||||
|
||||
insert into staging2.BUDNI_PTO_Spec_H1_block
|
||||
(make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,FIP_type,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,column9,column10,block_row_number
|
||||
from staging2.stg_process_table_budni_pto where block_tag='BUDNI_PTO_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_PTO_Spec_H1_block set file_syspk='||p_file_syspk||'';
|
||||
|
||||
update staging2.BUDNI_PTO_Spec_H1_block a
|
||||
set date= case
|
||||
when column12 like '%-%' then column12::timestamptz
|
||||
else date '1899-12-30' + column12::int * interval '1' day
|
||||
end
|
||||
from staging2.stg_process_table_budni_pto b
|
||||
where b.block_tag='BUDNI_PTO_Spec_H1'
|
||||
and b.block_row_number=1
|
||||
and a.file_syspk=b.file_syspk ;
|
||||
|
||||
--update staging2.BUDNI_PTO_Spec_H1_block a
|
||||
--set date= date '1899-12-30' + column12::int * interval '1' day
|
||||
--from staging2.stg_process_table_budni_pto b
|
||||
--where b.block_tag='BUDNI_PTO_Spec_H1'
|
||||
--and b.block_row_number=1
|
||||
--and a.file_syspk=b.file_syspk ;
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_Spec_H1_block a
|
||||
set steering_type=column3,Engine_to_PTO_ratio= column4
|
||||
from staging2.stg_process_table_budni_pto b
|
||||
where b.block_tag='BUDNI_PTO_Spec_H1'
|
||||
and b.block_row_number=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
update staging2.BUDNI_PTO_Spec_H1_block set make=__make, model=__model;
|
||||
execute 'update staging2.BUDNI_PTO_Spec_H1_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_Spec_H1_block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_PTO_Perf_Report_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_PTO_Perf_Report_block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_PTO_Perf_Report_block';
|
||||
|
||||
insert into staging2.BUDNI_PTO_Perf_Report_block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,block_row_number
|
||||
from staging2.stg_process_table_budni_pto
|
||||
where block_tag='BUDNI_PTO_Perf_Report';
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column2=column3 where column2 is null;
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column2=null
|
||||
where column2 like 'i%';
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column2=null
|
||||
where column2 like 'v%';
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block a
|
||||
set column2= b.first_value from (SELECT
|
||||
block_row_number, column2, value_partition, first_value(column2) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column2,
|
||||
sum(case when column2 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_PTO_Perf_Report_block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number ;
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block
|
||||
set column3 =null
|
||||
where column2=column3;
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block
|
||||
set trx_record=0 where block_row_number in (1,2);
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block set trx_record=0 where column3 is null
|
||||
and column2 in(
|
||||
select column2 from staging2.BUDNI_PTO_Perf_Report_block group by column2 having count(*)>1
|
||||
);
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_Perf_Report_block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_PTO_Perf_Report_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_Perf_Report_block');
|
||||
|
||||
|
||||
/* blocks data loading - BUDNI_PTO_MMTKeyword1_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_PTO_MMTKeyword1_block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='BUDNI_PTO_MMTKeyword1_block';
|
||||
|
||||
insert into staging2.BUDNI_PTO_MMTKeyword1_block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_budni_pto
|
||||
where block_tag='BUDNI_PTO_MMTKeyword1';
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_MMTKeyword1_block set trx_record=0 where block_row_number in (1,2);
|
||||
|
||||
update staging2.BUDNI_PTO_MMTKeyword1_block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_PTO_MMTKeyword1_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_MMTKeyword1_block');
|
||||
|
||||
/* blocks data loading - BUDNI_PTO_MMTKeyword2_block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_PTO_MMTKeyword2_block',__file_mnemonic,__file_sheet_mnemonic,4);
|
||||
err_block:='BUDNI_PTO_MMTKeyword2_block';
|
||||
|
||||
insert into staging2.BUDNI_PTO_MMTKeyword2_block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_budni_pto
|
||||
where block_tag='BUDNI_PTO_MMTKeyword2';
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_MMTKeyword2_block set trx_record=0 where block_row_number in (1,2);
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_MMTKeyword2_block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_PTO_MMTKeyword2_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_MMTKeyword2_block');
|
||||
|
||||
/* blocks data loading -BUDNI_PTO_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_PTO_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,5);
|
||||
err_block:='BUDNI_PTO_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_PTO_Summary_Block
|
||||
( column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number)
|
||||
select column2,column3,column4,column5,column6,column7,column8,column9,column10,column11,column12,block_row_number
|
||||
from staging2.stg_process_table_budni_pto
|
||||
where block_tag='BUDNI_PTO_Summary';
|
||||
|
||||
|
||||
update staging2.BUDNI_PTO_Summary_block
|
||||
set trx_record=0 where block_row_number in (1,2);
|
||||
|
||||
update staging2.BUDNI_PTO_Summary_block set make=__make, model=__model;
|
||||
execute 'update staging2.BUDNI_PTO_Summary_block set
|
||||
client_id='||p_client_id||',
|
||||
function_id='||p_function_id||',
|
||||
file_mnemonic='''||p_file_mnemonic||''',
|
||||
file_sheet_mnemonic='''||p_file_sheet_mnemonic||''',
|
||||
file_syspk='||p_file_syspk||'';
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_PTO_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_PTO_block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
239
onetime/dataloadfunctions/budni/BUDNI_VMT_ODS.sql
Executable file
239
onetime/dataloadfunctions/budni/BUDNI_VMT_ODS.sql
Executable file
@@ -0,0 +1,239 @@
|
||||
drop function if exists staging2.fn_BUDNI_VMT_TRX;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_VMT_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_instance_tractor_id int;
|
||||
begin
|
||||
__file_syspk := p_file_syspk;
|
||||
/************************************************************
|
||||
Function Name:fn_BUDNI_VMT_TRX
|
||||
Function Desc: This function populates data into ODS
|
||||
File Format: BUDNI
|
||||
Sheet Format: BUDNI_VMT
|
||||
Creation Date:
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_VMT_TRX()
|
||||
***************************************************************/
|
||||
|
||||
insert into transactional.test_instance_tractor_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
fip_type,
|
||||
steering_type,
|
||||
ballast_condition
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,
|
||||
model,
|
||||
tractor_HP::int tractor_engine_hp,
|
||||
configuration,
|
||||
transmission_type,
|
||||
wheel_drive_type,
|
||||
FIP_type,
|
||||
steering_type,
|
||||
Ballast_Condition
|
||||
from staging2.BUDNI_VMT_Spec_H1_block where trx_record=1;
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set mahindra_model_yn = (
|
||||
case when lower(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;
|
||||
|
||||
insert into transactional.test_instance
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model
|
||||
from
|
||||
staging2.BUDNI_VMT_Spec_H1_block where trx_record=1;
|
||||
|
||||
insert into transactional.test_instance_engine_info
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
rated_rpm,
|
||||
engine_to_pto_ratio_540_pto
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
rated_rpm::int,
|
||||
engine_to_pto_ratio engine_to_pto_ratio_540_pto
|
||||
from staging2.BUDNI_VMT_Spec_H1_block where trx_record=1;
|
||||
|
||||
insert into transactional.budni_vibration_measurement
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
srl_no,
|
||||
measuring_points,
|
||||
vibration_at_no_load_vd_microns,
|
||||
vibration_at_no_load_hd_microns,
|
||||
vibration_at_load_85_pct_of_max_pto_power_vd_microns,
|
||||
vibration_at_load_85_pct_of_max_pto_power_hd_microns
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
column3::numeric,
|
||||
column4,
|
||||
column6::numeric ,
|
||||
column7::numeric ,
|
||||
column8::numeric ,
|
||||
column9::numeric
|
||||
from staging2.BUDNI_VMT_Perf_Meas_Test_Block
|
||||
where trx_record =1
|
||||
order by block_row_number;
|
||||
|
||||
insert into transactional.budni_test_observations
|
||||
(
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
tractor_make,
|
||||
tractor_model,
|
||||
sequence_number,
|
||||
characteristic,
|
||||
category_evaluative_or_non_evaluative,
|
||||
requirements_as_per_is_12207_2008,
|
||||
values_declared_by_the_applicant_d_rqmt,
|
||||
as_observed,
|
||||
whether_meets_the_requirements_yn
|
||||
)
|
||||
select
|
||||
client_id,
|
||||
function_id,
|
||||
file_syspk,
|
||||
file_mnemonic,
|
||||
file_sheet_mnemonic,
|
||||
make,model,
|
||||
column3::INT,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9
|
||||
from staging2.BUDNI_VMT_test_obs_summary_block where trx_record=1;
|
||||
|
||||
|
||||
|
||||
select syspk into __test_instance_id from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_model into __model from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select tractor_make into __make from transactional.test_instance where file_syspk =__file_syspk;
|
||||
select syspk from transactional.test_master into __test_master_id where test_type ='BUDNI';
|
||||
select syspk into __test_instance_tractor_id from transactional.test_instance_tractor_info where file_syspk =__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance
|
||||
set test_master_id =__test_master_id,
|
||||
test_tractor_id =__test_instance_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,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.test_instance_tractor_info
|
||||
set test_instance_id=__test_instance_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_vibration_measurement
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
where file_syspk=__file_syspk;
|
||||
|
||||
|
||||
update transactional.budni_test_observations
|
||||
set test_instance_id=__test_instance_id,
|
||||
test_instance_tractor_id = __test_instance_tractor_id,
|
||||
tractor_model =__model,
|
||||
tractor_make=__make
|
||||
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_BUDNI_VMT_TRX', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
337
onetime/dataloadfunctions/budni/BUDNI_VMT_STG2.sql
Executable file
337
onetime/dataloadfunctions/budni/BUDNI_VMT_STG2.sql
Executable file
@@ -0,0 +1,337 @@
|
||||
drop function if exists staging2.fn_BUDNI_VMT_Block ;
|
||||
CREATE OR REPLACE FUNCTION staging2.fn_BUDNI_VMT_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
|
||||
|
||||
SET search_path TO staging2;
|
||||
|
||||
|
||||
/***********************************************************************************
|
||||
Function Name:fn_BUDNI_VMT_Block
|
||||
Function Desc: This function populates data into staging2 blocks
|
||||
File Format: BUDNI
|
||||
Sheet Format:BUDNI_VMT
|
||||
Creation Date: March 21 2021
|
||||
Updation Date:
|
||||
Author: compegence team
|
||||
Function Call: select staging2.fn_BUDNI_VMT_Block(20,1,'BUDNI','BUDNI_VMT',261);
|
||||
************************************************************************************/
|
||||
|
||||
|
||||
/* rerunnability - delete block tables and update config tables to null */
|
||||
truncate table staging2.BUDNI_VMT_Spec_H1_Block;
|
||||
truncate table staging2.BUDNI_VMT_Perf_Meas_Test_Block;
|
||||
truncate table staging2.BUDNI_VMT_Test_Obs_Summary_Block;
|
||||
truncate table staging2.stg_specific_table_BUDNI_VMT;
|
||||
truncate table staging2.stg_process_table_BUDNI_VMT;
|
||||
|
||||
|
||||
|
||||
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 BUDNI */
|
||||
execute 'insert into staging2.stg_specific_table_BUDNI_VMT
|
||||
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_BUDNI_VMT;
|
||||
|
||||
if err_query=0 then
|
||||
err_context := 'data not present';
|
||||
raise exception using
|
||||
message = 'No Data for Budni VMT',
|
||||
detail = 'No data in table stg_specific_table_BUDNI_VMT',
|
||||
errcode = '42704',
|
||||
hint = 'check sheet mnemonic in generic table, if it is null update it';
|
||||
end if;
|
||||
|
||||
|
||||
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_BUDNI_VMT b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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_BUDNI_VMT a
|
||||
set is_rownumber_fetched=1
|
||||
from transactional.source_config b
|
||||
where upper(F1_source)= upper(column3)
|
||||
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||'''';
|
||||
|
||||
/* update config files for row numbers start, end */
|
||||
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 =''AIR CLEANER OIL PULL OVER TEST Observations Summary''
|
||||
and a.file_mnemonic='''||p_file_mnemonic||''' and a.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''';
|
||||
|
||||
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_BUDNI_VMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_VMT 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 Tractor Specifiactions''
|
||||
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_BUDNI_VMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_VMT 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=''Machanical Vibration Measurement Test''
|
||||
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_BUDNI_VMT
|
||||
select a.* , RANK () OVER ( ORDER BY row_number) as block_row_number,b.block_tag as block_tag
|
||||
from staging2.stg_specific_table_BUDNI_VMT 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=''Noise Measurement Test Observations Summary''
|
||||
and b.file_mnemonic='''||p_file_mnemonic||''' and b.file_sheet_mnemonic='''||p_file_sheet_mnemonic||'''
|
||||
order by a.row_number';
|
||||
|
||||
/* fetching tractor model and make */
|
||||
select column3 into __make from staging2.stg_process_table_BUDNI_VMT a
|
||||
where block_tag='BUDNI_VMT_Spec_H1' and block_row_number=3;
|
||||
|
||||
select column4 into __model from staging2.stg_process_table_BUDNI_VMT a
|
||||
where block_tag='BUDNI_VMT_Spec_H1' and block_row_number=3;
|
||||
|
||||
|
||||
/* blocks data loading start - BUDNI_VMT_Spec_H1_block */
|
||||
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_VMT_Spec_H1_Block',__file_mnemonic,__file_sheet_mnemonic,1);
|
||||
err_block:='BUDNI_VMT_Spec_H1_Block';
|
||||
insert into staging2.BUDNI_VMT_Spec_H1_block
|
||||
(
|
||||
make,model,tractor_HP,rated_rpm,configuration,transmission_type,wheel_drive_type,block_row_number)
|
||||
select column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_VMT where block_tag='BUDNI_VMT_Spec_H1'
|
||||
and block_row_number=3;
|
||||
|
||||
|
||||
execute 'update staging2.BUDNI_VMT_Spec_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||'''';
|
||||
|
||||
|
||||
update staging2.BUDNI_VMT_Spec_H1_block a
|
||||
set FIP_type=column3,steering_type=column4,Engine_to_PTO_ratio= column5,Ballast_Condition=column6,
|
||||
Test_Engine_Set_RPM=column7,Type_of_track=column8
|
||||
from staging2.stg_process_table_BUDNI_VMT b
|
||||
where b.block_tag='BUDNI_VMT_Spec_H1'
|
||||
and b.block_row_number=5
|
||||
and a.file_syspk=b.file_syspk;
|
||||
|
||||
perform fw_core.fn_jobctl_block_end(__file_syspk,'BUDNI_VMT_Spec_H1_Block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_VMT_Perf_Meas_Test_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_VMT_Perf_Meas_Test_Block',__file_mnemonic,__file_sheet_mnemonic,2);
|
||||
err_block:='BUDNI_VMT_Perf_Meas_Test_Block';
|
||||
|
||||
insert into staging2.BUDNI_VMT_Perf_Meas_Test_Block
|
||||
(
|
||||
column3,
|
||||
column4,
|
||||
column5,
|
||||
column6,
|
||||
column7,
|
||||
column8,
|
||||
column9,
|
||||
block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_VMT a
|
||||
where block_tag ='BUDNI_VMT_Perf_Meas_Test'
|
||||
order by block_row_number;
|
||||
|
||||
|
||||
update staging2.BUDNI_VMT_Perf_Meas_Test_Block a
|
||||
set column3= b.first_value from (SELECT
|
||||
block_row_number, column3, value_partition, first_value(column3) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column3,
|
||||
sum(case when column3 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_VMT_Perf_Meas_Test_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number and a.block_row_number not in(1,2,3,4);
|
||||
|
||||
update staging2.BUDNI_VMT_Perf_Meas_Test_Block a
|
||||
set column4= b.first_value from (SELECT
|
||||
block_row_number, column4, value_partition, first_value(column4) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column4,
|
||||
sum(case when column4 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_VMT_Perf_Meas_Test_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number and a.block_row_number not in(1,2,3,4);
|
||||
|
||||
|
||||
update staging2.BUDNI_VMT_Perf_Meas_Test_Block
|
||||
set column4=concat(column4,'-',column5) where block_row_number not in(1,2,3,4) and column5 is not null;
|
||||
|
||||
update staging2.BUDNI_VMT_Perf_Meas_Test_Block
|
||||
set trx_record=0 where block_row_number in(1,2,3,4);
|
||||
|
||||
update staging2.BUDNI_VMT_Perf_Meas_Test_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_VMT_Perf_Meas_Test_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,'BUDNI_VMT_Perf_Meas_Test_Block');
|
||||
|
||||
|
||||
/* blocks data loading -BUDNI_VMT_Test_Obs_Summary_Block */
|
||||
|
||||
perform fw_core.fn_jobctl_block_begin(__client_id,__function_id,__file_syspk,
|
||||
'BUDNI_VMT_Test_Obs_Summary_Block',__file_mnemonic,__file_sheet_mnemonic,3);
|
||||
err_block:='BUDNI_VMT_Test_Obs_Summary_Block';
|
||||
|
||||
insert into staging2.BUDNI_VMT_Test_Obs_Summary_Block
|
||||
(
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
)
|
||||
select
|
||||
column3,column4,column5,column6,column7,
|
||||
column8,column9,block_row_number
|
||||
from staging2.stg_process_table_BUDNI_VMT a
|
||||
where block_tag='BUDNI_VMT_Test_Obs_Summary' and block_row_number <=6
|
||||
order by block_row_number;
|
||||
|
||||
update staging2.BUDNI_VMT_Test_Obs_Summary_Block a
|
||||
set column5= b.first_value from (SELECT
|
||||
block_row_number, column5, value_partition, first_value(column5) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column5,
|
||||
sum(case when column5 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_VMT_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.BUDNI_VMT_Test_Obs_Summary_Block a
|
||||
set column6= b.first_value from (SELECT
|
||||
block_row_number, column6, value_partition, first_value(column6) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column6,
|
||||
sum(case when column6 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_VMT_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.BUDNI_VMT_Test_Obs_Summary_Block a
|
||||
set column7= b.first_value from (SELECT
|
||||
block_row_number, column7, value_partition, first_value(column7) over (partition by value_partition order by block_row_number)
|
||||
FROM (
|
||||
SELECT
|
||||
block_row_number,
|
||||
column7,
|
||||
sum(case when column7 is null then 0 else 1 end) over (order by block_row_number) as value_partition
|
||||
FROM staging2.BUDNI_VMT_Test_Obs_Summary_Block
|
||||
ORDER BY block_row_number ASC
|
||||
) as q) b where a.block_row_number = b.block_row_number;
|
||||
|
||||
update staging2.BUDNI_VMT_Test_Obs_Summary_Block
|
||||
set trx_record=0 where
|
||||
block_row_number in(1,2);
|
||||
|
||||
|
||||
update staging2.BUDNI_VMT_Test_Obs_Summary_Block set make=__make,model=__model;
|
||||
execute 'update staging2.BUDNI_VMT_Test_Obs_Summary_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,'BUDNI_VMT_Test_Obs_Summary_Block');
|
||||
|
||||
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'stg2', 'fn_BUDNI_VMT_Block', err_state, err_msg, err_detail, err_hint, err_context,'success');
|
||||
|
||||
end
|
||||
$function$
|
||||
;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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