monitor designated magnets to enable or disable Update button

This commit is contained in:
2024-04-18 16:58:22 +02:00
parent 1c9ba0db79
commit 34c3940899
4 changed files with 572 additions and 425 deletions

120
hush.py
View File

@@ -1,41 +1,31 @@
"""Hush.py module for energy saving accounting
"""
import inspect
import logging
import os
import platform
import random
import sys
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 (
PYQT_VERSION_STR, QFile, QIODevice, Qt, QThread, Signal, Slot)
from qtpy.QtWidgets import (
QApplication, QDockWidget, QGridLayout, QGroupBox, QHBoxLayout, QLabel,
QMainWindow, QMessageBox, QProgressBar, QPushButton, QSizePolicy,
QSpacerItem, QTabWidget, QTableWidget, QTableWidgetItem, QVBoxLayout,
QWidget)
from qtpy.QtCore import PYQT_VERSION_STR, Signal, Slot
from qtpy.QtWidgets import QApplication, QMessageBox
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.hipa.sendeloghipa import QSendToELOG
from apps4ops.hipa.enumkind import ElogHIPA
from src.gui import AppGui
from pyrcc5 import hush_resources
from pyrcc5 import hush_resources
_pymodule = os.path.basename(__file__)
_appname, _appext = _pymodule.split(".")
_appversion = "2.0.0"
#_title = """HIPA Power Usage & Saving Hierarchy""" #, HUSH!"""
# _title = """HIPA Power Usage & Saving Hierarchy""" #, HUSH!"""
_title = """HUSH!"""
def _line():
"""Macro to return the current line number.
@@ -47,76 +37,79 @@ def _line():
"""
return inspect.currentframe().f_back.f_lineno
class StartMain(BaseWindow):
''' Main class for HUSH
'''
trigger_log_message = Signal(str, str, int, str, dict)
def __init__(self, parent=None):
super(StartMain, self).__init__(
parent=parent, pymodule=_pymodule, appversion=_appversion,
def __init__(self, parent=None):
#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,
title=_title, user_mode=UserMode.OPERATION, facility=Facility.HIPA,
has_optics=False, has_procedure=False)
self.appname = _appname
self.elog_enum = ElogHIPA()
self.gui = AppGui(self)
def prepare_elog_message(self):
self.projekt_idx = self.elog_enum.projekt.NONE
self.system_idx = self.elog_enum.system.ELECTRICAL_SUPPLY
self.eintrag_idx = self.elog_enum.eintrag.INFO
self.ort_idx = self.elog_enum.ort.GLOBAL
self.status_idx = self.elog_enum.status.NONE
self.effekt_idx = self.elog_enum.effekt.NO
self.attach_files = []
_simulation = self.input_parameters['simulation']
simulation = self.input_parameters["simulation"]
if self.all_data:
if self.all_data['Input data'] is not None:
if self.all_data["Input data"] is not None:
try:
_simulation = self.all_data['Input data']['simulation']
simulation = self.all_data["Input data"]["simulation"]
except KeyError:
_simulation = self.input_parameters['simulation']
simulation = self.input_parameters["simulation"]
pass
self.logbook = "Sandkasten" if _simulation else "HIPA"
self.logbook = "Sandkasten" if simulation else "HIPA"
self.title = _title
sector = ["<br>IP2: ","<br>IW2: ","<br>PK1: ", "<br>PK2: ","<br>SNQ: ",
"<br>UCN: ","<br>------------------<br>Tot: "]
sector = ["<br>IP2: ", "<br>IW2: ", "<br>PK1: ", "<br>PK2: ",
"<br>SNQ: ", "<br>UCN: ",
"<br>------------------<br>Tot: "]
pvlist = ['ZIP2-HUSH:TOTSAVE', 'ZIW2-HUSH:TOTSAVE', 'ZPK1-HUSH:TOTSAVE',
'ZPK2-HUSH:TOTSAVE', 'ZSINQ-HUSH:TOTSAVE', 'ZUCN-HUSH:TOTSAVE',
'ZHIPA-HUSH:TOTSAVE']
pvlist = ["ZIP2-HUSH:TOTSAVE", "ZIW2-HUSH:TOTSAVE", "ZPK1-HUSH:TOTSAVE",
"ZPK2-HUSH:TOTSAVE", "ZSINQ-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)
if stat != self.cyca.ICAFE_NORMAL:
self.check_status_list(_pymodule, "getScalarListCache",
pvlist, stat_list, _line())
message = ("Power saved for the current year stands at " +
"{:.3f} MWh:").format(value[-1])
for label, val in zip(sector, value):
message += label + "{:.3f}".format(val) + " MWh"
self.message = message
@Slot()
def send_to_elog(self):
@Slot()
def save_fig_thread_finished():
time.sleep(0.2)
if self.all_data:
QSendToELOG(self, logbook=self.logbook,
projektIdx=self.projekt_idx,
@@ -128,15 +121,14 @@ class StartMain(BaseWindow):
title=self.title,
message=self.message,
attachFile=self.attach_files)
time.sleep(1.0)
return
#if not self.verify_send_to_elog():
# if not self.verify_send_to_elog():
# return
self.prepare_elog_message()
print(self.message, flush=True)
if not self.all_data:
@@ -152,28 +144,26 @@ class StartMain(BaseWindow):
attachFile=self.attach_files)
return
folder_name = self.elog_dest
if not os.path.exists(folder_name):
os.makedirs(folder_name)
_folder_name = self.elog_dest
if not os.path.exists(_folder_name):
os.makedirs(_folder_name)
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']
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:
reanalysis_time = None
self.folder_name = _folder_name
self.folder_name = folder_name
save_fig_thread = self.SaveFigureThread(
self, self.folder_name, time_in_seconds, reanalysis_time)
save_fig_thread.finished.connect(save_fig_thread_finished)
save_fig_thread.start()
time.sleep(0.05)
@Slot()
def closeEvent(self, event):
@@ -198,7 +188,7 @@ class StartMain(BaseWindow):
<p>IOC Administrator: H. Lutz </p>
<p>1st Responsible: A. Barchetti, Tel. 4779
or 3301 (Control Room) </p>
<p>Initiates energy saving procedures and records power saved</p>
<p>Python {2} - Qt {3} - PyQt {4} <br>
cafe {5} - epics {6} on {7}""".format(
@@ -212,24 +202,24 @@ class StartMain(BaseWindow):
def show_help(self):
""" Invoke help pages from hush_resources
"""
index_html ="index.html" #self.appname + "/index.html"
help_base = ":" # + self.appname
index_html = "index.html" # self.appname + "/index.html"
help_base = ":" # + self.appname
help_page = HelpBrowser(help_base, index_html, self)
help_page.show()
#########################################################################
if __name__ == "__main__":
app = QApplication(sys.argv)
splash = BaseWindow.initialize_application(
app, appname=_appname, delay=25, facility=Facility.HIPA)
myapp = StartMain()
myapp.show()
if splash is not None:
splash.finish(myapp)
app.exec_()

View File

@@ -1,5 +1,5 @@
#!/bin/bash
cd /hipa/bd/applications/hush/hla/2.0.0
cd /hipa/bd/applications/hush/hla/2.1.0
# For use if script is sourced rather than executed
appNameDefault="hush.sh"
@@ -83,6 +83,8 @@ echo "nameLog: $nameLog"
#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 wakeup.py 00:00 &
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 test -f "$STDOUT_DIR/${nameLog}.log---"; then

File diff suppressed because it is too large Load Diff

57
wakeup.py Normal file
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_()