def fetchPSDAsync(from_ts, to_ts, get_power_dist=False, get_avg_power=True): selection = "id,ts" if get_avg_power: selection += ",total_power" if get_power_dist: selection += ",power_dist" query = SimpleStatement( "SELECT {0} FROM vtsil.psd_by_minute where date=%s and ts=%s".format(selection), fetch_size=None) # query = "SELECT {0} FROM vtsil.psd_by_minute where date=%s and ts=%s".format(selection) response = defaultdict(list) future_results = [] ts_list = splitRangeInSeconds(from_ts, to_ts) for ts in ts_list: date = time_utils.roundToMinute(ts) date = time_utils.formatTime(date, 'utc', constants.RES_DATE_FORMAT) ts = time_utils.formatTime(ts, 'utc', constants.RES_DATE_FORMAT) future_results.append(session.execute_async(query, [date, ts])) for future in future_results: result = future.result() for row in result: response[row['id']].append(row) return response
def fetchSensorDataById(from_ts, to_ts, sid): query = SimpleStatement( "SELECT id,ts,data FROM vtsil.sensor_data_by_minute where date=%s and ts=%s and id=%s", fetch_size=None) future_results = [] ts_list = splitRangeInSeconds(from_ts, to_ts) for ts in ts_list: date = time_utils.roundToMinute(ts) date = time_utils.formatTime(date, 'utc', constants.RES_DATE_FORMAT) ts = time_utils.formatTime(ts, 'utc', constants.RES_DATE_FORMAT) future_results.append(session.execute_async(query, [date, ts, sid])) return future_results
def insertSensorData(sid, ts, data): ts = time_utils.parseTime(ts, timezone, FILENAME_DATE_FORMAT) date = time_utils.roundToMinute(ts) SensorDataByHour.consistency(ConsistencyLevel.LOCAL_ONE).create( id=sid, ts=ts, date=date, data=data)
def insertPSDAsync(sid, total_power, power_dist, ts): date = time_utils.roundToMinute(ts) query = SimpleStatement( """INSERT INTO vtsil.psd_by_minute (id,date,ts,total_power,power_dist) VALUES(%s,%s,%s,%s,%s)""") return session.execute_async(query, (sid, date, ts, total_power, power_dist))