Sorry, there’s just a lot of unnecessary stuff in between I was trying to save you from.
lineCnt = 0
updateCnt = 0
newCnt = 0
print 'Starting import on ',db.getRowCount(),'rows'
for rowNum in range(db.getRowCount()):
schEvent = []
schDT = []
cell1 = db.getValueAt(rowNum,"Line # ").strip()
#print rowNum
#print repr(cell1)
if cell1!=u'':
#print 'Not blank'
if cell1.find('Line') > -1:
#LineNumCol = db.getValueAt(rowNum,"Line # ")
LineNum = ""
for char in cell1[cell1.find('Line')+5:]:
if char.isnumeric():
LineNum += char
elif char.isspace() and LineNum == "":
continue
else:
print 'Line', LineNum
break
else:
LineNum = ""
if LineNum != "" :
#print 'Line',LineNum,"-" + str(db.getValueAt(rowNum,"Process Order"))+"-",db.getValueAt(rowNum,"Process Order").isnumeric()
if (db.getValueAt(rowNum,"Process Order").replace(".0","")).isnumeric():
# while currEventsInd < currEventsRowCount:
# print currEvents.getValueAt(currEventsInd, "EventID"), "=",db.getValueAt(rowNum,"Process Order")
# if currEvents.getValueAt(currEventsInd, "EventID") == db.getValueAt(rowNum,"Process Order"):
# break
# currEventsInd += 1
try:
desc = str(db.getValueAt(rowNum,"Description ")).title()
shortDesc = desc
print '\t',shortDesc
def addToSchedule(eventDict, scheduledEvents = scheduledEvents ):
global updateCnt
global newCnt
#check for duplicates
if eventDict["EventID"] in existingEvents:
seRow = existingEvents.index(eventDict["EventID"])
#if its already in, then just update it
print "\t\tExisting event",eventDict["EventID"]," row ", seRow
#if updating, get current percent complete
eventDict["PctDone"] = scheduledEvents.getValueAt(seRow,'PctDone')
db = system.dataset.updateRow(scheduledEvents,seRow,eventDict)
scheduledEvents = db
updateCnt += 1
print updateCnt
#set back to 0 for next event
eventDict["PctDone"] = 0
else:
#if its not, then add it
print "\t\tadding new event",eventDict["EventID"]
schEvent = [eventDict["EventID"],eventDict["ItemID"],eventDict["StartDate"],eventDict["EndDate"],eventDict["Label"],
eventDict["Foreground"],eventDict["Background"],eventDict["LeadTime"],eventDict["LeadColor"],eventDict["PctDone"],
eventDict["Item"],eventDict["Qty"],eventDict["Hrs"],eventDict["Push"],eventDict["CIP"],eventDict["GPH"],eventDict["CPH"],eventDict["WM Needed"],eventDict["Protein"]]
#[ v for v in eventDict.values() ]
print '\t\tscheduledEvents',scheduledEvents
db = system.dataset.addRow(scheduledEvents,schEvent)
print ""
print '\t\tdb',db
scheduledEvents = db
newCnt += 1
print newCnt
return scheduledEvents
#end def
eventDict["EventID"] = db.getValueAt(rowNum,"Process Order")
eventDict["ItemID"] = LineNum
#print '\tStart',db.getValueAt(rowNum,"Start ")
eventDict["StartDate"] = system.date.parse(db.getValueAt(rowNum,"Start "),'M/dd/yy HH:mm')
eventDict["EndDate"] = system.date.parse(db.getValueAt(rowNum,"End "),'M/dd/yy HH:mm')
eventDict["Label"] = shortDesc
eventDict["Background"] = "color(214,255,198,255)"#Production light green
eventDict["Item"] = db.getValueAt(rowNum,"Item")
eventDict["Qty"] = db.getValueAt(rowNum,"Qty ")
eventDict["GPH"] = db.getValueAt(rowNum,"GPH")
eventDict["CPH"] = db.getValueAt(rowNum,"CPH")
eventDict["WM Needed"] = db.getValueAt(rowNum,"WM Needed")
eventDict["Protein"] = db.getValueAt(rowNum,"Protein")
eventDict["Hrs"] = db.getValueAt(rowNum,"Hrs. ")
eventDict["Push"] = db.getValueAt(rowNum,"Push ")
eventDict["CIP"] = db.getValueAt(rowNum,"CIP ")
scheduledEvents = addToSchedule(eventDict,scheduledEvents)
print '\tscheduledEvents',scheduledEvents
if db.getValueAt(rowNum,"CIP ") != '':
print '\tadding CIP'
time = db.getValueAt(rowNum,"CIP ").split(":")
hour = int(time[0])
min = int(time[1])
EndTime = system.date.addHours(system.date.addMinutes(system.date.parse(db.getValueAt(rowNum,"End "),'M/dd/yy HH:mm'),min-10),hour)
eventDict["EventID"] = eventDict["EventID"] + " CIP"
eventDict["StartDate"] = system.date.addMinutes(system.date.parse(db.getValueAt(rowNum,"End "),'M/dd/yy HH:mm'),5)
eventDict["EndDate"] = EndTime
eventDict["Label"] = "CIP"
eventDict["Background"] = "color(107,151,232,135)"#CIP Dark Blue
eventDict["Item"] = ""
eventDict["Qty"] = ""
eventDict["Hrs"] = ""
eventDict["Push"] = ""
eventDict["CIP"] = ""
scheduledEvents = addToSchedule(eventDict,scheduledEvents)
print '\tadding CIP'
print '\tscheduledEvents',scheduledEvents
except:
errorCnt += 1
print 'had error on ' + str(LineNum) + '\n' + str(traceback.format_exc())
#logger.error(str(traceback.format_exc()))
lineCnt += 1