Exemplo n.º 1
0
def readDay (file, otherDays=None):
  day = Day ()
  s = utils.readNextLine (file)
  if not s: return None
  numMeasurements = int (s.strip())
  assert numMeasurements > 0 and numMeasurements < 1000000
  while numMeasurements > 0:
    fields = file.readline ().strip().split (' ')
    assert len (fields) == 2
    day.addMeasurement (float (fields [0]), float (fields [1]))
    numMeasurements -= 1

  #if otherDays was specified, reset the periodZeroUtfSeconds
  #we have to wait until we've set up day because it needs
  #its julian day to be set
  #periodZeroUtfSeconds is for timestamp filtering based on a start-offset from some other
  #set of measurements
  if otherDays:
    otherDay = otherDays.getDay (day)
    if (otherDay):
      day.periodZeroUtfSeconds = otherDay.measurements [0][0]
      day.otherDayWasFound = True
  else:
    day.otherDayWasFound = True
  return day
Exemplo n.º 2
0
def readJulianDayLines (file):
  """
  return a list of strings, one string per line in the file
  where all the strings are on the same julian day as the
  first line read. when this returns
  the file is at the end or the first line of the
  next julian day. and each line in the file starts
  with a julian day
  :param file:
  :return: list of line strings or None if the file had no more lines
  """

  def julianDayFromLine (line):
    fields = line.strip().split (' ')
    assert len (fields) >= 1
    julianDate = float (fields [0])
    fraction = math.modf (julianDate)
    return fraction [1]

  #remember where we are in the file
  pos = file.tell ()

  #get julian day of first line
  line = utils.readNextLine (file)
  if not line: return None
  day = julianDayFromLine (line)

  #go back so we can do the iteration
  file.seek (pos)

  #collect lines into "lines" until the day changes
  lines = []
  while line and julianDayFromLine (line) == day:
    lines.append (line)
    pos = file.tell ()
    line = utils.readNextLine (file)

  #restore file pos to start of new day
  file.seek (pos)
  return lines