本文整理汇总了Python中progress.bar.IncrementalBar方法的典型用法代码示例。如果您正苦于以下问题:Python bar.IncrementalBar方法的具体用法?Python bar.IncrementalBar怎么用?Python bar.IncrementalBar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类progress.bar
的用法示例。
在下文中一共展示了bar.IncrementalBar方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: download_file
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def download_file(url: str, dest: str):
"""
Method to download a file from url and save at dest
"""
print(f'Downloading file from {url} and saving to {dest}')
response = requests.get(url, stream=True)
total_size = int(response.headers.get('content-length'))
chunk_size = 4096
total_steps = int(total_size / chunk_size)
progress_bar = IncrementalBar(max=total_steps, suffix='%(percent).1f%%')
with open(dest, mode='wb') as fd:
for chunk in response.iter_content(chunk_size=chunk_size):
fd.write(chunk)
progress_bar.next()
progress_bar.finish()
示例2: cargar_parecidos_con_distinto_humor
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def cargar_parecidos_con_distinto_humor():
with closing(open_db()) as conexion:
# buffered=True así sé la cantidad que son antes de iterarlos.
with closing(conexion.cursor() if DB_ENGINE == 'sqlite3' else conexion.cursor(buffered=True)) as cursor:
consulta = """
SELECT id_tweet_humor,
id_tweet_no_humor
FROM tweets_parecidos_distinto_humor
"""
cursor.execute(consulta)
pares_ids_parecidos_con_distinto_humor = []
bar = IncrementalBar("Cargando tweets parecidos\t", max=cursor.rowcount, suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
for par_ids in cursor:
pares_ids_parecidos_con_distinto_humor.append(par_ids)
bar.next()
bar.finish()
return pares_ids_parecidos_con_distinto_humor
示例3: guardar_parecidos_con_distinto_humor
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def guardar_parecidos_con_distinto_humor(pares_parecidos_distinto_humor):
with closing(open_db()) as conexion:
with closing(conexion.cursor()) as cursor:
consulta = "INSERT INTO tweets_parecidos_distinto_humor VALUES (%s, %s)" \
+ " ON DUPLICATE KEY UPDATE id_tweet_no_humor = %s"
bar = IncrementalBar("Guardando tweets parecidos\t", max=len(pares_parecidos_distinto_humor),
suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
for tweet_humor, tweet_no_humor in pares_parecidos_distinto_humor:
cursor.execute(consulta, (tweet_humor.id, tweet_no_humor.id, tweet_no_humor.id))
bar.next()
conexion.commit()
bar.finish()
示例4: init_progress_bar
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def init_progress_bar(frame_count, max_frames, show_progress=True, gen_all=False):
"""Helper to create progress bar for stabilizing processes
:param frame_count: input video's cv2.CAP_PROP_FRAME_COUNT
:param max_frames: user provided max number of frames to process
:param show_progress: user input if bar should be created
:param gen_all: if False progress message is 'Stabilizing'; otherwise 'Generating Transforms'
:return: a progress.bar.IncrementalBar
>>> progress_bar = init_progress_bar(30, float('inf'))
>>> # Stabilizing |█████████████████████████▋ | 80%
"""
if not show_progress:
return None
# frame count is negative during some cv2.CAP_PROP_FRAME_COUNT failures
bad_frame_count = frame_count <= 0
use_max_frames = bad_frame_count or frame_count > max_frames
if bad_frame_count and max_frames == float('inf'):
warnings.warn('No progress bar will be shown. (Unable to grab frame count & no max_frames provided.)')
return None
max_bar = max_frames if use_max_frames else frame_count
message = progress_message(gen_all)
return IncrementalBar(message, max=max_bar, suffix='%(percent)d%%')
示例5: download_chapters
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def download_chapters(app):
# download or generate cover
app.book_cover = download_cover(app)
if not app.book_cover:
app.book_cover = generate_cover(app)
# end if
if not app.book_cover:
logger.warn('No cover image')
# end if
bar = IncrementalBar('Downloading chapters', max=len(app.chapters))
bar.start()
if os.getenv('debug_mode') == 'yes':
bar.next = lambda: None # Hide in debug mode
# end if
futures_to_check = {
app.crawler.executor.submit(
download_chapter_body,
app,
chapter,
): str(chapter['id'])
for chapter in app.chapters
}
app.progress = 0
for future in futures.as_completed(futures_to_check):
result = future.result()
if result:
bar.clearln()
logger.error(result)
# end if
app.progress += 1
bar.next()
# end for
bar.finish()
print('Downloaded %d chapters' % len(app.chapters))
# end def
示例6: determinate_progress_cli
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def determinate_progress_cli(msg, max):
return IncrementalBar(msg, max=max)
示例7: mismas_features_distinto_humor
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def mismas_features_distinto_humor(corpus):
print("Buscando tweets con mismos valores de features pero distinto de humor...")
humoristicos = [tweet for tweet in corpus if tweet.es_humor]
no_humoristicos = [tweet for tweet in corpus if not tweet.es_humor]
res = []
bar = IncrementalBar("Buscando en tweets\t\t", max=len(humoristicos) * len(no_humoristicos),
suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
for tweet_humor in humoristicos:
for tweet_no_humor in no_humoristicos:
if tweet_humor.features == tweet_no_humor.features:
res.append((tweet_humor, tweet_no_humor))
if tweet_humor.texto_original == tweet_no_humor.texto_original:
print("-----MISMO TEXTO ORIGINAL------")
if tweet_humor.texto == tweet_no_humor.texto:
print("----------MISMO TEXTO----------")
if tweet_humor.id == tweet_no_humor.id:
print("-----------MISMO ID------------")
if tweet_humor.cuenta == tweet_no_humor.cuenta:
print("----------MISMA CUENTA---------")
print('')
print(tweet_humor.id)
print(tweet_humor.texto)
print("------------")
print(tweet_no_humor.id)
print(tweet_no_humor.texto)
print("------------")
print('')
bar.next()
bar.finish()
return res
示例8: guardar_features
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def guardar_features(tweets, **opciones):
nombre_feature = opciones.pop('nombre_feature', None)
conexion = open_db()
cursor = conexion.cursor()
consulta = "INSERT INTO features VALUES (%s, %s, %s) ON DUPLICATE KEY UPDATE valor_feature = %s"
if nombre_feature:
mensaje = 'Guardando feature ' + nombre_feature
else:
mensaje = 'Guardando features'
bar = IncrementalBar(mensaje, max=len(tweets), suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
for tweet in tweets:
if nombre_feature:
cursor.execute(
consulta,
(
tweet.id,
nombre_feature,
unicode(tweet.features[nombre_feature]),
unicode(tweet.features[nombre_feature])
)
)
else:
for nombre_feature, valor_feature in tweet.features.items():
cursor.execute(consulta, (tweet.id, nombre_feature, unicode(valor_feature), unicode(valor_feature)))
bar.next()
conexion.commit()
bar.finish()
cursor.close()
conexion.close()
示例9: calcular_feature_thread
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def calcular_feature_thread(self, tweets, nombre_feature, identificador):
if len(tweets) > 0:
bar = IncrementalBar("Calculando feature " + nombre_feature + ' - ' + unicode(identificador),
max=len(tweets),
suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
feature = self.features[nombre_feature]
self.abortar_si_feature_no_es_thread_safe(feature)
for tweet in tweets:
tweet.features[feature.nombre] = feature.calcular_feature(tweet)
bar.next()
bar.finish()
示例10: calcular_features_faltantes_thread
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def calcular_features_faltantes_thread(self, tweets, identificador):
if len(tweets) > 0:
bar = IncrementalBar("Calculando features - " + unicode(identificador),
max=len(tweets) * len(self.features),
suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
for tweet in tweets:
for feature in list(self.features.values()):
self.abortar_si_feature_no_es_thread_safe(feature)
if feature.nombre not in tweet.features:
tweet.features[feature.nombre] = feature.calcular_feature(tweet)
bar.next()
bar.finish()
示例11: idx_to_image
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def idx_to_image(self, image_file: str, label_file: str, label_mapping: Dict[str, str] = None):
print(f'Converting {image_file} to image files')
with open(image_file, mode='rb') as image_stream, open(label_file, mode='rb') as label_stream:
# save images dataset
magic, num_images = struct.unpack('>II', image_stream.read(8))
if magic != 2051:
raise ValueError('Magic number invalid')
num_rows, num_cols = struct.unpack('>II', image_stream.read(8))
images = np.fromfile(image_stream, dtype=np.dtype(np.uint8).newbyteorder('>'))
images = images.reshape((num_images, num_rows, num_cols))
# save labels dataset
magic, num_labels = struct.unpack('>II', label_stream.read(8))
if magic != 2049:
raise ValueError('Magic number invalid')
labels = np.fromfile(label_stream, dtype=np.dtype(np.uint8).newbyteorder('>'))
labels = labels.astype('str')
labels = np.vectorize(lambda x: label_mapping[x])(labels) if label_mapping is not None else labels
progress_bar = IncrementalBar(max=len(labels), suffix='%(percent).1f%%')
# create missing directories
for unique_label in np.unique(labels):
label_folder = osp.abspath(osp.join(self.data_dir_path, unique_label))
pathlib.Path(label_folder).mkdir(parents=True, exist_ok=True)
# save images to data directory
for label, image in zip(labels, images):
label_folder = osp.abspath(osp.join(self.data_dir_path, label))
image_fd, image_dest = tempfile.mkstemp(dir=label_folder, suffix='.png')
cv2.imwrite(f'{image_dest}', image.T)
os.close(image_fd) # if not closed, can get OSError: [Errno 24] Too many open files
progress_bar.next()
progress_bar.finish()
示例12: search_novels
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def search_novels(app):
executor = futures.ThreadPoolExecutor(10)
# Add future tasks
checked = {}
futures_to_check = {}
for link in app.crawler_links:
crawler = crawler_list[link]
if crawler in checked:
logger.info('A crawler for "%s" already exists', link)
continue
# end if
checked[crawler] = True
futures_to_check[
executor.submit(
get_search_result,
app.user_input,
link
)
] = str(crawler)
# end for
bar = IncrementalBar('Searching', max=len(futures_to_check.keys()))
bar.start()
if os.getenv('debug_mode') == 'yes':
bar.next = lambda: None # Hide in debug mode
# end if
# Resolve future tasks
app.progress = 0
combined_results = []
for future in futures.as_completed(futures_to_check):
combined_results += future.result()
app.progress += 1
bar.next()
# end for
# Process combined search results
app.search_results = process_results(combined_results)
bar.clearln()
bar.finish()
print('Found %d results' % len(app.search_results))
executor.shutdown()
# end def
示例13: cross_validation_y_reportar
# 需要导入模块: from progress import bar [as 别名]
# 或者: from progress.bar import IncrementalBar [as 别名]
def cross_validation_y_reportar(clasificador, features, clases, numero_particiones):
skf = cross_validation.StratifiedKFold(clases, n_folds=numero_particiones)
features = np.array(features)
clases = np.array(clases)
matrices = []
medidas = defaultdict(list)
bar = IncrementalBar("Realizando cross-validation\t", max=numero_particiones, suffix=SUFIJO_PROGRESS_BAR)
bar.next(0)
for entrenamiento, evaluacion in skf:
clasificador.fit(features[entrenamiento], clases[entrenamiento])
clases_predecidas = clasificador.predict(features[evaluacion])
matriz_de_confusion = metrics.confusion_matrix(clases[evaluacion], clases_predecidas).flatten()
matrices.append(matriz_de_confusion)
for medida, valor_medida in calcular_medidas(*matriz_de_confusion).items():
medidas[medida].append(valor_medida)
bar.next()
bar.finish()
promedios = {}
print('')
print("Resultados de cross-validation:")
print('')
for medida, valor_medida in medidas.items():
print("\t{medida: >18s}:\t{valor_medida}".format(medida=medida, valor_medida=valor_medida))
promedio = np.mean(valor_medida)
promedios[medida] = promedio
delta = np.std(valor_medida) * 1.96 / math.sqrt(numero_particiones)
print("Intervalo de confianza 95%:\t{promedio:0.4f} ± {delta:0.4f} --- [{inf:0.4f}, {sup:0.4f}]".format(
promedio=promedio, delta=delta, inf=promedio - delta, sup=promedio + delta))
print('')
imprimir_matriz_metricas(
promedios['Precision No humor'],
promedios['Recall No humor'],
promedios['F1-score No humor'],
promedios['Precision Humor'],
promedios['Recall Humor'],
promedios['F1-score Humor'],
)
print('')
print('')
print('')