本文整理汇总了Python中temperature.Temperature类的典型用法代码示例。如果您正苦于以下问题:Python Temperature类的具体用法?Python Temperature怎么用?Python Temperature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Temperature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read
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
示例2: test_1
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")
示例3: test_6
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")
示例4: test_4
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")
示例5: processtemp
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)
示例6: temperature
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)
示例7: task1
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)
示例8: __init__
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)
示例9: get_weather
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))
示例10: setUp
def setUp(self):
self.__oldDefaultScale = Temperature.DEFAULT_SCALE
Temperature.set_default_scale("C")
示例11: test_value_error3
def test_value_error3(self): # not in ["c", "C", "f", "F", "k", "K"]
with self.assertRaises(ValueError):
Temperature.set_default_scale("a")
示例12: test_value_error2
def test_value_error2(self): # not a single char str
with self.assertRaises(ValueError):
Temperature.set_default_scale("")
示例13: test_k2k
def test_k2k(self):
self.assertEquals(Temperature.k2k(100), 100)
示例14: test_type_error3
def test_type_error3(self): # not a str
with self.assertRaises(TypeError):
Temperature.set_default_scale(6)
示例15: test_2
def test_2(self):
t = Temperature("32F")
t.dscale = "c"
t -= 32.
self.assertEquals(t.value, 0)