def cf_flat_plate(Re, Mach, Altitude): xt = 0.05 T = temperature(Altitude) #Transition Rex = Re * xt if Rex <= 0: Rex = 0.0001 theta = .671 * xt / np.sqrt(Rex) xeff = (27.78 * theta * (Re**0.2))**1.25 Rext = Re * (1 - xt + xeff) Cfturb = 0.455 / ((np.log10(Rext))**2.58) # Original formula # Cfturb = 0.455/(((log10(Rext))^2.58)*((1+0.144*Mach*Mach)^0.65)) Cflam = 1.328 / np.sqrt(Rex) Cfstart = 0.455 / ((np.log10(Re * xeff))**2.58) cfval = Cflam * xt + Cfturb * (1 - xt + xeff) - Cfstart * xeff # Mach Effects Tw = 1.0 + .178 * Mach * Mach T1 = 1.0 + .035 * Mach * Mach + .45 * (Tw - 1) # mu1 = (T1**1.5) * (T + 216) / (T * T1 + 216) R1 = 1 / (mu1 * T1) CfRatio = 1 / (T1 * (R1**0.2)) cf_val = cfval * CfRatio # fprintf('\n Mach = #4.2f \n Altitude = #i ft \n Transition at #5.3f \n',Mach,Altitude,xt) # fprintf('\n cf = #7.5f \n',cfval) return (cf_val)
def get_temperature(self, outpath): """ :param outpath: path to out file with temperature values :return: set self.temperature, nothing """ # print status print 'Calculate temperature..' # set self.temperature self.temperature = temperature.temperature(self.k2, self.k1, self.rad) # save raster to out path save.saveRaster(outpath, self.path, self.temperature) # print status print 'Calculate temperature done!'
def temperature(self): # Temperature right now temp = round(temperature().getTemp(), 2) # Maximum and minimum temperatures max_temp = data["max_temperature"] min_temp = data["min_temperature"] # Comparing current temperature to min and max if temp > max_temp: result = ("Bad: "+ str(temp - max_temp) + "*C above maximum temperature.") if temp < min_temp: result = ("Bad: "+ str(min_temp - temp) + "*C under minimum temperature.") if (temp < max_temp) and (temp > min_temp): result = ("OK.") return result
def main(): blueConn = bluetooth pushbullet = pushbulletMessage() nearby_devices = blueConn.discover_devices() temp = temperature().getTemp() humid = humidity().getHumid() while (humid == 0): humid = humidity().getHumid() message = "Temperature is " + str(temp) + "*C and Humidity is " + str( humid) + "%" p = str(check_output(["bt-device", "--list"])) start = p.find("(") end = p.find(")") macAdd = p[start + 1:end] while (True): for macAddresses in nearby_devices: nearby_devices = blueConn.discover_devices() if macAdd == macAddresses: pushbullet.push_note("Raspberry Pi", message) time.sleep(600)
#t1 = Thread(target=pulse,args=("",s)) #t2 = Thread(target=temperature,args=("",s)) #t1.start() #t2.start() while True: a=array('i',[0,0,0,0,0,0,0,0]) v=0 for i in range(2,10): #runs from 2 to 9 inp=GPIO.input(i) v=v*2+inp a[i-2]=inp flag = 0 for i in range(10,12): #runs from 10 to 11 flag=flag*2+GPIO.input(i) print(str(v)+"#t"+str(flag)) print(a) if flag is 0: temperature(v,s) else: if flag is 1: pulse(v,s) time.sleep(1) s.close
def chat(): # keyword conditions condnext = False condweather = False condtime = False condlocation = False condtemp = False condkey = False condresponse = False foundinfo = False condtrain = False condcountry = False condspellcheck = True # global variables conversation = [] location = '' prevlocation = location time = 'today' key = '' keytemplate = [] fulltime = '' numdays = '' logstr = '' printstr = '' responsedict = {} # Dictionary to hold all inputs without predefined responses. This dictionary will be written into predefined_responses.txt before exiting the program. # read data files citylist = readfile.readfile('cities.txt') keylist = readfile.readfile('keywords.txt') timelist = readfile.readfile('time.txt') condlist = readfile.readfile('conditions.txt') numlist = readfile.readfile('numbers.txt') countrylist = readfile.readfile('countries.txt') exitlist = ['exit', 'quit', 'bye', 'ok'] # Greeting message printstr = 'Hello! You can ask me questions about the weather in any major city in the world. What would you like to know?' print printstr logstr += '\n\n' + printstr # Start main loop while True : foundinfo = False condtrain = False condcountry = False # read input from user input = raw_input('\nMe > ') logstr += '\nMe > ' + input + '\nBot > ' if input in exitlist: if input == 'ok': exitans = raw_input("Do you want to quit? (y/n)") if exitans in ('y','Y','Yes','YES','yes'): break else: continue break if input == 'disable spellcheck': condspellcheck = False continue if input == 'enable spellcheck': condspellcheck = True continue condcorrected = False if condspellcheck: corrected_input = '' for i in input.split(): str = spellcheck.correct(i) if str != i: condcorrected = True corrected_input += str + ' ' if condcorrected: print 'did you mean: \"' + corrected_input + '\"?' input = corrected_input currentstring = input.split() conversation.append(currentstring) # Start searching input for each of the keywords if input == 'train': condtrain = True printstr = 'Entering training mode. Enter input and response seperated by a "|": input|response. Type "exit" to quit training mode' print printstr logstr += '\n' + printstr + '\n' while True: traininput = raw_input('>') if traininput == 'exit': break if traininput.find('|') < 0: printstr = 'Format error: use input|response' print printstr logstr += '\n' + printstr + '\n' continue traininput = traininput.split('|') responsedict[traininput[0]] = traininput[1] if condtrain: continue for i in countrylist: for j in currentstring: if lower(i[0]) == lower(j): printstr = 'Which city in ' + i[0] + '?' condcountry = True foundinfo = True break if condcountry: print printstr logstr += printstr continue if 'next' in input: foundinfo = True condnext = True condtime = False numdays = currentstring[currentstring.index('next') + 1] for i in numlist: if numdays == i[0]: numdays = i[1] break if re.match('[0-9]*$',numdays): numdays = int(numdays) else: numdays = '' if 'weather' in input: foundinfo = True condweather = True condkey = False condtemp = False key = '' keytemplate = [] # get key from input for i in keylist: if i[0] in input: if 'sunday' in lower(input) and i[0] == 'sun': break else: foundinfo = True condkey = True condweather = False condtemp = False key = i[0] keytemplate = i break # get time from input for i in timelist: if lower(i[0]) in input: foundinfo = True condtime = True numdays = '' if lower(i[0]) != 'today' and lower(i[0]) != 'tomorrow': time = i[1] fulltime = i[0] break else: time = i[0] fulltime = time break if fulltime == '': fulltime = time if numdays != '': condtime = True if numdays > 4: printstr = 'Forecast is available only for the next 4 days.' print printstr logstr += '\n' + printstr + '\n' else: time = '' fulltime = '' count = numdays # get location from input for i in citylist: if lower(i[0]) in input: foundinfo = True condlocation = True location = i[0] break # find if a new location has been mentioned. if not, don't fetch data again if location != prevlocation: newlocation = True condlocation = True prevlocation = location else: newlocation = False if location is '': if prevlocation is '': condlocation = False else: location = prevlocation newlocation = False location = location.replace(' ','-') #Google requires a '-' in 2-word city names result = False # get temperature from input if 'temperature' in input: foundinfo = True condtemp = True # User gave no infomation about weather. Switching to general predefined response based chat if not foundinfo: response = predefined_responses.respond(input, responsedict) if response == '': printstr = "I don't know what that means. If I asked you the same question, what would you reply?" print printstr logstr += printstr responseinput = raw_input('Me > ') logstr += '\nMe > ' + responseinput if not responseinput in ('exit', 'quit'): responsedict[input] = responseinput print 'response learnt' else: printstr = response print printstr logstr += printstr continue if condlocation: if newlocation: #If location hasn't changed, don't fetch data again. It's already available printstr = 'Fetching weather information from Google...' print printstr logstr += printstr # Call Google weather to get current weather conditions google_result = weather.get_weather(location) if google_result == {}: print 'Could not get data from google.' continue # We have a valid location. Get further information # User has asked about temperature. Return temperature information and continue if condtemp: printstr = temperature.temperature(google_result, time) print printstr logstr += printstr continue # User has asked about a specific weather condition. Print information. There are 2 possibilities: # 1. Find the condition in the next n days # 2. Find the condition in a specified day if condkey: # 1. User has asked about a specific condition in the 'next x days'. Return appropriate response printstr = '' timecounter = 0 day_of_week = '' condition = '' if numdays != '': for i in google_result['forecasts']: count -= 1 if count < 0: break if key in lower(i['condition']): result = True day_of_week = i['day_of_week'] condition = i['condition'] break for i in timelist: if i[0] != 'today' and i[0] != 'tomorrow': if i[1] == day_of_week: fulltime = i[0] break if result: printstr = keytemplate[3] + keytemplate[0] + ' on ' + fulltime else: printstr = keytemplate[4] + keytemplate[0] + ' in the next ' + str(numdays) + ' days.' print printstr logstr += printstr continue # 2. User has asked about a particular condition on a particular day. Return appropriate response if time != 'today' and time != 'tomorrow': for i in google_result['forecasts']: if i['day_of_week'] == time: if key in lower(i['condition']): printstr = keytemplate[3] + keytemplate[0] + ' on' else: printstr = keytemplate[4] + keytemplate[0] + ' on' elif time == 'today': fulltime = time if key in lower(google_result['current_conditions']['condition']): printstr = keytemplate[1] + keytemplate[0] else: printstr = keytemplate[2] + keytemplate[0] elif time == 'tomorrow': fulltime = time if key in lower(google_result['forecasts'][1]['condition']): printstr = keytemplate[3] + keytemplate[0] else: printstr = keytemplate[4] + keytemplate[0] printstr = printstr + ' ' + fulltime print printstr logstr += printstr continue # User is asking about today's weather. Print details elif time == '' or time == 'today' : printstr = sentence.sentence(google_result['current_conditions']['condition'], time) printstr += ' ' + fulltime + '. ' + google_result['current_conditions']['humidity'] + ' ' if google_result['current_conditions'].has_key('wind_condition'): printstr += google_result['current_conditions']['wind_condition'] print printstr logstr += printstr continue # User is asking about weather of a particular day. Print details elif time == 'tomorrow': printstr = sentence.sentence(google_result['forecasts'][1]['condition'], time) printstr += ' ' + fulltime print printstr logstr += printstr else: found = False for i in range(4): if google_result['forecasts'][i]['day_of_week'] == time: printstr = sentence.sentence(google_result['forecasts'][i]['condition'], time) printstr += " on" + ' ' + fulltime print printstr logstr += printstr found = True if not found: printstr = "Forecast for " + time + " is not available currently." print printstr logstr += printstr continue else: printstr = 'What\'s the location?' print printstr logstr += printstr # End of outermost while loop. # Print message before exiting program dictcount = 0 for i in responsedict: dictcount += 1 if dictcount > 0: printstr = 'Writing new entries to database...' print printstr logstr += printstr datafile = file('predefined_responses.txt', 'a') for i in responsedict.keys(): trimmedi = re.sub('[^a-zA-Z0-9 ]+','', i) string = trimmedi + '|' + responsedict[i] + '\n' datafile.write(string) log.log(logstr) print 'Ending the program...' print 'Bye!' # End of function chat()
def bot(): conversation = [] location = '' time = 'today' key = '' keytemplate = [] fulltime = '' numdays = '' citylist = readfile.readfile('cities.txt') keylist = readfile.readfile('keywords.txt') timelist = readfile.readfile('time.txt') condlist = readfile.readfile('conditions.txt') numlist = readfile.readfile('numbers.txt') exitlist = ['exit', 'quit', 'bye', 'ok'] print 'Hello! You can ask me questions about the weather in any major city in the world. What would you like to know?' while True : input = raw_input('Me > ') if input in exitlist: break currentstring = input.split() conversation.append(currentstring) if 'next' in currentstring: numdays = currentstring[currentstring.index('next') + 1] for i in numlist: if numdays == i[0]: numdays = i[1] break if re.match('[0-9]*$',numdays): numdays = int(numdays) else: numdays = '' if 'weather' in currentstring: key = '' keytemplate = [] # get key from input for i in keylist: if i[0] in input: key = i[0] keytemplate = i break # get time from input for i in timelist: if lower(i[0]) in input: numdays = '' if lower(i[0]) != 'today' and lower(i[0]) != 'tomorrow': time = i[1] fulltime = i[0] break else: time = i[0] fulltime = time break if fulltime == '': fulltime = time if numdays != '': if numdays > 4: print 'Forecast is available only for the next 4 days.' else: time = '' fulltime = '' count = numdays prevlocation = location #We store previous location to avoid re-fetching data if the location hasn't been changed # Below, we check if any token in the input matches a city name, and if so, set location to that city newlocation = False # get location from input foundLocation = False for i in citylist: if lower(i[0]) in input: location = i[0] foundLocation = True break #if not foundLocation: #if location != '': #print "I didn't find any city name in your input. I'll get you information about " + location # find if a new location has been mentioned. if not, don't fetch data again if location is not prevlocation: newlocation = True if location is '': if prevlocation is '': print 'City not found' else: location = prevlocation newlocation = False location = location.replace(' ','-') #Google requires a '-' in 2-word city names result = False if location is not '': if newlocation: #If location hasn't changed, don't fetch data again. It's already available print 'Fetching weather information from Google...' # Call Google weather to get current weather conditions google_result = weather.get_weather(location) if 'temperature' in currentstring: print temperature.temperature(google_result, time) continue printed = False if key is not '': printstring = '' timecounter = 0 day_of_week = '' condition = '' if numdays != '': for i in google_result['forecasts']: count -= 1 if count < 0: break if key in lower(i['condition']): result = True day_of_week = i['day_of_week'] condition = i['condition'] break for i in timelist: if i[0] != 'today' and i[0] != 'tomorrow': if i[1] == day_of_week: fulltime = i[0] break if result: printstring = keytemplate[3] + keytemplate[0] + ' on ' + fulltime else: printstring = keytemplate[4] + keytemplate[0] + ' in the next ' + str(numdays) + ' days.' print printstring printed = True if not printed: if time != 'today' and time != 'tomorrow': for i in google_result['forecasts']: if i['day_of_week'] == time: if key in lower(i['condition']): printstring = keytemplate[3] + keytemplate[0] + ' on' else: printstring = keytemplate[4] + keytemplate[0] + ' on' elif time == 'today': fulltime = time if key in lower(google_result['current_conditions']['condition']): printstring = keytemplate[1] + keytemplate[0] else: printstring = keytemplate[2] + keytemplate[0] elif time == 'tomorrow': fulltime = time if key in lower(google_result['forecasts'][1]['condition']): printstring = keytemplate[3] + keytemplate[0] else: printstring = keytemplate[4] + keytemplate[0] print printstring, fulltime elif time == '' or time == 'today' : printstring = sentence.sentence(google_result['current_conditions']['condition'], time) print printstring, fulltime, google_result['current_conditions']['humidity'], google_result['current_conditions']['wind_condition'] else : if time == 'tomorrow': printstring = sentence.sentence(google_result['forecasts'][1]['condition'], time) print printstring, fulltime else: found = False for i in range(4): if google_result['forecasts'][i]['day_of_week'] == time: printstring = sentence.sentence(google_result['forecasts'][i]['condition'], time) print printstring, "on", fulltime found = True if not found: print "Forecast for " + time + " is not available currently." else: print 'What\'s the location?' #end of outermost while loop print 'ending the program...' print 'bye!'
foo["status"] = temp.Status(sensor) return foo @app.route("/temp/<sensor>") def getTemperature(sensor): return str(json.JSONEncoder().encode(getDetails(sensor))) @app.route("/temps/") def getTemperatures(): foo = {} for sensor in temp.sensors.keys(): foo[sensor] = getDetails(sensor) return str(json.JSONEncoder().encode(foo)) @app.route("/calibrate/<temperature>") def calibrate(temperature): temperature = float(temperature) for sensor in temp.sensors.keys(): temp.sensors[sensor].Calibrate(temperature) return getTemperatures() if __name__ == "__main__": if os.environ.get("WERKZEUG_RUN_MAIN") == "true": temp = temperature() temp.Start() app.run(host="0.0.0.0", debug=True, threaded=False)
def getTemperatures(self): sql = 'select * from temperature' temperatures = [] for x in self.db.execute(sql): temperatures.append(t.temperature(x[0], x[1])) return temperatures