Пример #1
0
def test_db_persistence():
    '''
    This test is a simple test of the DB, not important since the DB code and this test will need to get rewritten.
    '''
    import tube, db
    from data import tension, leak
    tubes = db.db()
    dbman = db.db_manager()
    dbman.wipe('confirm')
    tube1 = tube.Tube()
    tube2 = tube.Tube()
    tube1.m_tube_id = "MSU0000001"
    tube2.m_tube_id = "MSU0000001"
    tube1.tension.add_record(tension.TensionRecord(350))
    tube2.tension.add_record(tension.TensionRecord(355))
    tube2.leak.add_record(leak.LeakRecord(0))
    tubes.add_tube(tube1)
    tubes.add_tube(tube2)

    dbman.update()

    del tubes
    tubes = db.db()

    tube4 = tubes.get_tube("MSU0000001")
    assert len(tube4.tension.get_record('all')) == 2
    assert tube4.leak.get_record('last').leak_rate == 0

    del tubes

    tubes = db.db()
    dbman.wipe('confirm')
    with pytest.raises(KeyError):
        tube4 = tubes.get_tube("MSU0000001")
    assert tubes.size() == 0
Пример #2
0
def test_db_add_tube():
    '''
    This test is a simple test of adding tubes to the DB, not important since the DB code and this test will need to get rewritten.
    '''
    import tube, db
    from data import swage, tension, leak, dark_current
    tubes = db.db()
    dbman = db.db_manager()
    dbman.wipe('confirm')
    tube1 = tube.Tube()
    tube2 = tube.Tube()
    tube1.m_tube_id = "MSU0000001"
    tube2.m_tube_id = "MSU0000001"
    tube1.tension.add_record(tension.TensionRecord(350))
    tube2.tension.add_record(tension.TensionRecord(355))
    tube2.leak.add_record(leak.LeakRecord(0))
    tubes.add_tube(tube1)
    dbman.update()
    tube3 = tubes.get_tube("MSU0000001")
    assert len(tube3.tension.get_record('all')) == 1
    with pytest.raises(IndexError):
        tube3.leak.get_record('last').leak_rate == 0
    tubes.add_tube(tube2)
    dbman.update()

    tube4 = tubes.get_tube("MSU0000001")
    assert len(tube4.tension.get_record('all')) == 2
    assert tube4.leak.get_record('last').leak_rate == 0
Пример #3
0
def test_tube_comments():
    '''
    Simple test of the comment system
    '''
    import tube
    tube1 = tube.Tube()
    tube1.new_comment("This tube is for testing purposes")
    assert tube1.get_comments() == ["This tube is for testing purposes"]
Пример #4
0
def test_tube_add():
    '''
    This tests the __add__ override that tubes support.
    '''
    import tube
    from data import swage, tension, leak, dark_current
    tube1 = tube.Tube()
    tube2 = tube.Tube()
    tube1.m_tube_id = "MSU0000001"
    tube2.m_tube_id = "MSU0000001"
    tube1.tension.add_record(tension.TensionRecord(350, user='******'))
    tube2.tension.add_record(tension.TensionRecord(355, user='******'))
    tube2.leak.add_record(leak.LeakRecord(0))
    tube3 = tube1 + tube2
    print(tube3.tension.get_record('all'))
    assert len(tube3.tension.get_record('all')) == 2
    assert tube3.leak.get_record('last').leak_rate == 0
    assert tube3.tension.get_record('last').user == 'Reinhard'
    assert tube3.tension.get_record('first').user == 'Paul'
Пример #5
0
    def parse(self, wb):
        log.debug('Parsing workbook')
        # First, we want to grab data from the synthesis table though.
        root_sheet = wb.get_sheet_by_name(
            self.required_sheet_names.get('root_data'))
        synthesis_sheet = wb.get_sheet_by_name(
            self.required_sheet_names.get('synthesis_data'))

        self._process_synthesis_table(ws=synthesis_sheet)
        self._process_root_table(ws=root_sheet)

        if set(self.root_data.keys()) != set(self.synthesis_data.keys()):
            log.error('# Root data keys [{}]'.format(len(
                self.root_data.keys())))
            log.error('# Syn  data keys [{}]'.format(
                len(self.synthesis_data.keys())))
            log.error(self.synthesis_data)
            raise DataError(
                'Tube numbers from root_data does not match the tube numbers from the synthesis_data'
            )

        log.info('Processing collected data')
        for tn in self.root_data:
            log.info('Processing data for tube [{}]'.format(tn))
            tube_obj = tube.Tube(tn)
            raw_roots = self.root_data.get(tn)

            for root_obj in raw_roots:
                rsession = root_obj.get('Session#')
                if rsession > tube_obj.maxSessionCount:
                    tube_obj.maxSessionCount = rsession
                    log.debug('Max session count updated to {}'.format(
                        tube_obj.maxSessionCount))
                if rsession not in tube_obj.sessionDates:
                    tube_obj.sessionDates[rsession] = root_obj.get('Date')
                    log.debug('Inserted session {} - Date {}'.format(
                        rsession, root_obj.get('Date')))
            final_roots = []
            log.info('Inserting roots into tube [{}]'.format(tn))
            for root_obj in raw_roots:
                tube_obj.insert_or_update_root(root_obj)
                if root_obj.get('Session#') == tube_obj.maxSessionCount:
                    final_roots.append(root_obj)
            log.info('Finalizing roots')
            for root_obj in final_roots:
                status = tube_obj.finalize_root(root_obj,
                                                root_fields=self.root_fields)
                if not status:
                    log.error('Failed to finalize root {}'.format(
                        root_obj.identity))
            log.info('Inserting synthesis data')
            # Insert the sythesis data (containing the tip stats) into the roots.
            sdata = self.synthesis_data.get(tn)
            tube_obj.insert_synthesis_data(sdata)
            self.tubes.append(tube_obj)
Пример #6
0
def test_tube_init():
    '''
    Testing tube initialization and constructor
    '''
    import tube
    from data import swage, tension, leak, dark_current
    tube1 = tube.Tube()
    assert tube1.m_comments == []
    assert tube1.m_tube_id == None
    assert tube1.swage.get_record('all') == []
    assert tube1.tension.get_record('all') == []
    assert tube1.dark_current.get_record('all') == []
    assert tube1.leak.get_record('all') == []
Пример #7
0
    def calculate_tubes_position(self):
        for floor in self.floor_structure.get_floors():
            center = GeoMath.centerOfPoints(floor.get_absolute_points())
            #==================================================================
            # Guess how many tubes for each part. We divide the floor into 4 parts
            # in a half in x direction and in a half in z direction.
            #==================================================================
            boun = GeoMath.boundingBox(floor.get_absolute_points())

            height_x_tubes = boun.sizevec()[2]
            height_z_tubes = boun.sizevec()[0]
            orientation_x_tubes = 'z'
            orientation_z_tubes = 'x'
            size_x_half_section = boun.sizevec()[0] / 2.0
            put_tube_each_x = self.extract_parm_from_user_restrictions(
                'tube_default_put_each_x', DEFAULT_PUT_TUBE_EACH_X)
            n_tubes_x_half_section = int(
                math.floor(size_x_half_section / put_tube_each_x))

            size_z_half_section = boun.sizevec()[2] / 2.0
            put_tube_each_z = self.extract_parm_from_user_restrictions(
                'tube_default_put_each_z', DEFAULT_PUT_TUBE_EACH_Z)
            n_tubes_z_half_section = int(
                math.floor(size_z_half_section / put_tube_each_z))

            # The first time putting tubes in x we put a tube in the middle
            tube_instance = tube.Tube(self.tube_params, center, height_x_tubes,
                                      orientation_x_tubes)
            self.tubes['x'].append(tube_instance)
            # To the right in x, so we will adding 'x' value to the center
            # point
            increment = [put_tube_each_x, 0, 0]
            tube_center = GeoMath.vecPlus(center, increment)

            for _ in range(n_tubes_x_half_section):
                tube_instance = tube.Tube(self.tube_params, tube_center,
                                          height_x_tubes, orientation_x_tubes)
                self.tubes['x'].append(tube_instance)
                tube_center = GeoMath.vecPlus(tube_center, increment)

            # To the left
            increment = [-put_tube_each_x, 0, 0]
            tube_center = GeoMath.vecPlus(center, increment)
            for _ in range(n_tubes_x_half_section):
                tube_instance = tube.Tube(self.tube_params, tube_center,
                                          height_x_tubes, orientation_x_tubes)
                self.tubes['x'].append(tube_instance)
                tube_center = GeoMath.vecPlus(tube_center, increment)

            # The first time putting tubes in z we put a tube in the middle
            tube_instance = tube.Tube(self.tube_params, center, height_z_tubes,
                                      orientation_z_tubes)
            self.tubes['z'].append(tube_instance)
            # To the right in x, so we will adding 'x' value to the center
            # point
            increment = [0, 0, put_tube_each_z]
            tube_center = GeoMath.vecPlus(center, increment)

            for _ in range(n_tubes_z_half_section):
                tube_instance = tube.Tube(self.tube_params, tube_center,
                                          height_z_tubes, orientation_z_tubes)
                self.tubes['z'].append(tube_instance)
                tube_center = GeoMath.vecPlus(tube_center, increment)

            # To the left
            increment = [0, 0, -put_tube_each_z]
            tube_center = GeoMath.vecPlus(center, increment)
            for _ in range(n_tubes_z_half_section):
                tube_instance = tube.Tube(self.tube_params, tube_center,
                                          height_z_tubes, orientation_z_tubes)
                self.tubes['z'].append(tube_instance)
                tube_center = GeoMath.vecPlus(tube_center, increment)
Пример #8
0
def dict_to_tube_object():
    dict_db = open_database()

    if dict_db is None:
        return None

    # Time to construct the tube object. We are constructing this tube object
    # outside of the tube class for the time being. This is more for testing
    # purposes. Eventually, this code will be integrated into the tube class.
    list_of_tubes = []

    swage_date_fmt = '%m.%d.%Y_%H_%M_%S'
    tension_date_fmt = '%d.%m.%Y %H.%M.%S'
    leak_date_fmt = '%d.%m.%Y %H.%M.%S'
    dark_current_date_fmt = '%d_%m_%Y_%H_%M_%S'

    # Now we need to start to peel back the layers of the database.
    for (tube_id, data_dict) in dict_db.items():
        # We need this to check whether the data recorded has the particular
        # values that we need.
        recorded_dict_keys = data_dict.keys()

        swager_user           = get_attribute(data_dict, "swagerUser")
        raw_length            = get_attribute(data_dict, "rawLength")
        swage_length          = get_attribute(data_dict, "swageLength")
        swager_comment        = get_attribute(data_dict, "swagerComment")
        swager_date           = get_attribute(data_dict, "swagerDate")
        swager_file           = get_attribute(data_dict, "swagerFile")
        e_code                = get_attribute(data_dict, "eCode")
        c_code                = get_attribute(data_dict, "cCode")
        fails_swager          = get_attribute(data_dict, "failsSwager")

        tension_user          = get_attribute(data_dict, "tensionUser")
        tension_date          = get_attribute(data_dict, "tensionDateTime")
        tension_length        = get_attribute(data_dict, "tensionLength")
        frequency             = get_attribute(data_dict, "frequency")
        tensions              = get_attribute(data_dict, "tensions")
        tension_file          = get_attribute(data_dict, "tensionFile")
        first_tensions        = get_attribute(data_dict, "firstTensions")
        first_tension_users   = get_attribute(data_dict, "firstTensionUsers")
        first_tension_dates   = get_attribute(data_dict, "firstTensionDates")
        fails_first_tension   = get_attribute(data_dict, "failsFirstTension")
        second_tensions       = get_attribute(data_dict, "secondTensions")
        first_tension         = get_attribute(data_dict, "firstTension")
        first_tension_date    = get_attribute(data_dict, "firstTensionDate")
        first_frequency       = get_attribute(data_dict, "firstFrequency")

        leak_rate             = get_attribute(data_dict, "leakRate")
        leak_status           = get_attribute(data_dict, "leakStatus")
        leak_file             = get_attribute(data_dict, "leakFile")
        leak_date             = get_attribute(data_dict, "leakDateTime")
        leak_user             = get_attribute(data_dict, "leakUser")
        fails_leak            = get_attribute(data_dict, "failsLeak")

        current_test_dates    = get_attribute(data_dict, "currentTestDates")
        current_file          = get_attribute(data_dict, "currentFile")
        currents              = get_attribute(data_dict, "darkCurrents")
        fails_current         = get_attribute(data_dict, "failsCurrent")

        bool_flag             = get_attribute(data_dict, "good")

        # Now to construct the tube, the test data, and populate everything.
        tube_construct = tube.Tube()
        tube_construct.m_tube_id = tube_id

        # We will add in the comments. The swage station is the only place
        # where comments can be recorded.
        tube_construct.new_comment(swager_comment)

        ########################################################################
        #   A great test to run here is to check the size of the lists, and
        #   assert that they are the same length. Like the number of tension
        #   dates should match the number of tension files.
        ########################################################################

        # Here we are just getting the number of users.
        number_of_swage_tests = len(swager_user)
        number_of_tension_tests = len(tensions)
        number_of_leak_tests = len(leak_file)
        number_of_dark_current_tests = len(currents)

        # Now we will populate the tests by first constructing these lists, and
        # then constructing the station objects and inserting these lists in.
        list_of_swage_tests = []
        list_of_tension_tests = []
        list_of_leak_tests = []
        list_of_dark_current_tests = []

        for n in range(0, number_of_swage_tests):
            # First we construct the date object.
            date_obj = string_to_datetime(swager_date[n], swage_date_fmt)

            test = SwageTest(
                raw_length = raw_length[n],
                swage_length = swage_length[n],
                clean_code = c_code[n],
                error_code = e_code[n],
                date = date_obj
            )
            list_of_swage_tests.append(test)

        for n in range(0, number_of_tension_tests):
            date_obj = string_to_datetime(tension_date[n], tension_date_fmt)

            test = TensionTest(
                tension = tensions[n],
                frequency = frequency[n],
                date = date_obj,
                data_file = tension_file[n]
            )
            list_of_tension_tests.append(test)

        for n in range(0, number_of_leak_tests):
            try:
                date_obj = string_to_datetime(leak_date[n], leak_date_fmt)
            except IndexError:
                date_obj = None

            test = LeakTest(
                leak_rate = leak_rate[n],
                date = date_obj,
                data_file = leak_file[n]
            )
            list_of_leak_tests.append(test)

        for n in range(0, number_of_dark_current_tests):
            # It appears that the data file names have a '\n' character added
            # to the end. This just serves to fix that issue.
            date_fixed = current_test_dates[n][0:-1]
            date_obj = string_to_datetime(date_fixed, dark_current_date_fmt)

            test = DarkCurrentTest(
                dark_current = currents[n],
                date = date_obj,
                data_file = current_file
            )
            list_of_dark_current_tests.append(test)

        # Here are all of our station objects.
        s = Swage()
        t = Tension()
        l = Leak()
        d = DarkCurrent()

        s.m_users = swager_user
        s.m_tests = list_of_swage_tests

        t.m_users = tension_user
        t.m_tests = list_of_tension_tests

        l.m_users = leak_user
        l.m_tests = list_of_leak_tests

        # d.m_users = data_dict[dict_keys[]]
        d.m_tests = list_of_dark_current_tests

        tube_construct.swage = s
        tube_construct.tension = t
        tube_construct.leak = l
        tube_construct.dark_current = d

        list_of_tubes.append(tube_construct)

    return list_of_tubes