Skip to content

Commit

Permalink
progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristman75 committed Jun 6, 2021
1 parent a4621ff commit 01d3509
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
45 changes: 35 additions & 10 deletions plotmanager/library/utilities/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import psutil
import re
import socket
import math

from plotmanager.library.utilities.instrumentation import increment_plots_completed
from plotmanager.library.utilities.notifications import send_notifications
Expand Down Expand Up @@ -133,27 +134,48 @@ def get_progress(line_count, progress_settings):
phase3_weight = progress_settings['phase3_weight']
phase4_weight = progress_settings['phase4_weight']
progress = 0
phase_progress = 0
if line_count > phase1_line_end:
progress += phase1_weight
else:
progress += phase1_weight * (line_count / phase1_line_end)
return progress
phase_progress = (line_count / phase1_line_end)
progress += phase1_weight * phase_progress
return progress, phase_progress * 100.0
if line_count > phase2_line_end:
progress += phase2_weight
else:
progress += phase2_weight * ((line_count - phase1_line_end) / (phase2_line_end - phase1_line_end))
return progress
phase_progress = ((line_count - phase1_line_end) / (phase2_line_end - phase1_line_end))
progress += phase2_weight * phase_progress
return progress, phase_progress * 100.0
if line_count > phase3_line_end:
progress += phase3_weight
else:
progress += phase3_weight * ((line_count - phase2_line_end) / (phase3_line_end - phase2_line_end))
return progress
phase_progress = ((line_count - phase2_line_end) / (phase3_line_end - phase2_line_end))
progress += phase3_weight * phase_progress
return progress, phase_progress * 100.0
if line_count > phase4_line_end:
progress += phase4_weight
else:
progress += phase4_weight * ((line_count - phase3_line_end) / (phase4_line_end - phase3_line_end))
return progress

phase_progress = ((line_count - phase3_line_end) / (phase4_line_end - phase3_line_end))
progress += phase4_weight * phase_progress
return progress, phase_progress * 100.0

def progress_bar(progress):
if progress < 0.0: progress = 0.0
if progress > 100.0: progress = 100.0

prog_bars = progress / 10.0
bar = "▐"
segments = math.floor(prog_bars)
bar += "■" * segments
empty_segments = 10-segments
if prog_bars - segments >= 0.5:
bar += "□"
empty_segments -= 1

bar += " " * empty_segments
bar += "▌"
return bar

def check_log_progress(jobs, running_work, progress_settings, notification_settings, view_settings,
instrumentation_settings):
Expand All @@ -167,16 +189,19 @@ def check_log_progress(jobs, running_work, progress_settings, notification_setti

line_count = (data.count('\n') + 1)

progress = get_progress(line_count=line_count, progress_settings=progress_settings)
progress, phase_progress = get_progress(line_count=line_count, progress_settings=progress_settings)

phase_times, phase_dates = get_phase_info(data, view_settings)
current_phase = 1
if phase_times:
current_phase = max(phase_times.keys()) + 1

work.phase_times = phase_times
work.phase_dates = phase_dates
work.current_phase = current_phase
work.progress = f'{progress:.2f}%'
work.phase_progress = progress_bar(phase_progress)
#work.phase_progress = f'{phase_progress:.2f}%'

if psutil.pid_exists(pid) and 'renamed final file from ' not in data.lower():
logging.info(f'PID still alive: {pid}')
Expand Down
1 change: 1 addition & 0 deletions plotmanager/library/utilities/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Work:
completed = False

progress = 0
phase_progress = 0
temp_file_size = 0
k_size = None

Expand Down
3 changes: 2 additions & 1 deletion plotmanager/library/utilities/print.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def _get_row_info(pid, running_work, view_settings, as_raw_values=False):
work.current_phase,
' / '.join(phase_time_log),
work.progress,
work.phase_progress,
pretty_print_bytes(work.temp_file_size, 'gb', 0, " GiB"),
]
if not as_raw_values:
Expand Down Expand Up @@ -98,7 +99,7 @@ def get_job_data(jobs, running_work, view_settings, as_json=False):


def pretty_print_job_data(job_data):
headers = ['num', 'job', 'k', 'plot_id', 'pid', 'start', 'elapsed_time', 'phase', 'phase_times', 'progress', 'temp_size']
headers = ['num', 'job', 'k', 'plot_id', 'pid', 'start', 'elapsed_time', 'phase', 'phase_times', 'progress', 'phase_prog', 'temp_size']
rows = [headers] + job_data
return pretty_print_table(rows)

Expand Down

0 comments on commit 01d3509

Please sign in to comment.