def test_1(self): t = Temperature("64f") self.assertEquals(t.value, 64) self.assertEquals(t._Temperature__scale, "F") t.value = "100k" self.assertEquals(t.value, 100) self.assertEquals(t._Temperature__scale, "K")
def __init__(self, refPath, dataPath, dbFilename): GPIO.cleanup() GPIO.setmode(GPIO.BCM) GPIO.setup(self.AUTO_START_GPIO_PIN, GPIO.IN, pull_up_down=GPIO.PUD_UP) self.__i2c = I2C(2) self.__analog = Analog(sel.__i2c.getLock(), 0x49) self.default = Default() self.database = Database(dataPath, dbFilename) self.waterlevel = Waterlevel(debug, self.database) self.light = Light(self.database) self.curtain = Curtain(self.database) self.pressure = Pressure(self.database, self.default, self.__analog) self.temperature = Temperature("28-0417716a37ff", self.database) self.redox = Redox(debug, self.database, self.default, self.__analog) self.ph = PH(debug, self.database, self.default, self.__analog, self.temperature) self.robot = Robot(debug, self.database) self.pump = Pump(debug, self.database, self.default, self.robot, self.redox, self.ph, self.temperature) self.panel = Panel(debug, self.database, self.default, self.pump, self.redox, self.ph, self.__i2c) self.statistic = Statistic(debug, self.pump, self.robot, self.redox, self.ph, self.temperature, self.pressure, self.waterlevel) self.refPath = refPath self.__autoSaveTick = 0 self.__today = date.today().day - 1 debug.TRACE(debug.DEBUG, "Initialisation done (Verbosity level: %s)\n", debug)
def __init__(self): self.number = '+4917621929963' self.pictureInterval = 20 self.temperatureInterval = 60 self.smsListeningInterval = 10 self.gpsReportingInterval = 120 self.threadLockNumberReports = 0 self.threadLockNumberPictures = 0 self.threadLockNumberTemperature = 0 self.threadLockNumberGpsTime = 0 self.sendGPSSMS = False self.pictureDir = "/root/pictures" self.sendTemperature = False self.getTimeFromGpsLoop = True self.gpsParser = GpsParser() self.temperatureClass = Temperature() try: # Create state machine object self.sm = gammu.StateMachine() # Read ~/.gammurc self.sm.ReadConfig(Filename = "/root/.gammurc") # Connect to phone self.sm.Init() except Exception as e: # Unplugging the UMTS stick requires a restart print e self.logMessage(e, "__init__") if e.Code == 4: print "restarting in 300 sec..." time.sleep(300) os.system("reboot")
def test_6(self): Temperature.set_default_scale("f") t = Temperature("100") self.assertEquals(str(t), "100F") Temperature.set_default_scale("k") t = Temperature("-50") self.assertEquals(str(t), "-50K")
def test_5(self): # Kelvin + Celsius t1 = Temperature("273.15K") t2 = Temperature("0C") t3 = t1 - t2 self.assertEquals(t3.value, 0) self.assertEquals(t3.scale, "K") self.assertEquals(t3.dscale, "K")
def test_making_training_set(self): precipitation = { 170101: Precipitation(17, 1, 1, 20, 123456), 170102: Precipitation(17, 1, 2, 0.5, 123456) } water_level = { 170101: Water_level(17, 1, 1, 0.5), 170102: Water_level(17, 1, 2, 0.38) } max_temperature = { 170101: Temperature(17, 1, 1, 30.5, 123456), 170102: Temperature(17, 1, 2, 25.4, 123456) } min_temperature = { 170101: Temperature(17, 1, 1, 21.3, 123456), 170102: Temperature(17, 1, 2, 19.8, 123456) } solar_exposure = { 170101: Solar(17, 1, 1, 30.6, 123456), 170102: Solar(17, 1, 2, 20.1, 123456) } precipitation_key = [170101, 170102] water_level_key = [170101, 170102] max_temperature_key = [170101, 170102] min_temperature_key = [170101, 170102] solar_exposure_key = [170101, 170102] result = [[30.5, 21.3, 20, 30.6, 0.5], [25.4, 19.8, 0.5, 20.1, 0.38]] self.assertEqual( methods.making_training_set(precipitation, water_level, max_temperature, min_temperature, solar_exposure, precipitation_key, water_level_key, max_temperature_key, min_temperature_key, solar_exposure_key), result)
def test_4(self): # Fahrenheit + Celsius t1 = Temperature("32F") t2 = Temperature("0C") t1.dscale = "K" t2.dscale = "K" t3 = t1 - t2 self.assertEquals(t3.value, 0) self.assertEquals(t3.scale, "K") self.assertEquals(t3.dscale, "K")
def senseTempAndDisplay(): sense = SenseHat() while True: temp = int(round(float(sense.get_temperature()))) temperature = Temperature(temp, coldMax, hotMin, comfortableMax, comfortableMin, sense) temperature.checkAndDisplay() sleep(10)
def test_6_average(self): """Test if averaging works as specified.""" average_temperature = Temperature.average( [Temperature(temp) for temp in VALID_TEMPERATURES]).celsius self.assertTrue( equal_to_n_decimal_places(AVERAGE_TEMPERATURE, average_temperature, 4), f"Average temperature should be {AVERAGE_TEMPERATURE} " f"degrees celsius, but is {average_temperature} " "degrees celsius")
def processtemp(amount, inputunit, outputunit): degrees = Temperature(temperature=amount, system=inputunit) if outputunit == 'celsius': printtemperature(temp=degrees.celsius(), unit=outputunit) elif outputunit == 'fahrenheit': printtemperature(temp=degrees.fahrenheit(), unit=outputunit) elif outputunit == 'kalvin': printtemperature(temp=degrees.kalvin(), unit=outputunit) elif outputunit == 'rankine': printtemperature(temp=degrees.rankine(), unit=outputunit)
def test_notequal(self): t1 = Temperature() t2 = Temperature("273.15k") t3 = Temperature("32F") t4 = Temperature("100") t5 = Temperature("100F") self.assertEquals(t1 != t2, False) self.assertEquals(t1 != t3, False) self.assertEquals(t2 != t3, False) self.assertEquals(t3 <> t4, True) self.assertEquals(t3 <> t5, True) self.assertEquals(t4 <> t5, True)
def test_equal(self): t1 = Temperature() t2 = Temperature("273.15k") t3 = Temperature("32F") t4 = Temperature("100") t5 = Temperature("100F") self.assertEquals(t1 == t2, True) self.assertEquals(t1 == t3, True) self.assertEquals(t2 == t3, True) self.assertEquals(t3 == t4, False) self.assertEquals(t3 == t5, False) self.assertEquals(t4 == t5, False)
def test_less_than_or_equal(self): t1 = Temperature() t2 = Temperature("273.15k") t3 = Temperature("32F") t4 = Temperature("100") t5 = Temperature("100F") self.assertEquals(t1 <= t2, True) self.assertEquals(t1 <= t3, True) self.assertEquals(t2 <= t3, True) self.assertEquals(t5 <= t3, False) self.assertEquals(t4 <= t1, False) self.assertEquals(t4 <= t2, False)
def test_less_than(self): t1 = Temperature() t2 = Temperature("273.15k") t3 = Temperature("32F") t4 = Temperature("100") t5 = Temperature("100F") self.assertEquals(t1 < t2, False) self.assertEquals(t1 < t3, False) self.assertEquals(t2 < t3, False) self.assertEquals(t5 < t3, False) self.assertEquals(t3 < t5, True) self.assertEquals(t1 < t4, True)
def task1(): count = 0 while True: t = Temperature() _t = t.get_value() r.publish('temperature', _t) count += 1 print 'count: ', count print 'temperature: ', _t gevent.sleep(0)
def test_greater_than(self): t1 = Temperature() t2 = Temperature("273.15k") t3 = Temperature("32F") t4 = Temperature("100") t5 = Temperature("100F") self.assertEquals(t1 > t2, False) self.assertEquals(t1 > t3, False) self.assertEquals(t2 > t3, False) self.assertEquals(t4 > t1, True) self.assertEquals(t4 > t3, True) self.assertEquals(t5 > t3, True)
def test_greater_than_or_equal(self): t1 = Temperature() t2 = Temperature("273.15k") t3 = Temperature("32F") t4 = Temperature("100") t5 = Temperature("100F") self.assertEquals(t1 >= t2, True) self.assertEquals(t1 >= t3, True) self.assertEquals(t2 >= t3, True) self.assertEquals(t3 >= t4, False) self.assertEquals(t3 >= t5, False) self.assertEquals(t5 >= t4, False)
def handle(self, *args, **options): mTemp = Temperature(0) wTemp = Temperature(2) ws = create_connection("ws://127.0.0.1:8000/ws/") while True: #self.stdout.write(temp.getTemp()) # print(temp.getTemp()) m = mTemp.getTemp() Group("mTemp").send({'text': str(m)}) ws.send(str(m)) # Group("wTemp").send({'temp': wTemp.getTemp()}) time.sleep(5)
def temperature(): # TODO request shouldn't be forwarded to application code temp = Temperature(request) if request.args.get("accuracy"): temp.set_accuracy(int(request.args.get("accuracy"))) # TODO db_session is temporary here if request.method == 'GET': return temp.process_get(self.db_session) elif request.method == 'POST': return temp.process_post(self.db_session)
def task1(): count = 0 r = redis.Redis(host='localhost', port=6379, db=0) while True: t = Temperature() _t = t.get_value() r.set('temperature', _t) count += 1 print 'count: ', count print 'temperature: ', _t gevent.sleep(0)
def test_6(self): Temperature.set_default_scale("f") t1 = Temperature("1") t2 = Temperature("2") t3 = t1 + t2 t4 = t2 + t3 t5 = t3 + t4 for i in range(1, 6): self.assertEquals(str(eval("t"+str(i)))[-1], "F") self.assertEquals(t1.dvalue, 1) self.assertEquals(t2.dvalue, 2) self.assertEquals(t3.dvalue, 3) self.assertEquals(t4.dvalue, 5) self.assertEquals(t5.dvalue, 8)
def test_6(self): Temperature.set_default_scale("k") t1 = Temperature("10") t2 = Temperature("20") t3 = t1 - t2 t4 = t2 - t3 t5 = t3 - t4 for i in range(1, 6): self.assertEquals(str(eval("t" + str(i)))[-1], "K") self.assertEquals(t1.dvalue, 10) self.assertEquals(t2.dvalue, 20) self.assertEquals(t3.dvalue, -10) self.assertEquals(t4.dvalue, 30) self.assertEquals(t5.dvalue, -40)
def test_6(self): Temperature.set_default_scale("k") t1 = Temperature("10") t2 = Temperature("20") t3 = t1 - t2 t4 = t2 - t3 t5 = t3 - t4 for i in range(1, 6): self.assertEquals(str(eval("t"+str(i)))[-1], "K") self.assertEquals(t1.dvalue, 10) self.assertEquals(t2.dvalue, 20) self.assertEquals(t3.dvalue, -10) self.assertEquals(t4.dvalue, 30) self.assertEquals(t5.dvalue, -40)
def test_6(self): Temperature.set_default_scale("f") t1 = Temperature("1") t2 = Temperature("2") t3 = t1 + t2 t4 = t2 + t3 t5 = t3 + t4 for i in range(1, 6): self.assertEquals(str(eval("t" + str(i)))[-1], "F") self.assertEquals(t1.dvalue, 1) self.assertEquals(t2.dvalue, 2) self.assertEquals(t3.dvalue, 3) self.assertEquals(t4.dvalue, 5) self.assertEquals(t5.dvalue, 8)
def __init__(self, buss_id, address): self.gyro = Gyroscope(buss_id, address) self.gyro_full_scale = 245 self.acc = Accelerometer(buss_id, address) self.acc_full_scale = 2 self.fifo = Fifo(buss_id, address) self.temp = Temperature(buss_id, address)
def split_serial_values(string): data = str(string).split("'")[1] data = str(data).split("\\")[0] #values = list(filter(None, data)) variable = data.split(':')[1] temperature_real = variable global c c += 0.5 if (c >= 10): Temperature.add(temperature_real) print(temperature_real) c = 0 Temperature.log_realtime print(c) print(temperature_real)
def main(): # Setup the Rasp.IO LED Strings ledstrip = apa.Apa(led_config.numleds) # initiate an LED strip ledstrip.zero_leds() ledstrip.write_leds() clock = ClockRing(ledstrip) clock.start() # Set up the handler class handlerclass = Temperature(ledstrip) # Start MQTT Listener Messages.MQTTMessages(config.mqttconfig, handlerclass) handlerclass.start() pause()
def __init__(self, name, service, view, data, caller): Subject.__init__(self) self.observers = [] self.name = name self.caller = caller self.temperature = Temperature(None) self.rainfall = Rainfall(None) self.timestamp = None self.datestamp = None self.serviceType = service self.viewType = view self.dataType = data self.client = None self.timer = None self.setupClient()
def get_weather(request): town = request.matchdict.get('town', 'Paris') temp_per = Temperature.get_by(city=town) temp = 0 if temp_per: temp = temp_per.temperature else: d = weather.get_weather(town) temp = d[u'data'][u'current_condition'][0][u'temp_C'] temp_per = Temperature(city=town, temperature=temp) temp_per.save() return Response(""" <div style="text-align: center"> <div style="font-size: 72px">{}</div> <div style="font-size: 144px">{}°C</div> <div style="font-size: 24px">Current temperature</div> </div>"""\ .format(town, temp))
class Observation: """""" def __init__(self, latitude=None, longitude=None, temperature=None, precipitation=None, humidity=None, wind=None): """""" if temperature is None: self.temperature = Temperature() else: # TODO type check on input self.temperature = temperature # Feels like, unit self.humidity = None self.summary = None self.icon = None self.date_time = None self.latitude = latitude # TODO input validation self.longitude = longitude # TODO input validation self.altitude = None if precipitation is None: self.precipitation = Precipitation() else: # TODO type check on input self.precipitation = precipitation # TODO type check on input self.humidity = Reading(humidity, "%") if wind is None: self.wind = Wind() else: # TODO type check on input self.wind = wind self.cloud_cover = None self.moon_phase = None self.uv_index = None self.is_daytime = None self.alerts = [] self.unix = None def __str__(self): """""" # TODO handle empty location / time # TODO replace with parameters list return "<Observation lat/lon=" + str(self.latitude) + "/" + str( self.longitude) + " @" + str(self.date_time) + ">" def __repr__(self): """""" return '{is_daytime=' + self.is_daytime + ', precip_intensity=' + str( self.precipitation) + ', temperature=' + str( self.temperature) + ', feels_like=' + str( self.temperature.feels_like()) + '}'
def __init__(self): # self.URL = "http://192.168.179.227:5001" self.URL = "https://pruetpiflask.azurewebsites.net" self.token = self.login() self.temp_sensor = Temperature() self.outlets = Power() self.tz = pytz.timezone('US/Central') # default state self.state = { "Temperature": 0, "pH": 0, "Light_UV_On": True, "Light_Refugium_On": True, "GasInjection_On": True, "Heater_On": True, "Pump_Power": 3 } asyncio.run(self.main())
def convert_unit(self, value, input_unit, output_unit): if self.measurement is 'length': return Length(value, input_unit, output_unit).convert() if self.measurement is 'temperature': return Temperature(value, input_unit, output_unit).convert() if self.measurement is 'area': return Area(value, input_unit, output_unit).convert() if self.measurement is 'volume': return Volume(value, input_unit, output_unit).convert() if self.measurement is 'weight': return Weight(value, input_unit, output_unit).convert() return "Not a valid measurement is entered! Select from : length, temperature, volume, area, weight"
def __init__(self, latitude=None, longitude=None, temperature=None, precipitation=None, humidity=None, wind=None): """""" if temperature is None: self.temperature = Temperature() else: # TODO type check on input self.temperature = temperature # Feels like, unit self.humidity = None self.summary = None self.icon = None self.date_time = None self.latitude = latitude # TODO input validation self.longitude = longitude # TODO input validation self.altitude = None if precipitation is None: self.precipitation = Precipitation() else: # TODO type check on input self.precipitation = precipitation # TODO type check on input self.humidity = Reading(humidity, "%") if wind is None: self.wind = Wind() else: # TODO type check on input self.wind = wind self.cloud_cover = None self.moon_phase = None self.uv_index = None self.is_daytime = None self.alerts = [] self.unix = None
def test_4_kelvin(self): """Test if kelvin property exists and is computed properly.""" for temp_value, kelvin in zip(VALID_TEMPERATURES, KELVINS): temperature = Temperature(temp_value) try: self.assertTrue( equal_to_n_decimal_places(temperature.kelvin, kelvin, 4), f"Temperature temperature initialized with " f"{temp_value} should have temperature.kelvin " f"= {kelvin}, but it is " f"{temperature.kelvin}") except AttributeError: self.fail(f"Temperature instance has no property " "kelvin.")
def test_2_inits(self): """Test if the initializer properly sets celsius.""" for temp_value, celsius in zip(VALID_TEMPERATURES, DEGREES_celsius): temperature = Temperature(temp_value) try: self.assertTrue( equal_to_n_decimal_places(temperature.celsius, celsius, 4), f"Temperature temperature initialized with " f"{temp_value} should have temperature.celsius" f" = {celsius}, but it is " f"{temperature.celsius}") except AttributeError: self.fail(f"Temperature instance has no attribute " "celsius.")
def controlG(stop_event, arg): status = 0 while not stop_event.is_set(): temp = Temperature().getGlassT() if temp > 31 and status == 1: GPIO.output(20, True) status = 0 print "Glass OFF" elif temp < 29 and status == 0: GPIO.output(20, False) status = 1 print "Glass ON" time.sleep(10) print ("Thread killed: %s" % arg)
def controlC(stop_event, arg): status = 0 while not stop_event.is_set(): temp = Temperature().getConductT() if temp > 51 and status == 1: GPIO.output(16, True) status = 0 print "Conduct OFF" elif temp < 49 and status == 0: GPIO.output(16, False) status = 1 print "Conduct ON" time.sleep(10) print ("Thread killed: %s" % arg)
class Minimu: VERSION = 'minimu9v5' def __init__(self, buss_id, address): self.gyro = Gyroscope(buss_id, address) self.gyro_full_scale = 245 self.acc = Accelerometer(buss_id, address) self.acc_full_scale = 2 self.fifo = Fifo(buss_id, address) self.temp = Temperature(buss_id, address) def enable(self, odr=104): self.gyro.enable(odr) self.gyro_full_scale = self.gyro.get_full_scale_selection() self.acc.enable(odr) self.acc_full_scale = self.acc.get_full_scale_selection() self.fifo.enable(odr) def disable(self): self.gyro.disable() self.acc.disable() self.fifo.disable() def read_fifo_raw(self): data = np.array(self.fifo.get_data(), dtype=np.int) return data def read_fifo(self): data = np.array(self.fifo.get_data(), dtype=np.double) try: data[:, :3] *= 1 except IndexError: sleep(0.1) data = np.array(self.fifo.get_data(), dtype=np.double) data[:, :3] *= self.gyro_full_scale data[:, -3:] *= self.acc_full_scale data[data > 0] /= 32767 data[data < 0] /= 32768 return data def read_temperature(self): return self.temp.get_temperature()
def test_k2k(self): self.assertEquals(Temperature.k2k(100), 100)
def test_2(self): t = Temperature("32.F") self.assertEquals(t.dvalue, 32) t.dscale = "C" self.assertEquals(t.dvalue, 0)
def test_3(self): t = Temperature("0k") self.assertEquals(t.dvalue, 0) t.dscale = "c" self.assertEquals(t.dvalue, -273.15)
def test_1(self): t = Temperature("100c") self.assertEquals(t.scale, "C") t.scale = "k" self.assertEquals(t.scale, "K")
def tearDown(self): Temperature.set_default_scale(self.__oldDefaultScale)
def test_1(self): t = Temperature("100C") with self.assertRaises(TypeError): t.value = [1, 2]
def test_2(self): t = Temperature() with self.assertRaises(ValueError): t.value = "30h"
def test_type_error3(self): # not a str with self.assertRaises(TypeError): Temperature.set_default_scale(6)
def setUp(self): Temperature.set_default_scale("C")
def test_value_error2(self): # not a single char str with self.assertRaises(ValueError): Temperature.set_default_scale("")
def test_C(self): Temperature.set_default_scale("C") self.assertEquals(Temperature.DEFAULT_SCALE, 'C')
def test_value_error3(self): # not in ["c", "C", "f", "F", "k", "K"] with self.assertRaises(ValueError): Temperature.set_default_scale("a")
def test_1(self): t = Temperature("-50.5F") self.assertEquals(t.value, -50.5) t.value = "90k" self.assertEquals(t.value, 90)
def test_2(self): Temperature.set_default_scale("F") t = Temperature(32) self.assertEquals(str(t), "32F") t.scale = "c" self.assertEquals(t.scale, "C")
def get_temperature_demo(): tempc = Temperature(sense) # theoretically this should return the temperature in celsius from the sensehat print(tempc.temperature_c()) # it is untested however.
def test_1(self): t = Temperature(100) self.assertEquals(t._Temperature__scale, Temperature.DEFAULT_SCALE) t.scale = "k" self.assertEquals(t._Temperature__scale, "K")
def test_2(self): t = Temperature("32F") t.dscale = "c" t -= 32. self.assertEquals(t.value, 0)
def setUp(self): self.__oldDefaultScale = Temperature.DEFAULT_SCALE Temperature.set_default_scale("C")
def read(self, path=None): #f6 01 4b 46 7f ff 0a 10 eb : crc=eb YES #f6 01 4b 46 7f ff 0a 10 eb t=31375 path = self.path if not path else path temperature = Temperature() try: sensor = open(path, "r") data = sensor.readlines() sensor.close() if data[0].strip()[-3:] == "YES": equals_pos = data[1].find("t=") if equals_pos != -1: temperature.set_data(data[1][equals_pos+2:]) else: raise IndexError else: raise IndexError except IndexError: print 'sensor read error' #temperature.set_error(index) except IOError: print 'sensor not connected' #temperature.set_error(io) except: print 'error' #temperature.set_error(other) return temperature