"""Hush.py module for energy saving accounting """ import inspect import os import platform import sys import time from qtpy.QtCore import __version__ as QT_VERSION_STR 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 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 = "2.3.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): ''' 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, # 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"] 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 = ["
IP2: ", "
IW2: ", "
PK1: ", "
PK2: ", "
SNQ: ", "
UCN: ", "
------------------
Tot: "] 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( 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, 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) # if not self.verify_send_to_elog(): # return self.prepare_elog_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", """{0} v {1}

Copyright © Paul Scherrer Institut (PSI). All rights reserved.

Author: J. Chrin, Spring 2023

(EPICS db adapted from A. Kovach, 2016)

IOC Administrator: P. Fernandez (prev. H. Lutz)

1st Responsible: A. Barchetti, Tel. 4779 or 3301 (Control Room)

Initiates energy saving procedures and records power saved

Python {2} - Qt {3} - PyQt {4}
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=25, facility=Facility.HIPA) myapp = StartMain() myapp.show() if splash is not None: splash.finish(myapp) app.exec_()