Commit a16eac94 authored by bliss administrator's avatar bliss administrator
Browse files

Avoid negative diff values + Improve scan display to be adapted to terminal

window size
parent f9749468
......@@ -3,6 +3,7 @@ import gevent
import numpy as np
import time
import datetime
import shutil
import bliss
from bliss import setup_globals
......@@ -184,11 +185,12 @@ class ScanDisplay(DataWatchCallback):
else:
last_acq = cam._proxy.last_image_ready + 1
last_saved = cam._proxy.last_image_saved + 1
diff_trigger = self.__infos["trig"] - last_acq if self.__infos["trig"] - last_acq > 0 else 0
diff_trigger = self.__infos["trig"] - last_acq
data_readout_rate = round(cam._proxy.saving_statistics[3]/1024/1024,2)
#self.__infos[cam.name] = "{0} (saved {1} diff {2} data readout rate {3} MB/s)".format(last_acq, last_saved, diff_trigger, data_readout_rate)
self.__infos[cam.name] = "{0} (saved {1} data readout rate {2} MB/s)".format(last_acq, last_saved, data_readout_rate)
if diff_trigger > 0:
self.__infos[cam.name] = "{0} (saved {1} diff {2} data readout rate {3} MB/s)".format(last_acq, last_saved, diff_trigger, data_readout_rate)
else:
self.__infos[cam.name] = "{0} (saved {1} data readout rate {2} MB/s)".format(last_acq, last_saved, data_readout_rate)
msg = ""
......@@ -196,7 +198,24 @@ class ScanDisplay(DataWatchCallback):
msg += "{0} {1} ".format(BOLD(name), value)
if len(msg):
print(msg + "\r", end="")
terminal_width = shutil.get_terminal_size()[0]
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
bold_words = [word for word in msg_nonbold.split(' ') if word in self.__infos.keys()]
for word in bold_words:
msg = msg.replace(word,BOLD(word))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
else:
print(msg + "\r", end="")
for cam in self.__limas:
if cam.camera_type.lower() == 'pco' and 'dimax' in cam.camera.cam_name.lower():
......@@ -207,9 +226,8 @@ class ScanDisplay(DataWatchCallback):
diff = last_acq - last_saved
if cam._proxy.saving_mode == 'AUTO_FRAME':
if last_acq == cam._proxy.acq_nb_frames and diff != 0:
# erase line and go to beginning of line
print('\033[2K\033[1G', end="")
while diff != 0:
print("\033[2K\033[1G",end="")
time.sleep(0.5)
if 'pco' in cam.camera_type.lower() and 'dimax' in cam.camera.cam_name.lower():
last_acq = int(cam.camera.last_img_recorded/abs(cam._proxy.acc_nb_frames))
......@@ -218,7 +236,22 @@ class ScanDisplay(DataWatchCallback):
last_saved = cam._proxy.last_image_saved + 1
diff = last_acq - last_saved
msg = "Saving in progress... {0} saved {1}".format(BOLD(cam.name), last_saved)
print(msg + "\r", end="")
terminal_width = shutil.get_terminal_size()[0]
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
msg = msg.replace(cam.name,BOLD(cam.name))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
else:
print(msg + "\r", end="")
return
......
......@@ -170,13 +170,14 @@ class PcoTomoScanDisplay(DataWatchCallback):
else:
last_saved = cam._proxy.saving_next_number * cam._proxy.saving_frame_per_file
diff_trigger = self.__infos["trig"] - last_rec
if diff_trigger < 0:
diff_trigger = 0
scan = int(self.__infos["trig"] / info['technique']['scan']['tomo_n']) + 1
if self.__infos["trig"] % info['technique']['scan']['tomo_n'] == 0:
scan -= 1
self.__infos[cam.name] = "{0} (saved {1} diff {2} scan {3})".format(last_rec, last_saved, diff_trigger, scan)
if diff_trigger > 0:
self.__infos[cam.name] = "{0} (saved {1} diff {2} scan {3})".format(last_rec, last_saved, diff_trigger, scan)
else:
self.__infos[cam.name] = "{0} (saved {1} scan {2})".format(last_rec, last_saved, scan)
total_scan = info['technique']['scan']['nb_tomo']*info['technique']['scan']['nb_loop']
if self.__acq_time != 0 and self.__saving_time != 0 and last_saved % info['technique']['scan']['tomo_n'] == 0 and not self.__end:
#print('\033[2K\033[1G', end="")
......@@ -194,15 +195,19 @@ class PcoTomoScanDisplay(DataWatchCallback):
msg += "{0} {1} ".format(BOLD(name), value)
if len(msg):
# erase line and go to beginning of line
terminal_width = shutil.get_terminal_size()[0]
if len(msg) >= terminal_width:
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg)/terminal_width)):
lstr.append(msg[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg[terminal_width*(part+1):])
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
bold_words = [word for word in msg_nonbold.split(' ') if word in self.__infos.keys()]
for word in bold_words:
msg = msg.replace(word,BOLD(word))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
......@@ -235,13 +240,17 @@ class PcoTomoScanDisplay(DataWatchCallback):
last_saved = cam._proxy.saving_next_number * cam._proxy.saving_frame_per_file
msg = "Saving of scan {0} / {1} in progress... {2} saved {3} data readout rate {4} MB/s file saving rate {5} MB/s)".format(scan, total_scan, BOLD(cam.name), last_saved, round(cam._proxy.saving_statistics[3]/1024/1024,2), round(cam._proxy.saving_statistics[0]/1024/1024,2))
terminal_width = shutil.get_terminal_size()[0]
if len(msg) >= terminal_width:
msg_nonbold = msg.replace('\033[1m','')
msg_nonbold = msg_nonbold.replace('\033[0m','')
print('\033[2K\033[1G', end="")
if len(msg_nonbold) >= terminal_width:
lstr = []
#divide the entire string into multiples strings each one fitting terminal width
for part in range(int(len(msg)/terminal_width)):
lstr.append(msg[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg[terminal_width*(part+1):])
for part in range(int(len(msg_nonbold)/terminal_width)):
lstr.append(msg_nonbold[terminal_width*part:terminal_width*(part+1)])
lstr.append(msg_nonbold[terminal_width*(part+1):])
for msg in lstr:
msg = msg.replace(cam.name,BOLD(cam.name))
print(msg)
#put cursor back to previous lines allowing to overwriting each printed line
print("\033[F"*(len(lstr)+1))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment