How to change dates of an Operation after Production Run 3.0

Changing Dates of an Operation

When an Operation date change is required after a production run is completed.

This script will shift the operation and associated tag collectors by the time delta of the new start date.  (I.e. if you put in a start time 2 hours earlier than the original start time, the end time will also move back 2 hours).  This behavior can be modified in the script.

Add the steps involved:

  • Find the Operation UUID
    • If using Scheduling, from MES Schedule Selector Component
    • Via script using Equipment Path during production run:

      Python
      eqPath = '<enter your equipment path HERE>'
      op = system.mes.getCurrentOperation(eqPath)
      if op:
      operationsResponseUUID = op.getUUID()
    • Via Analysis using the Operation UUID data point (Analysis Selector or script) for time periods in the past.
  • Using the Script Console or Button Action Performed, paste the following Script and insert your data for newStartDate and operationsResponseUUID:

    Python
    def moveTagCollectorDate(eqPath, tagCollectorType, segOldStartDate, segOldEndDate, SecondsDelta):
    """
    Creates new Tag Collector at a new start and end date and deletes the old tag collector from the system

    :param tagCollectorType: String - Type of Tag collector defined: https://help.sepasoft.com/docs/display/MHD/Tag+Collector+Types#TagCollectorTypes-TagCollectorTypes
    :param segOldStartDate: Date - Original start date for the tag collector
    :param segOldEndDate: Date - Original end date for the tag collector
    :param SecondsDelta: Int - Seconds to shift the data forward or backward

    """

    print 'moving tag collector --', tagCollectorType, '-----'

    #Getting tag collector values in specified date range documented: https://help.sepasoft.com/docs/display/MHD/system.mes.getTagCollectorValues
    data = system.mes.getTagCollectorValues(eqPath, collectorType, '', segOldStartDate, segOldEndDate)

    #check if valid data is returned
    if data and data.getRowCount() > 0:

    for row in range(data.getRowCount()):
    currentTime = data.getValueAt(row, 'TimeStamp')
    value = data.getValueAt(row, 'Value')
    print 'moving tag collector --', tagCollectorType, '
    value --', value

    #shift the time stamp by the shifted seconds of the operations response
    newTime = system.date.addSeconds(currentTime, SecondsDelta)

    #First check if tag collector value exists, if so, update the value
    if containsTagCollectorValue(eqPath, tagCollectorType, '', newTime):

    #Update the current Tag collector value with new value. Ref: https://help.sepasoft.com/docs/display/MHD/system.mes.updateTagCollectorValue
    system.mes.updateTagCollectorValue(eqPath, tagCollectorType, '', newTime, value)

    else:
    #Adds new tag collector at new time stamp. Ref: https://help.sepasoft.com/docs/display/MHD/system.mes.addTagCollectorValue
    system.mes.addTagCollectorValue(eqPath, tagCollectorType, '', newTime, value)

    #Remove the old tag collector value from the previous datetime. Ref: https://help.sepasoft.com/docs/display/MHD/system.mes.removeTagCollectorValue
    system.mes.removeTagCollectorValue(eqPath, tagCollectorType, '', currentTime)


    def containsTagCollectorValue(eqPath, tagCollectorType, key, dateTime):
    """
    Attempts to get a tag collector value for the specified date. If no value is found, return False. Else if there is a value, return true

    :param: eqPath - String - The Equipment path to check if tag collector value is recorded.
    :param: tagCollectorType - String - Type of Tag collector defined: https://help.sepasoft.com/docs/display/MHD/Tag+Collector+Types#TagCollectorTypes-TagCollectorTypes
    :param: key - String - Name of the MES counter or the name of the Additional Factor. If not needed, pass an empty string.
    :param: dateTime - Date - Date to check for tag collector values

    """
    #get tag collector value and return True if exists, documented: https://help.sepasoft.com/docs/display/MHD/system.mes.getTagCollectorValue
    return system.mes.getTagCollectorValue(eqPath, tagCollectorType, key, dateTime) != None


    #Tag Collector Types to be updated during the date shift
    tagCollectors = [
    'Equipment Infeed Count Scale',
    'Equipment Infeed Units',
    'Equipment Operation UUID',
    'Equipment Outfeed Units',
    'Equipment Package Count',
    'Equipment Product Code',
    'Equipment Rate Period',
    'Equipment Reject Count Scale',
    'Equipment Reject Units',
    'Equipment Schedule Count',
    'Equipment Schedule Duration',
    'Equipment Schedule Rate',
    'Equipment Standard Rate',
    'Equipment Target Changeover Time',
    'Line Infeed Count Equipment UUID',
    'Line Outfeed Count Equipment UUID'
    ]

    #Input the Operations response UUID
    operationsResponseUUID = '<enter your Operation UUID HERE>'

    #create a new start dateTime
    newStartDate = system.date.parse('<enter new start date HERE>', 'MMMM dd, yyyy hh:mm')

    #if setting Equipment mode dynamically, set to True. If setting mode in GUI and not changing it at run time, set False
    dynamicEquipmentMode = True

    #If not setting mode at runtime, we can move the dates for equipment mode
    if not dynamicEquipmentMode:
    tagCollectors.append('Equipment Mode')

    #Load the operations response using the UUID
    opResponseObj = system.mes.loadMESObject(operationsResponseUUID)

    #load operations response current begin time
    opPrevBeginDate = opResponseObj.getPropertyValue('BeginDateTime')

    #load operations response current end time
    opPrevEndDate = opResponseObj.getPropertyValue('EndDateTime')

    #find the number of seconds from operation begin to new desired start date
    SecondsDelta = system.date.secondsBetween(opPrevBeginDate, newStartDate)

    newEndDate = system.date.addSeconds(opPrevEndDate, SecondsDelta)

    #get a list of response segment links part of the operations response. Ref: http://help.sepasoft.com/docs/display/MHD/system.mes.getResponseSegmentsForOperationsResponse
    rspSegLinks = system.mes.getResponseSegmentsForOperationsResponse(operationsResponseUUID)

    #get Equipment Path associated with this Operations Response object
    eqPath = opResponseObj.getEquipmentLink().getMESObject().getEquipmentPath()

    for responseSegmentLink in rspSegLinks:

    #get response object current link references
    seg = responseSegmentLink.getMESObject()

    #get the current Response Segment Start and End dates
    segOldStartDate = seg.getPropertyValue('BeginDateTime')
    segOldEndDate = seg.getPropertyValue('EndDateTime')

    for collectorType in tagCollectors:

    #for each tag collector, change the dates using the delta
    moveTagCollectorDate(eqPath, collectorType, segOldStartDate, segOldEndDate, SecondsDelta)

    #Add delta to each response segment start date
    segNewStartDate = system.date.addSeconds(segOldStartDate, SecondsDelta)
    seg.setPropertyValue('BeginDateTime', segNewStartDate)

    #Add delta to each response segment end date
    segNewEndDate = system.date.addSeconds(segOldEndDate, SecondsDelta)
    seg.setPropertyValue('EndDateTime', segNewEndDate)

    #save the updated response segment
    system.mes.saveMESObject(seg)

    #set the new begin and end dateTime for the Operatios Response
    opResponseObj.setPropertyValue('BeginDateTime', newStartDate)
    opResponseObj.setPropertyValue('EndDateTime', newEndDate)

    #save your operations Response Object
    system.mes.saveMESObject(opResponseObj)

    #Reload the response object
    opResponseObj = system.mes.loadMESObject(opResponseObj.getUUID())
Information

Help Documentation Links from this article:

MES Schedule Selector

Tag Collector Types

system.mes.getCurrentOperations

system.mes.getTagCollectorValues

system.mes.getTagCollectorValue

system.mes.updateTagCollectorValue

system.mes.removeTagCollectorValue