Esempio n. 1
0
def process_record(filename, record):
  if '~' not in record: return 'No proper start of record'
  if '~A' not in record: return 'No delimited data block'

  halves = record[record.index('~'):].strip().split('~A')
  metadata = las.parse_metadata(\
    las.sanitize(line.strip('.').strip()) for line in las.filter_lines(halves[0], ['-'])\
  )
  if len(metadata['curveAliases']) < 1: return 'bad format in metadata block'

  try:
    halves[1] = halves[1][halves[1].index('\n'):]
    #filter blank and lines starting with #, split resulting text into tokens
    tokens = '\t'.join(las.filter_lines(halves[1], ['#'])).split()
  except: return 'bad separation between metadata and curve data'

  if len(tokens) % len(metadata['curveAliases']) != 0: return 'mismatched reading count'

  null_vals = get_nulls(metadata)
  curve_aliases = metadata['curveAliases']
  step_type = curve_aliases[0]
  for idx in xrange(0, len(tokens), len(curve_aliases)): # idx is index of first reading on a step
    step_values = tokens[idx : idx + len(curve_aliases)] # get all readings for the next step
    try:
      for idy, reading in enumerate(filter(lambda x: float(x) not in null_vals, step_values)[1:]):
        helper.emit('\t'.join([filename, step_type, step_values[0], curve_aliases[idy], metadata['C'][curve_aliases[idy]].get('UOM', ''), reading]))
    except ValueError: pass
Esempio n. 2
0
def process_record(filename, record):
  if '~' not in record: return 'No proper start of record'
  halves = record[record.index('~'):].strip().split('~A')
  if len(halves) < 2: return 'Improperly separated metadata & data blocks'

  metadata = las.parse_metadata(\
    las.sanitize(line.strip('.').strip()) for line in las.filter_lines(halves[0], ['-'])\
  )
  if len(metadata['curveAliases']) < 1: return 'Improperly formatted metadata block'

  for block in ['V', 'W', 'C']:
    if block in metadata:
      for mnemonic, val in metadata[block].iteritems():
        helper.emit('%s\t%s\t%s\t%s\t%s' % \
          (filename, block, mnemonic, val.get('UOM', ''), val.get('description', '')))
Esempio n. 3
0
def process_record(filename, record):
    if '~' not in record: return 'No proper start of record'
    halves = record[record.index('~'):].strip().split('~A')
    if len(halves) < 2: return 'Improperly separated metadata & data blocks'

    metadata = las.parse_metadata(\
      las.sanitize(line.strip('.').strip()) for line in las.filter_lines(halves[0], ['-'])\
    )
    if len(metadata['curveAliases']) < 1:
        return 'Improperly formatted metadata block'

    for block in ['V', 'W', 'C']:
        if block in metadata:
            for mnemonic, val in metadata[block].iteritems():
                helper.emit('%s\t%s\t%s\t%s\t%s' % \
                  (filename, block, mnemonic, val.get('UOM', ''), val.get('description', '')))
Esempio n. 4
0
def process_record(filename, record):
    if '~' not in record: return 'No proper start of record'
    if '~A' not in record: return 'No delimited data block'

    halves = record[record.index('~'):].strip().split('~A')
    metadata = las.parse_metadata(\
      las.sanitize(line.strip('.').strip()) for line in las.filter_lines(halves[0], ['-'])\
    )
    if len(metadata['curveAliases']) < 1: return 'bad format in metadata block'

    try:
        halves[1] = halves[1][halves[1].index('\n'):]
        #filter blank and lines starting with #, split resulting text into tokens
        tokens = '\t'.join(las.filter_lines(halves[1], ['#'])).split()
    except:
        return 'bad separation between metadata and curve data'

    if len(tokens) % len(metadata['curveAliases']) != 0:
        return 'mismatched reading count'

    null_vals = get_nulls(metadata)
    curve_aliases = metadata['curveAliases']
    step_type = curve_aliases[0]
    for idx in xrange(
            0, len(tokens),
            len(curve_aliases)):  # idx is index of first reading on a step
        step_values = tokens[
            idx:idx + len(curve_aliases)]  # get all readings for the next step
        try:
            for idy, reading in enumerate(
                    filter(lambda x: float(x) not in null_vals,
                           step_values)[1:]):
                helper.emit('\t'.join([
                    filename, step_type, step_values[0], curve_aliases[idy],
                    metadata['C'][curve_aliases[idy]].get('UOM', ''), reading
                ]))
        except ValueError:
            pass
Esempio n. 5
0
def process_rec(key, rec):
    cells = pq(rec)("table")("td")
    records = [cells[x : x + 13] for x in xrange(0, len(cells), 13)]
    for record in records:
        helper.emit("\t".join([sanitize(cell) for cell in record]))
Esempio n. 6
0
def emit(fields, cells):
    #Print tab separated list of fields concatted with array of extracted cell values
    helper.emit('\t'.join(fields + [cell.text_content() for cell in cells]))
Esempio n. 7
0
def emit(fields, text):
    helper.emit('\t'.join(fields + [text]))
Esempio n. 8
0
def emit(fields, cells): helper.emit('\t'.join(fields + [cell.text_content() for cell in cells]))

def process_rec(key, rec):
Esempio n. 9
0
def emit(fields, cells):
  #Print tab separated list of fields concatted with array of extracted cell values
  helper.emit('\t'.join(fields + [cell.text_content() for cell in cells]))
Esempio n. 10
0
def process_rec(key, rec):
    cells = pq(rec)('table')('td')
    records = [cells[x:x + 13] for x in xrange(0, len(cells), 13)]
    for record in records:
        helper.emit('\t'.join([sanitize(cell) for cell in record]))
Esempio n. 11
0
def emit(fields, cells):
    helper.emit('\t'.join(fields + [cell.text_content() for cell in cells]))
Esempio n. 12
0
def emit(fields, text): helper.emit('\t'.join(fields + [text]))

def process_rec(key, rec):