5 Commits

4 changed files with 657 additions and 442 deletions
+55 -65
View File
@@ -1,41 +1,31 @@
"""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
from pyrcc5 import hush_resources 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.0.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,76 +37,79 @@ 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, # 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,
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
self.ort_idx = self.elog_enum.ort.GLOBAL self.ort_idx = self.elog_enum.ort.GLOBAL
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:
self.check_status_list(_pymodule, "getScalarListCache", self.check_status_list(_pymodule, "getScalarListCache",
pvlist, stat_list, _line()) pvlist, stat_list, _line())
message = ("Power saved for the current year stands at " + message = ("Power saved for the current year stands at " +
"{:.3f} MWh:").format(value[-1]) "{:.3f} MWh:").format(value[-1])
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()
def send_to_elog(self): def send_to_elog(self):
@Slot() @Slot()
def save_fig_thread_finished(): def save_fig_thread_finished():
time.sleep(0.2) time.sleep(0.2)
if self.all_data: if self.all_data:
QSendToELOG(self, logbook=self.logbook, QSendToELOG(self, logbook=self.logbook,
projektIdx=self.projekt_idx, projektIdx=self.projekt_idx,
@@ -128,15 +121,14 @@ class StartMain(BaseWindow):
title=self.title, title=self.title,
message=self.message, message=self.message,
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()
print(self.message, flush=True) print(self.message, flush=True)
if not self.all_data: if not self.all_data:
@@ -152,28 +144,26 @@ 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)
save_fig_thread.finished.connect(save_fig_thread_finished) save_fig_thread.finished.connect(save_fig_thread_finished)
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):
@@ -198,7 +188,7 @@ class StartMain(BaseWindow):
<p>IOC Administrator: H. Lutz </p> <p>IOC Administrator: 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>
<p>Initiates energy saving procedures and records power saved</p> <p>Initiates energy saving procedures and records power saved</p>
<p>Python {2} - Qt {3} - PyQt {4} <br> <p>Python {2} - Qt {3} - PyQt {4} <br>
cafe {5} - epics {6} on {7}""".format( cafe {5} - epics {6} on {7}""".format(
@@ -212,24 +202,24 @@ 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__":
app = QApplication(sys.argv) app = QApplication(sys.argv)
splash = BaseWindow.initialize_application( splash = BaseWindow.initialize_application(
app, appname=_appname, delay=25, facility=Facility.HIPA) app, appname=_appname, delay=25, facility=Facility.HIPA)
myapp = StartMain() myapp = StartMain()
myapp.show() myapp.show()
if splash is not None: if splash is not None:
splash.finish(myapp) splash.finish(myapp)
app.exec_() app.exec_()
+5 -3
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.2.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+ ...
@@ -56,7 +56,7 @@ _EPICS_HOST_ARCH=${RHREL}-x86_64
#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.20.0-gcc-7.5.0/lib/${_EPICS_HOST_ARCH}:/hipa/bd/applications/deps/apps4ops/v1.11.0
echo $PYTHONPATH echo $PYTHONPATH
@@ -83,6 +83,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
+540 -374
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_()