Files
MMT/MMT_SQL/ods/FTDRY_SUM_ODS.sql
2021-03-30 17:35:08 +05:30

303 lines
7.6 KiB
PL/PgSQL

drop function if exists mmt_staging2.fn_FTDRY_SUM_ODS ;
CREATE OR REPLACE FUNCTION mmt_staging2.fn_FTDRY_SUM_ODS()
RETURNS void AS $$
declare __test_instance_id int;
declare __file_syspk int;
begin
/************************************************************
Function Name:fn_FTDRY_SUM_ODS
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 mmt_staging2.fn_FTDRY_SUM_ODS()
***************************************************************/
delete from mmt_ods.field_perf_summary where test_file_ref_no =258;
delete from mmt_ods.field_perf_summary_implement_info where test_file_ref_no =258;
delete from mmt_ods.field_perf_summary_tractor_info where test_file_ref_no =258;
insert into mmt_ods.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,
test_file_ref_no,
test_file_format,
test_file_sheet_format
)
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_format,
sheet_mnemonic
from mmt_staging2.ftdry_sum_trac_h1_block where tractor_model<> '0' and ods_record=1;
insert into mmt_ods.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,
test_file_ref_no,
test_file_format,
test_file_sheet_format
)
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_format,
sheet_mnemonic
from mmt_staging2.ftdry_sum_implement_block where ods_record=1;
insert into mmt_ods.field_perf_summary
(
client_id,
function_id,
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_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_index,
pulverization_quality,
test_file_ref_no,
test_file_format,
test_file_sheet_format
)
select
client_id,
function_id,
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 ,
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,
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_format,
sheet_mnemonic
from mmt_staging2.ftdry_sum_test_condition_1_block where engine_rpm_set <> '0' and ods_record=1;
insert into mmt_ods.field_perf_summary
(
client_id,
function_id,
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_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_index,
pulverization_quality,
test_file_ref_no,
test_file_format,
test_file_sheet_format
)
select
client_id,
function_id,
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 ,
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,
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_format,
sheet_mnemonic
from mmt_staging2.ftdry_sum_test_condition_2_block where engine_rpm_set <> '0' and ods_record=1;
select file_syspk into __file_syspk from mmt_staging2.ftdry_sum_trac_h1_block;
select syspk into __test_instance_id from mmt_ods.test_instance where test_file_ref_no =__file_syspk;
update mmt_ods.field_perf_summary
set test_instance_id=__test_instance_id
where test_file_ref_no=__file_syspk;
update mmt_ods.field_perf_summary_implement_info
set test_instance_id=__test_instance_id
where test_file_ref_no=__file_syspk;
update mmt_ods.field_perf_summary_tractor_info
set test_instance_id=__test_instance_id
where test_file_ref_no=__file_syspk;
end
$$ LANGUAGE plpgsql;