This commit is contained in:
dheepa
2021-08-09 11:14:23 +00:00
parent a0d3257be0
commit f3cf5e1d2d
89 changed files with 4769 additions and 1508 deletions

View File

@@ -0,0 +1,253 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_budni_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed'
loop
if f.file_mnemonic = 'BUDNI'
then
insert into fw_ods.fw_ods (
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
season,
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
-- season and date
mahindra_model_yn,
test_tractor_yn,
test_type,
--subtype, condition hierarchy
location_name,
test_condition,
-- location name
engine_speed_var,
fuel_consumption_lit_per_hr,
speed_kmph,
wheel_slippage_pct,
power_kw,
pull_kn,
temp_engine_oil_c,
temp_trans_oil_c,
temp_coolant_c,
temp_fuel_in_c,
temp_engine_oil_high_c,
temp_trans_oil_high_c,
temp_coolant_high_c,
temp_fuel_high_c,
specific_energy_kwh_per_ltr
-- test specific dimensions
-- test specific measures ----
-- audit fields
-- validate how it is being done
--created_by, updated_by, create_timestamp, update_timestamp
)
select
d.client_id,
d.function_id,
d.file_mnemonic,
d.file_sheet_mnemonic,
d.test_name,
d.file_syspk,
d.test_file_name,
d.syspk,
b.tractor_make,
b.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
-- -- test specific date & test dimensions
concat(lpad(extract( month from d.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
d.date_of_test,
extract( year from d.date_of_test) ,
extract( quarter from d.date_of_test),
extract( month from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
b.mahindra_model_yn,
b.test_tractor_yn,
d.test_type,
d.test_location_name ,
case split_part(a.test_condtion,' ',6)
when 'ballasted)' then 'ballasted'
when 'Unballasted)' then 'Unballasted'
end,
-- test specific dimensions
-- test specific measures
a.engine_speed_rpm,
a.fuel_consumption_ltr_per_hr,
a.travel_speed_km_per_hr,
a.wheel_slippage_pct,
a.drawbar_power_kw,
a.drawbar_pull_kn,
case split_part(a.temp_fuel_c,'to',2) when '' then a.temp_fuel_c::numeric else trim(split_part(a.temp_fuel_c,'to',1))::numeric end,
case split_part(a.temp_trans_oil_c,'to',2) when '' then a.temp_trans_oil_c::numeric else trim(split_part(a.temp_trans_oil_c,'to',1))::numeric end,
case split_part(a.temp_coolant_c,'to',2) when '' then a.temp_coolant_c::numeric else trim(split_part(a.temp_coolant_c,'to',1))::numeric end,
case split_part(a.temp_engine_oil_c,'to',2) when '' then a.temp_engine_oil_c::numeric else trim(split_part(a.temp_engine_oil_c,'to',1))::numeric end,
case split_part(a.temp_fuel_c,'to',2) when '' then null else trim(split_part(a.temp_fuel_c,'to',2))::numeric end,
case split_part(a.temp_trans_oil_c,'to',2) when '' then null else trim(split_part(a.temp_trans_oil_c,'to',2))::numeric end,
case split_part(a.temp_coolant_c,'to',2) when '' then null else trim(split_part(a.temp_coolant_c,'to',2))::numeric end,
case split_part(a.temp_engine_oil_c,'to',2) when '' then null else trim(split_part(a.temp_engine_oil_c,'to',2))::numeric end,
a.specific_energy_kwh_per_ltr
-- add user and timestamp fields
from transactional.budni_drawbar_perf_results a, transactional.test_instance_tractor_info b,transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = d.file_syspk
and a.file_syspk = __file_syspk
and b.tractor_model = a.tractor_model
and b.file_sheet_mnemonic in ('BUDNI_DBP') and d.file_mnemonic =('BUDNI') and d.file_sheet_mnemonic in ('BUDNI_DBP');
insert into fw_ods.fw_ods (
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
season,
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
mahindra_model_yn,
test_tractor_yn,
-- season and date
test_type,
test_sub_type,
-- test mode, type, subtype, condition hierarchy
location_name,
-- location name
engine_speed_var,
fuel_consumption_lit_per_hr,
power_kw,
speed_pto_rpm
-- test specific dimensions
-- test specific measures ----
-- audit fields
-- validate how it is being done
--created_by, updated_by, create_timestamp, update_timestamp
)
--SELECT COUNT(*) from(
select
d.client_id,
d.function_id,
d.file_mnemonic,
d.file_sheet_mnemonic,
d.test_name,
d.file_syspk,
d.test_file_name,
d.syspk,
b.tractor_make,
b.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
-- -- test specific date & test dimensions
concat(extract( month from d.date_of_test),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
d.date_of_test,
extract( year from d.date_of_test) ,
extract( quarter from d.date_of_test),
extract( month from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
b.mahindra_model_yn,
b.test_tractor_yn,
a.pto_category,
a.pto_sub_category,
d.test_location_name ,
-- test specific dimensions
-- test specific measures
a.speed_rpm_engine,
a.fuel_consumption_ltr_per_hr,
a.power_kw,
a.speed_rpm_pto
-- add user and timestamp fields
from transactional.budni_pto_perf_results_summary a, transactional.test_instance_tractor_info b,transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = d.file_syspk
AND a.file_syspk = __file_syspk
and b.tractor_model = a.tractor_model
and b.file_sheet_mnemonic in ('BUDNI_PTO') and d.file_mnemonic =('BUDNI') and d.file_sheet_mnemonic in ('BUDNI_PTO');
END if;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_budni_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_budni_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;

View File

@@ -0,0 +1,217 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_comments_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
CREATE SEQUENCE if not exists mysequence INCREMENT 1 START 1;
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed'
loop
if f.file_mnemonic in('FTDRY','FTWET')
then
INSERT INTO fw_ods.fw_ods_comments(
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_file_id,
test_file_name,
test_instance_id,
tractor_make,
tractor_model,
test_iteration_number,
--old_test_file_name,
--platform,
--benchmark_yn,
wheel_drive_type,
tractor_engine_hp,
name_of_implement,
type_of_implement,
season,
users,
"role",
role_level,
note_or_title,
"timestamp",
"sequence",
note_or_comment,
created_by,
create_timestamp
)
SELECT
a.client_id,
a.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
a.file_syspk,
a.test_file_name,
a.syspk,
c.tractor_make,
b.tractor_model,
b.test_iteration_number,
--old filename,
--'platform data',
--'benchmark',
c.wheel_drive_type,
c.tractor_engine_hp,
d.name_of_implement,
d.Type_of_implement,
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from a.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
a.test_engineer,
case WHEN b.test_engr_comments is not null THEN 'Test Engineer'
WHEN b.test_mgr_comments is not null THEN 'Test Manager'
else null
end,
case WHEN b.test_engr_comments is not null THEN 1
WHEN b.test_mgr_comments is not null THEN 2
else null
end,
'note',
a.test_report_date::date,
nextval('mysequence'),
b.test_engr_comments,
current_user,
current_timestamp
FROM
transactional.test_instance a,
transactional.field_perf_summary b,
transactional.test_instance_tractor_info c,
transactional.test_instance_implement_info d
WHERE
a.file_syspk = b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and c.tractor_model = b.tractor_model
and a.file_syspk = __file_syspk;
ALTER SEQUENCE mysequence RESTART WITH 1;
elsif f.file_mnemonic in('FTHLG')
then
INSERT INTO fw_ods.fw_ods_comments(
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_file_id,
test_file_name,
test_instance_id,
tractor_make,
tractor_model,
test_iteration_number,
--old_test_file_name,
--platform,
--benchmark_yn,
wheel_drive_type,
tractor_engine_hp,
name_of_implement,
type_of_implement,
season,
users,
"role",
role_level,
note_or_title,
"timestamp",
"sequence",
note_or_comment,
created_by,
create_timestamp
)
SELECT
a.client_id,
a.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
a.file_syspk,
a.test_file_name,
a.syspk,
c.tractor_make,
b.tractor_model,
b.test_iteration_number,
--old filename,
--'platform data',
--'benchmark',
c.wheel_drive_type,
c.tractor_engine_hp,
'Trailer',
d.trailer_type,
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from a.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
a.test_engineer,
case WHEN b.test_engr_comments is not null THEN 'Test Engineer'
WHEN b.test_mgr_comments is not null THEN 'Test Manager'
else null
end,
case WHEN b.test_engr_comments is not null THEN 1
WHEN b.test_mgr_comments is not null THEN 2
else null
end,
'note',
a.test_report_date::date,
nextval('mysequence'),
b.test_engr_comments,
current_user,
current_timestamp
FROM
transactional.test_instance a,
transactional.field_perf_summary b,
transactional.test_instance_tractor_info c,
transactional.field_perf_summary_trailer_info d
WHERE
a.file_syspk = b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and c.tractor_model = b.tractor_model
and a.file_syspk = __file_syspk;
ALTER SEQUENCE mysequence RESTART WITH 1;
END IF;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_comments_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_comments_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;

View File

@@ -0,0 +1,149 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_detailed_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed'
loop
if f.file_mnemonic = 'IHTEMT'
then
insert into fw_ods.fw_ods_detailed
(
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type,
configuration,
test_instance_tractor_id,
--test specific: date & test dimensions
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
--test specific: location
location_name,
test_type,
--test specific:time_sec, Steering angle type and Effort_kg
time_sec,
steering_angle_degree,
effort_kg,
created_by,
create_timestamp
)
select
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
a.client_id,
a.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
a.test_name,
a.file_syspk,
a.test_file_name,
a.syspk,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
b.tractor_make,
b.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
--test specific: date & test dimensions
a.date_of_test,
extract( year from a.date_of_test),
extract( quarter from a.date_of_test),
extract( month from a.date_of_test),
extract( day from a.date_of_test),
extract( dow from a.date_of_test),
--test specific: location
a.test_location_name,
a.test_type,
--test specific:time_sec, Steering angle type and Effort_kg
c.time_sec,
c.steering_anglel,
c.effort_kg,
current_user,
current_timestamp
from
transactional.test_instance a,
transactional.test_instance_tractor_info b,
transactional.iht_steering_effort_raw_data c
where
a.file_syspk = b.file_syspk
and b.file_syspk = c.file_syspk
and a.file_syspk = __file_syspk
-- and c.tractor_model = b.tractor_model
and a.file_mnemonic in ('IHTEMT');
update fw_ods.fw_ods b
set platform = a.tractor_platform
from transactional.test_instance_tractor_info a
where
b.platform is null and
b.test_file_id = a.file_syspk
and a.file_syspk = __file_syspk
and test_file_mnemonic = a.file_mnemonic
and a.file_mnemonic like 'IHT%';
end if;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_detailed_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_detailed_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;

View File

@@ -0,0 +1,175 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_drawbar_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed' and file_mnemonic = 'DBSTD'
loop
insert into fw_ods.fw_ods(
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_file_id,
test_file_name,
test_instance_id,
test_name,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type ,
"configuration",
test_instance_tractor_id,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
season,
mahindra_model_yn,
test_tractor_yn,
test_condition,
-- test mode, type, subtype, condition hierarchy
location_name,
test_type,
-- location name
tyre_size,
tyre_ply_rating,
tyre_pressure_kg_per_cm2,
engine_speed_var,
gear_used,
fuel_consumption_lit_per_hr,
speed_kmph,
wheel_slippage_pct,
power_kw,
power_hp,
pull_kn,
pull_kgf,
temp_engine_oil_c,
temp_trans_oil_c,
temp_coolant_c,
temp_fuel_in_c,
temp_fuel_out_c,
sfc_g_per_kwh,
specific_energy_kwh_per_ltr
)
select
d.client_id,
d.function_id,
d.file_mnemonic,
d.file_sheet_mnemonic,
d.file_syspk,
d.test_file_name,
d.syspk,
d.test_name,
b.tractor_make,
b.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
-- -- test specific date & test dimensions
d.date_of_test,
extract( year from d.date_of_test) ,
extract( month from d.date_of_test),
extract( quarter from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
concat(lpad(extract( month from d.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
'Y',
'Y',
d.test_condition,
d.test_location_name ,
d.test_type,
-- test specific dimensions
c.tyre_size,
c.tyre_ply_rating,
c.tyre_pressure_kg_per_cm2,
a.engine_speed_min_1,
-- test specific measures
a.gear_number_and_range,
a.fuel_consumption_l_per_h,
a.travel_speed_km_per_hr,
a.wheel_slip_pct_rear,
a.drawbar_power_kw,
a.drawbar_power_hp,
a.drawbar_pull_kn,
a.drawbar_pull_kgf,
a.temp_engine_oil_c,
a.temp_trans_oil_c,
a.temp_coolant_c,
a.temp_fuel_in_c,
a.temp_fuel_out_c,
a.fuel_consumption_g_per_kwh,
a.fuel_consumption_kwh_per_l
-- add user and timestamp fields
from transactional.drawbar_perf_results_summary a, transactional.test_instance_tractor_info b,transactional.test_instance_tyre_info c,transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = c.file_syspk
and a.file_syspk = d.file_syspk
and a.file_syspk = __file_syspk
and b.tractor_model = a.tractor_model
and d.file_mnemonic in ('DBSTD') and c.tyre_type = 'rear';
update fw_ods.fw_ods set test_file_name = file_name from staging1.staging_generic_table a where file_mnemonic = 'DBSTD' and test_file_id = a.file_syspk;
update fw_ods.fw_ods set wheel_drive_type = substring(a.file_name from '%#"_WD#"%' for '#') from staging1.staging_generic_table a where file_mnemonic = 'DBSTD' and test_file_id = a.file_syspk;
UPDATE fw_ods.fw_ods set test_mode = CASE WHEN a.file_name like '%Normal%' THEN 'Normal'
WHEN a.file_name like '%Eco%' THEN 'Eco'
WHEN a.file_name like '%Boost%' THEN 'Boost'
ELSE NULL
END
FROM staging1.staging_generic_table a where file_mnemonic = 'DBSTD' and test_file_id = a.file_syspk;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_drawbar_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_drawbar_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;

View File

@@ -0,0 +1,190 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_drawbar_performance_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed'
loop
if f.file_mnemonic = 'DBSTD'
then
insert into fw_ods.fw_ods_drawbar_performance (
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_file_id,
test_file_name,
test_instance_id,
test_name,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type ,
"configuration",
test_instance_tractor_id,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
season,
mahindra_model_yn,
test_tractor_yn,
summary_yn,
test_condition,
test_type,
--subtype, condition hierarchy
location_name,
-- location name
tyre_size,
tyre_ply_rating,
tyre_pressure_kg_per_cm2,
engine_speed_var,
gear_used,
fuel_consumption_lit_per_hr,
speed_kmph,
wheel_slippage_pct_front,
wheel_slippage_pct,
power_kw,
power_hp,
pull_kn,
pull_kgf,
temp_engine_oil_c,
temp_trans_oil_c,
temp_coolant_c,
temp_fuel_in_c,
temp_fuel_out_c,
sfc_g_per_kwh,
specific_energy_kwh_per_ltr,
fan_speed_rpm_var,
no_of_load_lugs_front,
fuel_consumption_kg_per_kwh,
atm_rh_pct,
atm_temp_c,
atm_pressure_kpa
)
select
d.client_id,
d.function_id,
d.file_mnemonic,
d.file_sheet_mnemonic,
d.file_syspk,
d.test_file_name,
d.syspk,
d.test_name,
b.tractor_make,
b.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
-- -- test specific date & test dimensions
d.date_of_test,
extract( year from d.date_of_test) ,
extract( month from d.date_of_test),
extract( quarter from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
concat(lpad(extract( month from d.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
'Y',
'Y',
'N',
d.test_condition,
d.test_type,
d.test_location_name ,
-- test specific dimensions
c.tyre_size,
c.tyre_ply_rating,
c.tyre_pressure_kg_per_cm2,
a.engine_speed_min_1,
-- test specific measures
a.gear_number_and_range,
a.fuel_consumption_l_per_h,
a.travel_speed_km_per_hr,
a.wheel_slip_pct_front,
a.wheel_slip_pct_rear,
a.drawbar_power_kw,
a.drawbar_power_hp,
a.drawbar_pull_kn,
a.drawbar_pull_kgf,
a.temp_engine_oil_c,
a.temp_trans_oil_c,
a.temp_coolant_c,
a.temp_fuel_in_c,
a.temp_fuel_out_c,
a.fuel_consumption_g_per_kwh,
a.fuel_consumption_kwh_per_l ,
a.fan_speed_min_1,
a.no_of_load_lugs_front,
a.fuel_consumption_kg_per_kwh,
atm_conditions_rh_pct,
atm_conditions_temp_c,
atm_conditions_pressure_kpa
-- add user and timestamp fields
from transactional.drawbar_perf_results a, transactional.test_instance_tractor_info b , transactional.test_instance_tyre_info c, transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = c.file_syspk
and a.file_syspk = d.file_syspk
and a.file_syspk = __file_syspk
and b.tractor_model = a.tractor_model
and d.file_mnemonic in ('DBSTD') and c.tyre_type = 'rear';
END IF;
update fw_ods.fw_ods_drawbar_performance set test_file_name = file_name from staging1.staging_generic_table a where file_mnemonic = 'DBSTD' and test_file_id = a.file_syspk;
update fw_ods.fw_ods_drawbar_performance set wheel_drive_type = substring(a.tractor_model from '%#"_WD#"%' for '#') from fw_ods.fw_ods_drawbar_performance a where fw_ods.fw_ods_drawbar_performance.test_file_mnemonic = 'DBSTD' and fw_ods.fw_ods_drawbar_performance.test_file_id = a.test_file_id;
update fw_ods.fw_ods_drawbar_performance set test_mode = CASE WHEN a.file_name like '%Normal%' THEN 'Normal'
WHEN a.file_name like '%Eco%' THEN 'Eco'
WHEN a.file_name like '%Boost%' THEN 'Boost'
ELSE NULL
END
FROM staging1.staging_generic_table a where file_mnemonic = 'DBSTD' and test_file_id = a.file_syspk;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_drawbar_performance_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_drawbar_performance_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;

View File

@@ -0,0 +1,483 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_field_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed'
loop
if f.file_mnemonic = 'FTDRY'
then
insert into fw_ods.fw_ods
(
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
test_iteration_number,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
tractor_make,
tractor_model,
mahindra_model_yn,
test_tractor_yn,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
-- Test Season:
season,
--test specific: date & test dimensions
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
--test specific: condition
test_condition,
--test specific: location
location_name,
test_type,
----test specific: Implement details(name, type and Weight_kg)
name_of_implement,
type_of_implement,
implement_weight_kg,
-- test specific measures: Speed and gear
engine_speed_var,
gear_used,
-- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation
fuel_consumption_lit_per_hr,
fuel_consumption_lit_per_acr,
area_covered_acr_per_hr,
speed_kmph,
wheel_slippage_pct,
field_efficiency_pct,
erpmdrop_straight_1stpass_low,
erpmdrop_straight_1stpass_high,
depth_of_cut_cm_low,
depth_of_cut_cm_high,
created_by,
updated_by,
create_timestamp,
update_timestamp
)
select
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
a.client_id,
a.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
a.test_name,
a.file_syspk,
a.test_file_name,
a.syspk,
c.test_iteration_number,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
b.tractor_make,
b.tractor_model,
b.mahindra_model_yn,
b.test_tractor_yn,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
-- Test Season:
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',a.season) AS "Month Name",
--test specific: date & test dimensions
a.date_of_test,
extract( year from a.date_of_test),
extract( quarter from a.date_of_test),
extract( month from a.date_of_test),
extract( day from a.date_of_test),
extract( dow from a.date_of_test),
--test specific: condition
c.test_condition,
--test specific: location
a.test_location_name,
a.test_type,
----test specific: Implement details(name, type and Weight_kg)
d.name_of_implement,
d.Type_of_implement,
d.implement_weight_kg,
-- test specific measures: Speed and gear
c.engine_rpm_set,
c.gear_used,
-- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation
c.fuel_consumption_lit_per_hr,
c.fuel_consumption_lit_per_acr,
c.area_covered_acr_per_hr,
c.on_load_speed_kmph,
c.wheel_slippage_pct,
---- test specific measures: effeciency
null,
---- test specific measures: productivity,rpm and depth-of-operation
c.erpmdrop_straight_1stpass_low,
c.erpmdrop_straight_1stpass_high,
c.depth_of_cut_cm_low ,
c.depth_of_cut_cm_high,
current_user,
current_user,
current_timestamp,
current_timestamp
-- add user and timestamp fields
from
transactional.test_instance a,
transactional.test_instance_tractor_info b,
transactional.field_perf_summary c,
transactional.test_instance_implement_info d
where
a.file_syspk = b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and c.tractor_model = b.tractor_model
and a.file_mnemonic = f.file_mnemonic
and a.file_syspk = __file_syspk;
elsif f.file_mnemonic = 'FTWET'
then
insert into fw_ods.fw_ods
(
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
test_iteration_number,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
tractor_make,
tractor_model,
mahindra_model_yn,
test_tractor_yn,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
-- Test Season:
season,
--test specific: date & test dimensions
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
--test specific: condition
test_condition,
--test specific: location
location_name,
test_type,
----test specific: Implement details(name, type and Weight_kg)
name_of_implement,
type_of_implement,
implement_weight_kg,
-- test specific measures: Speed and gear
engine_speed_var,
gear_used,
-- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation
fuel_consumption_lit_per_hr,
fuel_consumption_lit_per_acr,
area_covered_acr_per_hr,
speed_kmph,
speed_pto_rpm,
wheel_slippage_pct,
no_of_passes,
field_efficiency_pct,
erpmdrop_straight_1stpass_low,
erpmdrop_straight_1stpass_high,
erpmdrop_straight_2ndpass_low,
erpmdrop_straight_2ndpass_high,
erpmdrop_straight_3rdpass_low,
erpmdrop_straight_3rdpass_high,
erpmdrop_turn_1stpass_low,
erpmdrop_turn_1stpass_high,
erpmdrop_turn_2ndpass_low,
erpmdrop_turn_2ndpass_high,
erpmdrop_turn_3rdpass_low,
erpmdrop_turn_3rdpass_high,
depth_of_cut_cm_low,
depth_of_cut_cm_high,
created_by,
updated_by,
create_timestamp,
update_timestamp
--created_by, updated_by, create_timestamp, update_timestamp
)
select
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
a.client_id,
a.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
a.test_name,
a.file_syspk,
a.test_file_name,
a.syspk,
c.test_iteration_number,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
b.tractor_make,
b.tractor_model,
b.mahindra_model_yn,
b.test_tractor_yn,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
-- Test Season:
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',a.season) AS "Month Name",
--test specific: date & test dimensions
a.date_of_test,
extract( year from a.date_of_test),
extract( quarter from a.date_of_test),
extract( month from a.date_of_test),
extract( day from a.date_of_test),
extract( dow from a.date_of_test),
--test specific: condition
c.test_condition,
--test specific: location
a.test_location_name,
a.test_type,
----test specific: Implement details(name, type and Weight_kg)
d.name_of_implement,
d.Type_of_implement,
d.implement_weight_kg,
-- test specific measures: Speed and gear
c.engine_rpm_set,
c.gear_used,
-- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation
c.fuel_consumption_lit_per_hr,
c.fuel_consumption_lit_per_acr,
c.area_covered_acr_per_hr,
c.nominal_speed_kmph,
c.pto_rpm_set,
c.wheel_slippage_pct,
c.no_of_passes,
---- test specific measures: effeciency
null,
---- test specific measures: productivity,rpm and depth-of-operation
c.erpmdrop_straight_1stpass_low,
c.erpmdrop_straight_1stpass_high,
c.erpmdrop_straight_2ndpass_low,
c.erpmdrop_straight_2ndpass_high,
c.erpmdrop_straight_3rdpass_low,
c.erpmdrop_straight_3rdpass_high,
c.erpmdrop_turn_1stpass_low,
c.erpmdrop_turn_1stpass_high,
c.erpmdrop_turn_2ndpass_low,
c.erpmdrop_turn_2ndpass_high,
c.erpmdrop_turn_3rdpass_low,
c.erpmdrop_turn_3rdpass_high,
c.depth_of_cut_cm_low ,
c.depth_of_cut_cm_high,
current_user,
current_user,
current_timestamp,
current_timestamp
-- add user and timestamp fields
from
transactional.test_instance a,
transactional.test_instance_tractor_info b,
transactional.field_perf_summary c,
transactional.test_instance_implement_info d
where
a.file_syspk = b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and c.tractor_model = b.tractor_model
and a.file_mnemonic = f.file_mnemonic
and a.file_syspk = __file_syspk;
elsif f.file_mnemonic = 'FTHLG'
then
insert into fw_ods.fw_ods
(
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
tractor_make,
tractor_model,
mahindra_model_yn,
test_tractor_yn,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
--test specific: date & test dimensions
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
season,
--test specific: condition
test_condition,
test_iteration_number,
--test specific: location
location_name,
test_type,
----test specific: Implement details(name, type and Weight_kg)
name_of_implement,
type_of_implement,
implement_weight_kg,
-- test specific measures: Speed and gear
-- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation
fuel_consumption_lit_per_hr,
gear_used,
gear_used_up_slope_1,
gear_used_up_slope_2,
gear_used_down_slope,
speed_kmph,
mileage_kmpl,
total_dist_travelled_km,
erpmdrop_straight_1stpass_low,
erpmdrop_straight_1stpass_high,
erpmdrop_turn_1stpass_low,
erpmdrop_turn_1stpass_high,
erpmdrop_turn_2ndpass_low,
erpmdrop_turn_2ndpass_high,
erpmdrop_turn_3rdpass_low,
erpmdrop_turn_3rdpass_high,
created_by,
updated_by,
create_timestamp,
update_timestamp
--created_by, updated_by, create_timestamp, update_timestamp
)
select
-- File Identifier: Test_Mnemonic, Sheet_Mnemonic, file_syspk(id), test_instance_id, test_file_name,
a.client_id,
a.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
a.test_name,
a.file_syspk,
a.test_file_name,
a.syspk,
-- Tractor Identifier: tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
b.tractor_make,
b.tractor_model,
b.mahindra_model_yn,
b.test_tractor_yn,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
--test specific: date & test dimensions
a.date_of_test,
extract( year from a.date_of_test),
extract( quarter from a.date_of_test),
extract( month from a.date_of_test),
extract( day from a.date_of_test),
extract( dow from a.date_of_test),
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from a.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
--test specific: condition
c.test_condition,
c.test_iteration_number,
--test specific: location
a.test_location_name,
a.test_type,
----test specific: Implement details(name, type and Weight_kg)
'Trailer',
d.trailer_type,
d.trailer_gross_weight_kg,
-- test specific measures: Speed and gear
-- test specific measures: fuel, area, speed,wheel-slip, productivity,rpm and depth-of-operation
c.fuel_consumption_lit_per_hr,
c. gear_used_on_straight_road,
c.gear_used_on_up_slope_1,
c.gear_used_on_up_slope_2,
c.gear_used_on_down_slope,
c.avg_speed_of_travel_kmph,
c.Mileage_Km_per_Ltr,
c.total_dist_travelled_km,
c.erpmdrop_straight_1stpass_low,
c.erpmdrop_straight_1stpass_high,
c.erpmdrop_turn_1stpass_low,
c.erpmdrop_turn_1stpass_high,
c.erpmdrop_turn_2ndpass_low,
c.erpmdrop_turn_2ndpass_high,
c.erpmdrop_turn_3rdpass_low,
c.erpmdrop_turn_3rdpass_high,
current_user,
current_user,
current_timestamp,
current_timestamp
-- add user and timestamp fields
from
transactional.test_instance a,
transactional.test_instance_tractor_info b,
transactional.field_perf_summary c,
transactional.field_perf_summary_trailer_info d
where
a.file_syspk = b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and c.tractor_model = b.tractor_model
and a.file_mnemonic = f.file_mnemonic
and a.file_syspk = __file_syspk;
end if;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_field_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_field_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;

View File

@@ -0,0 +1,185 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_implement_details_update(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed' and file_mnemonic like 'FT%'
loop
-- FTDRY:
update fw_ods.fw_ods a
set
implement_size= b.implement_size,
hitch_category= b.hitch_category,
type_of_cage_wheel= b.type_of_cage_wheel,
cage_wheel_width_mm = b.cage_wheel_width_mm ,
cage_wheel_weight = b.cage_wheel_weight ,
cage_wheel_inner_and_outer_ring_dia_mm = b.cage_wheel_inner_and_outer_ring_dia_mm ,
cage_wheel_center_ring_dia_mm = b.cage_wheel_center_ring_dia_mm ,
dist_between_rhs_and_lhs_cage_wheel_inner_ring_mm = b.dist_between_rhs_and_lhs_cage_wheel_inner_ring_mm ,
no_of_angles_on_cage_wheel = b.no_of_angles_on_cage_wheel ,
soil_moisture_content_pct= b.soil_moisture_content_pct,
soil_bulk_density_g_per_cc= b.soil_bulk_density_g_per_cc,
soil_cone_index= b.soil_cone_index,
field_condition= b.field_condition
from transactional.field_perf_summary_implement_info b
where a.test_file_mnemonic = b.file_mnemonic
and a.test_instance_id = b.test_instance_id
and a.test_file_mnemonic ='FTDRY'
and b.file_syspk = a.test_file_id
and b.file_syspk = __file_syspk
;
update fw_ods.fw_ods a
set
fuel_consumption_var_lit_per_hr= b.fuel_consumption_var_lit_per_hr,
mileage_var_km_per_ltr= b.mileage_var_km_per_ltr,
area_covered_var_acr_per_hr= b.area_covered_var_acr_per_hr,
fuel_consumption_var_lit_per_acr= b.fuel_consumption_var_lit_per_acr,
fuel_consumption_var_pct_lit_per_hr= b.fuel_consumption_var_pct_lit_per_hr,
mileage_var_pct_km_per_ltr= b.mileage_var_pct_km_per_ltr,
area_covered_var_pct_acr_per_hr= b.area_covered_var_pct_acr_per_hr,
fuel_consumption_var_pct_lit_per_acr = b.fuel_consumption_var_pct_lit_per_acr
from transactional.field_perf_summary b
where b.file_syspk = a.test_file_id
and a.test_file_mnemonic = b.file_mnemonic
and a.test_iteration_number = b.test_iteration_number
and a.tractor_model = b.tractor_model
and a.test_instance_tractor_id = b.test_instance_tractor_id
and b.test_instance_id = a.test_instance_id
and b.file_mnemonic = 'FTDRY'
and b.file_syspk = __file_syspk
;
-- FTWET:
update fw_ods.fw_ods a
set
implement_size= b.implement_size,
hitch_category= b.hitch_category,
type_of_cage_wheel= b.type_of_cage_wheel,
cage_wheel_width_mm = b.cage_wheel_width_mm ,
cage_wheel_weight = b.cage_wheel_weight ,
cage_wheel_inner_and_outer_ring_dia_mm = b.cage_wheel_inner_and_outer_ring_dia_mm ,
cage_wheel_center_ring_dia_mm = b.cage_wheel_center_ring_dia_mm ,
dist_between_rhs_and_lhs_cage_wheel_inner_ring_mm = b.dist_between_rhs_and_lhs_cage_wheel_inner_ring_mm ,
no_of_angles_on_cage_wheel = b.no_of_angles_on_cage_wheel ,
soil_moisture_content_pct= b.soil_moisture_content_pct,
soil_bulk_density_g_per_cc= b.soil_bulk_density_g_per_cc,
soil_cone_index= b.soil_cone_index,
field_condition= b.field_condition
from transactional.field_perf_summary_implement_info b
where a.test_file_mnemonic = b.file_mnemonic
and a.test_instance_id = b.test_instance_id
and a.test_file_mnemonic ='FTWET'
and b.file_syspk = a.test_file_id
and b.file_syspk = __file_syspk
;
update fw_ods.fw_ods a
set
fuel_consumption_var_lit_per_hr= b.fuel_consumption_var_lit_per_hr,
mileage_var_km_per_ltr= b.mileage_var_km_per_ltr,
area_covered_var_acr_per_hr= b.area_covered_var_acr_per_hr,
fuel_consumption_var_lit_per_acr= b.fuel_consumption_var_lit_per_acr,
fuel_consumption_var_pct_lit_per_hr= b.fuel_consumption_var_pct_lit_per_hr,
mileage_var_pct_km_per_ltr= b.mileage_var_pct_km_per_ltr,
area_covered_var_pct_acr_per_hr= b.area_covered_var_pct_acr_per_hr,
fuel_consumption_var_pct_lit_per_acr = b.fuel_consumption_var_pct_lit_per_acr
from transactional.field_perf_summary b
where b.file_syspk = a.test_file_id
and a.test_file_mnemonic = b.file_mnemonic
and a.test_iteration_number = b.test_iteration_number
and a.tractor_model = b.tractor_model
and a.test_instance_tractor_id = b.test_instance_tractor_id
and b.test_instance_id = a.test_instance_id
and b.file_mnemonic = 'FTWET'
and b.file_syspk = __file_syspk
;
-- FTHLG:
update fw_ods.fw_ods a
set
tire_size_and_inflation_pressure_psi= b.tire_size_and_inflation_pressure_psi,
no_of_axle= b.no_of_axle,
no_of_wheels = b.no_of_wheels,
trailer_gross_weight_kg= b.trailer_gross_weight_kg,
tractor_rwc_to_hitch_point_center_dist_mm= b.tractor_rwc_to_hitch_point_center_dist_mm,
trailer_hitch_height_above_ground_level_mm= b.trailer_hitch_height_above_ground_level_mm,
gradient_slope_1_degree= b.gradient_slope_1_degree,
gradient_slope_2_degree = b.gradient_slope_2_degree
from transactional.field_perf_summary_trailer_info b
where a.test_file_mnemonic = b.file_mnemonic
and a.test_instance_id = b.test_instance_id
and a.test_file_mnemonic ='FTHLG'
and b.file_syspk = a.test_file_id
and b.file_syspk = __file_syspk
;
update fw_ods.fw_ods a
set
fuel_consumption_var_lit_per_hr= b.fuel_consumption_var_lit_per_hr,
mileage_var_km_per_ltr= b.mileage_var_km_per_ltr,
area_covered_var_acr_per_hr= b.area_covered_var_acr_per_hr,
fuel_consumption_var_lit_per_acr= b.fuel_consumption_var_lit_per_acr,
fuel_consumption_var_pct_lit_per_hr= b.fuel_consumption_var_pct_lit_per_hr,
mileage_var_pct_km_per_ltr= b.mileage_var_pct_km_per_ltr,
area_covered_var_pct_acr_per_hr= b.area_covered_var_pct_acr_per_hr,
fuel_consumption_var_pct_lit_per_acr = b.fuel_consumption_var_pct_lit_per_acr
from transactional.field_perf_summary b
where b.file_syspk = a.test_file_id
and a.test_file_mnemonic = b.file_mnemonic
and a.test_iteration_number = b.test_iteration_number
and a.tractor_model = b.tractor_model
and a.test_instance_tractor_id = b.test_instance_tractor_id
and b.test_instance_id = a.test_instance_id
and b.file_mnemonic = 'FTHLG'
and b.file_syspk = __file_syspk
;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_implement_details_update', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_implement_details_update', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,214 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_observations_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed' and file_mnemonic like 'FT%'
loop
insert into fw_ods.fw_ods_observations
(
client_id ,
function_id ,
test_file_mnemonic ,
test_sheet_mnemonic ,
test_file_id ,
test_file_name ,
test_iteration_number ,
--platform ,
--benchmark_yn ,
tractor_make ,
tractor_model ,
tractor_engine_hp ,
wheel_drive_type ,
name_of_implement ,
type_of_implement ,
season ,
engine_smoke_on_load,
engine_acceleration_smoke ,
range_gear_shifting ,
speed_gear_shifting ,
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_lifing_lowering_response ,
pulverization_quality ,
pulverization_index
)
select
a.client_id ,
a.function_id ,
a.file_mnemonic,
a.file_sheet_mnemonic ,
b.file_syspk ,
a.test_file_name ,
b.test_iteration_number ,
--platform ,
--benchmark_yn ,
b.tractor_make ,
b.tractor_model ,
d.tractor_engine_hp ,
d.wheel_drive_type ,
c.name_of_implement ,
c.type_of_implement ,
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',a.season) AS "Month Name",
b.engine_smoke_on_load,
b.engine_acceleration_smoke ,
b.range_gear_shifting ,
b.speed_gear_shifting ,
b.draft_response ,
b.tractor_steer_ability ,
b.tractor_braking_perf ,
b.front_visibility ,
b.implement_accessibility ,
b.front_wheel_dragging_at_turning ,
b.front_end_lifting_during_operation ,
b.rpm_recovery_time ,
b.engine_vibration ,
b.engine_sound ,
b.implement_lifting_per_lowering_response,
b.pulverization_quality ,
b.pulverization_index
from
transactional.test_instance a,
transactional.field_perf_summary b,
transactional.test_instance_implement_info c ,
transactional.test_instance_tractor_info d
where
a.file_syspk= b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and d.tractor_model = b.tractor_model
and a.file_mnemonic in ('FTDRY','FTWET')
and a.file_syspk = __file_syspk;
insert into fw_ods.fw_ods_observations
(
client_id ,
function_id ,
test_file_mnemonic ,
test_sheet_mnemonic ,
test_file_id ,
test_file_name ,
test_iteration_number ,
--platform ,
--benchmark_yn ,
tractor_make ,
tractor_model ,
tractor_engine_hp ,
wheel_drive_type ,
name_of_implement ,
type_of_implement ,
season ,
engine_smoke_on_load,
engine_acceleration_smoke ,
range_gear_shifting ,
speed_gear_shifting ,
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_lifing_lowering_response ,
pulverization_quality ,
pulverization_index
)
select
a.client_id ,
a.function_id ,
a.file_mnemonic,
a.file_sheet_mnemonic ,
b.file_syspk ,
a.test_file_name ,
b.test_iteration_number ,
--platform ,
--benchmark_yn ,
b.tractor_make ,
b.tractor_model ,
d.tractor_engine_hp ,
d.wheel_drive_type ,
'Trailer',
c.trailer_type ,
concat(lpad(extract( month from a.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from a.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
b.engine_smoke_on_load,
b.engine_acceleration_smoke ,
b.range_gear_shifting ,
b.speed_gear_shifting ,
b.draft_response ,
b.tractor_steer_ability ,
b.tractor_braking_perf ,
b.front_visibility ,
b.implement_accessibility ,
b.front_wheel_dragging_at_turning ,
b.front_end_lifting_during_operation ,
b.rpm_recovery_time ,
b.engine_vibration ,
b.engine_sound ,
b.implement_lifting_per_lowering_response,
b.pulverization_quality ,
b.pulverization_index
from
transactional.test_instance a,
transactional.field_perf_summary b,
transactional.field_perf_summary_trailer_info c ,
transactional.test_instance_tractor_info d
where
a.file_syspk= b.file_syspk
and b.file_syspk = c.file_syspk
and c.file_syspk = d.file_syspk
and d.tractor_model = b.tractor_model
and a.file_mnemonic= 'FTHLG'
and a.file_syspk = __file_syspk;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_observations_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_observations_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$ LANGUAGE plpgsql;

View File

@@ -0,0 +1,364 @@
CREATE OR REPLACE FUNCTION fw_ods.fn_fw_ods_PTO_load(p_client_id int,p_function_id int, p_file_mnemonic text,
p_file_sheet_mnemonic text, p_file_syspk int)
RETURNS void
AS $$
declare
f record;
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;
begin
-- Adding data to file fw_ods_field:
for f in select distinct file_mnemonic from fw_core.fw_jobctl_file_runschedule
where latest_runschedule_flag = '1' and end_status = 'success' and end_status_note = 'TRX_completed'
loop
if f.file_mnemonic LIKE 'PTO%'
then
--pto_perf_results
insert into fw_ods.fw_ods (
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
mahindra_model_yn,
test_tractor_yn,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
season,
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
-- season and date
test_mode,
test_type,
test_sub_type,
-- test mode, type, subtype, condition hierarchy
location_name,
-- location name
engine_speed_var,
-- test specific dimensions
-- test specific measures ----
fuel_consumption_lit_per_hr,
power_kw,
power_hp,
torque_kg_m ,
sfc_gms_per_hp_hr ,
fuelling_mm3_per_stroke_per_cyl,
temp_engine_oil_c,
equ_crank_torque_nm,
speed_pto_rpm,
torque_Nm ,
temp_water_outlet_c,
temp_exhaust_c,
temp_fuel_temp_c
-- audit fields
-- validate how it is being done
--created_by, updated_by, create_timestamp, update_timestamp
)
select
d.client_id,
d.function_id,
d.file_mnemonic,
d.file_sheet_mnemonic,
d.test_name,
d.file_syspk,
d.test_file_name,
d.syspk,
b.tractor_make,
b.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
'Y',
'Y',
-- -- test specific date & test dimensions
concat(lpad(extract( month from d.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
d.date_of_test,
extract( year from d.date_of_test) ,
extract( month from d.date_of_test),
extract( quarter from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
a.test_mode,
a.pto_test_type ,
a.pto_test_sub_type ,
d.test_location_name ,
-- test specific dimensions
a.speed_engine_rpm,
a.fuel_consumption_ltr_per_hr,
a.power_kw,
a.power_hp,
-- test specific measures
a.brake_torque_kg_m,
a.fuel_consumption_gm_per_hp_hr ,
a.fuel_consumption_mm3_per_str_per_cyl ,
a.temperatures_engine_oil_c ,
a.eq_crank_torque_nm,
a.speed_pto_rpm,
a.brake_torque_n_m,
a.temperatures_water_outlet_c,
a.temperatures_exhaust_c,
a.temperatures_fuel_c
-- add user and timestamp fields
from transactional.pto_perf_results a,
transactional.test_instance_tractor_info b,
transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = d.file_syspk
and b.tractor_model = a.tractor_model
and a.test_mode = d.test_mode
and a.file_syspk = __file_syspk
and d.file_mnemonic in ('PTOSTD','PTOBEN') and case a.test_mode
when 'Boost' then b.file_sheet_mnemonic = 'PTOBEN_PRFB'
when 'Normal' then b.file_sheet_mnemonic = 'PTOBEN_PRFN'
when 'Eco' then b.file_sheet_mnemonic = 'PTOBEN_PRFE'
when 'Standard' then b.file_sheet_mnemonic = 'PTOSTD_PRF'
end;
--transactional.pto_multipoint_mapping
insert into fw_ods.fw_ods (
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
mahindra_model_yn,
test_tractor_yn,
season,
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
-- season and date
test_mode,
test_type,
test_condition,
-- test mode, type, subtype, condition hierarchy
location_name,
-- location name
engine_speed_var,
engine_load_pct_var,
-- test specific dimensions
-- test specific measures ----
sfc_gms_per_hp_hr,
fuel_consumption_lit_per_hr
-- audit fields
-- validate how it is being done
--created_by, updated_by, create_timestamp, update_timestamp
)
select
d.client_id,
d.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
d.test_name,
a.file_syspk,
d.test_file_name,
d.syspk,
-- d.syspk = test_instance_id, b.syspk = test_instance_tractor_id
b.tractor_make,
a.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
'Y',
'Y',
-- -- test specific date & test dimensions
concat(lpad(extract( month from d.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
d.date_of_test,
extract( year from d.date_of_test) ,
extract( month from d.date_of_test),
extract( quarter from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
a.test_mode,
a.test_condition,
a.test_condition,
d.test_location_name ,
-- test specific dimensions
a.engine_speed_rpm,
a.engine_load_pct,
-- test specific measures
a.sfc_gm_per_hp_hr,
a.fuel_consumption_ltr_per_hr
-- add user and timestamp fields
from transactional.pto_multipoint_mapping a, transactional.test_instance_tractor_info b,transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = d.file_syspk
and b.tractor_model = a.tractor_model
and a.file_syspk = __file_syspk
and d.file_mnemonic in ('PTOSTD','PTOBEN')
and b.file_sheet_mnemonic in ('PTOBEN_PRFN','PTOSTD_PRF') and
d.file_sheet_mnemonic in ('PTOSTD_MPM','PTOBEN_MPM');
--pto_perf_governing_graph
insert into fw_ods.fw_ods (
client_id,
function_id,
test_file_mnemonic,
test_sheet_mnemonic,
test_name,
test_file_id,
test_file_name,
test_instance_id,
-- File Identifier
tractor_make,
tractor_model,
tractor_engine_hp,
wheel_drive_type,
"configuration",
test_instance_tractor_id,
-- Tractor Identifier tractor make,tractor model,tractor engine hp,wheel drive type,configuration,Test insance tractor id
mahindra_model_yn,
test_tractor_yn,
season,
test_date,
test_date_year,
test_date_quarter,
test_date_month,
test_date_dayofmonth,
test_date_dayofweek,
-- season and date
test_mode,
test_type,
test_condition,
-- test mode, type, subtype, condition hierarchy
location_name,
-- location name
-- test specific dimensions
-- test specific measures ----
engine_speed_var,
power_hp,
torque_kg_m,
fuelling_mm3_per_stroke_per_cyl
-- audit fields
-- validate how it is being done
--created_by, updated_by, create_timestamp, update_timestamp
)
select
d.client_id,
d.function_id,
a.file_mnemonic,
a.file_sheet_mnemonic,
d.test_name,
a.file_syspk,
d.test_file_name,
d.syspk,
-- d.syspk = test_instance_id, b.syspk = test_instance_tractor_id
b.tractor_make,
a.tractor_model,
b.tractor_engine_hp,
b.wheel_drive_type,
b.configuration,
b.syspk,
'Y',
'Y',
-- -- test specific date & test dimensions
concat(lpad(extract( month from d.date_of_test)::text,2,'0'),'-',(TO_CHAR(
TO_DATE (extract( month from d.date_of_test)::text, 'MM'), 'Month'
))) AS "Month Name",
d.date_of_test,
extract( year from d.date_of_test) ,
extract( month from d.date_of_test),
extract( quarter from d.date_of_test),
extract( DAY from d.date_of_test),
date_part('dow',d.date_of_test) dow,
a.test_mode,
--a.test_condition,
a.test_condition,
a.test_type,
d.test_location_name ,
-- test specific dimensions
a.engine_speed_rpm,
a.power_hp,
-- test specific measures
a.torque_kg_m,
a.fuelling_mm3_per_stroke_per_cyl
-- add user and timestamp fields
from transactional.pto_perf_governing_graph a, transactional.test_instance_tractor_info b,transactional.test_instance d
where a.file_syspk = b.file_syspk
and a.file_syspk = d.file_syspk
and b.tractor_model = a.tractor_model
and a.file_syspk = __file_syspk
and d.file_mnemonic in ('PTOSTD','PTOBEN')
and b.file_sheet_mnemonic in ('PTOBEN_PRFN','PTOSTD_PRF')
and d.file_sheet_mnemonic in ('PTOSTD_GVG','PTOBEN_GVG');
update fw_ods.fw_ods set test_ambient = CASE WHEN test_type like '%Natural Ambient%' THEN 'Natural'
WHEN test_type like '%High Ambient%' THEN 'High'
END ;
update fw_ods.fw_ods set tractor_engine_hp = trim((substring(lower(tractor_model) from '%#"___hp#"%' for '#')),'hp')::int where test_file_mnemonic in ('PTOSTD','PTOBEN') and test_file_id = __file_syspk;
update fw_ods.fw_ods set configuration = 'NA' where test_file_mnemonic in ('PTOSTD','PTOBEN') and test_file_id = __file_syspk;
end if;
end loop;
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_pto_load', err_state, err_msg, err_detail, err_hint, err_context,'success');
EXCEPTION when OTHERS then
err_state = returned_sqlstate, /* P0002 */
err_msg = message_text, /* No Data in FTDRY */
err_detail = pg_exception_detail, /* No data in table t_test_new */
err_hint = pg_exception_hint, /* No data error capture */
err_context = pg_exception_context; /* PL/pgSQL function staging2.fn_ftdry_trs_block(integer,integer,text,text,integer) line 69 at RAISE*/
perform fw_core.fn_insert_db_error ( __client_id, __function_id, 1001, 'Compegence', __file_syspk ,__file_mnemonic,__file_sheet_mnemonic ,null,'ods', 'fn_fw_ods_pto_load', err_state, err_msg, err_detail, err_hint, err_context,'error');
end
$$
LANGUAGE plpgsql;