########################################################################### # # Copyright (c) 2021-2024 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) Dara Navaei # @date (last) 02-Dec-2021 # @author (original) Peter Lucia # @date (original) 29-Apr-2021 # ############################################################################ import sys sys.path.append("../../") from dialin.dg.dialysate_generator import DG from dialin.hd.hemodialysis_device import HD def gen_publish_requirements(module) -> dict: """ Generates a list of publish requirements @param module: the module to generate publish requirements for @return: """ result = {} 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 == "logger" and \ not attr.startswith("_") and \ not attr.isupper(): result[module.__class__.__name__] = result.get(module.__class__.__name__, []) + [attr] for _, attrs in result.items(): 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(module) -> dict: """ Generates requirements from leahi_dialin commands @param module: the module to generate command requirements for @return: """ result = {} 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 _, attrs in result.items(): for attr in attrs: print("The Dialin API shall provide a command that constructs and sends the {0} command.".format( attr.replace("_uf_", "_UF_") .replace("_ui_", "_UI_") .replace("cmd_", "") .replace("_", " ") )) return result hd = HD() dg = DG() hd_modules = [ hd, hd.accel, hd.air_bubbles, hd.air_trap, hd.alarms, hd.bloodflow, hd.blood_leak, hd.buttons, hd.calibration_record, hd.dialysate_inlet_flow, hd.dialysate_outlet_flow, hd.fluid_leak, hd.pressure_occlusion, hd.pretreatment, hd.rtc, hd.service_record, hd.switches, hd.syringe_pump, hd.system_record, hd.treatment, hd.ui, hd.valves, hd.voltages, hd.watchdog, ] dg_modules = [ dg, dg.accel, dg.alarms, dg.calibration_record, dg.chemical_disinfect, dg.concentrate_pumps, dg.conductivity_sensors, dg.drain_pump, dg.fans, dg.fluid_leak, dg.flush, dg.hd_proxy, dg.heat_disinfect, dg.heaters, dg.load_cells, dg.pressures, dg.reservoirs, dg.ro_pump, dg.rtc, dg.samplewater, dg.scheduled_runs_record, dg.service_record, dg.switches, dg.system_record, dg.temperatures, dg.thermistors, dg.uv_reactors, dg.valves, dg.voltages, ] def generate_requirements(modules): """ Generates requirements for given modules @param modules: the modules to generate requirements for @return: None """ for module in modules: print("\n{0}\n".format(module.__class__.__name__)) gen_publish_requirements(module) gen_cmd_requirements(module) if __name__ == '__main__': generate_requirements(hd_modules) generate_requirements(dg_modules)