def getMergeResults(self): if not self._updatedTable and not self._purgedTable and not self._changes: return None updatedList = ArrayList() for rec in self._updatedTable: updatedList.add(rec.javaRecord()) purgedList = ArrayList() for rec in self._purgedTable: purgedList.add(rec.javaRecord()) changeList = ArrayList() for c in self._changes: changeList.add(VTECChange(c[0], c[1], c[2], c[3])) result = MergeResult(updatedList, purgedList, changeList) return result
def mergeFromJava(siteId, activeTable, newRecords, logger, mode, offsetSecs=0): perfStat.log( "mergeFromJava called for site: %s, activeTable: %d , newRecords: %d" % (siteId, activeTable.size(), newRecords.size())) timer = TimeUtil.getTimer() timer.start() pyActive = [] szActive = activeTable.size() for i in range(szActive): pyActive.append( ActiveTableRecord.ActiveTableRecord(activeTable.get(i), "Previous")) pyNew = [] szNew = newRecords.size() for i in range(szNew): rec = ActiveTableRecord.ActiveTableRecord(newRecords.get(i)) pyNew.append(rec) active = ActiveTable(mode, logger) logger.info("Updating " + mode + " Active Table: new records\n" + active.printActiveTable(pyNew, combine=1)) timer.stop() perfStat.logDuration("mergeFromJava preprocess", timer.getElapsedTime()) updatedTable, purgeRecords, changes, changedFlag = active.activeTableMerge( pyActive, pyNew, offsetSecs) perfStat.log( "mergeFromJava activeTableMerge returned updateTable: %d, purgeRecords: %d, changes: %d" % (len(updatedTable), len(purgeRecords), len(changes))) timer.reset() timer.start() logger.info("Updated " + mode + " Active Table: purged\n" + active.printActiveTable(purgeRecords, combine=1)) stateDict = {} for r in updatedTable: recs = stateDict.get(r['state'], []) recs.append(r) stateDict[r['state']] = recs keys = stateDict.keys() keys.sort() for key in keys: if key == "Previous": continue logger.info("Updated " + mode + " Active Table: " + key + "\n" + active.printActiveTable(stateDict[key], combine=1)) updatedList = ArrayList(len(updatedTable)) for r in updatedTable: if r['state'] not in ["Previous", "Replaced"]: updatedList.add(r.javaRecord()) purgedList = ArrayList(len(purgeRecords)) for r in purgeRecords: purgedList.add(r.javaRecord()) changeList = ArrayList(len(changes)) if (changedFlag): from com.raytheon.uf.common.activetable import VTECChange for c in changes: changeList.add(VTECChange(c[0], c[1], c[2], c[3])) from com.raytheon.uf.common.activetable import MergeResult result = MergeResult(updatedList, purgedList, changeList) timer.stop() perfStat.logDuration("mergeFromJava postprocess", timer.getElapsedTime()) return result