from psdi.server import MXServer;
from psdi.mbo import MboConstants;
from java.text import SimpleDateFormat;
from java.util import Date
import sys;
## Defined function to create a table based upon a child MboSet
## parameter intent:
## source MBO set to loop through
## p_fields [] array that contains the following
## 0 [] array of fields for which data should be pulled, in order, into each cell
## 1 header title (used if table has headers)
## 2 header style (if needing to override default as defined here in function)
## 3 simple date format for date formatting
## 4 desired cell width
## 5 cell style (if needing to override default as defined here in function)
## 6 cell style override (if False, then APPEND)
## 7 PRE-pend string
## 8 POST-pend string
## [[[], header_title, header_style, SDF, cell_width, cell_style]]
## std_header flag to use loop to generate standard header (if true)
## ovr_header flag to use overridden header (passed as a parameter)
## header_override code for overridden header
## table_tags additional tags for the TABLE control
## table_style style for the TABLE control
## empty_table_msg what to display if no content
def create_table(source, p_fields, std_header, ovr_header, header_override, table_tags, table_style, empty_table_msg):
## define defaults
dflt_cell_style = " padding-left: 5px; padding-right: 5px; background-color: #DDDDDD;";
dflt_head_style = " padding-left: 5px; padding-right: 5px; text-align: center; background-color: #DDDDDD; font-weight: bold;";
dflt_date_SDF = "MM/dd/yyyy";
HTML = "";
## begin to build
s = source.moveFirst();
while (s != None):
HTML = HTML + '
'; ## start a row
for f in p_fields: ## this is the primary loop since fields by column are arrayed...
value = "";
for g in f[0]:
try: ## check to see if we have a real field or just need a blank cell...
found = s.isNull(g);
try: ## check to see if we are dealing w/a date
x = s.getDate(g); ## if this succeeds, we're dealing w/a date
try: ## see if we have an SDF passed
SDF = f[3];
SDF = dflt_date_SDF if SDF == "" else SDF;
except:
SDF = dflt_date_SDF;
value = value + " " + SimpleDateFormat(SDF).format(x);
except:
value = value + " " + s.getString(g) if value != "" else value + s.getString(g);
except:
value = " ";
try: ## PRE-pend
value = str(f[7]) + value;
except:
value = value;
try: ## POST-pend
value = value + str(f[8]);
except:
value = value;
try: ## see if we have a cell width defined
cell_width = str(f[4]);
cell_width = "" if cell_width == "" else " width: " + cell_width + "; ";
except:
cell_width = "";
try: ## see if we have a cell style defined
cell_style = str(f[5]);
except:
cell_style = dflt_cell_style;
try: ## see if cell style should override or append
cell_style_override = f[6];
except:
cell_style_override = False;
cell_style = cell_style if cell_style_override else dflt_cell_style + cell_style;
HTML = HTML + '' + value + ' | ';
HTML = HTML + '
'; ## end a row
s = source.moveNext();
if (source.moveFirst()): ## if we actually have rows in our table, then we need to finalize the HTML...
## build our header
if (std_header):
header = "";
for f in p_fields:
try:
header_style = str(f[2])
header_style = dflt_head_style if header_style == "" else header_style;
except:
header_style = dflt_head_style;
try:
header = header + '' + f[1] + ' | ';
except:
header = header + ' | ';
header = header + "
";
elif (ovr_header):
header = header_override;
else:
header = "";
HTML = ''; ## finalize the table
else:
HTML = empty_table_msg;
return HTML;
def create_multi_table(source, p_fields, p_columns, p_SDF, font_size, font_face, cell_shading, cell_style, table_tags, table_style, empty_table_msg):
## begin to build
HTML = ''; ## start a row
s = source.moveFirst();
i = 0;
while (s != None):
if (i%p_columns == 0 and i > 0):
HTML = HTML + "
";
value = "";
for f in p_fields: ## this is the primary loop since fields by column are arrayed...
try: ## check to see if we are dealing w/a date
x = s.getDate(f); ## if this succeeds, we're dealing w/a date
value = value + " " + SimpleDateFormat(p_SDF).format(x);
except:
value = value + " " + s.getString(f) if value != "" else value + s.getString(f);
HTML = HTML + '' + value + ' | ';
i = i + 1;
s = source.moveNext();
if (source.moveFirst()): ## if we actually have rows in our table, then we need to finalize the HTML...
HTML = ''; ## finalize the table
else:
HTML = empty_table_msg;
return HTML;
## Defined function to create an unnumbered list based upon a child MboSet
def create_list(source, p_fields, empty_table_msg):
## begin to build
HTML = "";
s = source.moveFirst();
while (s != None):
for f in p_fields: ## this is the primary loop since fields by column are arrayed...
value = ""
for g in f:
value = value + " " + s.getString(g) if value != "" else value + s.getString(g);
if (value != ""):
HTML = HTML + '' + value + '';
break;
s = source.moveNext();
if (source.moveFirst()):
HTML = ' 0 else "";
if (elapsedhours > 0):
time_part = str(elapsedhours) + " hours " + str(elapsedminutes) + " minutes";
elif (elapsedminutes > 0):
time_part = str(elapsedminutes) + " minutes";
else:
time_part = "";
return day_part + time_part;
## script constants
SDF_LONG_DATE = "EEEEE, MMMMM dd, yyyy";
SDF_LONG_DATE_TIME = "EEEEE, MMMMM dd, yyyy hh:mm a";
SDF_SHORT_DATE = "MM/dd/yy";
SDF_SHORT_DATE_TIME = "MM/dd/yy hh:mm a";
SDF_SHORT_DATE_TIME_24 = "MM/dd/yy HH:mm";
SDF_SHORT_TIME_DATE_24 = "HH:mm MM/dd/yy";
SDF_TIME = "hh:mm a";
SDF_TIME_24 = "HHmm";
## figure out our context
vServer = MXServer.getMXServer().getRegistryHostName(); ## Figure out our listener e-mail address
owner = mbo.getOwner();
owner_name = owner.getName();
try:
owner_status = owner.getString("STATUS");
except:
owner_status = "";
if (vServer[:1].upper() in ("T", "D", "Q")):
LISTENER = "qmaxit@max.grenergy.com"
INSTANCE = "qmaxtran.grenergy.com"
INSTANCE = "tmgeam04:9444"
else:
LISTENER = "max2252@max.grenergy.com" #
INSTANCE = "maxtran.grenergy.com"
## Take care of "DESCRIPTION" field for e-mail links
invalid_characters = ["(", ")", "<", ">", "\\", "/", ":", "&", "'", "[", "]", chr(10), chr(13)];
try:
email_desc = owner.getString("DESCRIPTION");
for c in invalid_characters:
email_desc = email_desc.replace(c, " ", 11L);
email_desc = email_desc.decode('utf-8', 'ignore');
email_desc = email_desc.replace("\u2013", "-"); #en dash
email_desc = email_desc.replace("\u2014", "--"); #em dash
except:
email_desc = "";
# # # # # INSTANTIATE ALL VALUES SO WE CAN JUST FIND & REPLACE LATER ON # # # # #
## dates
start_date = None;
end_date = None;
due_date = None;
report_date = None;
long_start_date = "";
long_end_date = "";
long_due_date = "";
long_start_date_time = "";
long_end_date_time = "";
long_due_date_time = "";
short_start_date = "";
short_end_date = "";
short_due_date = "";
short_start_date_time = "";
short_end_date_time = "";
short_due_date_time = "";
start_time = "";
start_time_24 = "";
end_time = "";
end_time_24 = "";
duration = "";
short_report_date = "";
record_age = "";
parent_age = "";
actual_date = "";
## myXP
table_myxp_piie = "";
table_myxp_owners = "";
table_myxp_actions = "";
csv_myxp_owners = "";
csv_myxp_ownermails = "";
myxp_piie_response = "";
myxp_anonymous = "";
myxp_injuries = "";
myxp_injuries_tr = "";
myxp_piie = "";
myxp_piie_div_dept = "";
myxp_piie_div_dept_fac = "";
myxp_owners = "";
myxp_owners_csv = "";
myxp_owners_emails = "";
myxp_actions = "";
myxp_actions_comp = "";
myxp_actions_wappr = "";
myxp_piie_response = "";
myxp_factors_types_record = "";
## WO specific fields
draft_watermark = "";
revision = "";
multi_poc = "";
multi_eq = "";
multi_parent_poc = "";
multi_parent_eq = "";
gen_ramp_down = "";
gen_ramp_up = "";
gen_ramp_hold = "";
clr_tasks = "";
clr_areas_affected_not = "";
clr_worklog = "";
clr_worklog_parent = "";
related_records = "";
list_wos = "";
list_prc027_wos = "";
## Change specific fields
chg_save_work = "";
chg_contact_2252 = "";
## Log specific fields
log_oid = "";
log_outages = "";
log_relays = "";
log_asst_clr = "";
log_children = "";
## General items
multi_asset_set = None;
multi_asset_name = "";
multi_asset_full = "";
list_multi = "";
email_desc = "";
table_parent_worklog = "";
status_color = "";
# # # # # ACTUALLY PULL VALUES, BASED UPON DIFFERENT OBJECTS # # # # #
if (owner_name in ("WORKORDER", "WOACTIVITY", "PLUSGACT", "CLR_GRE", "GEN_GRE")): ## work order type records
start_date = owner.getDate("ACTSTART");
end_date = owner.getDate("ACTFINISH");
due_date = owner.getDate("FNLCONSTRAINT");
report_date = owner.getDate("REPORTDATE");
## DRAFT
if (owner_status not in ('APPR', 'INPRG', 'COMP', 'POSTPONE')):
draft_watermark = "
** DRAFT **
"
## REVISION #
if (not owner.isNull("CLRREVNUM_GRE")):
revision = " REV #" + owner.getString("CLRREVNUM_GRE");
## Multi-asset
multi_asset_set = owner.getMboSet("PMCHGALLTARGETS");
if (owner_name in ("WOCHANGE")): ## work order type records
start_date = owner.getDate("TARGSTARTDATE");
end_date = owner.getDate("TARGCOMPDATE");
due_date = owner.getDate("TARGCOMPDATE");
if (owner.getString("PMCHGTYPE") == "Emergency"):
chg_save_work = "";
else:
chg_save_work = "~ Save all your open work and log out of the affected systems prior to the outage.
";
chg_contact_2252 = "~ Contact the IT Service Desk at x2252 with questions or concerns.
";
multi_asset_set = owner.getMboSet("PMCHGALLTARGETS");
if (owner_name in ("ESTIMATE_GRE")):
start_date = owner.getDate("ACTSTART");
end_date = owner.getDate("ACTFINISH");
due_date = owner.getDate("TARGETCONTACTDATE_GRE");
if (owner_name in ("PLUSGSHFTLOGENTRY")):
start_date = owner.getDate("EVENTDATE");
end_date = owner.getDate("RTNDATE_GRE");
due_date = None;
varOID = owner.getString("OID_GRE");
varTKT = owner.getString("TICKETID_GRE");
if (varOID != ""):
if (varTKT != ""):
log_oid = '
' + varOID + ' -- Ticket #' + varTKT + ' |
';
else:
log_oid = '' + varOID + ' |
';
if (owner_name in ("TICKET", "SR", "PROBLEM", "EVENT")): ## ticket type records
start_date = owner.getDate("REPORTDATE");
end_date = owner.getDate("ACTUALFINISH");
due_date = owner.getDate("FNLCONSTRAINT_GRE");
report_date = owner.getDate("REPORTDATE");
if (not owner.isNull("AFFECTEDDATE")):
actual_date = SimpleDateFormat(SDF_LONG_DATE_TIME).format(owner.getDate("AFFECTEDDATE"));
if (owner.getBoolean("ANONYMOUS_GRE")):
myxp_anonymous = " ANONYMOUS ";
## Multi-asset
multi_asset_set = owner.getMboSet("ALLMULTIASSETLOCCI");
if (owner_name in ("PLUSGINCPERSON")):
status = owner.getString("STATUS_GRE");
comments = owner.getString("STATUS_COMMENT_GRE");
if (status == "REJECTED"):
if (comments != ""):
comments = " with the following comments: " + comments;
myxp_piie_response = "REJECTED" + comments;
if (status == "APPROVED" and comments == ""):
myxp_piie_response = "APPROVED";
if (status == "APPROVED" and comments != ""):
if (comments != ""):
comments = " with suggested changes or comments: " + comments;
myxp_piie_response = "APPROVED" + comments;
# # # # # DO VARIOUS PROCESSING # # # # #
## Various date formats...
if (start_date):
long_start_date = SimpleDateFormat(SDF_LONG_DATE).format(start_date);
long_start_date_time = SimpleDateFormat(SDF_LONG_DATE_TIME).format(start_date);
short_start_date = SimpleDateFormat(SDF_SHORT_DATE).format(start_date);
short_start_date_time = SimpleDateFormat(SDF_SHORT_DATE_TIME).format(start_date);
start_time = SimpleDateFormat(SDF_TIME).format(start_date);
start_time_24 = SimpleDateFormat(SDF_TIME_24).format(start_date);
if (end_date):
long_end_date = SimpleDateFormat(SDF_LONG_DATE).format(end_date);
long_end_date_time = SimpleDateFormat(SDF_LONG_DATE_TIME).format(end_date);
short_end_date = SimpleDateFormat(SDF_SHORT_DATE).format(end_date);
short_end_date_time = SimpleDateFormat(SDF_SHORT_DATE_TIME).format(end_date);
end_time = SimpleDateFormat(SDF_TIME).format(end_date);
end_time_24 = SimpleDateFormat(SDF_TIME_24).format(end_date);
if (due_date):
long_due_date = SimpleDateFormat(SDF_LONG_DATE).format(due_date);
long_due_date_time = SimpleDateFormat(SDF_LONG_DATE_TIME).format(due_date);
short_due_date = SimpleDateFormat(SDF_SHORT_DATE).format(due_date);
short_due_date_time = SimpleDateFormat(SDF_SHORT_DATE_TIME).format(due_date);
else:
long_due_date = "-- no due date specified --";
long_due_date_time = "-- no due date specified --";
short_due_date = "-- no due date specified --";
short_due_date_time = "-- no due date specified --";
if (report_date):
short_report_date = SimpleDateFormat(SDF_SHORT_DATE).format(report_date);
## Finalize duration processing
if (start_date != None and end_date != None):
timediff = end_date.getTime() - start_date.getTime();
duration = calcelapsedtime(timediff);
elif (start_date != None):
duration = "ONGOING";
elif (start_date == None and end_date == None):
duration = "NOT STARTED";
else:
duration = "";
## Age calculation
try:
timediff = (MXServer.getMXServer().getDate().getTime() - report_date.getTime()) / 86400000;
record_age = calcelapsedtime(timediff);
except:
record_age = "";
if (owner_name in ("WOACTIVITY", "PLUSGACT")):
try:
act_parent = owner.getMboSet("PARENT").moveFirst();
act_ticket = owner.getMboSet("TICKET").moveFirst()
if (act_parent):
timediff = MXServer.getMXServer().getDate().getTime() - act_parent.getDate("REPORTDATE").getTime();
parent_age = calcelapsedtime(timediff);
elif (act_ticket):
timediff = MXServer.getMXServer().getDate().getTime() - act_ticket.getDate("REPORTDATE").getTime();
parent_age = calcelapsedtime(timediff);
else:
parent_age = "";
except:
parent_age = "";
## Color code STATUS
try:
owner_status = owner.getString("STATUS");
sl = int((10 - len(owner_status)) / 2); ## figure out padding
sx = "";
for i in range(0,sl):
sx = sx + " ";
if (owner_status == "REGISTERED"):
status_color = "" + sx + owner_status + sx + "";
elif (owner_status == "SUBMITTED"):
status_color = "" + owner_status + "";
elif (owner_status == "APPR"):
status_color = "" + sx + owner_status + sx + "";
elif (owner_status == "INPRG"):
status_color = "" + sx + owner_status + sx + "";
elif (owner_status == "COMP"):
status_color = "" + sx + owner_status + sx + "";
elif (owner_status in ("CAN", "POSTPONED")):
status_color = "" + sx + owner_status + sx + "";
elif (owner_status == "DENIED"):
status_color = "" + sx + owner_status + sx + "";
else:
status_color = owner_status;
except:
status_color = "";
## Attachments
try:
set = owner.getMboSet("DOCLINKS");
set.setOrderBy("ESTDOCTYPE_GRE");
set.reset();
doc_links = "";
flag = 0;
s = set.moveFirst();
while (s):
doc_links = doc_links + "" + s.getString("ESTDOCTYPE_GRE.DESCRIPTION") + " |
";
flag = 1;
s = set.moveNext();
doclinks = "" if flag else "";
except:
doc_links = "";
## Multi Assets
try:
if (multi_asset_set):
multi_asset_name = create_list(multi_asset_set, ["ASSET.NAME.ALNVALUE"], "-- no assets listed --");
multi_asset_full = create_list(multi_asset_set, ["ASSETNUM", "DESCRIPTION", "STATUS"], "-- no assets listed --");
except:
multi_asset_name = "";
multi_asset_full = "";
## myExperience
if (owner_name in ("PROBLEM", "EVENT")):
myxp_piie = create_table(owner.getMboSet("MYXP_PIIE"), [[["PERSON.FIRSTNAME", "PERSON.LASTNAME"], "Involved Party"], [["DIVISION.DESCRIPTION"], "GRE Division"]], True, False, "", "", "", "-- no involved parties --");
myxp_piie_div_dept = create_table(owner.getMboSet("MYXP_PIIE"), [[["DIVISION.DESCRIPTION"], "GRE Division"], [["DEPARTMENT.DESCRIPTION"], "Department"]], True, False, "", "", "", "-- no involved parties --");
myxp_piie_div_dept_fac = create_table(owner.getMboSet("MYXP_PIIE"), [[["DIVISION.DESCRIPTION"], "Employee Division"], [["DEPARTMENT.DESCRIPTION"], "Employee Department"], [["LOCATION.DESCRIPTION"], "Employee Facility"]], True, False, "", "", "", "-- no involved parties --");
myxp_injuries = create_table(owner.getMboSet("MYXP_INJURIES"), [[["PERSON.DIVISION.DESCRIPTION"], "Employee Division"], [["LOCATION.DESCRIPTION"], "Injury Location"]], True, False, "", "", "", "-- no injuries --");
myxp_injuries_tr = create_table(owner.getMboSet("MYXP_TR_INJURIES"), [[["INJORILLDATE"], "Date of Injury / Illness", "", SDF_SHORT_DATE_TIME], [["LOCATION.DESCRIPTION"], "Injury Location"]], True, False, "", "", "", "-- no injuries --");
myxp_factors_types_record = create_table(owner.getMboSet("MYXP_V_HFRESULTS_RECORD"), [[["FACTOR_DESCRIPTION"], "Factor"], [["TYPE_DESCRIPTION"], "Type"]], True, False, "", "", "", "-- no factors / types --");
## actions
action_set = owner.getMboSet("SHOWTASKS_GRE");
action_set.setOrderBy("WOSEQUENCE");
action_set.reset();
myxp_actions = create_table(action_set, [[["WOSEQUENCE"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --");
action_set = owner.getMboSet("MYXP_ACTIONS_REAL");
action_set.setOrderBy("WOSEQUENCE");
action_set.reset();
myxp_actions_comp = create_table(action_set, [[["WOSEQUENCE"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --");
action_set = owner.getMboSet("MYXP_ACTIONS_WAPPR");
action_set.setOrderBy("WOSEQUENCE");
action_set.reset();
myxp_actions_wappr = create_table(action_set, [[["WOSEQUENCE"], "Action #"], [["DESCRIPTION"], "Description"], [["OWNERPERSON.FIRSTNAME", "OWNERPERSON.LASTNAME"], "Owner"], [["STATUS"], "Status"], [["STATUSDATE"], "Status Date", "", SDF_LONG_DATE]], True, False, "", "", "", "-- no actions --");
## WORK ORDER TYPE RECORDS
if (owner_name in ("PLUSGRCFARESULTS", "PLUSGACT", "PROBLEM", "EVENT", "WOOWNERHISTORY", "WOACTIVITY", "WORKORDER")):
myxp_owners = create_table(owner.getMboSet("MYXP_OWNERS"), [[["PERSON.FIRSTNAME", "PERSON.LASTNAME"], "Owner"], [["DIVISION.DESCRIPTION"], "GRE Division"], [["PHONE"], "Phone #"], [["EMAIL"], "E-mail"]], True, False, "", "", "", "-- no owners designated --");
myxp_owners_csv = create_csv(owner.getMboSet("MYXP_OWNERS"), [["PERSON.FIRSTNAME", "PERSON.LASTNAME"]], ", ", "-- no owners designated --");
myxp_owners_emails = create_csv(owner.getMboSet("MYXP_OWNERS"), [["PERSON.PRIMARYEMAIL"]], "; ", "");
if (owner_name in ("WORKORDER", "WOACTIVITY", "PLUSGACT", "CLR_GRE", "GEN_GRE")): ## work order type records
## General
list_wos = create_table(owner.getThisMboSet(), [[["WONUM"], "WO #"], [["DESCRIPTION"], "Description"], [["STATUS"], "Status"]], True, False, "", "", "", "");
list_prc027_wos = create_table(owner.getThisMboSet(), [[["WONUM"], "WO #"], [["DESCRIPTION"], "Description"], [["JPNUM"], "Job Plan"]], True, False, "", "", "", "");
## Multi-asset
multi_poc = create_table(owner.getMboSet("POC"), [[["COMMENTS"], ""], [["CKT_POS_LOC_GRE"], ""], [["TARGETDESC"], ""]], False, True, "", "", "", "-- no points of clearance designated --");
multi_eq = create_table(owner.getMboSet("EQUIPMENT"), [[["COMMENTS"], ""], [["CKT_POS_LOC_GRE"], ""], [["TARGETDESC"], ""]], False, True, "", "", "", "-- no affected equipment designated --");
multi_parent_poc = create_table(owner.getMboSet("PARENT.POC"), [[["COMMENTS"], ""], [["CKT_POS_LOC_GRE"], ""], [["TARGETDESC"], ""]], False, True, "", "", "", "-- no points of clearance designated --");
multi_parent_eq = create_table(owner.getMboSet("PARENT.EQUIPMENT"), [[["COMMENTS"], ""], [["CKT_POS_LOC_GRE"], ""], [["TARGETDESC"], ""]], False, True, "", "", "", "-- no affected equipment designated --");
## Tasks
task_set = owner.getMboSet("SHOWTASKS_GRE");
task_set.setOrderBy("WOSEQUENCE");
task_set.reset();
clr_tasks = create_table(task_set, [[[""], "", "", "", "15%"], [["WOSEQUENCE"], "", "", "", "10%", "text-align: center;", False], [["DESCRIPTION", "DESCRIPTION_LONGDESCRIPTION"], "", "", "", "75%"]], False, True, "", "", "", "-- no switching steps defined --");
## Work Log
wl_set = owner.getMboSet("GRE_MODIFYWORKLOG");
wl_set.setOrderBy("WORKDATE_GRE");
wl_set.reset();
clr_worklog = create_table(wl_set, [[["WORKDATE_GRE"], "Date", "", SDF_SHORT_DATE, "15%", "text-align: center;", False], [["DESCRIPTION"], "Remark", "", "", "85%"]], True, False, "", "", "", "No remarks recorded");
wl_set = owner.getMboSet("PARENT.GRE_MODIFYWORKLOG");
wl_set.setOrderBy("WORKDATE_GRE");
wl_set.reset();
clr_worklog = create_table(wl_set, [[["WORKDATE_GRE"], "Date", "", SDF_SHORT_DATE, "15%", "text-align: center;", False], [["DESCRIPTION"], "Remark", "", "", "85%"]], True, False, "", "", "", "");
## Generation ramp points
gen_set = owner.getMboSet("GEN_RAMPDOWN");
gen_set.setOrderBy("SEQUENCE");
gen_set.reset();
gen_ramp_down = create_table(gen_set, [[["ENDDATE"], "START"], [["STARTDATE"], "END"], [["DURATION"], "DURATION"], [["MW"], "MW/hr"]], True, False, "", "", "", "-- no ramp down points recorded --");
gen_set = owner.getMboSet("GEN_RAMPUP");
gen_set.setOrderBy("SEQUENCE");
gen_set.reset();
gen_ramp_up = create_table(gen_set, [[["STARTDATE"], "START"], [["ENDDATE"], "END"], [["DURATION"], "DURATION"], [["MW"], "MW/hr"]], True, False, "", "", "", "-- no ramp up points recorded --");
gen_set = owner.getMboSet("GEN_HOLD");
gen_set.setOrderBy("SEQUENCE");
gen_set.reset();
gen_ramp_hold = create_table(gen_set, [[["STARTDATE"], "START"], [["ENDDATE"], "END"], [["DURATION"], "DURATION"], [["MW"], "MW"]], True, False, "", "", "", "-- no ramp hold points recorded --");
## Areas affected
aa_set = owner.getMboSet("WO_AREASAFFECTED_NOT");
aa_set.setOrderBy("CONTACTDATE_GRE DESC");
aa_set.reset();
clr_areas_affected_not = create_multi_table(aa_set, ["CONTACT.FIRSTNAME", "CONTACT.LASTNAME", "CONTACTDATE_GRE"], 4, SDF_SHORT_DATE, "2", "courier", "#DDDDDD", "", "", "", "-- no notification entries specified --");
## Related Records
rel_set = owner.getMboSet("RELATEDWO");
rel_set.setOrderBy("RECORDKEY");
rel_set.reset();
if (rel_set.moveFirst()):
r = rel_set.moveFirst();
while (r):
if (r.getString("RELATEDRECWO.CLR_GRE.CLEAR_TYPE") != ""):
varX = "Clearance #";
elif (r.getString("RELATEDRECWO.GEN.GEN_TYPE") == "OUTAGE"):
varX = "Outage #";
elif (r.getString("RELATEDRECWO.GEN.GEN_TYPE") == "DERATE"):
varX = "Outage #";
elif (r.getString("RELATEDRECWO.GEN.GEN_TYPE") == "TEST"):
varX = "Outage #";
else:
varX = "Work Order #";
related_records = related_records + '' + varX + " " + cm.getString("RELATEDRECKEY") + ' | ' + cm.getString("RELATEDRECWO.DESCRIPTION") + ' |
'
r = rel_set.moveNext();
rel_set = owner.getMboSet("RELATEDTICKET");
rel_set.setOrderBy("RECORDKEY");
rel_set.reset();
if (rel_set.moveFirst()):
r = rel_set.moveFirst();
while (r):
related_records = related_records + 'Ticket # ' + cm.getString("RELATEDRECKEY") + ' | ' + cm.getString("RELATEDRECWO.DESCRIPTION") + ' |
'
r = rel_set.moveNext();
if (related_records != ""):
related_records = '';
else:
related_records = "
";
if (owner_name in ("PLUSGSHFTLOGENTRY")):
## relays
oset = owner.getMboSet("OUTAGE_BREAKERS");
oset.setOrderBy("ACTUALSTART");
oset.reset();
log_relays = create_table(oset, [[["LOCATION.GENERICNAME.ALNVALUE"], "", "", "", "20%", "border: 1px solid black;", False], [["LOGTEXT_GRE"], "", "", "", "80%", "border: 1px solid black;", False]], True, False, "", "", "", "-- no relay operations --");
log_relays = '
Relay Information |
' + log_relays + ' |
';
## children
oset = owner.getMboSet("CHILD_NO_CLR");
oset.setOrderBy("EVENTDATE");
oset.reset();
log_children = create_table(oset, [[["EVENTDATE"], "", "", SDF_SHORT_DATE_TIME_24, "20%", "text-align: center; border: 1px solid black; background-color: #a9d1ff; ", True], [["LOGTEXT_GRE"], "", "", "", "80%", "border: 1px solid black;", False]], True, False, "", "", "", "");
## outages
oset = owner.getMboSet("OUTAGE_SUBS");
oset.setOrderBy("ACTUALSTART");
oset.reset();
log_outages = create_table(oset, [[["ASSET.DESCRIPTION"], "", "", "", "60%", "border: 1px solid black; background-color: #ffffdb; ", False], [["ACTUALSTART"], "", "", SDF_SHORT_TIME_DATE_24, "10%", "text-align: center; border: 1px solid black;", False], [["ACTUALFINISH"], "", "", SDF_SHORT_TIME_DATE_24, "10%", "text-align: center; border: 1px solid black;", False], [["OUTAGEDURATION"], "", "", "", "20%", "text-align: center; border: 1px solid black; background-color: #c0c0c0; ", False, "DURATION:
", ""]], True, False, "", "", "", "-- no distribution substation outages --");
log_outages = '
Distribution Substation Outages |
' + log_outages + ' |
';
## associated clearances
oset = owner.getMboSet("CHILD_ASST_CLR");
oset.setOrderBy("TOANUM_GRE");
oset.reset();
o = oset.moveFirst();
while (o):
varE = SimpleDateFormat(SDF_SHORT_TIME_DATE_24).format(o.getDate("EVENTDATE"));
if (o.getString("TOANUM_GRE.ACTSTART") == ""):
varD = "NOT STARTED";
varF = "";
elif (o.getString("TOANUM_GRE.ACTFINISH") == ""):
varD = "ONGOING";
varF = "";
else:
timediff = o.getDate("TOANUM_GRE.ACTFINISH").getTime() - o.getDate("TOANUM_GRE.ACTSTART").getTime()
timespent = calcelapsedtime(timediff)
varD = timespent;
varF = SimpleDateFormat(SDF_SHORT_TIME_DATE_24).format(o.getDate("TOANUM_GRE.ACTFINISH"));
varL = "Clearance #" + o.getString("TOANUM_GRE");
if (o.getString("TOANUM_GRE.SCHEDSTART") != ""):
start_date = SimpleDateFormat("MM/dd/yy").format(o.getDate("TOANUM_GRE.SCHEDSTART"));
start_time = SimpleDateFormat("HH:mm").format(o.getDate("TOANUM_GRE.SCHEDSTART"));
else:
start_date = "";
start_time = "";
if (o.getString("TOANUM_GRE.SCHEDFINISH") != ""):
end_date = SimpleDateFormat("MM/dd/yy").format(o.getDate("TOANUM_GRE.SCHEDFINISH"));
end_time = SimpleDateFormat("HH:mm").format(o.getDate("TOANUM_GRE.SCHEDFINISH"));
else:
end_date = "";
end_time = "";
varLS = "Scheduled: " + start_date + " " + start_time + " to " + end_date + " " + end_time;
log_asst_clr = log_asst_clr + '' + varL + ' | ' + o.getString("TOANUM_GRE.DESCRIPTION") + '
' + varLS + ' | ' + varE + ' | ' + varF + ' | DURATION: ' + varD + ' |
';
o = oset.moveNext();
if (log_asst_clr != ""):
log_asst_clr = '
Associated Clearances |
' + log_asst_clr + '
';
# # # # # DO THE ACTUAL REPLACEMENTS # # # # #
## Context
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LISTENER#", LISTENER, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#INSTANCE#", INSTANCE, 11L));
## Records
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#EST_DOCLINKS#", doc_links, 11L));
## Dates
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#SHORT_DUE_DATE#", short_due_date, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#SHORT_DUE_DATE_TIME#", short_due_date_time, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LONG_DUE_DATE#", long_due_date, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LONG_DUE_DATE_TIME#", long_due_date_time, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#DURATION#", duration, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#AGE#", record_age, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#PARENT_AGE#", parent_age, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#SHORT_REPORT_DATE#", short_report_date, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#ACTUAL_DATE#", actual_date, 11L));
## myXP
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_PIIE#", myxp_piie, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_PIIE_DIV_DEPT#", myxp_piie_div_dept, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_PIIE_DIV_DEPT_FAC#", myxp_piie_div_dept_fac, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_OWNERS#", myxp_owners, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_OWNERS_CSV#", myxp_owners_csv, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_OWNERS_EMAILS#", myxp_owners_emails, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_INJURIES#", myxp_injuries, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_TR_INJURIES#", myxp_injuries_tr, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_PIIE_RESPONSE#", myxp_piie_response, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_ANONYMOUS#", myxp_anonymous, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_ACTIONS#", myxp_actions, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_ACTIONS_COMP#", myxp_actions_comp, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_ACTIONS_WAPPR#", myxp_actions_wappr, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_PIIE_RESPONSE#", myxp_piie_response, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MYXP_FACTORS_TYPES_RECORD#", myxp_factors_types_record, 11L));
## Change
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#CHG_SAVE_WORK#", chg_save_work, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#CHG_CONTACT_2252#", chg_contact_2252, 11L));
## Log entries
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LOG_OID#", log_oid, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LOG_CHILDREN#", log_children, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LOG_RELAYS#", log_relays, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LOG_OUTAGES#", log_outages, 11L));
## General
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MULTI_ASSET#", multi_asset_name, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#MULTI_ASSET_FULL#", multi_asset_full, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#AREAS_AFFECTED_NOT#", clr_areas_affected_not, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#CLR_SWITCHING#", clr_tasks, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#CLR_WORKLOG#", clr_worklog, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#CLR_WORKLOG_PARENT#", clr_worklog_parent, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#LIST_WOS#", list_wos, 11L));
mbo.setValue("MESSAGE", mbo.getString("MESSAGE").replace("#REL_PRC027_WOS#", list_prc027_wos, 11L));