Exemplo n.º 1
0
def storing_data_preparation(data):
    participations = etl.rowmapmany(
        etl.cut(data, 'room_id', 'summary'),
        rowgenerator,
        header=['room_id', 'participant_id', 'start_time', 'end_time', 'role'])
    rooms = etl.cut(data, 'room_id', 'created_at', 'end_time', 'creator')
    return (rooms, participations)
Exemplo n.º 2
0
 def get_relationships(self):
     "Parses a list of `Relationship` objects."
     core_file = _find_loinc_table_core_file(self.uri.path)
     core = etl.fromcsv(core_file, delimiter=',')
     core = etl.cut(core, ['LOINC_NUM', 'LONG_COMMON_NAME'])
     hierarchy_file = _find_multi_axial_hierarchy_file(self.uri.path)
     hierarchy = etl.fromcsv(hierarchy_file, delimiter=',')
     hierarchy = etl.leftjoin(hierarchy, core, lkey='CODE', rkey='LOINC_NUM')
     hierarchy = etl.cut(hierarchy, ['IMMEDIATE_PARENT', 'CODE', 'CODE_TEXT', 'LONG_COMMON_NAME'])
     hierarchy = etl.fillright(hierarchy)
     hierarchy = etl.cut(hierarchy, ['IMMEDIATE_PARENT', 'CODE', 'LONG_COMMON_NAME'])
     hierarchy = etl.rename(hierarchy, 'LONG_COMMON_NAME', 'CODE_TEXT')
     parents = etl.cut(hierarchy, ['CODE', 'CODE_TEXT'])
     hierarchy = etl.selectne(hierarchy, 'IMMEDIATE_PARENT', '')
     hierarchy = etl.leftjoin(hierarchy, parents, lkey='IMMEDIATE_PARENT', rkey='CODE', lprefix='source.', rprefix='target.')
     hierarchy = etl.distinct(hierarchy)
     if self.versioned:
         version = _parse_version(hierarchy_file)
         hierarchy = etl.addfield(hierarchy, 'version', version)
     hierarchy = etl.rowmapmany(hierarchy, _to_json, ['relationship'])
     return hierarchy
Exemplo n.º 3
0
table1 = [['id', 'sex', 'age', 'height', 'weight'],
          [1, 'male', 16, 1.45, 62.0],
          [2, 'female', 19, 1.34, 55.4],
          [3, '-', 17, 1.78, 74.4],
          [4, 'male', 21, 1.33]]

from petl import rowmapmany, look    
look(table1)
def rowgenerator(row):
    transmf = {'male': 'M', 'female': 'F'}
    yield [row[0], 'gender', transmf[row[1]] if row[1] in transmf else row[1]]
    yield [row[0], 'age_months', row[2] * 12]
    yield [row[0], 'bmi', row[4] / row[3] ** 2]

table2 = rowmapmany(table1, rowgenerator, fields=['subject_id', 'variable', 'value'])  
look(table2)


# recordmapmany

table1 = [['id', 'sex', 'age', 'height', 'weight'],
          [1, 'male', 16, 1.45, 62.0],
          [2, 'female', 19, 1.34, 55.4],
          [3, '-', 17, 1.78, 74.4],
          [4, 'male', 21, 1.33]]

from petl import recordmapmany, look    
look(table1)
def rowgenerator(rec):
    transmf = {'male': 'M', 'female': 'F'}
Exemplo n.º 4
0
table1 = [['id', 'sex', 'age', 'height', 'weight'],
          [1, 'male', 16, 1.45, 62.0],
          [2, 'female', 19, 1.34, 55.4],
          [3, '-', 17, 1.78, 74.4],
          [4, 'male', 21, 1.33]]

from petl import rowmapmany, look    
look(table1)
def rowgenerator(row):
    transmf = {'male': 'M', 'female': 'F'}
    yield [row[0], 'gender', transmf[row[1]] if row[1] in transmf else row[1]]
    yield [row[0], 'age_months', row[2] * 12]
    yield [row[0], 'bmi', row[4] / row[3] ** 2]

table2 = rowmapmany(table1, rowgenerator, fields=['subject_id', 'variable', 'value'])  
look(table2)


# recordmapmany

table1 = [['id', 'sex', 'age', 'height', 'weight'],
          [1, 'male', 16, 1.45, 62.0],
          [2, 'female', 19, 1.34, 55.4],
          [3, '-', 17, 1.78, 74.4],
          [4, 'male', 21, 1.33]]

from petl import recordmapmany, look    
look(table1)
def rowgenerator(rec):
    transmf = {'male': 'M', 'female': 'F'}
Exemplo n.º 5
0
def tokenize(table):
    return petl.rowmapmany(table, generate_row, header=['created_at','word'])