def wait_for_task_done_or_error(self, initial_task: 'Task'): """ Wait until the given task is DONE or ERROR :param initial_task: :return: The last state of the Task """ # Initialize web-socket connection websocket = self.__init_ws_connection() current_task = initial_task bar = ChargingBar(current_task.type(), max=current_task.total_step()) bar.next(0) if current_task.current_step_description() is not None: bar.message = current_task.current_step_description() while current_task.status() != Status.DONE and current_task.status( ) != Status.ERROR: current_task = self.__wait_for_task_message( websocket, initial_task) bar.next() bar.message = current_task.current_step_description() bar.finish() # Closing web-socket websocket.close() return current_task
def tag_dir(dir_path): ''' Takes a directory at <dir_path> Tags its content (audio files only) with metadata retrieved through the AcoustID API ''' lth = 0 for _file in listdir(dir_path): if is_audio_file(dir_path + '/' + _file): lth += 1 bar = ChargingBar(max=lth, suffix='[%(index)d/%(max)d]') for _file in listdir(dir_path): song_path = dir_path + '/' + _file if is_audio_file(song_path): bar.message = INDENT + cyan_fg(_file) + '\n' tag(song_path) bar.next()
def process_default(out_file, algorithm): global CONFIG csv_file = open(out_file, 'w', newline='') csv_writer = csv.writer(csv_file, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) engine = create_engine(CONFIG['mysql']) print(f'Processing with {algorithm} algorithm...') stores = CONFIG['stores'] barcodes = CONFIG['barcodes'] periods = CONFIG['periods'] iter_cnt = len(stores) * len(barcodes) * len(periods) bar = ChargingBar('Waiting...', max=iter_cnt) bar.start() for store_id in stores: for barcode in barcodes: bar.message = f'[Store: {store_id}] {str(barcode).ljust(13, " ")}' bar.update() df_barcode = get_barcode_daily_sales(engine, store_id, barcode) for period in periods: forecast_from_date = arrow.get(period['date'], 'DD.MM.YYYY') forecast_before_date = forecast_from_date.shift( days=period['days']) forecast = do_forecast(algorithm, df_barcode, forecast_from_date, forecast_before_date) csv_writer.writerow([ store_id, barcode, period['date'], period['days'], forecast ]) bar.next() bar.finish() csv_file.close() print(f'\nDone. Result was written to {args.output}')
def create_dir_metadata(dir_path, sample_dir_path): # Getting the number of audio files in <dir_path> lth = 0 for _file in listdir(dir_path): if is_audio_file(dir_path + '/' + _file): lth += 1 # Retrieving metadata for audio files in <dir_path> while creating samples metadata_tab = [] bar = ChargingBar(max=lth, suffix='[%(index)d/%(max)d]') for _file in listdir(dir_path): if is_audio_file(dir_path + '/' + _file): bar.message = INDENT + cyan_fg(_file) + '\n' start_time = time() metadata_tab.append( create_metadata(dir_path + '/' + _file, sample_dir_path)) end_time = time() elapsed_time = end_time - start_time print("\nSong exportation time : " + dim('{:02d}s:{:02d}cs'.format( int(elapsed_time), int((elapsed_time % 1) * 100)))) bar.next() return metadata_tab
def process_short(out_file, in_file, algorithm): global CONFIG beg_date = arrow.get('2019-10-01', 'YYYY-MM-DD') end_date = arrow.get('2020-01-31', 'YYYY-MM-DD') write_stdout(f'Forecast from {beg_date} to {end_date}\n') # 123 days lines_count = 0 if wc and sed: write_stdout(f'Counting {in_file} non-blank lines... ') lines_count = int(wc(sed(r'/^\s*$/d', in_file), '-l')) print(lines_count) ops_count = lines_count * 123 out_csv_file = open(out_file, 'w', newline='') in_csv_file = open(in_file, 'r', newline='\n') csv_writer = csv.writer(out_csv_file, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) csv_reader = csv.reader(in_csv_file, delimiter=',') engine = create_engine(CONFIG['mysql']) print(f'Processing short output with {algorithm} algorithm...') bar = None if ops_count > 0: bar = ChargingBar('Waiting...', max=ops_count) bar.start() i = 0 dfs = {} for row in csv_reader: if row is not None and len(row): store_id = int(row[0]) barcode = int(row[1]) key = f'{store_id}-{barcode}' try: df_barcode = dfs[key] except KeyError: df_barcode = get_barcode_daily_sales(engine, store_id, barcode) dfs[key] = df_barcode for j, d in enumerate(arrow.Arrow.range('day', beg_date, end_date)): forecast_from_date = d forecast_before_date = forecast_from_date.shift(days=5) forecast = do_forecast(algorithm, df_barcode, forecast_from_date, forecast_before_date) csv_writer.writerow([int(round(forecast))]) if bar: curr_op = i * 123 + j if curr_op % 5 == 0: bar.message = f'{curr_op} of {ops_count}' bar.update() bar.next() i += 1 bar.message = 'Done' bar.update() out_csv_file.close() in_csv_file.close()
engine = create_engine(config['mysql']) print(f'Processing...') stores = config['stores'] barcodes = config['barcodes'] periods = config['periods'] iter_cnt = len(stores) * len(barcodes) * len(periods) bar = ChargingBar('Waiting...', max=iter_cnt) bar.start() for s in range(len(stores)): store_id = stores[s] for b in range(len(barcodes)): barcode = barcodes[b] bar.message = f'[Store: {store_id}] {str(barcode).ljust(13, " ")}' bar.update() df_barcode = get_barcode_daily_sales(engine, store_id, barcode) for plot in range(len(periods)): period = periods[plot] today = arrow.get(period['date'], 'DD.MM.YYYY') beg = today.shift(days=1) end = beg.shift(days=period['days']) sales = df_barcode.loc[beg.date():end.date()] sales_sum = sales['quantity'].sum() csv_writer.writerow([ store_id,