def test_survey_simulation(): year = 2009 input_data_frame = get_input_data_frame(year) survey_scenario = SurveyScenario().init_from_data_frame( input_data_frame = input_data_frame, year = year, ) simulation = survey_scenario.new_simulation(trace = True) data_frame_by_entity_key_plural = survey_scenario.create_data_frame_by_entity_key_plural( variables = [ 'aspa', 'aide_logement_montant_brut', 'idmen', 'quimen', 'idfoy', 'quifoy', 'idfam', 'quifam', 'age', 'activite', 'br_rmi_i', 'champm_individus', 'pensions_alimentaires_percues', 'salaire_imposable', 'salaire_net', 'smic55', 'txtppb', 'af_nbenf', 'af', 'br_rmi', 'rsa', 'rstnet', 'weight_familles', 'revdisp', ] ) assert ( data_frame_by_entity_key_plural['familles'].weight_familles * data_frame_by_entity_key_plural['familles'].af ).sum() / 1e9 > 10 return data_frame_by_entity_key_plural, simulation
def test_survey_simulation(): year = 2009 input_data_frame = get_input_data_frame(year) survey_scenario = SurveyScenario().init_from_data_frame( input_data_frame=input_data_frame, year=year, ) simulation = survey_scenario.new_simulation(trace=True) data_frame_by_entity_key_plural = survey_scenario.create_data_frame_by_entity_key_plural( variables=[ 'aspa', 'aide_logement_montant_brut', 'idmen', 'quimen', 'idfoy', 'quifoy', 'idfam', 'quifam', 'age', 'activite', 'br_rmi_i', 'champm_individus', 'pensions_alimentaires_percues', 'salaire_imposable', 'salaire_net', 'smic55', 'txtppb', 'af_nbenf', 'af', 'br_rmi', 'rsa', 'rstnet', 'weight_familles', 'revdisp', ]) assert (data_frame_by_entity_key_plural['familles'].weight_familles * data_frame_by_entity_key_plural['familles'].af).sum() / 1e9 > 10 return data_frame_by_entity_key_plural, simulation
def test_fake_survey_simulation(): year = 2006 input_data_frame = get_fake_input_data_frame(year) assert input_data_frame.salaire_imposable.loc[0] == 20000 assert input_data_frame.salaire_imposable.loc[1] == 10000 survey_scenario = SurveyScenario().init_from_data_frame( input_data_frame = input_data_frame, year = year, ) assert (survey_scenario.input_data_frame.salaire_imposable.loc[0] == 20000).all() assert (survey_scenario.input_data_frame.salaire_imposable.loc[1] == 10000).all() simulation = survey_scenario.new_simulation() salaire_imposable = simulation.calculate('salaire_imposable') assert (salaire_imposable[0:1] == 20000).all() assert (salaire_imposable[1:2] == 10000).all() age = simulation.calculate('age') assert age[0] == 77 assert age[1] == 37 age_en_mois = simulation.calculate('age_en_mois') assert age_en_mois[0] == 924 assert age_en_mois[1] == 444 sal_2003 = simulation.calculate_add('salaire_imposable', period = "2003") sal_2004 = simulation.calculate_add('salaire_imposable', period = "2004") sal_2005 = simulation.calculate_add('salaire_imposable', period = "2005") sal_2006 = simulation.calculate_add('salaire_imposable', period = "2006") assert (sal_2003 == 0).all() assert (sal_2004 == sal_2006).all() assert (sal_2005 == sal_2006).all() import itertools for year, month in itertools.product(range(2002, 2004), range(1, 13)): assert (simulation.calculate_add('salaire_imposable', period = "{}-{}".format(year, month)) == 0).all() for year, month in itertools.product(range(2004, 2007), range(1, 13)): print "{}-{}".format(year, month) print simulation.calculate_add_divide('salaire_imposable', period = "{}-{}".format(year, month)) print sal_2006 / 12 assert (simulation.calculate('salaire_imposable', period = "{}-{}".format(year, month)) == sal_2006 / 12).all() data_frame_by_entity_key_plural = survey_scenario.create_data_frame_by_entity_key_plural( variables = [ 'idmen', 'quimen', 'idfoy', 'quifoy', 'idfam', 'quifam', 'age', 'activite', 'br_rmi_i', 'champm_individus', 'salaire_imposable', 'salaire_net', 'smic55', 'txtppb', 'af_nbenf', 'af', 'br_rmi', 'rsa', 'aspa', 'aide_logement_montant_brut', 'weight_familles', 'revdisp', 'impo', ] ) return data_frame_by_entity_key_plural, simulation
def test_fake_survey_simulation(): year = 2006 input_data_frame = get_fake_input_data_frame(year) assert input_data_frame.salaire_imposable.loc[0] == 20000 assert input_data_frame.salaire_imposable.loc[1] == 10000 survey_scenario = SurveyScenario().init_from_data_frame( input_data_frame = input_data_frame, year = year, ) assert (survey_scenario.input_data_frame.salaire_imposable.loc[0] == 20000).all() assert (survey_scenario.input_data_frame.salaire_imposable.loc[1] == 10000).all() simulation = survey_scenario.new_simulation() salaire_imposable = simulation.calculate('salaire_imposable') assert (salaire_imposable[0:1] == 20000).all() assert (salaire_imposable[1:2] == 10000).all() age = simulation.calculate('age') assert age[0] == 77 assert age[1] == 37 age_en_mois = simulation.calculate('age_en_mois') assert age_en_mois[0] == 924 assert age_en_mois[1] == 444 sal_2003 = simulation.calculate_add('salaire_imposable', period = "2003") sal_2004 = simulation.calculate_add('salaire_imposable', period = "2004") sal_2005 = simulation.calculate_add('salaire_imposable', period = "2005") sal_2006 = simulation.calculate_add('salaire_imposable', period = "2006") assert (sal_2003 == 0).all() assert (sal_2004 == sal_2006).all() assert (sal_2005 == sal_2006).all() import itertools for year, month in itertools.product(range(2002, 2004), range(1, 13)): assert (simulation.calculate_add('salaire_imposable', period = "{}-{}".format(year, month)) == 0).all() for year, month in itertools.product(range(2004, 2007), range(1, 13)): print "{}-{}".format(year, month) print simulation.calculate_add_divide('salaire_imposable', period = "{}-{}".format(year, month)) print sal_2006 / 12 assert (simulation.calculate('salaire_imposable', period = "{}-{}".format(year, month)) == sal_2006 / 12).all() data_frame_by_entity_key_plural = survey_scenario.create_data_frame_by_entity_key_plural( variables = [ 'idmen', 'quimen', 'idfoy', 'quifoy', 'idfam', 'quifam', 'age', 'activite', 'br_rmi_i', 'champm_individus', 'salaire_imposable', 'salaire_net', 'smic55', 'txtppb', 'af_nbenf', 'af', 'br_rmi', 'rsa', 'aspa', 'aide_logement_montant_brut', 'weight_familles', 'revdisp', 'impo', ] ) return data_frame_by_entity_key_plural, simulation