def sensors_delete(id): row = util.getRowFromTableById("sensor", int(id)) if not row: abort(404, "Sensor not found.") util.deleteRowFromTableById("sensor", int(id)) return HTTPResponse(output="Sensor deleted", status=204)
def sensor_mirrors_get(id): row = util.getRowFromTableById("sensor_mirror", id) if not row: abort(404, "Sensor Mirror not found.") return row
def bin_sections_get(id): row = util.getRowFromTableById("bin_section", int(id)) if (not row): abort(404, "Bin Section not found.") return row
def sensors_get(id): row = util.getRowFromTableById("sensor", int(id)) if not row: abort(404, "Sensor not found.") row["bias"] = float(row["bias"]) return row
def air_deductions_del(id): air_deduct = util.getRowFromTableById("air_deduct", id) if not air_deduct: abort(404, 'Air deduct not found') util.deleteRowFromTableById("air_deduct", id) return HTTPResponse(output="Air Deduction Deleted", status=202)
def air_deductions_get(id): row = util.getRowFromTableById("air_deductions", id) if (row): return util.responseJSON(row) else: abort(404, 'Air deduction not found.')
def data_graph_selections(id): true_bin = False selections = {} tops = [] conn = util.getConn() binr = util.getRowFromTableById("bin", int(id), conn=conn) bin_sections = [] bin_sections_names = [] if not binr: abort(404, 'Bin not found') sql = """SELECT DISTINCT ON (read_type_id, bin_section_id) rt.id AS read_type_id, rt.short_name AS read_type_name, rt.units, bs.id AS bin_section_id, bs.name AS bin_section_name FROM reading_subsample rs, reading_data_subsample rds, read_type rt, bin_section bs WHERE rt.id = rds.read_type_id AND bs.id = rds.bin_section_id AND rds.bin_id = %s AND rds.reading_subsample_id = rs.id AND rs.id IN (SELECT id from reading_subsample where sample_period = 5 ORDER by datetime desc limit 100)""" cur = conn.cursor() cur.execute(sql, (id, )) # TODO: Virtual Sensor detection (Dew, jfactor) for row in cur: read_type_id = row[0] read_type_name = row[1] units = row[2] bin_section_id = row[3] bin_section_name = row[4] if not bin_section_id in bin_sections: bin_sections.append(bin_section_id) bin_sections_names.append(bin_section_name) if not units in selections: selections[units] = [] selections[units].append([ bin_section_name + ' ' + read_type_name, 'sensor', [bin_section_id, read_type_id] ]) if bin_section_id == TOP_BIN_SECTION: tops.append(read_type_id) if bin_section_id == BOTTOM_BIN_SECTION: if read_type_id in tops: true_bin = True selections[units].append( ['Inlet ' + read_type_name, 'inlet', [read_type_id]]) selections[units].append( ['Outlet ' + read_type_name, 'outlet', [read_type_id]]) #Guage pressure if read_type_id == PRESSURE_READ_TYPE_ID: if not "inH2O" in selections: selections["inH2O"] = [] selections["inH2O"].append([ bin_section_name + ' ' + read_type_name, 'sensor', [bin_section_id, GPRESSURE_READ_TYPE_ID] ]) if bin_section_id == TOP_BIN_SECTION: tops.append(read_type_id) if bin_section_id == BOTTOM_BIN_SECTION: if read_type_id in tops: selections["inH2O"].append([ 'Inlet ' + read_type_name, 'inlet', [GPRESSURE_READ_TYPE_ID] ]) selections["inH2O"].append([ 'Outlet ' + read_type_name, 'outlet', [GPRESSURE_READ_TYPE_ID] ]) general = util.getRowFromTableById('general_config', 1, conn=conn) if true_bin: # Virtual Options if general['jfactor']: selections['Misc'] = [[ 'jFactor', 'sensor', [TOP_BIN_SECTION, JFACTOR_READ_TYPE_ID] ]] #selections['°F'].append(['Max Temp', 'maxtemp', []]) selections['°F'].append( ['Top Dew', 'sensor', [TOP_BIN_SECTION, DEW_READ_TYPE_ID]]) selections['°F'].append( ['Bottom Dew', 'sensor', [BOTTOM_BIN_SECTION, DEW_READ_TYPE_ID]]) selections['°F'].append(['Inlet Dew', 'inlet', [DEW_READ_TYPE_ID]]) selections['°F'].append( ['Outlet Dew', 'outlet', [DEW_READ_TYPE_ID]]) selections['°F'].append( ['Top WB', 'sensor', [TOP_BIN_SECTION, WB_READ_TYPE_ID]]) selections['°F'].append( ['Bottom WB', 'sensor', [BOTTOM_BIN_SECTION, WB_READ_TYPE_ID]]) selections['°F'].append(['Inlet WB', 'inlet', [WB_READ_TYPE_ID]]) selections['°F'].append(['Outlet WB', 'outlet', [WB_READ_TYPE_ID]]) else: for i in range(len(bin_sections)): selections['°F'].append([ bin_sections_names[i] + ' WB', 'sensor', [bin_sections[i], WB_READ_TYPE_ID] ]) rlist = [] for key, value in selections.iteritems(): rlist.append([key, value]) return {'options': rlist}
def device_types_get(id): row = util.getRowFromTableById("device_type", int(id)) if(not row): abort(404, "Device Type not found.") return row
def devices_delete(id): row = util.getRowFromTableById("device", int(id)) if not row: abort(404, "Device not found.") util.deleteRowFromTableById("device", int(id)) return HTTPResponse(output="Device deleted.", status=204)
def devices_get(id): row = util.getRowFromTableById("device", int(id)) if not row: abort(404, "Device not found.") return row
def service_alarms(): row = util.getRowFromTableById('general_config', 1) configs = json.loads(row["configs"]) return configs["alarms"]