def onThermostatValueWork(msg): try: msg.payload = msg.payload.decode("utf-8") value = utils.parseFloat(msg.payload) tags = utils.getTags(msg.topic) except: logger.error( f'The message: "{msg.payload}" cannot be processed. Topic: "{msg.topic}" is malformed. Ignoring data' ) return try: fields = {tags["endpoint"]: value} tagsToSave = ["locationId", "sensorId"] measurement = "thermostatData" influxDb.writeData( measurement, utils.selectTags(tagsToSave, tags), fields, retentionPolicy="3years", ) except: logger.error( f"onThermostatValueWork message failed. message: {msg.payload}. Exception: ", exc_info=True, )
def onStatusWork(msg): try: msg.payload = msg.payload.decode("utf-8") status = utils.decodeStatus(msg.payload) tags = utils.getTags(msg.topic) except: logger.error( f'The message: "{msg.payload}" cannot be processed. Topic: "{msg.topic}" is malformed. Ignoring data', extra={"area": "status"}, ) return try: fields = {"status": status} tagsToSave = ["locationId", "deviceId"] measurement = "sensorsData" influxDb.writeData( measurement, utils.selectTags(tagsToSave, tags), fields, retentionPolicy="3years", ) except: logger.error( f"onStatusWork message failed. message: {msg.payload}. Exception: ", exc_info=True, extra={"area": "status"}, )
def onValueWork(msg): # Avoid string values as mathematical operations cant # be made afterwards try: msg.payload = msg.payload.decode("utf-8") value = utils.parseFloat(msg.payload) tags = utils.getTags(msg.topic) except: logger.error( f'The message: "{msg.payload}" cannot be processed. Topic: "{msg.topic}" is malformed. Ignoring data', extra={"area": "value"}, ) return try: fields = {"value": value} tagsToSave = ["locationId", "sensorId"] measurement = "sensorsData" influxDb.writeData( measurement, utils.selectTags(tagsToSave, tags), fields, retentionPolicy="raw", ) except: logger.error( f"onValueWork message failed. message: {msg.payload}. Exception: ", exc_info=True, extra={"area": "value"}, )
def local(): file = request.files['file'] if file and checkFile(file.filename): fn = request.form['filename'] name = stripPunctuation(fn) ext = file.filename.rsplit('.',1)[1] filename = secure_filename(name+"."+ext) filename = repeatedName(filename,0,False) file.save(os.path.join(path,filename)) uid = user.get_UID(session['username']) link = utils.uploadPic (os.path.join(path,filename)) tags = utils.getTags(link, Access_token) stringTags=",".join(tags) user.add_pic(os.path.join(path,filename),uid,fn,stringTags) return render_template("index.html",username=session['username'],message="Image Uploaded!",category="success") return render_template("upload.html",upload="True",message="Invalid File",category="danger")
def preprocess(filename, genre=None): workbook = xlrd.open_workbook(filename) # 读取excel文件 sheet_names = workbook.sheet_names() # 获取表格名 sheet = workbook.sheet_by_name(sheet_names[0]) # 获取第i-1张表格数据 clean_train_reviews = [] for i in range(1, sheet.nrows): if ((i + 1) % 100 == 0): print("Review %d of %d\n" % (i + 1, sheet.nrows)) clean_train_reviews.append(plotToWords(sheet.row_values(i)[1])) tagVector = getTags(genre, sheet) data = {'plot': clean_train_reviews, 'tags': tagVector} df = pd.DataFrame(data) return df
def web(): if checkFile(request.form['link']): ext = request.form['link'].rsplit('.',1)[1] response = urllib.urlopen(request.form['link']) image = response.read() filename = stripPunctuation(request.form['filename'])+"."+ext filename = secure_filename(filename) filename = repeatedName(filename,0,False) uid = user.get_UID(session['username']) with open(path+"/"+filename,"wb") as out: out.write(image) link = utils.uploadPic (os.path.join(path,filename)) tags = utils.getTags(link, Access_token) stringTags=",".join(tags) user.add_pic(os.path.join(path,filename),uid,request.form['filename'],stringTags) return render_template("index.html",username=session['username'],message="Image Uploaded!", category="succe\ ss") return render_template("upload.html",upload="True",message="Invalid File",category="danger")
def preprocess(filename): train = pd.read_csv(filename) # counts = train.Genre1.value_counts() # counts.plot(kind='bar') # plt.show() # print counts num_reviews = train["Plot"].size clean_train_reviews = [] for i in range(0, num_reviews): if ((i + 1) % 100 == 0): print ("Review %d of %d\n" % (i + 1, num_reviews)) clean_train_reviews.append(plotToWords(train["Plot"][i])) tagVector = getTags('Comedy', train) data = {'plot': clean_train_reviews, 'tags': tagVector} df = pd.DataFrame(data) return df
def onDeviceDataWork(msg): try: msg.payload = msg.payload.decode("utf-8") data = msg.payload assert data tags = utils.getTags(msg.topic) except: logger.error( f'The message: "{msg.payload}" cannot be processed. Topic: "{msg.topic}" is malformed. Ignoring data', extra={"area": "IP"}, ) return match tags["endpoint"]: case "ip": fields = {"ip": data} case "model": fields = {"model": data} case "version": fields = {"version": data} case _: logger.error( f"Endpoint: '{tags['endpoint']}' not recognized. Topic: {msg.topic}. Ignoring data") return try: tagsToSave = ["locationId", "deviceId"] measurement = "devicesData" influxDb.writeData( measurement, utils.selectTags(tagsToSave, tags), fields, retentionPolicy="raw", ) except: logger.error( f"onIPWork message failed. message: {msg.payload}. Exception: ", exc_info=True )