Ejemplo n.º 1
0
    def test_110_run_dpmean_calculation(self):
        """(110) Run another DP mean calculation"""
        msgt(self.test_110_run_dpmean_calculation.__doc__)

        spec_props = self.spec_props_income

        dp_mean = DPMeanSpec(spec_props)
        print('Is this spec valid?', dp_mean.is_chain_valid())
        if dp_mean.has_error():
            print(dp_mean.get_error_messages())
            print(dp_mean.get_error_msg_dict())
            return
        self.assertTrue(dp_mean.is_chain_valid())

        # ------------------------------------------------------
        # Run the actual mean
        # ------------------------------------------------------
        # Column indexes - We know this data has 11 columns
        col_indexes = [idx for idx in range(0, 11)]

        # File object
        #
        pums_filepath = join(TEST_DATA_DIR, 'PUMS5extract10000.csv')
        self.assertTrue(isfile(pums_filepath))

        file_like_obj = open(pums_filepath, 'r')

        # Call run_chain
        #
        dp_mean.run_chain(col_indexes, file_like_obj)
        if dp_mean.has_error():
            print(dp_mean.get_error_messages())
            return

        final_dict = dp_mean.get_release_dict()

        json_str = json.dumps(final_dict, indent=4)
        print(json_str)

        print('-- actual vals --')
        print(('mean: 30,943.4566' '\nmin: -10,000.0' '\nmax: 713,000.0'))

        self.assertIn('description', final_dict)
        self.assertIn('text', final_dict['description'])
        self.assertIn('html', final_dict['description'])
Ejemplo n.º 2
0
    def test_100_run_dpmean_calculation(self):
        """(100) Run DP mean calculation"""
        msgt(self.test_100_run_dpmean_calculation.__doc__)

        spec_props = self.spec_props

        dp_mean = DPMeanSpec(spec_props)
        self.assertTrue(dp_mean.is_chain_valid())
        if dp_mean.has_error():
            print(dp_mean.get_error_messages())
            return
        #print('\nUI info:', json.dumps(dp_mean.get_success_msg_dict()))

        # ------------------------------------------------------
        # Run the actual mean
        # ------------------------------------------------------
        # Column indexes - We know this data has 20 columns
        col_indexes = [idx for idx in range(0, 20)]

        # File object
        #
        eye_fatigue_filepath = join(TEST_DATA_DIR, 'Fatigue_data.tab')
        #print('eye_fatigue_filepath', eye_fatigue_filepath)
        self.assertTrue(isfile(eye_fatigue_filepath))

        file_obj = open(eye_fatigue_filepath, 'r')

        # Call run_chain
        #
        dp_mean.run_chain(col_indexes, file_obj, sep_char="\t")

        final_dict = dp_mean.get_release_dict()
        self.assertIn('description', final_dict)
        self.assertIn('text', final_dict['description'])
        self.assertIn('html', final_dict['description'])

        print('Actual mean: -0.9503854412185792')