232 lines
7.5 KiB
Python
232 lines
7.5 KiB
Python
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 apps4ops.bdbase.base import BaseWindow
|
|
from apps4ops.bdbase.enumkind import MsgSeverity, 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
|
|
|
|
_pymodule = os.path.basename(__file__)
|
|
_appname, _appext = _pymodule.split(".")
|
|
_appversion = "1.0.0"
|
|
#_title = """HIPA Power Usage & Saving Hierarchy""" #, HUSH!"""
|
|
_title = """HUSH!"""
|
|
|
|
def _line():
|
|
"""Macro to return the current line number.
|
|
|
|
The current line number within the file is used when
|
|
reporting messages to the message logging window.
|
|
|
|
Returns:
|
|
int: Current line number.
|
|
"""
|
|
return inspect.currentframe().f_back.f_lineno
|
|
|
|
class StartMain(BaseWindow):
|
|
trigger_log_message = Signal(str, str, int, str, dict)
|
|
|
|
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)
|
|
|
|
self.appname = _appname
|
|
self.gui = AppGui(self)
|
|
|
|
|
|
@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,
|
|
eintragIdx=self.eintrag_idx,
|
|
systemIdx=self.system_idx,
|
|
statusIdx=self.status_idx,
|
|
ordIdx=self.ort_idx,
|
|
effektIdx=self.effekt_idx,
|
|
title=self.title,
|
|
message=self.message,
|
|
attachFile=self.attach_files)
|
|
|
|
time.sleep(1.0)
|
|
return
|
|
|
|
#if not self.verify_send_to_elog():
|
|
# return
|
|
|
|
|
|
elog = ElogHIPA()
|
|
self.projekt_idx = elog.projekt.NONE
|
|
self.system_idx = elog.system.ELECTRICAL_SUPPLY
|
|
self.eintrag_idx = elog.eintrag.INFO
|
|
self.ort_idx = elog.ort.GLOBAL
|
|
self.status_idx = elog.status.NONE
|
|
self.effekt_idx = elog.effekt.NO
|
|
|
|
|
|
self.attach_files = []
|
|
|
|
_simulation = self.input_parameters['simulation']
|
|
|
|
if self.all_data:
|
|
if self.all_data['Input data'] is not None:
|
|
try:
|
|
_simulation = self.all_data['Input data']['simulation']
|
|
except KeyError:
|
|
_simulation = self.input_parameters['simulation']
|
|
pass
|
|
|
|
|
|
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: "]
|
|
pvlist = ['SEC-IP2:TOTSAVE', 'SEC-IW2:TOTSAVE', 'SEC-PK1:TOTSAVE',
|
|
'SEC-PK2:TOTSAVE', 'SEC-SINQ:TOTSAVE', 'SEC-UCN:TOTSAVE',
|
|
'HUSH:TOTSAVE']
|
|
|
|
value, stat, stat_list =self.cafe.getScalarList(pvlist, cacheFlag=True)
|
|
|
|
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"
|
|
|
|
'''
|
|
message += "IP2: " + str(value[0])+ " MWh <br>"
|
|
message += "IW2: " + str(value[1])+ " MWh <br>"
|
|
message += "PK1: " + str(value[2])+ " MWh <br>"
|
|
message += "PK2: " + str(value[3])+ " MWh <br>"
|
|
message += "SNQ: " + str(value[4])+ " MWh <br>"
|
|
message += "UCN: " + str(value[5])+ " MWh <br>"
|
|
message += "Tot: " + str(value[6])+ " MWh"
|
|
'''
|
|
self.message = message
|
|
print(self.message, flush=True)
|
|
|
|
if not self.all_data:
|
|
QSendToELOG(self, logbook=self.logbook,
|
|
projektIdx=self.projekt_idx,
|
|
eintragIdx=self.eintrag_idx,
|
|
systemIdx=self.system_idx,
|
|
statusIdx=self.status_idx,
|
|
ortIdx=self.ort_idx,
|
|
effektIdx=self.effekt_idx,
|
|
title=self.title,
|
|
message=self.message,
|
|
attachFile=self.attach_files)
|
|
return
|
|
|
|
|
|
_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']
|
|
else:
|
|
reanalysis_time = None
|
|
|
|
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):
|
|
|
|
if not self.verify_close_event():
|
|
event.ignore()
|
|
return
|
|
|
|
BaseWindow.closeEvent(self, event)
|
|
|
|
@Slot()
|
|
def show_about(self):
|
|
""" To overide by application
|
|
"""
|
|
QApplication.processEvents()
|
|
QMessageBox.about(
|
|
self, "About",
|
|
"""<b>{0}</b> v {1}
|
|
<p>Copyright © Paul Scherrer Institut (PSI).
|
|
All rights reserved.</p>
|
|
<p>Author: J. Chrin, Spring 2023 </p>
|
|
<p>(EPICS db adapted from A. Kovach, 2016) <p>
|
|
<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(
|
|
_pymodule, _appversion, platform.python_version(),
|
|
QT_VERSION_STR, PYQT_VERSION_STR,
|
|
self.cafe.CAFE_version(), self.cafe.EPICS_version(),
|
|
platform.system()))
|
|
QApplication.processEvents()
|
|
|
|
@Slot()
|
|
def show_help(self):
|
|
""" Invoke help pages from hush_resources
|
|
"""
|
|
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=20, facility=Facility.HIPA)
|
|
|
|
myapp = StartMain()
|
|
|
|
myapp.show()
|
|
|
|
if splash is not None:
|
|
splash.finish(myapp)
|
|
|
|
app.exec_()
|
|
|