Files
MMT/deployment-20210427T103328Z-001/deployment/pto-V0-April22/PTO-RPT-ods.txt
2021-04-27 16:13:33 +05:30

304 lines
7.2 KiB
Plaintext

drop function if exists mmt_staging2.fn_PTO_report_ODS;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_PTO_report_ODS(p_file_syspk int)
RETURNS text AS $$
declare __test_instance_id int;
declare __file_syspk int;
declare __make text;
declare __model text;
declare v_state text;
declare v_msg text;
declare v_detail text;
declare v_hint text;
declare v_context text;
declare _error int;
begin
__file_syspk := p_file_syspk;
SET search_path TO mmt_staging2;
/*************************************************************
Function Name:fn_PTO_REPORT_ODS
Function Desc: This function populates data into ODS blocks
File Format: PTOBST
Sheet Format: PTOBST_PNA
Creation Date: March 21 2021
Updation Date:
Author: compegence team
Function Call: select mmt_staging2.fn_PTO_report_ODS(880)
***************************************************************/
insert into mmt_ods.test_instance_tractor_info
(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
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_format,
sheet_mnemonic,
make,model,tractor_HP::int,configuration,FIP_type,steering_type,transmission_type,wheel_drive_type
from
mmt_staging2.PTOBST_RPT_tractor_specs_block;
select tractor_model into __model from mmt_ods.test_instance_tractor_info where test_file_ref_no =__file_syspk;
select tractor_make into __make from mmt_ods.test_instance_tractor_info where test_file_ref_no =__file_syspk;
insert into mmt_ods.test_instance
(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
tractor_make,
tractor_model
)
select
client_id,
function_id,
file_syspk,
file_format,
sheet_mnemonic,
make,model
from
mmt_staging2.PTOBST_RPT_tractor_specs_block;
insert into mmt_ods.test_instance_engine_info
(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
tractor_make,
tractor_model,
rated_rpm,
engine_to_pto_ratio_540_pto
)
select
client_id,
function_id,
file_syspk,
file_format,
sheet_mnemonic,
make,model,rated_rpm::int,engine_to_pto_ratio
from mmt_staging2.PTOBST_RPT_tractor_specs_block;
/*block */
insert into mmt_ods.PTO_Perf_Report_Summary
(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
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_h ,
sfc_kg_per_kwh ,
specifc_energy_kwh_per_ltr
)
select
client_id,
function_id,
file_syspk,
file_format,
sheet_mnemonic,
make,model,
c2,
c3,
c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric
from mmt_staging2.PTOBST_RPT_PTO_performance_report_block where ods_record=1
order by rank;
/*block */
insert into mmt_ods.PTO_Perf_Report_Details
(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
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,
pct_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_format,
sheet_mnemonic,
make,model,
c3,
c4::int,
c5::numeric,
c6::numeric,c7::int,c8::numeric,
c9::numeric,c10,c11,c12
from mmt_staging2.PTOBST_RPT_MMTKeyword1_block
where ods_record=1;
/* block */
insert into mmt_ods.PTO_Perf_Report_Details
(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
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_format,
sheet_mnemonic,
make,model,
c3,
c4::numeric,c5::numeric,c6::numeric,c7::numeric,c8::numeric,c9::numeric,c10::numeric,c11::numeric,c12::numeric
from mmt_staging2.PTOBST_RPT_MMTKeyword2_block
where ods_record=1 and c3='High Ambient';
update mmt_ods.PTO_Perf_Report_Details a
set
max_temp_engine_oil_c=c4::numeric,
max_temp_coolant_water_c=c5::numeric,
max_temp_fuel_c=c6::numeric,
max_temp_air_intake_c=c7::numeric,
max_temp_exhaust_gas_c=c8::numeric,
pressure_at_max_power_intake_air_kpa=c9::numeric,
pressure_at_max_power_exhst_gas_bfr_turbo_charger_kpa=c10::numeric,
consumptions_lub_oil_gkwh=c11::numeric,
consumptions_coolant_water_pct_of_total_coolant_capacity=c12::numeric
from mmt_staging2.PTOBST_RPT_MMTKeyword2_block b
where a.ambient_type=b.c3
and a.ambient_type='Natural Ambient' and ods_record=1;
/* block */
insert into mmt_ods.PTO_Perf_Test_Observations(
client_id,
function_id,
test_file_ref_no,
test_file_format,
test_file_sheet_format,
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_format,
sheet_mnemonic,
make,
model,
c3::text,
c4,c7,c8,c10::numeric,c11::numeric,c12
from mmt_staging2.PTOBST_RPT_PTO_Performance_Test_Observations_Summary_block
where rank in (3,4) and ods_record=1;
select file_syspk into __file_syspk from mmt_staging2.PTOBST_RPT_tractor_specs_block;
select syspk into __test_instance_id from mmt_ods.test_instance where test_file_ref_no =__file_syspk;
update mmt_ods.test_instance_tractor_info
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where test_file_ref_no=__file_syspk;
update mmt_ods.test_instance_engine_info
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where test_file_ref_no=__file_syspk;
update mmt_ods.PTO_Perf_Report_Summary
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where test_file_ref_no=__file_syspk;
update mmt_ods.PTO_Perf_Test_Observations
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where test_file_ref_no=__file_syspk;
update mmt_ods.PTO_Perf_Report_Details
set test_instance_id=__test_instance_id,
tractor_model =__model,
tractor_make=__make
where test_file_ref_no=__file_syspk;
v_context := '';
perform mmt_staging2.mmt_insert_db_error ( null, null, 1001, 'Compegence', __file_syspk ,'PTO','PTO_RPT' ,null,'ods', 'fn_PTO_report_ODS', v_state, v_msg, v_detail, v_hint, v_context,'success');
return v_context;
EXCEPTION when OTHERS then
GET STACKED DIAGNOSTICS
v_state = returned_sqlstate,
v_msg = message_text,
v_detail = pg_exception_detail,
v_hint = pg_exception_hint,
v_context = pg_exception_context;
perform mmt_staging2.mmt_insert_db_error ( null, null, 1001, 'Compegence', __file_syspk ,'PTO','PTO_RPT' ,null,'ods', 'fn_PTO_report_ODS', v_state, v_msg, v_detail, v_hint, v_context,'error');
return v_context;
end
$$ LANGUAGE plpgsql;