本文整理汇总了Python中ipywidgets.IntProgress方法的典型用法代码示例。如果您正苦于以下问题:Python ipywidgets.IntProgress方法的具体用法?Python ipywidgets.IntProgress怎么用?Python ipywidgets.IntProgress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ipywidgets
的用法示例。
在下文中一共展示了ipywidgets.IntProgress方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def __init__(self,
*,
max=10,
description='Progressing',
loop=None,
hiden=False):
self.start_ts = monotonic()
self.avg = 0
self._avg_update_ts = self.start_ts
self._ts = self.start_ts
self._xput = deque(maxlen=self.sma_window)
self._ProgressWidget = widgets.IntProgress(value=0,
min=0,
max=max,
step=1,
description=description,
bar_style='')
self._elapsedTimeLabel = widgets.Label(value='Used time: 00:00:00')
self._etaTimeLabel = widgets.Label(value='Remaining time: --:--:--')
self.ui = widgets.HBox(
[self._ProgressWidget, self._elapsedTimeLabel, self._etaTimeLabel])
self.loop = asyncio.get_event_loop() if loop is None else loop
self._update_loop = None
self._displayed = False if not hiden else True
示例2: _multi_kfold_scoring
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def _multi_kfold_scoring(dataset, algo, L=10, k=2):
"""
Performs multiple scorings of the given dataset.
Parameters
----------
dataset : rankeval.dataset.Dataset
The dataset instance.
algo : function
See :func:`bias_variance`.
L : int
Number of iterations
k : int
Number of folds.
Returns
-------
score : numpy.ndarray
A matrix num_instances x L.
"""
if ipywidgets:
progress_bar = ipywidgets.IntProgress(
min=0, max=L, description="Computing L scores")
display(progress_bar)
scores = np.zeros( (dataset.n_instances, L), dtype=np.float32)
for l in range(L):
if ipywidgets:
progress_bar.value += 1
scores[:,l] = _kfold_scoring(dataset, k, algo)
if ipywidgets:
progress_bar.bar_style = "success"
progress_bar.close()
return scores
示例3: __init__
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def __init__(self, completed_len: int, visible: bool = True):
"""
Instantiate new _Progress UI.
Parameters
----------
completed_len : int
The expected value that indicates 100% done.
visible : bool
If True start the progress UI visible, by default True.
"""
self._completed = 0
self._total = completed_len
self._progress = widgets.IntProgress(
value=0,
max=100,
step=1,
description="Progress:",
bar_style="info",
orientation="horizontal",
)
self._done_label = widgets.Label(value="0%")
self._progress.visible = visible
self._done_label.visible = visible
self.layout = widgets.HBox([self._progress, self._done_label])
self.display()
示例4: __init__
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def __init__(self,max_it,name= 'Progress:',est_cycle_time=None,dummy=False):
if debug:
print("new style progress bar")
self._dummy=dummy
if self._dummy:
return
self.starttime = time.time()
self.start_eta_time = self.starttime
self.max_it = max_it
self.name = name
self.progr = 0
#check for old (finished) progressbar with the same name
for p in pb_list:
if p[0] == self.name:
p[1].close()
p[2].close()
self.pb = IntProgress(
value=0,
min=0,
max=self.max_it,
description=self.name,
layout={"width": "95%"},
)
self.pi = HTML(
#value = "(0/%i) <br>✈ -?- <br>🕐 --:--:-- (estimated)<br>✚ 00:00:00 (elapsed) <br>⚊ --:--:-- (remaining)"% (self.max_it),
value = "<table style='width:100%%'><tr><td>%s (%i/%i) </td><td>✈ %s </td><td>🕐 %s (estimated)</td><td>✚ %s (elapsed) </td><td>⚊ %s (remaining)</td></tr></table>"%("",
0,
self.max_it,
"-?-" if est_cycle_time==None else time.strftime('%Y-%m-%d (%a) %H:%M:%S', time.localtime(time.time() + est_cycle_time * self.max_it )),
"--:--:--" if est_cycle_time==None else hourformat(est_cycle_time*self.max_it),
"00:00:00",
"--:--:--" if est_cycle_time==None else hourformat(est_cycle_time*self.max_it)),
)
display(self.pi)
display(self.pb)
示例5: cliRunSync
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def cliRunSync(module, node=None, parameters=None, delete_temporary_files=True, update_display=True):
"""Run CLI module. If ipywidgets are installed then it reports progress.
"""
try:
from ipywidgets import IntProgress
from IPython.display import display
# Asynchronous run, with progerss reporting using widget
node = slicer.cli.run(module, node=node, parameters=parameters, wait_for_completion=False,
delete_temporary_files=delete_temporary_files, update_display=update_display)
import time
progress = IntProgress()
display(progress) # display progress bar
while node.IsBusy():
progress.value = node.GetProgress()
slicer.app.processEvents()
time.sleep(.3)
progress.layout.display = 'none' # hide progress bar
except ImportError:
# No widgets, therefore no progress reporting - do just a simpe synchronous CLI run
node = slicer.cli.runSync(module, node=node, parameters=parameters, wait_for_completion=False,
delete_temporary_files=delete_temporary_files, update_display=update_display)
return node
示例6: _kfold_scoring
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def _kfold_scoring(dataset, k, algo):
"""
Scored the given datset with the given algo unsing k-fold train/test.
Parameters
----------
dataset : rankeval.dataset.Dataset
The dataset instance.
k : int
Number of folds.
algo : function
See :func:`bias_variance`.
Returns
-------
score : numpy.ndarray
A vecotr of num_instances scores.
"""
if ipywidgets:
progress_bar = ipywidgets.IntProgress(
min=0, max=k, description="Processing k folds")
display(progress_bar)
scores = np.zeros(dataset.n_instances, dtype=np.float32)
query_sizes = dataset.get_query_sizes()
# shuffle queries
shuffled_qid = np.random.permutation(dataset.n_queries)
chunk_query_size = int(math.ceil(dataset.n_queries/float(k)))
for p in range(0, dataset.n_queries, chunk_query_size):
if ipywidgets:
progress_bar.value += 1
# p-th fold is used for testing
test_rows = np.full(dataset.n_instances,
fill_value=False,
dtype=np.bool)
for q in shuffled_qid[p: p + chunk_query_size]:
test_rows[dataset.query_offsets[q]:dataset.query_offsets[q+1]] = True
# other folds are used for training
train_rows = np.logical_not(test_rows)
train_q = np.full(dataset.n_queries,
fill_value=True,
dtype=np.bool)
train_q[shuffled_qid[p: p+chunk_query_size]] = False
# get algorithm predictions
fold_scores = algo(
dataset.X[train_rows],
dataset.y[train_rows],
query_sizes[train_q],
dataset.X[test_rows]
)
# update scores for the current fold
scores[test_rows] = fold_scores
progress_bar.bar_style = "success"
progress_bar.close()
return scores
示例7: log_progress
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def log_progress(sequence, every=None, size=None, name='Items'):
"""Taken from https://github.com/alexanderkuk/log-progress"""
from ipywidgets import IntProgress, HTML, VBox
from IPython.display import display
is_iterator = False
if size is None:
try:
size = len(sequence)
except TypeError:
is_iterator = True
if size is not None:
if every is None:
if size <= 200:
every = 1
else:
every = int(size / 200) # every 0.5%
else:
assert every is not None, 'sequence is iterator, set every'
if is_iterator:
progress = IntProgress(min=0, max=1, value=1)
progress.bar_style = 'info'
else:
progress = IntProgress(min=0, max=size, value=0)
label = HTML()
box = VBox(children=[label, progress])
display(box)
index = 0
try:
for index, record in enumerate(sequence, 1):
if index == 1 or index % every == 0:
if is_iterator:
label.value = '{name}: {index} / ?'.format(
name=name,
index=index
)
else:
progress.value = index
label.value = u'{name}: {index} / {size}'.format(
name=name,
index=index,
size=size
)
yield record
except Exception as e:
progress.bar_style = 'danger'
raise
else:
progress.bar_style = 'success'
progress.value = index
label.value = "{name}: {index}".format(
name=name,
index=str(index or '?')
)
示例8: _log_progress
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def _log_progress(sequence, every=None, size=None, desc='Items'):
"""
Make and display a progress bar.
Parameters
----------
sequence : list.
Represents a elements sequence.
every : int, optional, default None.
Represents the steps in which the bar will be updated
size : int, optional, default None.
Represents the size/number elements in sequence.
desc : String, optional, default 'Items'.
Represents the description of the operation.
"""
is_iterator = False
if size is None:
try:
size = len(sequence)
except TypeError:
is_iterator = True
if size is not None:
if every is None:
if size <= 200:
every = 1
else:
every = int(size / 200)
else:
if every is None:
raise AssertionError('Sequence is iterator, set every')
if is_iterator:
progress = IntProgress(min=0, max=1, value=1)
progress.bar_style = 'info'
else:
progress = IntProgress(min=0, max=size, value=0)
label = HTML()
box = VBox(children=[label, progress])
display(box)
index = 0
try:
for index, record in enumerate(sequence, 1):
if index == 1 or index % every == 0:
if is_iterator:
label.value = '%s: %s / ?' % (desc, index)
else:
progress.value = index
label.value = u'%s: %s / %s' % (desc, index, size)
yield record
except Exception:
progress.bar_style = 'danger'
raise
else:
progress.bar_style = 'success'
progress.value = index
label.value = '%s: %s' % (desc, str(index or '?'))
示例9: log_progress
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def log_progress(sequence, every=None, size=None, name='Items'):
from ipywidgets import IntProgress, HTML, VBox
from IPython.display import display
is_iterator = False
if size is None:
try:
size = len(sequence)
except TypeError:
is_iterator = True
if size is not None:
if every is None:
if size <= 200:
every = 1
else:
every = int(size / 200) # every 0.5%
else:
assert every is not None, 'sequence is iterator, set every'
if is_iterator:
progress = IntProgress(min=0, max=1, value=1)
progress.bar_style = 'info'
else:
progress = IntProgress(min=0, max=size, value=0)
label = HTML()
box = VBox(children=[label, progress])
display(box)
index = 0
try:
for index, record in enumerate(sequence, 1):
if index == 1 or index % every == 0:
if is_iterator:
label.value = '{name}: {index} / ?'.format(
name=name,
index=index
)
else:
progress.value = index
label.value = u'{name}: {index} / {size}'.format(
name=name,
index=index,
size=size
)
yield record
except Exception:
progress.bar_style = 'danger'
raise
else:
progress.bar_style = 'success'
progress.value = index
label.value = "{name}: {index}".format(
name=name,
index=str(index or '?')
)
示例10: downloadFromURL
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def downloadFromURL(uris=None, fileNames=None, nodeNames=None, checksums=None, loadFiles=None,
customDownloader=None, loadFileTypes=None, loadFileProperties={}):
"""Download data from custom URL with progress bar.
See API description in SampleData.downloadFromURL.
"""
import SampleData
sampleDataLogic = SampleData.SampleDataLogic()
try:
from ipywidgets import IntProgress
from IPython.display import display
progress = IntProgress()
except ImportError:
progress = None
def reporthook(msg, level=None):
# Download will only account for 90 percent of the time
# (10% is left for loading time).
progress.value=sampleDataLogic.downloadPercent*0.9
if progress:
sampleDataLogic.logMessage = reporthook
display(progress) # show progress bar
computeFileNames = not fileNames
computeNodeNames = not nodeNames
if computeFileNames or computeNodeNames:
urisList = uris if type(uris) == list else [uris]
if computeFileNames:
fileNames = []
else:
filenamesList = fileNames if type(fileNames) == list else [fileNames]
if computeNodeNames:
nodeNames = []
else:
nodeNamesList = nodeNames if type(nodeNamesList) == list else [nodeNames]
import os
for index, uri in enumerate(urisList):
if computeFileNames:
fileName = getFileNameFromURL(uri)
fileNames.append(fileName)
else:
fileName = fileNames[index]
if computeNodeNames:
fileNameWithoutExtension, _ = os.path.splitext(fileName)
nodeNames.append(fileNameWithoutExtension)
if type(uris) != list:
if type(fileNames) == list:
fileNames = fileNames[0]
if type(nodeNames) == list:
nodeNames = nodeNames[0]
downloaded = sampleDataLogic.downloadFromURL(uris, fileNames, nodeNames, checksums, loadFiles,
customDownloader, loadFileTypes, loadFileProperties)
if progress:
progress.layout.display = 'none' # hide progress bar
return downloaded[0] if len(downloaded) == 1 else downloaded
示例11: status_printer
# 需要导入模块: import ipywidgets [as 别名]
# 或者: from ipywidgets import IntProgress [as 别名]
def status_printer(_, total=None, desc=None, ncols=None, img=None):
"""
Manage the printing of an IPython/Jupyter Notebook progress bar widget.
"""
# Fallback to text bar if there's no total
# DEPRECATED: replaced with an 'info' style bar
# if not total:
# return super(mytqdm, mytqdm).status_printer(file)
# fp = file
# Prepare IPython progress bar
try:
if total:
pbar = IntProgress(min=0, max=total)
else: # No total? Show info style bar with no progress tqdm status
pbar = IntProgress(min=0, max=1)
pbar.value = 1
pbar.bar_style = 'info'
except NameError:
# #187 #451 #558
raise ImportError(
"IntProgress not found. Please update jupyter and ipywidgets."
" See https://ipywidgets.readthedocs.io/en/stable"
"/user_install.html")
if desc:
pbar.description = desc
if IPYW >= 7:
pbar.style.description_width = 'initial'
# Prepare status text
ptext = HTML()
timg = HTML()
if img:
timg.value = "<br>%s<br>" % img
# Only way to place text to the right of the bar is to use a container
container = VBox([HBox(children=[pbar, ptext]), timg])
# Prepare layout
if ncols is not None: # use default style of ipywidgets
# ncols could be 100, "100px", "100%"
ncols = str(ncols) # ipywidgets only accepts string
try:
if int(ncols) > 0: # isnumeric and positive
ncols += 'px'
except ValueError:
pass
pbar.layout.flex = '2'
container.layout.width = ncols
container.layout.display = 'inline-flex'
container.layout.flex_flow = 'row wrap'
display(container)
return container