########################################################################### # # Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. # # THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN # WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. # # @file test_gen_requirements.py # # @author (last) Peter Lucia # @date (last) 10-Nov-2020 # @author (original) Peter Lucia # @date (original) 09-Jul-2020 # ############################################################################ import sys sys.path.append("../../") from dialin.dg.dialysate_generator import DG from dialin.hd.hemodialysis_device import HD from typing import List def gen_publish_requirements(modules: List[object]) -> dict: """ Generates a list of publish requirements @param modules: @return: """ result = {} for module in modules: for attr in dir(module): if not callable(getattr(module, attr)) and \ not attr.startswith("MSG") and \ not attr.startswith("START") and \ not attr.startswith("END") and \ not attr == "can_interface" and \ not attr.startswith("_") and \ not attr.isupper(): result[module.__class__.__name__] = result.get(module.__class__.__name__, []) + [attr] for module, attrs in result.items(): print("\n{0} \n ".format(module)) for attr in attrs: print("The Dialin API shall publish the {0} to all observers upon HD messaging.".format(attr.replace("_", " "))) return result def gen_cmd_requirements(modules: List[object]) -> dict: """ Generates requirements from dialin commands @param modules: the list of modules to generate requirements for @return: """ result = {} for module in modules: for attr in dir(module): if callable(getattr(module, attr)) and attr.startswith("cmd"): result[module.__class__.__name__] = result.get(module.__class__.__name__, []) + [attr] for module, attrs in result.items(): print("\n{0} \n ".format(module)) for attr in attrs: print("The Dialin API shall provide a command that constructs and sends the {0} command.".format(attr .replace("_", " ") .replace("cmd ", "") .replace("uf", "UF") .replace("ui", "UI") )) return result def generate_hd_requirements(): """ Generates requires for the HD @return: None """ hd = HD() modules = [ hd.alarms, hd.buttons, hd.ui, hd.rtc, hd.watchdog, hd.bloodflow, hd.dialysate_inlet_flow, hd.dialysate_outlet_flow, hd.treatment, hd.pressure_occlusion, hd.valves, hd.air_trap, hd.accel ] gen_publish_requirements(modules) gen_cmd_requirements(modules) def generate_dg_requirements(): """ Generates requires for the DG @return: None """ dg = DG() modules = [ dg.alarms, dg.concentrate_pumps, dg.fans, dg.heat_disinfect, dg.thermistors, dg.uv_reactors, ] gen_publish_requirements(modules) gen_cmd_requirements(modules) if __name__ == '__main__': generate_dg_requirements() generate_hd_requirements()