def send_texts(rows): python_questions = read_file(f"{DIR_PATH}/resources/python_questions.json") javascript_questions = read_file(f"{DIR_PATH}/resources/javascript_questions.json") for item in rows: obj = from_dynamodb_to_json(item) number = obj['number'] level = obj['level'] name = obj['name'].split(" ")[0] formatted_name = name.capitalize() if obj['category'] == "python": questions = list(filter(lambda x: str(x['level']) == level, python_questions)) question_id = int(obj['python_id']) title = obj['category'] message = questions[question_id]["tip"] elif obj['category'] == "javascript": questions = list(filter(lambda x: str(x['level']) == level, javascript_questions)) question_id = int(obj['javascript_id']) title = obj['category'] message = questions[question_id]["tip"] print(f"Sending text message to {number}") send_message(SENDER, obj['number'], message, title, formatted_name, obj['country'], obj['category']) time.sleep(2)
def test_fitness(self): weapons = main.read_file('../testdata/armas.tsv') boots = main.read_file('../testdata/botas.tsv') helmets = main.read_file('../testdata/cascos.tsv') gloves = main.read_file('../testdata/guantes.tsv') shirts = main.read_file('../testdata/pecheras.tsv') attack_multiplier = 0.9 defense_multiplier = 0.1 force_multiplier = 0.9 agility_multiplier = 1.1 expertise_multiplier = 1 resistance_multiplier = 0.9 life_multiplier = 0.8 expected_p_force = 100 * np.tanh( 0.01 * force_multiplier * (6.222216242390499 + 2.2027931206638347 + 7.658380825287503 + 1.5663864556588252 + 9.723360073495009)) expected_p_agility = np.tanh( 0.01 * agility_multiplier * (6.541324168418127 + 2.1657134566632457 + 4.820703103477169 + 2.9881879858036853 + 3.3550178576619367)) expected_p_expertise = 0.6 * np.tanh( 0.01 * expertise_multiplier * (12.31869383349377 + 0.8576268312008092 + 2.5555670851728705 + 0.6172399843576923 + 5.242037515433561)) expected_p_resistance = np.tanh( 0.01 * resistance_multiplier * (7.171230587646848 + 2.117799836003941 + 6.664915444307471 + 0.971997463425301 + 17.913489499483834)) expected_p_life = 100 * np.tanh( 0.01 * life_multiplier * (9.506924539924945 + 1.4986193316990624 + 4.495328669692497 + 3.0986140589878577 + 2.726878650158977)) expected_atm = 1.4375 expected_dem = 1.0625 attack = (expected_p_agility + expected_p_expertise) * expected_p_force * expected_atm defense = (expected_p_resistance + expected_p_expertise) * expected_p_life * expected_dem expected_fitness = attack * attack_multiplier + defense * defense_multiplier fitness = chromosome1.calculate_fitness( attack_multiplier, defense_multiplier, force_multiplier, agility_multiplier, expertise_multiplier, resistance_multiplier, life_multiplier, weapons, boots, helmets, gloves, shirts) self.assertEqual(fitness, expected_fitness)
def read_data(): try: file_name = request.args.get('file_name','file1.txt') start = request.args.get('start',None) end = request.args.get('end',None) data = read_file(file_name,start, end) return render_template("index.html",text = data) except requests.exceptions.RequestException as e: pass
def test_read_file_returns_lines_of_file_as_list() -> None: lines = read_file('./files/input-example.txt') assert lines == [ 'forward 5', 'down 5', 'forward 8', 'up 3', 'down 8', 'forward 2', ]
def multiplex_or_create(pkt, address): # with lock: packet = main.Packetize(pkt) if address in thread_table: pass_pkt(packet, address) else: packets = chunks_into_pkts(main.read_file(packet.data)) protocol = int( input( "please select a protocol for sending \n 1) Go Back N\n2) Selective Repeat\n 3) Stop And Wait \n" )) choose_protocol(packets, address, protocol, file_name=packet.data)
def test_calculate(self): self.assertEqual(calculate(read_file("test_files/1.txt")), 1) self.assertEqual(calculate(read_file("test_files/2.txt")), 1) self.assertEqual(calculate(read_file("test_files/3.txt")), 2) self.assertEqual(calculate(read_file("test_files/4.txt")), 3) self.assertEqual(calculate(read_file("test_files/5.txt")), 0) self.assertEqual(calculate(read_file("test_files/6.txt")), 1)
def main_alg(): r, c, l, h, matrix = read_file('./pizza/example.in') shapes = get_shapes(l, h) shapes_with_deviation = get_shapes_with_deviation(shapes) print len(shapes_with_deviation) for a_shape in shapes_with_deviation: print a_shape.__unicode__() score_matrix = init_score_matrix(c, r) for i in range(len(matrix)): row = matrix[i] for j in range(len(row)): for a_shape in shapes_with_deviation: if shapes_fits(matrix, a_shape, l, i, j): score_matrix[i][j] += 1 print score_matrix
def main2(): min, max, matrix = main.read_file('small.in') result = [] # print matrix shapes = shape(min, max) print shapes for i in range(0,999): for j in range(0,999): for k in shapes: submatrix = getSubmatrix(matrix, i, j, k[0], k[1]) if submatrix: print submatrix fits = checkShape(submatrix, min) if fits: matrix = replaceSubmatrix(matrix, i, j, i+k[0], j+k[1]) print [i,j, i+k[0]-1, j+k[1]-1] result.append([i,j, i+k[0], j+k[1]]) break
def test_read_file(): if main.read_file(0) != ['ccabab\n', ['ba -> ab\n', 'ca -> ac\n', 'cb -> bc\n']]: print("Error read_file on test #1") if main.read_file(1) != ['aababab\n', ['ab -> \n', 'a -> b\n']]: print("Error read_file on test #2") if main.read_file(2) != ['aaa\n', ['b ->. a\n', 'a -> b\n']]: print("Error read_file on test #3") if main.read_file(3) != ['|||||||||\n', ['||| -> \n', '|| ->. \n', '| ->. \n', ' ->. |']]: print("Error read_file on test #4") if main.read_file(4) != ['ababa\n', ['*a ->. \n', '*b ->. \n', '* ->. \n', ' -> *']]: print("Error read_file on test #5") if main.read_file(5) != ['1010101\n', ['0b ->. 1\n', '1b -> b0\n', 'b ->. 1\n', 'a0 -> 0a\n', 'a1 -> 1a\n', '0a -> 0b\n', '1a -> 1b\n', ' -> a']]: print("Error read_file on test #6")
""" Responsible for the calling of functions. """ import main import player_comments if __name__ == '__main__': PLAYERS = main.read_file() HEADER = True for player in PLAYERS: player_comments.get_comments(player[1]) print("Terminou o jogador: ", player[0])
def test_read_file(mocker): mocker.patch('builtins.open').return_value = StringIO('Some text') result = read_file('some file.txt') assert list(result) == ['Some text']
# Bubble Sort version 1 import main import time import psutil import os start = time.time() process = psutil.Process(os.getpid()) list = main.read_file(100) comparisons = 0 exchanges = 0 for i in range(len(list)): for j in range(len(list) - 1): comparisons += 1 if list[j] > list[j+1]: aux = list[j] list[j] = list[j+1] list[j+1] = aux exchanges += 1 runtime = (time.time() - start)*1000 print('Quantidade de quantidade de comparações: ', str(comparisons)) print('Quantidade de trocas: ', str(exchanges)) print('Tempo de execução: ', str(runtime)) print('Uso da CPU: ', str(psutil.cpu_percent(interval=1)),'%') print('Uso da memória: ', str(process.memory_percent()*100),'%')
def test_read_file(): assert main.read_file("test.txt") == [ "000325175", "005420021", "005420120", "005420120" ]
conn = psycopg2.connect(user="******", database="sports_stats") cur = conn.cursor() cur.execute("DROP TABLE if exists player_stats;") create_table_string = """ CREATE TABLE player_stats ( player_name varchar(50), receptions numeric(3), receiving_yards numeric(4), touchdowns numeric(2), position varchar(3) )""" cur.execute(create_table_string) conn.commit() insert_template = "INSERT INTO player_stats VALUES (%s,%s,%s,%s,%s)" roster = read_file() for player in roster: cur.execute(insert_template, player) conn.commit() cur.close() conn.close()
def test_readfile(self): self.assertTrue(main.read_file(SAMPLE) == self.testdata)
def clean_json_str(filename): v = read_file("1.tmp").strip() return v[1:-1]
def test_read_file(): mock_open = mock.mock_open(read_data='test contents') with mock.patch('__builtin__.open', mock_open): result = read_file('test_path') assert result['file'] == 'test contents'
def test_read_file(): path = pathlib.Path( "./src/2018-07-10-just-enough-static-site-generator/main.md") post = main.read_file(path) assert type(post) is main.Post
def test_wrong_path(): path = 'wrong-path' with pytest.raises(FileNotFoundError) as excinfo: next(read_file(path)) print(excinfo.value)