示例#1
0
 def add_measurement(self,
                     image_id,
                     structure,
                     measurement,
                     unit,
                     value,
                     side=None,
                     software=None,
                     comments=None):
     args = {
         'image_id': image_id,
         'structure': structure,
         'measurement': measurement,
         'unit': unit,
         'value': value
     }
     if side:
         args['side'] = side
     if software:
         args['software'] = software
     if comments:
         args['comments'] = comments
     new_measurement = models.Measurement(**args)
     self.session.add(new_measurement)
     self.session.commit()
示例#2
0
    def __call__(self, value):
        v = self.typef(value)
        mes = models.Measurement(str(v),
                                 self.metric,
                                 self.units,
                                 instrument=self.instrument,
                                 station=self.site,
                                 offset=self.offset)
        if hasattr(v, 'flags'):
            mes.flags = getattr(v, 'flags')

        return mes
示例#3
0
def do_publish(identifier, type_, value, consolidate_every, ts=None):
    measurement = models.Measurement(identifier=identifier,
                                     type=type_,
                                     value=value)
    if ts is not None:
        measurement.timestamp = ts
    measurement.put()

    if consolidate_every:
        if random.random(
        ) < 1.0 / consolidate_every:  # consolidate every consolidate_every calls on average
            deferred.defer(consolidate.consolidate_measurements,
                           identifier,
                           type_,
                           _queue="index-queue")
示例#4
0
def index():
    obj = dict2obj(new_measurements=[
        dict2obj(type=m.label) for m in current_user.measurements
    ])
    form = forms.AddMeasurementsForm(obj=obj)
    if form.validate_on_submit():
        timestamp = datetime.now()
        for measurement in form.new_measurements:
            value = measurement.data['value']
            if value is None: continue
            series_label = measurement.data['type']
            series = current_user.measurements.filter_by(
                label=series_label).one()
            models.Measurement(series, value, timestamp)
        return redirect(url_for('.index'))
    flash_errors(form)
    return render_template('measurements.html', form=form, user=current_user)
示例#5
0
def create_meas_record(meas_date, event_type, manufacturerID, gluc_value,
                       insulin_value, carb, userRecord, deviceRecord):
    ''' options for create measurement require measurement date, glucose value, insulin value, carbohydrate value, event type, manufacturerID, device_id and user_id '''
    print('Measurement Record Created: ', meas_date, event_type,
          manufacturerID, gluc_value, insulin_value, carb, deviceRecord.id)
    measVars = {
        'meas_date': meas_date,
        'event_type': event_type,
        'manufacturerID': manufacturerID,
        'gluc_value': gluc_value,
        'insulin_value': insulin_value,
        'carb': carb,
        'user_id': userRecord.id,
        'device_id': deviceRecord.id
    }
    try:
        return s.query(m.Measurement).filter_by(**measVars).one()
    except NoResultFound:
        record = m.Measurement(**measVars)
        print("Create Meas record record: ", record, record.__dict__,
              dir(record))
    return record
示例#6
0
def rock_block():
    imei = request.form.get('imei')
    momsn = request.form.get('momsn')
    transmit_time = request.form.get('transmit_time')
    iridium_latitude = request.form.get("iridium_latitude")
    iridium_longitude = request.form.get("iridium_longitude")
    iridum_cep = request.form.get("iridium_cep")
    payload = request.form.get('data')

    print(request.form, file=sys.stdout)
    #deployment = 1 ##TODO Look up database for deployments
    dep = models.Deployment.query.filter_by(imei=imei).order_by(
        models.Deployment.deployed.desc()).first()
    deployment = dep.id

    period = int(payload[8:12], 16)

    time1 = datetime.utcfromtimestamp(int(payload[0:8], 16))
    level1 = int(payload[12:16], 16)
    water_temp1 = int(payload[16:20], 16) / 100.0
    air_temp1 = int(payload[20:24], 16) / 100.0
    humidity1 = int(payload[24:28], 16) / 100.0
    pressure1 = int(payload[28:32], 16) / 1000.0

    time2 = time1 + timedelta(minutes=period)
    level2 = int(payload[32:36], 16)
    water_temp2 = int(payload[36:40], 16) / 100.0
    air_temp2 = int(payload[40:44], 16) / 100.0
    humidity2 = int(payload[44:48], 16) / 100.0
    pressure2 = int(payload[48:52], 16) / 1000.0

    time3 = time2 + timedelta(minutes=period)
    level3 = int(payload[52:56], 16)
    water_temp3 = int(payload[56:60], 16) / 100.0
    air_temp3 = int(payload[60:64], 16) / 100.0
    humidity3 = int(payload[64:68], 16) / 100.0
    pressure3 = int(payload[68:72], 16) / 1000.0

    time4 = time3 + timedelta(minutes=period)
    level4 = int(payload[72:76], 16)
    water_temp4 = int(payload[76:80], 16) / 100.0
    air_temp4 = int(payload[80:84], 16) / 100.0
    humidity4 = int(payload[84:88], 16) / 100.0
    pressure4 = int(payload[88:92], 16) / 1000.0

    entry1 = models.Measurement(deployment, time1, level1, water_temp1,
                                air_temp1, humidity1, pressure1, imei,
                                iridium_latitude, iridium_longitude)
    db.session.add(entry1)

    entry2 = models.Measurement(deployment, time2, level2, water_temp2,
                                air_temp2, humidity2, pressure2, imei,
                                iridium_latitude, iridium_longitude)
    db.session.add(entry2)

    entry3 = models.Measurement(deployment, time3, level3, water_temp3,
                                air_temp3, humidity3, pressure3, imei,
                                iridium_latitude, iridium_longitude)
    db.session.add(entry3)

    entry4 = models.Measurement(deployment, time4, level4, water_temp4,
                                air_temp4, humidity4, pressure4, imei,
                                iridium_latitude, iridium_longitude)
    db.session.add(entry4)

    db.session.commit()

    return Response(status=200, mimetype='application/json')