def import_logs(mode): edit = False if request.json: for key,value in request.items(): if key == "edit": if value == "1": edit = True return jsonify(DataManager().import_logs(mode, edit))
def update_alarm_limit(request): for key, value in request.items(): if key.startswith("low_"): key2 = key[4:] alarm[key2].change_limit("low", request[key]) print("change alarm success!") if key.startswith("high_"): key2 = key[5:] alarm[key2].change_limit("high", request[key]) print("change alarm success!")
def login(): if request.method == 'GET': datas = request.items() for data in datas: print(data.get('user','')) print(data.get('password','')) return '' if request.method == 'POST': # 遍历参数 return render_template('login.html', name=request.form.get('name', ''), password=request.form.get('password', ''))
def update_shed_request(request): # update shed request from webpage input for key, value in request.items(): key_fixed = key[:5] shed_status[key_fixed].change_request(value) shed_status[key_fixed].update_state() #Below required for Deadhead prevention print(shed_status[key_fixed].configs[shed_status[key_fixed].state]) for key2, value2 in shed_status[key_fixed].configs[ shed_status[key_fixed].state].items(): if "Pump" in key2: key3 = "Valve" + key2[4:] deadhead[key3].state = value daq.write_channels(shed_status[key_fixed].new_state_output()) if shed_status["SHED1"].state == shed_status["SHED2"].state == shed_status[ "SHED3"].state == "off": daq.write_channels(all_off)
def get_actual_price(ticket): request = dict() act = Actives.query.filter(Actives.ticket == ticket).all() try: request = fm.get_actual_crypto(act, request) except: pass try: request = fm.get_actual_shares(act, request) except: pass request = { name: fm.correct_price(price) for name, price in request.items() } return request
def get_actual_prices(): request = dict() crypto = fm.get_actives('crypto', 'bought') request = fm.get_actual_crypto(crypto, request) shares = fm.get_actives('shares', 'bought') try: request = fm.get_actual_shares(shares, request) except: request = request print(request) request = { name: fm.correct_price(price) for name, price in request.items() } print(request) return request
def select_keys(request={}, l=[]): return dict((k,v) for (k,v) in request.items() if k in l)
def get_request_params(request, exclude=''): params = '' for name, param in request.items(): if name != exclude: params += f'{name}={param}&' return params
def submit(): form = MyForm() if form.validate_on_submit(): genre = form.dropdown.data file = form.file.data if file and allowed_file(file.filename): filename = secure_filename(file.filename) file.save(os.path.join(filename)) else: flash('mp3 file format is required') return redirect('/') if genre == 'Pop': directory = 'music/Pop' index = joblib.load('index_pop.pkl') elif genre == 'Hiphop': directory = 'music/Hiphop' index = joblib.load('index_hiphop.pkl') elif genre == 'Folk': directory = 'music/Folk' index = joblib.load('index_folk.pkl') elif genre == 'Rock': directory = 'music/Rock' index = joblib.load('index_rock.pkl') else: directory = 'music' index = joblib.load('index_all.pkl') path_f = [] for d, dirs, files in os.walk(directory): audio = filter(lambda x: x.endswith('.mp3'), files) for f in audio: path = os.path.join(d, f) # формирование адреса path_f.append(path) # добавление адреса в список # print(path_f) def read_and_resample(path, sample_rate): # read and resample to 22KHz y, sr = librosa.load(path, sr=sample_rate) # print(f"{path}") return y sample_rate = 22050 # reading request audio request_data = read_and_resample(filename, sample_rate) # Let's make and display a mel-scaled power (energy-squared) spectrogram S = librosa.feature.melspectrogram(request_data, sr=sample_rate, n_mels=128) neighborhood_size = 10 # sec/sample - constant for all files wav = request_data time_resolution = (wav.shape[0] / sample_rate) / S.shape[1] # print("Time resolution:", time_resolution) def form_constellation(wav, sample_rate): S = librosa.feature.melspectrogram(wav, sr=sample_rate, n_mels=256, fmax=4000) S = librosa.power_to_db(S, ref=np.max) # get local maxima Sb = maximum_filter(S, neighborhood_size) == S Sbd, num_objects = ndimage.label(Sb) objs = ndimage.find_objects(Sbd) points = [] for dy, dx in objs: x_center = (dx.start + dx.stop - 1) // 2 y_center = (dy.start + dy.stop - 1) // 2 if (dx.stop - dx.start) * (dy.stop - dy.start) == 1: points.append((x_center, y_center)) # print(len(points)) return sorted(points) request_constellation = form_constellation(request_data, sample_rate) target = (int(1 / time_resolution), int(3 / time_resolution), -30, 30) # start, end, Hz low, Hz high def build_constellation_index(constellation_collection, target): result_index = {} for name, points in constellation_collection.items(): # print(name) for point in points: f1 = point[1] tg = [p for p in points if point[0] + target[0] <= p[0] < point[0] + target[1] and point[1] + target[2] <= p[1] < point[1] + target[3] ] for p in tg: f2 = p[1] dt = p[0] - point[0] t = p[0] if (f1, f2, dt) in result_index: result_index[(f1, f2, dt)].append((t, name)) else: result_index[(f1, f2, dt)] = [(t, name)] return result_index request = build_constellation_index({filename: request_constellation}, target) # print(path_f) times = dict((name, []) for name in path_f) for key, v in request.items(): if key in index: for t_r, name_r in v: for pair in index[key]: t_i, name_i = pair times[name_i].append(t_i - t_r) # print(times) result = [] for name, matches in times.items(): if matches: result.append((name, max(matches))) # print(result) result_sorted = sorted(result, key=lambda x: x[1], reverse=True) output = result_sorted[0][0] output1 = output.split('/') output2 = output1[2].split('.mp3') final_result = output2[0] # print(final_result) return redirect(url_for('result', result=final_result)) return render_template('submit.html', form=form)