def main(): command_configs = { '-i': { 'longInputForm': '--input-dir', 'field': 'input_dir', }, '-o': { 'longInputForm': '--output-dir', 'field': 'output_dir', }, } commands = parse_commands(sys.argv[1:], command_configs) dir_file_map = to_dir_file_map(commands.input_dir) for dir_name, files in dir_file_map.items(): tag = to_tag_from_dir(dir_name, commands.input_dir) for file_name in files: input_file_path = os.path.join(dir_name, file_name) output_file_path = os.path \ .join(commands.output_dir, tag, file_name) \ .replace('.tsv', '.txt') if not os.path.exists(os.path.dirname(output_file_path)): os.makedirs(os.path.dirname(output_file_path)) print(input_file_path) print(output_file_path) with open(input_file_path, 'r') as input_file, \ open(output_file_path, 'w', newline='') as output_file: tag_to_file(input_file, output_file, tag)
def on_message(self, client, userdata, msg): try: payload = parse_commands(msg.payload) log(LogLevel.notice, "MQTT payload received @ " + msg.topic + " : " + str(payload)) log(LogLevel.notice, "doors[{}].{}()".format(str(self.id), payload["command"])) except KeyError: log(LogLevel.error, "The message don't contain a command instruction") except IndexError: log(LogLevel.error, "Invalid message received !")
def main(): command_configs = { '-t': { 'longInputForm': '--target', 'field': 'target', }, '-i': { 'longInputForm': '--input-file-label', 'field': 'input_file_label', }, } commands = parse_commands(sys.argv[1:], command_configs) if commands.target == 'hw5': hw5.run_all(commands) elif commands.target == 'project': project.run(commands) else: target_list = ['hw5', 'project'] raise RuntimeError( 'Please select "target" among these list: ' + target_list)
def main(): command_configs = { '-c': { 'longInputForm': '--count', 'field': 'count', }, '-f': { 'longInputForm': '--frequent-cdr-ratio', 'field': 'frequent_cdr_ratio', }, '-l': { 'longInputForm': '--long-cdr-ratio', 'field': 'long_cdr_ratio', }, '-s': { 'longInputForm': '--short-cdr-ratio', 'field': 'short_cdr_ratio', }, '-e': { 'longInputForm': '--error-ratio', 'field': 'error_ratio', }, '-o': { 'longInputForm': '--output', 'field': 'output', }, } commands = parse_commands(sys.argv[1:], command_configs) count = int(commands.count) first_frequent_cdr_ratio = float(commands.frequent_cdr_ratio) long_cdr_ratio = float(commands.long_cdr_ratio) short_cdr_ratio = float(commands.long_cdr_ratio) second_frequent_cdr_ratio = 1 - first_frequent_cdr_ratio \ - long_cdr_ratio - short_cdr_ratio error_ratio = float(commands.error_ratio) sampler = CDRSampler() serialized_cdrs = [] print('# Job Start') with open(commands.output, 'wb') as f: for i in range(count): if i % 10000 == 0: print('{0} iteration'.format(i)) pick = random.choices( [ DataType.FIRST_FREQUENT, DataType.SECOND_FREQUENT, DataType.SHORT, DataType.LONG ], [ first_frequent_cdr_ratio, second_frequent_cdr_ratio, short_cdr_ratio, long_cdr_ratio ], ) if pick == DataType.SHORT: sampler.make(CDRSamplerMode.SHORT).serialize_to_file(f) elif pick == DataType.LONG: sampler.make(CDRSamplerMode.LONG).serialize_to_file(f) else: # TODO(totorody): Diverse frequent cdr ratio to first and second. sampler.make().serialize_to_file(f) print('# Job Finish')
def main(): ip, port, registrar_ip_port = utils.parse_commands() this_node_address = f"http://{ip}:{port}" device.set_ip_and_port(this_node_address) utils.start_flask_app(ip, port, this_node_address, registrar_ip_port)
while True: try: message = next(generator) message += (50 - len(message)) * ' ' logger.info(f'Enviando mensagem: {message.strip()}') data = conn.send(bytes(message, 'utf-8')) data = conn.recv(50) if data: data = data.decode('latin-1') command, args = parse_commands(data) if command == 'SENSORDATA': logger.info( f'Informações BM280 - temperature {args[0]} e humidity {args[1]}' ) elif command == 'EVENT': logger.info( f'Evento recebido do pino: {args[0].strip()}') except (BrokenPipeError, ConnectionResetError): logger.info('Connection closed') break # I think that the with clause handle this... server_socket.close()