Skip to content

Commit

Permalink
Refs #10450. Consider the case of duplicated records.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Nov 10, 2014
1 parent aaa91ef commit 686c162
Showing 1 changed file with 20 additions and 9 deletions.
Expand Up @@ -43,10 +43,12 @@ def PyInit(self):
self.declareProperty("FileFormat", "tab", mantid.kernel.StringListValidator(fileformates), des)

self.declareProperty("OrderByTitle", "", "Log file will be ordered by the value of this title from low to high.")
self.declareProperty("RemoveDuplicateRecord", False, "Coupled with OrderByTitle, duplicated record will be removed.")

overrideprop = StringArrayProperty("OverrideLogValue", values=[], direction=Direction.Input)
self.declareProperty(overrideprop, "List of paired strings as log title and value to override values from workspace.")


# Time zone
timezones = ["UTC", "America/New_York"]
self.declareProperty("TimeZone", "America/New_York", StringListValidator(timezones))
Expand Down Expand Up @@ -161,10 +163,14 @@ def _processInputs(self):
ordertitle = self.getProperty("OrderByTitle").value
if ordertitle in self._headerTitles:
self._orderRecord = True
self._removeDupRecord = self.getProperty("RemoveDuplicateRecord").value
self.titleToOrder = ordertitle
else:
self.log().warning("Specified title to order by (%s) is not in given log titles." % (ordertitle))

if self._orderRecord is False:
self._removeDupRecord = False

# Override log values: it will not work in fastappend mode to override
overridelist = self.getProperty("OverrideLogValue").value
if len(self._headerTitles) > 0:
Expand Down Expand Up @@ -330,6 +336,7 @@ def _orderRecordFile(self):
linedict = {}
ilog = self._headerTitles.index(self.titleToOrder)

totnumlines = 0
for line in lines:
cline = line.strip()
if len(cline) == 0:
Expand All @@ -341,11 +348,14 @@ def _orderRecordFile(self):
else:
# value line
try:
keyvalue = line.split(self._valuesep)[ilog]
keyvalue = line.split(self._valuesep)[ilog].strip()
except IndexError:
self.log().error("Order record failed.")
return
linedict[keyvalue] = line
if linedict.has_key(keyvalue) is False:
linedict[keyvalue] = []
linedict[keyvalue].append(line)
totnumlines += 1
# ENDIFELSE
# ENDFOR

Expand All @@ -359,14 +369,15 @@ def _orderRecordFile(self):
wbuf += line

# log entry line
iline = 0
numlines = len(linedict.keys())
numlines = 0
for ivalue in sorted(linedict.keys()):
wbuf += linedict[ivalue]
# Add extra \n in case reordered
if iline != numlines-1 and wbuf[-1] != '\n':
wbuf += '\n'
iline += 1
for line in linedict[ivalue]:
wbuf += line
# Add extra \n in case reordered
if numlines != totnumlines-1 and wbuf[-1] != '\n':
wbuf += '\n'
numlines += 1
# ENDFOR
# ENDFOR

# Last line should not ends with \n
Expand Down

0 comments on commit 686c162

Please sign in to comment.