/****************************************************************************** ** Confidential and Proprietary Information of Puget Sound Power and ** Light Company(PSPL). Copyright © 1995 PSPL. All rights reserved. ** ** Module: mf_tag_status frame script ** ** Purpose: ** ** can be used to validate INGRES and Habitat operation tags ** against each other. ** ** This Functionality is implemented here in the following manner: ** ** 1) A tablefield that shows all the devices with tags in the INGRES ** database is assembled on the form from several tables using ** RMS custom extraction alogrithms. ** 2) A tablefield that shows all the devices with tags in the Habitat ** database is assembled from one of the selectable Habitat servers. ** ** Both tablefields represent a snapshot of the each database in time. ** ** Validation is accomplished by searching the INGRES tablefield for ** each entry in the Habitat tablefield. Each time a match is found in ** INGRES, the row is deleted from the INGRES tablefield. Each time a ** match could not be found in INGRES, a row is added to an exception ** tablefield. ** ** After all the rows in the Habitat tablefield have been validated, ** the INGRES tablefield represents those devices that have tags set ** in INGRES but not in habitat. Conversely, the exception tablefield ** is a list of all the devices that have tags set in habitat but not ** in INGRES. ** ** Control is provided via menu items to refresh either tablefield or ** to make a formatted report of any exceptions. ** ** Revisions: ** ** 03/07/97 - Started - JJM. ** *********************************************************************************/ INITIALIZE ( print_txt = StringObject, i = integer, /* some non-descriptive int */ j = integer, /* varibles */ k = integer, hab_counter = integer, /* counts rows in habitat tablefield */ ing_counter = integer, /* counts rows in ingres tablefield */ ing_10_30_tag = integer, /* used to make ingres tags 30 = 10 */ found_a_match = integer, /* set if a match was found */ temp = varchar(20), /* dummy array for SELECT statements */ hab_host = varchar(20), /* habitat tablefield source */ string_txt = varchar(80), /* used in exceptions dump/print */ system_command = varchar(200) ) = BEGIN hab_host = 'INGRES'; /* call some user events to init form tablefields */ CurFrame.SendUserEvent (eventname = 'load_hab_tablefield'); CurFrame.SendUserEvent (eventname = 'load_ingres_tablefield'); END; /**************** end INITIALIZATION SECTION ************************************/ /*****************| user event handlers |****************************************/ /****************** load_ingres_tablefield ************************************** * * loads the ingres tablefield on the form from the dms_operation table using * the current tag_type and RMS's lookup alogrithm * ********************************************************************************/ ON USEREVENT 'load_ingres_tablefield' = BEGIN i = 1; ingres.Clear(); status = 'loading INGRES table'; REPEATED SELECT :ingres[i].device = o.device_name, :ingres[i].region = r.name, :ingres[i].tag = o.operation_cd_val FROM dms_operation o, region_list r, grouping g WHERE o.operation_comp_id = 0 AND (o.operation_cd_val = 10 OR o.operation_cd_val = 12 OR o.operation_cd_val = 14 OR o.operation_cd_val = 16 OR o.operation_cd_val = 18 OR o.operation_cd_val = 22 OR o.operation_cd_val = 30) AND o.device_fk = g.member AND g.groupingtype = 20005 AND g.grouping = r.object ORDER BY region, device BEGIN i = i +1; END; ingres_total = i - 1; except.Clear(); except_total = 0; status = 'Validation required.'; END; /***************** end load_ingres_tablefield *********************************/ /****************** load_habitat_tablefield ************************************ * * loads the habitat tablefield on the form from the hab_tag table * *******************************************************************************/ ON USEREVENT 'load_hab_tablefield' = BEGIN j = 1; habitat.Clear(); status = 'loading Habitat table'; REPEATED SELECT :habitat[j].region = hab_region, :habitat[j].device = hab_device, :habitat[j].tag = hab_op_code FROM hab_tag ORDER BY region, device BEGIN j = j +1; END; habitat_total = j - 1; except.Clear(); except_total = 0; status = 'Validation required.'; END; /***************** end load_hab_tablefield *************************************/ /***************** validate_hab ************************************************* * * confirms that each entry in the habitat tablefield has a matching entry * in the ingres tablefield. A match is established if the region, device * and tag in each are the same. In the case of tag type 10 in the habitat * tablefield, a tag value of either 10 or 30 in the ingres tablefield will * qualify a match since either can set the 10 flag in habitat. * *********************************************************************************/ ON USEREVENT 'validate_hab' = BEGIN except.Clear(); except_total = 0; hab_counter = 1; i = 1; WHILE ( hab_counter <= habitat_total ) DO ing_counter = 1; found_a_match = 0; status = 'Validating ' + habitat[hab_counter].region + ' ' + habitat[hab_counter].device; WHILE( ing_counter <= ingres.LastRow() ) DO /* make ingres[].tag 10 and 30 equivilant */ ing_10_30_tag = ingres[ing_counter].tag; IF ing_10_30_tag = 30 THEN ing_10_30_tag = 10; ENDIF; IF habitat[hab_counter].region = ingres[ing_counter].region AND habitat[hab_counter].device = ingres[ing_counter].device AND habitat[hab_counter].tag = ingres[ing_counter].tag THEN found_a_match = 1; ingres_total = ingres_total - 1; ingres.RemoveRow(rownumber=ing_counter); /* ing_counter = + except.LastRow() + 1; break WHILE-DO loop */ ENDIF; ing_counter = ing_counter + 1; ENDWHILE; /* last ingres tablefield row */ IF found_a_match = 0 THEN except[i].region = habitat[hab_counter].region; except[i].device = habitat[hab_counter].device; except[i].tag = habitat[hab_counter].tag; except_total = i; i = i + 1; ENDIF; hab_counter = hab_counter + 1; ENDWHILE; /* last habitat tablefield row */ status = 'Waiting for user command.'; END; /***************** end validate_hab ****************************************/ /*****************| menu item handlers |**********************************/ /****************** start_validation *************************************** * * ****************************************************************************/ ON CLICK menu.file_menu.file_start = BEGIN CurFrame.SendUserEvent (eventname = 'validate_hab'); END; /****************** end start_validation ***********************************/ /****************** refresh habitat table ********************************* * * handles refreshing hab_tag table in ingres from habitat servers. * ****************************************************************************/ ON CLICK menu.file_menu.refresh_menu.hab_refresh.host = BEGIN IF menu.file_menu.refresh_menu.hab_refresh.host = 1 THEN hab_host = 'tiger1'; ENDIF; IF menu.file_menu.refresh_menu.hab_refresh.host = 2 THEN hab_host = 'tiger2'; ENDIF; IF menu.file_menu.refresh_menu.hab_refresh.host = 3 THEN hab_host = 'lion1'; ENDIF; IF menu.file_menu.refresh_menu.hab_refresh.host = 4 THEN hab_host = 'lion2'; ENDIF; status = 'starting /usr/users/dms/bin/hab_tags.csh'; SYSTEM_COMMAND = '/usr/users/dms/bin/hab_tags.csh ' + hab_host; CALL SYSTEM SYSTEM_COMMAND; current_hab_host = 'Habitat table from: ' + hab_host; CurFrame.SendUserEvent (eventname = 'load_hab_tablefield'); END; /****************** end refresh habitat table *************************/ /***************** dump exceptions *********************************** * * makes a file of exceptions using WriteTofile string method * and prints it using format_print.scr * *********************************************************************/ ON CLICK menu.file_menu.file_dump = BEGIN /* dump except tablefield */ IF except.LastRow() > 0 THEN status = 'Building print image file...'; print_txt = print_txt.ConcatVarchar(text=X'0C'); string_txt = X'0D0A' + 'Set in Habitat ('+ hab_host + '), Clear in INGRES' + X'0D0A'; print_txt = print_txt.ConcatVarchar(text=string_txt); i = except.FirstRow(); WHILE i <= except.LastRow() DO IF except[i].tag = 10 THEN temp = 'TAG '; ELSEIF except[i].tag = 12 THEN temp = 'CLEARANCE '; ELSEIF except[i].tag = 14 THEN temp = 'HOLD '; ELSEIF except[i].tag = 16 THEN temp = 'C/O RECL '; ELSEIF except[i].tag = 18 THEN temp = 'ABNORMAL '; ELSEIF except[i].tag = 22 THEN temp = 'HLWS '; ELSEIF except[i].tag = 30 THEN temp = 'GRND TAG '; ENDIf; status = 'Dumping ' + ' ' + except[i].region + ' ' + except[i].device + ' ' + temp; string_txt = X'0D0A' + except[i].region + ' ' + except[i].device; k = length(except[i].device); j = 1; WHILE j <=(20 - k) DO string_txt = string_txt + ' '; j = j + 1; ENDWHILE; string_txt = string_txt + temp; print_txt = print_txt.ConcatVarchar(text=string_txt); i = i + 1; ENDWHILE; string_txt = X'0D0A' + 'Total Habitat exceptions: ' + except_total; print_txt = print_txt.ConcatVarchar(text=string_txt); ENDIF; /* dump ingres tablefield */ IF ingres.LastRow() > 0 THEN print_txt = print_txt.ConcatVarchar(text=X'0C'); string_txt = X'0D0A' + 'Set in INGRES, Clear in Habitat (' + hab_host + ').' + X'0D0A'; print_txt = print_txt.ConcatVarchar(text=string_txt); i = ingres.FirstRow(); WHILE i <= ingres.LastRow() DO IF ingres[i].tag = 10 THEN temp = 'TAG '; ELSEIF ingres[i].tag = 12 THEN temp = 'CLEARANCE '; ELSEIF ingres[i].tag = 14 THEN temp = 'HOLD '; ELSEIF ingres[i].tag = 16 THEN temp = 'C/O RECL '; ELSEIF ingres[i].tag = 18 THEN temp = 'ABNORMAL '; ELSEIF ingres[i].tag = 22 THEN temp = 'HLWS '; ELSEIF ingres[i].tag = 30 THEN temp = 'GRND TAG '; ENDIf; status = 'Dumping ' + ' ' + ingres[i].region + ' ' + ingres[i].device + ' ' + temp; string_txt = X'0D0A' + ingres[i].region + ' ' + ingres[i].device; k = length(ingres[i].device); j = 1; WHILE j <=(20 - k) DO string_txt = string_txt + ' '; j = j + 1; ENDWHILE; string_txt = string_txt + temp; print_txt = print_txt.ConcatVarchar(text=string_txt); i = i + 1; ENDWHILE; string_txt = X'0D0A' + 'Total INGRES exceptions: ' + ingres_total; print_txt = print_txt.ConcatVarchar(text=string_txt); ENDIF; /* write print_txt to print.txt and print it using format_print.scr */ print_txt.WriteToFile (Filename = '/usr/users/dms/print_scripts/print.txt'); system_command = '/usr/users/dms/print_scripts/format_print.scr ' + vv_console_user + ' ' + vv_console_name; CALL SYSTEM system_command; status = 'Waiting for user command.'; END; /***************** end dump exceptions *******************************/ /****************** refresh ingres table **************************** * * click event to connect some code to run if I want to reload the * the ingres_tablefield from somewhere... perhaps a different * ingres server? currently changes tablefield little..... * ********************************************************************/ ON CLICK menu.file_menu.refresh_menu.ing_refresh = BEGIN CurFrame.SendUserEvent (eventname = 'load_ingres_tablefield'); except.Clear(); except_total = 0; status = 'Validation required'; END; /****************** end refresh ingres table *************************/