def remove_data(args): d = Database(args.database_path) c = d._conn.cursor() filt = generate_filter(args, c) # populate the temp tables tmp_event_rids, tmp_raw_data_rids filt.select_events() filt.select_raw_data() c.execute("""SELECT rid FROM tmp_event_rids""") event_rowids = c.fetchall() c.execute("""SELECT rid FROM tmp_raw_data_rids""") raw_data_rowids = c.fetchall() if confirmation('Remove %d events and %d raw_date records (y/N)? ' % ( len(event_rowids), len(raw_data_rowids))): c.execute(""" DELETE FROM event WHERE EXISTS ( SELECT 1 FROM tmp_event_rids t WHERE t.rid = event.rowid ) """) c.execute(""" DELETE FROM raw_data WHERE EXISTS ( SELECT 1 FROM tmp_raw_data_rids t WHERE t.rid = raw_data.rowid ) """) c.execute(""" SELECT id, path FROM input_file WHERE NOT EXISTS ( SELECT 1 FROM event e WHERE e.file_id = input_file.id ) AND NOT EXISTS ( SELECT 1 FROM raw_data r WHERE r.file_id = input_file.id )""") for r in c.fetchall(): print('Removing input file %s as it no longer has events / raw_data' % r[1]) c.execute(""" DELETE FROM input_file WHERE NOT EXISTS ( SELECT 1 FROM event e WHERE e.file_id = input_file.id ) AND NOT EXISTS ( SELECT 1 FROM raw_data r WHERE r.file_id = input_file.id )""") d.commit()
def calibrate(args): log.debug('calibrate(%s)' % args.ref) d = Database(args.database_path) c = d._conn.cursor() c.execute("""SELECT 1 FROM calibration WHERE ref = ?""", (args.ref,)) if len(c.fetchall()) > 0: log.debug('calibrate() updating existing record for ref %s' % args.ref) c.execute(""" UPDATE calibration SET anemometer_1_factor = ?, anemometer_2_factor = ?, max_windspeed_ms = ?, irradiance_factor = ?, max_irradiance = ? WHERE ref = ? """, (args.anemometer_1_factor, args.anemometer_2_factor, args.max_windspeed_ms, args.irradiance_factor, args.max_irradiance, args.ref)) else: log.debug('calibrate() inserting new record for ref %s' % args.ref) c.execute(""" INSERT INTO calibration ( ref, anemometer_1_factor, anemometer_2_factor, max_windspeed_ms, irradiance_factor, max_irradiance ) VALUES ( ?, ?, ?, ?, ?, ? ) """, (args.ref, args.anemometer_1_factor, args.anemometer_2_factor, args.max_windspeed_ms, args.irradiance_factor, args.max_irradiance)) d.commit()