def test_filter_records(self): records = [ ("5678", mpc.ENH_COUCH_CHECKS, "2020-06-25-07-11", [ mpc.mpc_path_to_meta( "NDS-WKS-SN5678-2020-06-25-07-11-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch" ) ]), # noqa: E501 ("6789", mpc.ENH_MLC_CHECKS, "2020-09-30-09-15", [ mpc.mpc_path_to_meta( "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x" ) ]), ("1234", mpc.ENH_MLC_CHECKS, "2020-09-30-09-15", [ mpc.mpc_path_to_meta( "NDS-WKS-SN1234-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x" ) ]), ] cutoff = (dt.now() - dt(2020, 7, 1)).days * 24 * 60 self.pump.state = { "MPC": { 'subsections': [[{ 'config_name': 'wait time', 'value': cutoff }]] } } assert self.pump.filter_records(records) == records[:1]
def test_group_by_sn(): dir_names = [ "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN4567-2020-10-01-11-26-55-0010-GeometryCheckTemplate6xMVkVEnhancedCouch", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", ] metas = [mpc.mpc_path_to_meta(f) for f in dir_names] groups = { sn: [m['path'] for m in metas] for sn, metas in mpc.group_by_sn(metas).items() } expected = { "1234": [ "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", ], "4567": [ "NDS-WKS-SN4567-2020-10-01-11-26-55-0010-GeometryCheckTemplate6xMVkVEnhancedCouch", ], "6789": [ "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", ], } assert groups == expected
def test_group_by_dates(): dir_names = [ "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-09-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-55-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-09-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-50-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-10-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-59-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-55-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-50-21-0000-BeamCheckTemplate6xFFF", ] grouped = { "2020-11-06-09-59": [ "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-09-55": [ "NDS-WKS-SN1234-2020-11-06-09-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-55-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-09-50": [ "NDS-WKS-SN1234-2020-11-06-09-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-50-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-10-59": [ "NDS-WKS-SN1234-2020-11-06-10-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-10-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-59-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-10-55": [ "NDS-WKS-SN1234-2020-11-06-10-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-55-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-10-50": [ "NDS-WKS-SN1234-2020-11-06-10-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-50-21-0000-BeamCheckTemplate6xFFF", ], } minutes = 3 metas = [mpc.mpc_path_to_meta(f) for f in dir_names] groups = { date: [m['path'] for m in metas] for date, metas in mpc.group_by_dates(metas, minutes).items() } assert groups == grouped
def test_group_records(self): dir_names = [ "NDS-WKS-SN5678-2020-06-25-07-11-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch", "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", "NDS-WKS-SN1234-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", "NDS-WKS-SN1234-2020-10-01-11-26-55-0010-GeometryCheckTemplate6xMVkVEnhancedCouch", "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-09-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-55-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-09-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-50-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-10-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-59-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-55-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-50-21-0000-BeamCheckTemplate6xFFF", ] expected_grouped = [ ("5678", mpc.ENH_COUCH_CHECKS, "2020-06-25-07-11", [ "NDS-WKS-SN5678-2020-06-25-07-11-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch" ]), ("6789", mpc.ENH_MLC_CHECKS, "2020-09-30-09-15", [ "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x" ]), ("1234", mpc.ENH_MLC_CHECKS, "2020-09-30-09-15", [ "NDS-WKS-SN1234-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x" ]), ("1234", mpc.ENH_COUCH_CHECKS, "2020-10-01-11-26", [ "NDS-WKS-SN1234-2020-10-01-11-26-55-0010-GeometryCheckTemplate6xMVkVEnhancedCouch" ]), ("1234", mpc.BEAM_AND_GEOMETRY_CHECKS, "2020-11-06-09-50", [ "NDS-WKS-SN1234-2020-11-06-09-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-50-21-0000-BeamCheckTemplate6xFFF", ]), ("1234", mpc.BEAM_AND_GEOMETRY_CHECKS, "2020-11-06-09-55", [ "NDS-WKS-SN1234-2020-11-06-09-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-55-21-0000-BeamCheckTemplate6xFFF", ]), ("1234", mpc.BEAM_AND_GEOMETRY_CHECKS, "2020-11-06-09-59", [ "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", ]), ("1234", mpc.BEAM_AND_GEOMETRY_CHECKS, "2020-11-06-10-50", [ "NDS-WKS-SN1234-2020-11-06-10-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-50-21-0000-BeamCheckTemplate6xFFF", ]), ("1234", mpc.BEAM_AND_GEOMETRY_CHECKS, "2020-11-06-10-55", [ "NDS-WKS-SN1234-2020-11-06-10-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-55-21-0000-BeamCheckTemplate6xFFF", ]), ("1234", mpc.BEAM_AND_GEOMETRY_CHECKS, "2020-11-06-10-59", [ "NDS-WKS-SN1234-2020-11-06-10-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-10-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-59-21-0000-BeamCheckTemplate6xFFF", ]), ] expected_grouped_with_meta = [] for sn, template, date, paths in expected_grouped: expected_grouped_with_meta.append( (sn, template, date, list([mpc.mpc_path_to_meta(p) for p in paths]))) self.pump.state = { "MPC": { 'subsections': [[{ 'config_name': 'grouping window', 'value': 3 }]] } } assert self.pump.group_records(dir_names) == expected_grouped_with_meta
def test_group_by_metas(): dir_names = [ "NDS-WKS-SN5678-2020-06-25-07-11-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch", "NDS-WKS-SN5678-2020-06-25-07-12-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch", "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", "NDS-WKS-SN1234-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", "NDS-WKS-SN1234-2020-10-01-11-26-55-0010-GeometryCheckTemplate6xMVkVEnhancedCouch", "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-09-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-55-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-09-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-50-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-10-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-59-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-55-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN1234-2020-11-06-10-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-50-21-0000-BeamCheckTemplate6xFFF", "NDS-WKS-SN7890-2020-10-02-09-08-58-0009-BeamCheckTemplate6eHDTSE" ] expected_grouped = { "5678": { mpc.ENH_COUCH_CHECKS: { "2020-06-25-07-11": [ "NDS-WKS-SN5678-2020-06-25-07-11-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch" ], "2020-06-25-07-12": [ "NDS-WKS-SN5678-2020-06-25-07-12-30-0000-GeometryCheckTemplate6xMVkVEnhancedCouch" ], }, }, "6789": { mpc.ENH_MLC_CHECKS: { "2020-09-30-09-15": [ "NDS-WKS-SN6789-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x" ], }, }, "1234": { mpc.ENH_MLC_CHECKS: { "2020-09-30-09-15": [ "NDS-WKS-SN1234-2020-09-30-09-15-17-0011-EnhancedMLCCheckTemplate6x", ], }, mpc.ENH_COUCH_CHECKS: { "2020-10-01-11-26": [ "NDS-WKS-SN1234-2020-10-01-11-26-55-0010-GeometryCheckTemplate6xMVkVEnhancedCouch", ], }, mpc.BEAM_AND_GEOMETRY_CHECKS: { "2020-11-06-09-59": [ "NDS-WKS-SN1234-2020-11-06-09-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-09-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-59-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-09-55": [ "NDS-WKS-SN1234-2020-11-06-09-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-55-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-09-50": [ "NDS-WKS-SN1234-2020-11-06-09-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-09-50-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-10-59": [ "NDS-WKS-SN1234-2020-11-06-10-59-21-0009-GeometryCheckTemplate6xMVkV", "NDS-WKS-SN1234-2020-11-06-10-59-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-59-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-10-55": [ "NDS-WKS-SN1234-2020-11-06-10-55-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-55-21-0000-BeamCheckTemplate6xFFF", ], "2020-11-06-10-50": [ "NDS-WKS-SN1234-2020-11-06-10-50-21-0007-BeamCheckTemplate16e", "NDS-WKS-SN1234-2020-11-06-10-50-21-0000-BeamCheckTemplate6xFFF", ], } }, "7890": { mpc.BEAM_AND_GEOMETRY_CHECKS: { "2020-10-02-09-08": [ "NDS-WKS-SN7890-2020-10-02-09-08-58-0009-BeamCheckTemplate6eHDTSE" ], }, }, } minutes = 3 metas = [mpc.mpc_path_to_meta(f) for f in dir_names] grouped_metas = mpc.group_by_meta(metas, minutes) groups = {} for serial_no, template_type_metas in grouped_metas.items(): groups[serial_no] = {} for template_type, date_metas in template_type_metas.items(): groups[serial_no][template_type] = { date: [m['path'] for m in metas] for date, metas in date_metas.items() } assert groups == expected_grouped
def test_mpc_path_to_meta(path, expected): assert mpc.mpc_path_to_meta(path) == expected