def test_is_init_working_correctly_with_kwargs(self):
        #test whether objects are created correctly when passed all kwargs

        #create object with state 'Michigan' and full data from
        #imported CSV (above)
        analyzer1 = ExcessDeathsAnalyzer('Michigan', test_data1)

        #Check that the state attribute was set correctly
        self.assertEqual(analyzer1.state, 'Michigan')

        #Check that the full data set attribute was set correctly
        self.assertEqual(analyzer1.full_data.equals(test_data1), True)

        #Check that the state's data was obtained correctly from full data set
        self.assertEqual(analyzer1.data.equals(test_data2), True)

        #Check that type for "Week Ending Date" column was converted correctly
        self.assertEqual(analyzer1.data['Week Ending Date'].dtype,
                         test_data2['Week Ending Date'].dtype)

        #Check that data_allCauses attribute is correct
        self.assertEqual(
            analyzer1.data_allCauses.equals(
                test_data2[test_data2['Outcome'] == 'All causes']), True)

        #Check that data_exceptCovid attribute is correct
        self.assertEqual(
            analyzer1.data_exceptCovid.equals(test_data2[
                test_data2['Outcome'] == 'All causes, excluding COVID-19']),
            True)
Exemplo n.º 2
0
    def test_is_init_data_working_correctly(self):
        #Check that the state's data was obtained correctly from full data set

        #setup
        #create object with state 'Michigan' and full data from
        #imported CSV (above)
        analyzer1 = eda.ExcessDeathsAnalyzer('Michigan', test_data1)

        #check
        self.assertEqual(analyzer1.data.equals(test_data2), True)
Exemplo n.º 3
0
    def test_is_init_full_data_working_correctly(self):
        #Check that the full data set attribute was set correctly

        #setup
        #create object with state 'Michigan' and full data from
        #imported CSV (above)
        analyzer1 = eda.ExcessDeathsAnalyzer('Michigan', test_data1)

        #check
        self.assertEqual(analyzer1.full_data.equals(test_data1), True)
Exemplo n.º 4
0
    def test_is_timeSeries_saving_right(self):
        #confirms that .timeSeries() method saves a file with the expected
        #name
        #setup:
        analyzer1 = eda.ExcessDeathsAnalyzer('Michigan', test_data1)
        analyzer1.timeSeries(save=True, filename='Test_Plot')

        #check
        check = os.path.isfile('Test_Plot.png')
        self.assertTrue(check)
Exemplo n.º 5
0
    def test_is_init_data_converting_column_to_datetime(self):
        #Check that type for "Week Ending Date" column was converted correctly

        #setup
        #create object with state 'Michigan' and full data from
        #imported CSV (above)
        analyzer1 = eda.ExcessDeathsAnalyzer('Michigan', test_data1)

        #check
        self.assertEqual(analyzer1.data['Week Ending Date'].dtype,
                         test_data2['Week Ending Date'].dtype)
Exemplo n.º 6
0
    def test_is_init_data_allCauses_correct(self):
        #Check that data_allCauses attribute is correct

        #setup
        #create object with state 'Michigan' and full data from
        #imported CSV (above)
        analyzer1 = eda.ExcessDeathsAnalyzer('Michigan', test_data1)

        #check
        self.assertEqual(
            analyzer1.data_allCauses.equals(
                test_data2[test_data2['Outcome'] == 'All causes']), True)
Exemplo n.º 7
0
    def test_is_compareToState_plot_created(self):
        # Is compareToState() method successfully creating the plot that is
        # being produced. If not, something within the code failed for the plot
        # to not be produced/called. ie: Did we plot something?

        Analyzer1 = eda.ExcessDeathsAnalyzer("Michigan", test_data1)

        # Sets up a mock test to see if a plot is retuned
        with patch('matplotlib.pyplot.show') as show_patch:
            Analyzer1.compareToState("Ohio")

            # Asserts that a plot is returned by plt.show() at the end of the
            # compareToState method. If a plot is returned - test is ok. If a
            # plot is not returned - test fails
            assert show_patch.called
Exemplo n.º 8
0
    def test_is_string_output_correct(self):
        # Is peakValue() method successfully calculating and storing the value
        # that the peak excess deaths reached within a given state and
        # returning the correct strings for this

        # Set-up: create object with state 'Michigan' and full data from
        # imported CSV (above)
        analyzer1 = eda.ExcessDeathsAnalyzer("Michigan", test_data1)
        analyzer1.peakValue()

        # Assert that returned string will equal the given string
        # If equal, test passes. If not equal, test fails
        self.assertEqual(
            analyzer1.peakValue(),
            'The peak of Excess Deaths, all causes, for Michigan was at 95 excess deathsThe peak of Excess Deaths, all causes except for COVID-19, for Michigan was at 74 excess deaths'
        )
def create_user_object(state):
    """
    This function takes a state as input and creates a
    ExcessDeathsAnalyzer object for that class.
    
    In the wrapper function, this function will be fed the output
    from get_user_state().
    
    We deliberately do not allow the user to change the input data here,
    as we leave the determination of the input data set up to the developer.
    
    """
    
    #Initialize the class object based on the state input
    user_object = ExcessDeathsAnalyzer(state, input_data)
    
    #Return this class object for querying in later functions
    return user_object
Exemplo n.º 10
0
    def test_is_compareToState_plotting_right(self):
        #confirms that compareToState() method produces the correct plot
        #Note: checking for whether graphics look exactly like eachother can
        #by tricky and time consuming, especially as minor formatting tweaks are
        #are implemented.  Instead of automating the check, this test will show
        #the tester what graphic is created for visual inspection.
        #setup:
        analyzer1 = eda.ExcessDeathsAnalyzer('Michigan', test_data1)
        analyzer1.timeSeries()

        # Shows the sample chart for comparison purposes for the visual
        # inspection accomplished below
        im = Image.open("testingSuite_compareToState.png")
        im.show()

        #check (by asking tester to confirm the plot is correct)
        check = input(
            "This is a visual test.\nDoes this plot look correct? [Y or N]: ")
        self.assertEqual(check, "Y")
## clean dataset
input_data = excess_deaths_final


#%%
input_data = pd.read_csv('Excess Deaths Cleaned.csv')
#%%
#Read in ExcessDeathsAnalyzer class from ExcessDeathsAnalyzer.py
from ExcessDeathsAnalyzer import *


#%%Run our queries

#Query 1: National Time Series 
National = ExcessDeathsAnalyzer("United States", input_data)
National.timeSeries(save = True, filename = "testplot.png")


#%%

#Query 2: Peak date of excess deaths for national
National.peakDate()

#%%

#Query 3: Peak number of excess deaths for national
National.peakValue()

#%%
Exemplo n.º 12
0
#%%

#Read in data from url and perform data cleaning
from ReadIn_EDA_Clean_Export import *

## clean dataset
input_data = excess_deaths_final

#%%
#Read in ExcessDeathsAnalyzer class from ExcessDeathsAnalyzer.py
from ExcessDeathsAnalyzer import *

#%%Run our queries

#Query 1: National Time Series
National = ExcessDeathsAnalyzer("United States", input_data)
National.timeSeries(save=True, filename="testplot.png")

#%%

#Query 2: Peak date of excess deaths for national
National.peakDate()

#%%

#Query 3: Peak number of excess deaths for national
National.peakValue()

#%%

#Query 4: Virginia time series