8 Commits

5 changed files with 685 additions and 451 deletions
+39 -49
View File
@@ -1,30 +1,19 @@
"""Hush.py module for energy saving accounting """Hush.py module for energy saving accounting
""" """
import inspect import inspect
import logging
import os import os
import platform import platform
import random
import sys import sys
import time import time
from qtpy import QtCore, QtGui
from qtpy.QtGui import QColor, QFont, QIcon
from qtpy.QtCore import __version__ as QT_VERSION_STR from qtpy.QtCore import __version__ as QT_VERSION_STR
from qtpy.QtCore import ( from qtpy.QtCore import PYQT_VERSION_STR, Signal, Slot
PYQT_VERSION_STR, QFile, QIODevice, Qt, QThread, Signal, Slot) from qtpy.QtWidgets import QApplication, QMessageBox
from qtpy.QtWidgets import (
QApplication, QDockWidget, QGridLayout, QGroupBox, QHBoxLayout, QLabel,
QMainWindow, QMessageBox, QProgressBar, QPushButton, QSizePolicy,
QSpacerItem, QTabWidget, QTableWidget, QTableWidgetItem, QVBoxLayout,
QWidget)
from apps4ops.bdbase.base import BaseWindow from apps4ops.bdbase.base import BaseWindow
from apps4ops.bdbase.enumkind import MsgSeverity, UserMode, Facility from apps4ops.bdbase.enumkind import UserMode, Facility
from apps4ops.bdbase.helpbrowser import HelpBrowser from apps4ops.bdbase.helpbrowser import HelpBrowser
from apps4ops.hipa.sendeloghipa import QSendToELOG from apps4ops.hipa.sendeloghipa import QSendToELOG
from apps4ops.hipa.enumkind import ElogHIPA from apps4ops.hipa.enumkind import ElogHIPA
from src.gui import AppGui from src.gui import AppGui
@@ -32,10 +21,11 @@ from pyrcc5 import hush_resources
_pymodule = os.path.basename(__file__) _pymodule = os.path.basename(__file__)
_appname, _appext = _pymodule.split(".") _appname, _appext = _pymodule.split(".")
_appversion = "2.0.0" _appversion = "2.3.0"
#_title = """HIPA Power Usage & Saving Hierarchy""" #, HUSH!""" # _title = """HIPA Power Usage & Saving Hierarchy""" #, HUSH!"""
_title = """HUSH!""" _title = """HUSH!"""
def _line(): def _line():
"""Macro to return the current line number. """Macro to return the current line number.
@@ -47,22 +37,27 @@ def _line():
""" """
return inspect.currentframe().f_back.f_lineno return inspect.currentframe().f_back.f_lineno
class StartMain(BaseWindow): class StartMain(BaseWindow):
''' Main class for HUSH
'''
trigger_log_message = Signal(str, str, int, str, dict) trigger_log_message = Signal(str, str, int, str, dict)
def __init__(self, parent=None): def __init__(self, parent=None):
super(StartMain, self).__init__( #super(StartMain, self).__init__(
# parent=parent, pymodule=_pymodule, appversion=_appversion,
# title=_title, user_mode=UserMode.OPERATION, facility=Facility.HIPA,
# has_optics=False, has_procedure=False)
super().__init__(
parent=parent, pymodule=_pymodule, appversion=_appversion, parent=parent, pymodule=_pymodule, appversion=_appversion,
title=_title, user_mode=UserMode.OPERATION, facility=Facility.HIPA, title=_title, user_mode=UserMode.OPERATION, facility=Facility.HIPA,
has_optics=False, has_procedure=False) has_optics=False, has_procedure=False)
self.appname = _appname self.appname = _appname
self.elog_enum = ElogHIPA() self.elog_enum = ElogHIPA()
self.gui = AppGui(self) self.gui = AppGui(self)
def prepare_elog_message(self): def prepare_elog_message(self):
self.projekt_idx = self.elog_enum.projekt.NONE self.projekt_idx = self.elog_enum.projekt.NONE
self.system_idx = self.elog_enum.system.ELECTRICAL_SUPPLY self.system_idx = self.elog_enum.system.ELECTRICAL_SUPPLY
self.eintrag_idx = self.elog_enum.eintrag.INFO self.eintrag_idx = self.elog_enum.eintrag.INFO
@@ -70,31 +65,30 @@ class StartMain(BaseWindow):
self.status_idx = self.elog_enum.status.NONE self.status_idx = self.elog_enum.status.NONE
self.effekt_idx = self.elog_enum.effekt.NO self.effekt_idx = self.elog_enum.effekt.NO
self.attach_files = [] self.attach_files = []
_simulation = self.input_parameters['simulation'] simulation = self.input_parameters["simulation"]
if self.all_data: if self.all_data:
if self.all_data['Input data'] is not None: if self.all_data["Input data"] is not None:
try: try:
_simulation = self.all_data['Input data']['simulation'] simulation = self.all_data["Input data"]["simulation"]
except KeyError: except KeyError:
_simulation = self.input_parameters['simulation'] simulation = self.input_parameters["simulation"]
pass pass
self.logbook = "Sandkasten" if simulation else "HIPA"
self.logbook = "Sandkasten" if _simulation else "HIPA"
self.title = _title self.title = _title
sector = ["<br>IP2: ","<br>IW2: ","<br>PK1: ", "<br>PK2: ","<br>SNQ: ", sector = ["<br>IP2: ", "<br>IW2: ", "<br>PK1: ", "<br>PK2: ",
"<br>UCN: ","<br>------------------<br>Tot: "] "<br>SNQ: ", "<br>UCN: ",
"<br>------------------<br>Tot: "]
pvlist = ['ZIP2-HUSH:TOTSAVE', 'ZIW2-HUSH:TOTSAVE', 'ZPK1-HUSH:TOTSAVE', pvlist = ["ZIP2-HUSH:TOTSAVE", "ZIW2-HUSH:TOTSAVE", "ZPK1-HUSH:TOTSAVE",
'ZPK2-HUSH:TOTSAVE', 'ZSINQ-HUSH:TOTSAVE', 'ZUCN-HUSH:TOTSAVE', "ZPK2-HUSH:TOTSAVE", "ZSINQ-HUSH:TOTSAVE",
'ZHIPA-HUSH:TOTSAVE'] "ZUCN-HUSH:TOTSAVE", "ZHIPA-HUSH:TOTSAVE"]
value, stat, stat_list =self.cafe.getScalarList( value, stat, stat_list = self.cafe.getScalarList(
pvlist, cacheFlag=True) pvlist, cacheFlag=True)
if stat != self.cyca.ICAFE_NORMAL: if stat != self.cyca.ICAFE_NORMAL:
@@ -106,7 +100,6 @@ class StartMain(BaseWindow):
for label, val in zip(sector, value): for label, val in zip(sector, value):
message += label + "{:.3f}".format(val) + " MWh" message += label + "{:.3f}".format(val) + " MWh"
self.message = message self.message = message
@Slot() @Slot()
@@ -130,9 +123,8 @@ class StartMain(BaseWindow):
attachFile=self.attach_files) attachFile=self.attach_files)
time.sleep(1.0) time.sleep(1.0)
return
#if not self.verify_send_to_elog(): # if not self.verify_send_to_elog():
# return # return
self.prepare_elog_message() self.prepare_elog_message()
@@ -152,19 +144,18 @@ class StartMain(BaseWindow):
attachFile=self.attach_files) attachFile=self.attach_files)
return return
folder_name = self.elog_dest
if not os.path.exists(folder_name):
os.makedirs(folder_name)
_folder_name = self.elog_dest time_in_seconds = self.all_data["Ambient data"]["Time in seconds"]
if not os.path.exists(_folder_name): if self.all_data["Processed data"]["Reanalysis time"]:
os.makedirs(_folder_name) reanalysis_time = self.all_data["Processed data"][
"Reanalysis time in seconds"]
time_in_seconds = self.all_data['Ambient data']['Time in seconds']
if self.all_data['Processed data']['Reanalysis time']:
reanalysis_time = self.all_data['Processed data'][
'Reanalysis time in seconds']
else: else:
reanalysis_time = None reanalysis_time = None
self.folder_name = _folder_name self.folder_name = folder_name
save_fig_thread = self.SaveFigureThread( save_fig_thread = self.SaveFigureThread(
self, self.folder_name, time_in_seconds, reanalysis_time) self, self.folder_name, time_in_seconds, reanalysis_time)
@@ -173,7 +164,6 @@ class StartMain(BaseWindow):
save_fig_thread.start() save_fig_thread.start()
time.sleep(0.05) time.sleep(0.05)
@Slot() @Slot()
def closeEvent(self, event): def closeEvent(self, event):
@@ -195,7 +185,7 @@ class StartMain(BaseWindow):
All rights reserved.</p> All rights reserved.</p>
<p>Author: J. Chrin, Spring 2023 </p> <p>Author: J. Chrin, Spring 2023 </p>
<p>(EPICS db adapted from A. Kovach, 2016) <p> <p>(EPICS db adapted from A. Kovach, 2016) <p>
<p>IOC Administrator: H. Lutz </p> <p>IOC Administrator: P. Fernandez (prev. H. Lutz) </p>
<p>1st Responsible: A. Barchetti, Tel. 4779 <p>1st Responsible: A. Barchetti, Tel. 4779
or 3301 (Control Room) </p> or 3301 (Control Room) </p>
@@ -212,11 +202,12 @@ class StartMain(BaseWindow):
def show_help(self): def show_help(self):
""" Invoke help pages from hush_resources """ Invoke help pages from hush_resources
""" """
index_html ="index.html" #self.appname + "/index.html" index_html = "index.html" # self.appname + "/index.html"
help_base = ":" # + self.appname help_base = ":" # + self.appname
help_page = HelpBrowser(help_base, index_html, self) help_page = HelpBrowser(help_base, index_html, self)
help_page.show() help_page.show()
######################################################################### #########################################################################
if __name__ == "__main__": if __name__ == "__main__":
@@ -232,4 +223,3 @@ if __name__ == "__main__":
splash.finish(myapp) splash.finish(myapp)
app.exec_() app.exec_()
+12 -5
View File
@@ -1,11 +1,11 @@
#!/bin/bash #!/bin/bash
cd /hipa/bd/applications/hush/hla/2.0.0 cd /hipa/bd/applications/hush/hla/2.3.0
# For use if script is sourced rather than executed # For use if script is sourced rather than executed
appNameDefault="hush.sh" appNameDefault="hush.sh"
module unload gcc module unload gcc
module load gcc/7.3.0 module load gcc/7.5.0
if [ -z "$PS1" ] # no prompt? if [ -z "$PS1" ] # no prompt?
### if [ -v PS1 ] # On Bash 4.2+ ... ### if [ -v PS1 ] # On Bash 4.2+ ...
@@ -17,6 +17,9 @@ else
echo "Interactive/sourced script" echo "Interactive/sourced script"
fi fi
_EPICS_HOST_ARCH=${RHREL}-x86_64
_EPICS_BASE=base-7.0.8
# Select Python Version here. Currently one of 3.5, 3.7, 3.8 and 3.10 # Select Python Version here. Currently one of 3.5, 3.7, 3.8 and 3.10
PYTHON_VERSION=3.10 PYTHON_VERSION=3.10
@@ -32,6 +35,7 @@ if [ "$1" ]; then
elif [ "$1" == "3.7" -o "$1" == "37" ]; then elif [ "$1" == "3.7" -o "$1" == "37" ]; then
PYTHON_VERSION=3.7 PYTHON_VERSION=3.7
PYTHON_VERSION_DIR=37 PYTHON_VERSION_DIR=37
export LD_PRELOAD=/usr/local/epics/${_EPICS_BASE}/lib/${_EPICS_HOST_ARCH}/libca.so:/usr/local/epics/${_EPICS_BASE}/lib/${_EPICS_HOST_ARCH}/libCom.so
elif [ "$1" == "3.8" -o "$1" == "38" ]; then elif [ "$1" == "3.8" -o "$1" == "38" ]; then
PYTHON_VERSION=3.8 PYTHON_VERSION=3.8
PYTHON_VERSION_DIR=38 PYTHON_VERSION_DIR=38
@@ -50,13 +54,11 @@ fi
echo "PYTHON_VERSION $PYTHON_VERSION" echo "PYTHON_VERSION $PYTHON_VERSION"
_EPICS_HOST_ARCH=${RHREL}-x86_64
#_EPICS_HOST_ARCH=${EPICS_HOST_ARCH}
. /opt/gfa/python $PYTHON_VERSION . /opt/gfa/python $PYTHON_VERSION
#C_EXT version for Py 3.5, 3.7. 3.8, 3.10: #C_EXT version for Py 3.5, 3.7. 3.8, 3.10:
export PYTHONPATH=.:/opt/gfa/cafe/python/pycafe/cafe-1.19.3/lib/${_EPICS_HOST_ARCH}:/hipa/bd/applications/deps/apps4ops/v1.10.0 export PYTHONPATH=.:/opt/gfa/cafe/python/pycafe/cafe-1.21.0/lib/${_EPICS_HOST_ARCH}:/hipa/bd/applications/deps/apps4ops/v1.12.0
echo $PYTHONPATH echo $PYTHONPATH
@@ -83,6 +85,8 @@ echo "nameLog: $nameLog"
#Configuration files can be overwritten #Configuration files can be overwritten
#python ${name}.py -s="/sf/bd/deps/pyqtacc/common/config/style.json" -f="/sf/bd/deps/pyqtacc/v1.0.0/pyqtacc/qrc_resources/facility/sf/config/base.json" -q="/sf/bd/deps/pyqtacc/common/config/acc.qss" & #python ${name}.py -s="/sf/bd/deps/pyqtacc/common/config/style.json" -f="/sf/bd/deps/pyqtacc/v1.0.0/pyqtacc/qrc_resources/facility/sf/config/base.json" -q="/sf/bd/deps/pyqtacc/common/config/acc.qss" &
python wakeup.py 00:00 &
if [ "${STDOUT_FLAG}" -gt "0" ] ; then if [ "${STDOUT_FLAG}" -gt "0" ] ; then
#if changing the std::out destination, remember to also change it in your json config file (for reading) #if changing the std::out destination, remember to also change it in your json config file (for reading)
if test -f "$STDOUT_DIR/${nameLog}.log---"; then if test -f "$STDOUT_DIR/${nameLog}.log---"; then
@@ -109,3 +113,6 @@ else
fi fi
if [ "${PYTHON_VERSION}" == "3.7" ] ; then
unset LD_PRELOAD
fi
Binary file not shown.
+443 -263
View File
File diff suppressed because it is too large Load Diff
+57
View File
@@ -0,0 +1,57 @@
'''Precedes splashscreen of main application
'''
import sys
import time
from qtpy.QtCore import Qt, QTime, QTimer
from qtpy.QtGui import QColor, QImage, QPainter, QPixmap
from qtpy.QtWidgets import QApplication, QLabel
from pyqtacc.qrc_resources.facility.proscan.pyrcc5 import qrc_resources
app = QApplication(sys.argv)
try:
due = QTime.currentTime()
message = "HUSH! will begin to load shortly"
if len(sys.argv) < 2:
raise ValueError
hours, mins = sys.argv[1].split(":")
due = QTime(int(hours), int(mins))
if not due.isValid():
raise ValueError
if len(sys.argv) > 2:
message = " ".join(sys.argv[2:])
except ValueError:
message = "Usage: wakeup.py HH:MM [optional message]"
while QTime.currentTime() < due:
time.sleep(1)
image = QImage(":/Hush.jpg")
p = QPainter(image)
font = p.font()
font.setPixelSize(54)
p.setFont(font)
p.setPen(QColor(Qt.red))
#p.setStyleSheet("color:red;")
#p.save()
p.drawText(40, 350, message)
#p.restore()
pixmap = QPixmap.fromImage(image)
label = QLabel()
label.setPixmap(pixmap)
label.setScaledContents(True)
label.setWindowFlags(Qt.SplashScreen)
label.setAlignment(Qt.AlignCenter)
label.setFixedHeight(600)
label.setFixedWidth(600)
label.show()
QTimer.singleShot(5000, app.quit) #5 seconds
app.exec_()