Ejemplo n.º 1
0
def input_data(session, point, data, definition, unit='mg', unit_type='mass'):
    res = session.query(Data_Def).filter(Data_Def.name == definition).first()
    if not res:
        print 'Data definition <%s> non existent, please check' % definition
        return
    d = Data()
    d.data_type_id = res.id
    d.data_point_id = point.id

    #Todo  def SI_Unit(unit_type)-> returns e.g. 'kg'
    ### conversion from input unit to storage unit [SI]
    if unit != 'kg' and unit_type == 'mass':
        d_conv = data[1]
        d_conv *= RPhelper.convert2(unit, 'kg', 'mass')
        d.unit = 'kg'
    if unit != 'm' and unit_type == 'length':
        if definition == 'height':
            d_conv = data[2]
        if definition == 'diameter':
            d_conv = data[3]

        d_conv *= RPhelper.convert2(unit, 'm', 'length')
        d.unit = 'm'

    d.valA = d_conv
    d.physical_property = definition

    session.add(d)
    session.commit()
Ejemplo n.º 2
0
 def mass_conv(self, out_unit):
     return self.mass * helper.convert2('kg', out_unit, 'mass')