def voice_analyzer(filename): y, sr = librosa.load(filename, sr=22050) stft = np.abs(librosa.stft(y)) mfccs = np.mean(librosa.feature.mfcc(y=y, sr=sr, n_mfcc=40).T, axis=0) mel = np.mean(librosa.feature.melspectrogram(y, sr=sr).T, axis=0) contrast = np.mean(librosa.feature.spectral_contrast(S=stft, sr=sr).T, axis=0) tonnetz = np.mean(librosa.feature.tonnetz(y=librosa.effects.harmonic(y), sr=sr).T, axis=0) chroma = np.mean(librosa.feature.chroma_stft(S=stft, sr=sr).T, axis=0) features = np.hstack([mfccs, chroma, mel, contrast, tonnetz]) features = features.reshape(1, -1) info = dict() myValue = utils.calc(mel, 3, 4) if (myValue < 1.0): info['gender'] = "Female Speaker" else: info['gender'] = "Male Speaker" return info
def test_calc_fail(self): self.assertEqual(500, calc(10))
def do_GET(self): """This method is called whenever the client invokes the GET method in the HTTP protocol request""" # Print the request line termcolor.cprint(self.requestline, 'green') termcolor.cprint(self.path, "blue") o = urlparse(self.path) path_name = o.path arguments = parse_qs(o.query) print("Resource requested:", path_name) print("Parameters:", arguments) context = {} if path_name == "/": context["n_sequences"] = len(LIST_SEQUENCES) context["list_genes"] = LIST_GENES context["list_operations"] = LIST_OPERATIONS contents = su.read_template_html_file("./html/index.html").render( context=context) elif path_name == "/test": contents = su.read_template_html_file("./html/test.html").render() elif path_name == "/ping": contents = su.read_template_html_file("./html/ping.html").render() elif path_name == "/get": number_sequence = arguments["sequence"][0] contents = su.get(LIST_SEQUENCES, number_sequence) elif path_name == "/gene": gene = arguments["gene"][0] contents = su.gene(gene) elif path_name == "/operation": try: sequence = arguments["sequence"][0] except KeyError: sequence = "" operation = arguments["calculation"][0] if operation == "Info": contents = su.calc(sequence) elif operation == "Rev": contents = su.rev(sequence) elif operation == "Comp": contents = su.comp(sequence) else: contents = su.read_template_html_file("html/error.html").render() # Message to send back to the client # Generating the response message self.send_response(200) # -- Status line: OK! # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(contents.encode())) # The header is finished self.end_headers() # Send the response message self.wfile.write(contents.encode()) return
def test_calc_success(self): self.assertEqual(50, calc(5))
from selenium import webdriver import time from utils import print_answer, calc link = "http://suninjuly.github.io/get_attribute.html" browser = webdriver.Chrome() browser.get(link) try: x_element = browser.find_element_by_id('treasure') x = x_element.get_attribute('valuex') y = calc(x) # Ваш код, который заполняет обязательные поля element = browser.find_element_by_id("answer") element.send_keys(y) option1 = browser.find_element_by_css_selector("input#robotcheckbox") option1.click() option2 = browser.find_element_by_css_selector("#robotsrule") option2.click() # Отправляем заполненную форму button = browser.find_element_by_class_name("btn") button.click() # Проверяем, что смогли зарегистрироваться # ждем загрузки страницы time.sleep(1) print_answer(browser)
from selenium import webdriver from time import sleep from utils import calc, text_to_buffer link = "http://suninjuly.github.io/alert_accept.html" browser = webdriver.Chrome() browser.get(link) try: browser.find_element_by_css_selector("button.btn").click() browser.switch_to.alert.accept() x_value = browser.find_element_by_id("input_value").text answer = calc(int(x_value)) answer_field = browser.find_element_by_id("answer") answer_field.send_keys(answer) browser.find_element_by_css_selector("button.btn").click() text_alert = browser.switch_to.alert.text text_to_buffer(text_alert) finally: sleep(1) browser.quit()
def test_calc_success(self): self.assertEqual(50, calc(5))
def test_calc_fail(self): self.assertEqual(500, calc(10))
timeout_in_seconds = 5 rs485_socket = socket.socket() rs485_socket.connect(("192.168.0.7", 26)) rs485_socket.setblocking(0) address = chr(0x01) function_code = chr(0x06) start_at_reg = chr(0x00) + chr(0x00) num_of_reg = chr(0x00) + chr(0x01) read_device = address + function_code + start_at_reg + num_of_reg print(type(read_device)) print(read_device) crc = calc(read_device) crc_hi = crc / 256 crc_lo = crc & 0xFF print "meter add: " + str(ord(address)) print "crc_lo: " + str(hex(crc_lo)) print "crc_hi: " + str(hex(crc_hi)) read_switch_str = '010600000001' bytearray_switch = bytearray.fromhex(read_switch_str) hexstr_switch = str(bytearray_switch) print(hex(calc(hexstr_switch))) while True: # s_open = '010f00100004010fbf51'
from selenium import webdriver import time from utils import print_answer, calc from selenium.webdriver.common.by import By link = "http://suninjuly.github.io/redirect_accept.html" browser = webdriver.Chrome() browser.get(link) try: btn = browser.find_element_by_class_name('trollface') btn.click() new_win = browser.window_handles[1] browser.switch_to.window(new_win) x_el = browser.find_element(By.ID, 'input_value') x = x_el.text browser.find_element_by_id("answer").send_keys(calc(x)) button = browser.find_element_by_class_name("btn") button.click() time.sleep(1) print_answer(browser) finally: browser.quit()
formatted_message = utils.format_command(msg) formatted_message = formatted_message.split(" ") if len(formatted_message) == 1: command = formatted_message[0] else: command = formatted_message[0] argument = formatted_message[1] if command == "PING": utils.ping() # -- Send a response message to the client response = "OK!" # -- The message has to be encoded into bytes cs.send(str(response).encode()) elif command == "GET": utils.get(cs, list_sequences, argument) elif command == "INFO": utils.calc(cs) elif command == "COMP": utils.comp(cs, list_sequences, argument) elif command == "REV": utils.rev(cs, list_sequences, argument) elif command == "GENE": utils.gene(cs, argument) else: response = "Not available command" cs.send(str(response).encode()) # -- Close the data socket cs.close()
def main(): for i in xrange(1, len(sys.argv)): filepath = sys.argv[i] print "| Building for {0}\n".format(filepath) utils.calc(filepath) print "\n"
def do_GET(self): """This method is called whenever the client invokes the GET method in the HTTP protocol request""" # Print the request line termcolor.cprint(self.requestline, 'green') termcolor.cprint(self.path, "blue") o = urlparse(self.path) path_name = o.path arguments = parse_qs(o.query) print("Resource requested:", path_name) print("Parameters:", arguments) json_check = "json" in arguments and arguments["json"][0] == "1" context = {} print("path", path_name) if path_name == "/": context["list_genes"] = DICT_GENES.keys() context["dict_operations"] = {"1) Gene Sequence": "geneSeq", "2) Gene Information": "geneInfo", "3) Gene Calculations": "geneCalc"} context["op_names"] = ["1) Gene Sequence", "2) Gene Information", "3) Gene Calculations"] contents = us.read_template_html_file("./html/index.html").render(context=context) context.clear() elif path_name == "/listSpecies": limit = arguments["limit"][0] context = us.list_sp(limit) if json_check: contents = str(context) print(contents) else: if "error" in context: contents = us.read_template_html_file("./html/error.html").render(context=context) else: contents = us.read_template_html_file("./html/list_species.html").render(context=context) elif path_name == "/karyotype": context = us.karyotype(arguments["specie"][0]) if json_check: contents = str(context) else: if "error" in context: contents = us.read_template_html_file("./html/error.html").render(context=context) else: contents = us.read_template_html_file("./html/karyotype.html").render(context=context) elif path_name == "/chromosomeLength": context = us.chromo_len(arguments["specie"][0], arguments["chromo"][0]) if json_check: contents = str(context) else: if "error" in context: contents = us.read_template_html_file("./html/error.html").render(context=context) else: contents = us.read_template_html_file("./html/chromo_length.html").render(context=context) elif path_name == "/geneSeq": gene_name = arguments["gene"][0] seq = us.seq(gene_name).strbases context = {"gene_contents": seq, "gene_name": gene_name} if json_check: contents = str(context) else: contents = us.read_template_html_file("./html/geneSeq.html").render(context=context) elif path_name == "/geneInfo": gene_name = arguments["gene"][0] context = us.info(gene_name) if json_check: contents = str(context) else: contents = us.read_template_html_file("./html/geneInfo.html").render(context=context) elif path_name == "/geneCalc": gene_name = arguments["gene"][0] context = us.calc(gene_name) if json_check: contents = str(context) else: contents = us.read_template_html_file("./html/geneCalc.html").render(context=context) else: context["error"] = "Not a valid path" contents = us.read_template_html_file("./html/error.html").render(context=context) # Message to send back to the client # Generating the response message self.send_response(200) # -- Status line: OK! # Define the content-type header: self.send_header('Content-Type', 'text/html') self.send_header('Content-Length', len(contents.encode())) # The header is finished self.end_headers() # Send the response message self.wfile.write(contents.encode()) return
import pyperclip from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium import webdriver from utils import calc, copy_answer browser = webdriver.Chrome() browser.get("http://suninjuly.github.io/explicit_wait2.html") button = WebDriverWait(browser, 12).until( EC.text_to_be_present_in_element((By.ID, "price"), '100')) browser.find_element(By.ID, 'book').click() x = browser.find_element(By.ID, 'input_value').text browser.find_element(By.ID, 'answer').send_keys(calc(x)) browser.find_element(By.ID, 'solve').click() copy_answer(browser) browser.quit()
import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from utils import print_answer, calc browser = webdriver.Chrome() get_el = browser.find_element try: browser.get("http://suninjuly.github.io/explicit_wait2.html") # проверять в течение 12 до цены 100$ price = WebDriverWait(browser, 12).until( EC.text_to_be_present_in_element((By.ID, "price"), '$100')) button = get_el(value='book') button.click() x_element = get_el(value='input_value') x = x_element.text get_el(value="answer").send_keys(calc(x)) button = get_el(value="solve") button.click() # ждем загрузки страницы time.sleep(1) print_answer(browser) finally: browser.quit()