def getPressures(self, dev): """Read sensor data.""" # Iterate through sensors 1 to 6. for i in range(1, 7): # The serial command 'PRx' tells the device that we are # talking about sensor x. yield self.dev.write("PR{0}\r\n".format(i)) # Give the device time to receive and process the request. yield sleep(0.1) # The device responds with an acknowledge, discard it. yield self.dev.read() yield sleep(0.1) # Write the 'enquire' code to the serial bus. This tells the # device that we want a reading. yield self.dev.write("\x05\r\n") yield sleep(0.1) response = yield self.dev.read() # The reading is formatted in the following way: # 'status,measurement.' # Separate the status code from the measurement. response = response.rsplit(',') pressure = response[1] status = response[0] self.measurements[i-1] = 1e-3 * float(response[1]) * units.bar self.statusCodes[i-1] = response[0]
async def test_start_end_channel_incr(interface): await guild.system_channel.send(me_command) prev_stats = await utilities.get_user_stats(redis_client, bot_id, timepoint=timepoint) voice_channel = [channel for channel in guild.voice_channels if "screen/cam" in channel.name][1] voice_client = await voice_channel.connect() start_channel_time = utilities.get_time() utilities.sleep(time_to_stay) await voice_client.disconnect() end_channel_time = utilities.get_time() await guild.system_channel.send(me_command) utilities.sleep(discord_delay) cur_stats = await utilities.get_user_stats(redis_client, bot_id, timepoint=timepoint) # TODO test - use fields to check description? # reply = await guild.system_channel.history(limit=1).flatten()[0].embeds[0].description assert (utilities.check_stats_diff(prev_stats, cur_stats, time_to_stay, 1, redis_tolerance)) # Check SQL records = sqlalchemy_session.query(Action) \ .filter(Action.user_id == bot_id) \ .filter(Action.category.in_(["end channel", "start channel"])) \ .order_by(Action.creation_time.desc()).limit(2).all() records.reverse() assert (records[0].category == "start channel") assert (records[0].detail == records[1].detail == voice_channel.id) assert (records[0].creation_time - start_channel_time <= db_tolerance) assert (records[1].creation_time - end_channel_time <= db_tolerance)
async def test_in_session(interface): # TODO find out why this test can't be before test_p await guild.system_channel.send(me_command) prev_stats = await utilities.get_user_stats(redis_client, bot_id, timepoint=timepoint) voice_channel = [ channel for channel in guild.voice_channels if "screen/cam" in channel.name ][1] voice_client = await voice_channel.connect() multiplier = 2 # multiplier = 175 utilities.sleep(time_to_stay * multiplier) await guild.system_channel.send(me_command) utilities.sleep(discord_delay) mid_stats = await utilities.get_user_stats(redis_client, bot_id, timepoint=timepoint) assert (utilities.check_stats_diff(prev_stats, mid_stats, time_to_stay, multiplier, redis_tolerance)) multiplier = 5 # multiplier = 2147 utilities.sleep(time_to_stay * multiplier) await voice_client.disconnect() await guild.system_channel.send(me_command) utilities.sleep(discord_delay) cur_stats = await utilities.get_user_stats(redis_client, bot_id, timepoint=timepoint) assert (utilities.check_stats_diff(mid_stats, cur_stats, time_to_stay, multiplier, redis_tolerance))
def getInfo(self, ctx): self.dev = self.selectedDevice(ctx) yield self.dev.write_line('?') yield sleep(0.05) reading = yield self.dev.read_line() returnValue(reading)
def getTemperatures(self, ctx): readings = [] self.dev = self.selectedDevice(ctx) for i in range(2): yield self.dev.write_line(str(i + 1)) yield sleep(0.2) reading = yield self.dev.read_line() reading = reading.strip() if reading == "OL": readings.append(np.nan) elif len(reading) is 0: readings.append(np.nan) else: if i is 0: print "50K: ", reading else: print "3K: ", reading reading = reading.strip() # print float(reading) # print self.resToTemp(900) readings.append(self.resToTemp(float(reading)) + 273.15) # print readings readings = readings * units.K reading1 = readings[1] reading2 = readings[0] returnValue([reading1, reading2])
def initialize(self): # Create a new packet p = self._packet() # Write to the packet # This is the system->preset command p.write('SYST:PRES') yield p.send() yield sleep(0.1)
def getReading(self, ctx): self.dev = self.selectedDevice(ctx) yield self.dev.write_line("1") yield sleep(0.1) reading = yield self.dev.read_line() reading = reading.strip() reading = float(reading) reading = reading*units.V returnValue(reading)
def sweep_points(self, pn): """ Set or get number of points in a sweep. The number will be automatically coarsen to 3, 11, 21, 26, 51, 101, 201, 401, 801, or 1601 by the network analyzer. """ if pn is not None: yield self.write('POIN%i' %pn) t = yield self.query('SWET?') yield sleep(2 * float(t)) # Be sure to wait for two sweep # times as required in the docs. resp = yield self.query('POIN?') pn = int(float(resp)) returnValue(pn)
def getRate(self, dev): """Get flow rate.""" # The string '@U?V' asks the device for the current reading # The '\r' at the end is the carriage return letting the device # know that it was the end of the command. #print("getting rate") yield dev.write_line("@U?V\r") yield sleep(0.5) reading = yield dev.read_line() # Instrument randomly decides not to return, here's a hack. if not reading: returnValue(None) else: # Get the last number in the string. reading.rsplit(None, 1)[-1] # Strip the 'L' off the string. reading = float(reading.lstrip("L")) # Convert the reading to the correct units. gal = units.WithUnit(1, 'gal') output = reading * gal / units.min #print(output) returnValue(output)
async def test_me(interface): embed = Embed(title=utilities.config["embed_titles"]["me"]) await interface.assert_reply_embed_equals(os.getenv("prefix") + "me", embed, attributes_to_check=["title"]) utilities.sleep(discord_delay)
def initialize(self): p = self._packet() p.write('SYST:PRES') yield p.send() yield sleep(0.1)
num_votes = count_tweets_of_app(name_app) print name_app, "=>", num_votes if num_votes >= 0: #Store votes and last update df.set_value(name_app, date, num_votes) df.set_value(name_app, LAST_UPDATE, time.time()) #Reorder by votes of last day df = df.sort_values(by=[date], ascending=[False]) #Save results to csv df.to_csv(uri, sep=";", decimal=",") print "\n", df[date], except IOError: print "CSV not found, aborting" if __name__ == '__main__': """ It calculates 15 apps every 15 minutes and store the votes in a csv """ while True: calculate_oldest() #sleep 15 minutes print "\n\nThis process will sleep 15 minutes due to Twitter api limits\n" u.sleep(15)