Exemple #1
0
def test_individual_numbers():
    # Loading data
    employees = pd.read_csv(path + "employees.csv", sep=";", decimal=",")
    spouses = pd.read_csv(path + "spouses.csv", sep=";", decimal=",")
    children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

    # Projection of population
    # Number of years to project
    MAX_ANNEES = 10

    # Projection
    numbers_ = eff.projectNumbers(employees,
                                  spouses,
                                  children,
                                  'TV 88-90',
                                  MAX_ANNEES,
                                  law_replacement_=law_replacement1)

    # global numbers
    global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                    MAX_ANNEES)

    # verify first id in live individual numbers
    indiv_lives = eff.individual_employees_numbers(numbers_[0])[0]

    res = list(indiv_lives.iloc[0, 8:])

    expected_res = [
        1, 0.99945, 0.99887, 0.99825, 0.99761, 0.99695, 0.99623, 0.99542,
        0.99452, 0.99359
    ]

    diff = [abs(i - j) for i, j in zip(res, expected_res)]

    assert max(diff) < 5

    # strict comparaison of global numbers
    # load expected numbers
    expected_global_numbers = pd.DataFrame(
        pd.read_csv("./pop_projection/test/expected_global_numbers.csv",
                    sep=";",
                    decimal=","))

    # assert expected_global_numbers.equals(global_numb)

    cols = list(expected_global_numbers.columns)

    for c in cols:
        res = list(global_numb[c])
        expected_res = list(expected_global_numbers[c])
        diff = [abs(i - j) for i, j in zip(res, expected_res)]
        assert max(diff) < 5, "Numbers in column " + c + " far from expected!"
Exemple #2
0
def test_walk_actives():

    # Path for input data
    path = "./pop_projection/test/data/"

    # Loading data
    employees = pd.read_csv(path + "employees.csv", sep=";", decimal=",")
    spouses = pd.read_csv(path + "spouses.csv", sep=";", decimal=",")
    children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

    # Projection of population
    # Number of years to project
    MAX_ANNEES = 50

    # Projection
    numbers_ = eff.projectNumbers(employees,
                                  spouses,
                                  children,
                                  'TV 88-90',
                                  MAX_ANNEES,
                                  law_replacement_=None)

    # global numbers
    global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                    MAX_ANNEES)

    # departures
    departures = eff.leavingNumbers(numbers_[0], numbers_[4], MAX_ANNEES)

    # employees_walk
    employees_walk = pd.merge(global_numb.loc[:, ['Year', 'effectif_actifs']],
                              departures,
                              on='Year')

    # In case of no replacement, employees numbers must satisfy :
    # Numbers(year N + 1 ) = Numbers(year N) - Deaths(year N) -
    #                        Reignations(year N) - New Retirees(year N)

    for i in range(1, MAX_ANNEES):
        temp = (employees_walk.loc[i - 1, 'effectif_actifs'] -
                employees_walk.loc[i, 'Total Leaving'] -
                employees_walk.loc[i, 'effectif_deces_nouveaux_retraites'])
        temp_diff = abs(temp - employees_walk.loc[i, 'effectif_actifs'])
        assert temp_diff < 0.00001, "Walk equality not satisfaied in year " + str(
            i) + " diff : " + str(temp_diff)
Exemple #3
0
def test_glob_num_no_rep():

    # Path for input data
    path = "./pop_projection/test/data/"

    # Loading data
    employees = pd.read_csv(path + "employees.csv", sep=";", decimal=",")
    spouses = pd.read_csv(path + "spouses.csv", sep=";", decimal=",")
    children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

    # Projection of population
    # Number of years to project
    MAX_ANNEES = 60

    # Projection
    numbers_ = eff.projectNumbers(employees,
                                  spouses,
                                  children,
                                  'TV 88-90',
                                  MAX_ANNEES,
                                  law_replacement_=None,
                                  law_resignation_=sl.turnover,
                                  law_retirement_=law_ret1)

    # global numbers
    global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                    MAX_ANNEES)

    # load expected numbers
    expected_global_numbers = pd.DataFrame(
        pd.read_csv("./pop_projection/test/expected_glob_num_no_rep.csv",
                    sep=";",
                    decimal=","))

    cols = list(expected_global_numbers.columns)

    for c in cols[1:4]:
        res = list(global_numb[c])
        expected_res = list(expected_global_numbers[c])
        for i in range(len(res)):
            assert abs(
                res[i] - expected_res[i]
            ) < 0.000001, "Numbers in column " + c + " far from expected at year " + str(
                i) + " !"
Exemple #4
0
def test_simulerEffectif_2():

    # Path for input data
    path = "./pop_projection/test/data/"

    # Loading data
    employees = pd.read_csv(path + "employees.csv", sep=";", decimal=",")
    spouses = pd.read_csv(path + "spouses.csv", sep=";", decimal=",")
    children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

    # Projection of population
    # Number of years to project
    MAX_ANNEES = 60

    # Projection
    numbers_ = eff.projectNumbers(employees, spouses, children)

    # global numbers
    global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                    MAX_ANNEES)
plot_num = 1

min_age_ = 19

max_age_ = 100

color_males = (149 / 255, 125 / 255, 98 / 255)
color_females = (0 / 255, 128 / 255, 0 / 255)

for t in tables:

    # Projection of population
    numbers_ = eff.projectNumbers(employees,
                                  spouses,
                                  children,
                                  t,
                                  MAX_ANNEES,
                                  law_replacement_=sl.law_replacement1,
                                  law_marriage_=sl.law_mar1)

    # Pyramid of spouses
    ind_spo_numbers = eff.individual_spouses_numbers(numbers_[1])
    spouses_proj = ind_spo_numbers[0]

    emp_grouped = spouses_proj.groupby(
        ['age', 'sex'], as_index=False)['year_' + str((year_ - 1))].sum()

    # update colum age to be age at year (year_-1)
    emp_grouped['age'] = emp_grouped['age'] - MAX_ANNEES + (year_ - 1)

    emp_grouped = emp_grouped.loc[(emp_grouped['age'] < max_age_)
Exemple #6
0
children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

# Loading salaries
salaries = pd.read_csv(path + "salaries.csv", sep=";", decimal=",")

# Loading pensions
pensions = pd.read_csv(path + "pensions.csv", sep=";", decimal=",")

print('Chargement données : ', time.asctime( time.localtime(time.time())))

# Projection of population
# Number of years to project
MAX_ANNEES = 60

# Projection
numbers_ = eff.projectNumbers( employees, spouses, children, 'TV 88-90', MAX_ANNEES, 
                                law_replacement_=law_replacement1)

print('Simulation effectifs : ', time.asctime( time.localtime(time.time())))

df_salaries = cf.project_salaries(numbers_[0], salaries, MAX_ANNEES, salaries_new_emp_1, 0.035)

print('Projection salaires : ', time.asctime( time.localtime(time.time())))

# rate_contr = pd.read_csv(path + "rate_contr.csv", sep=";", decimal=",")

def rate_contr(sex, year):
    return 0.325

df_contr = cf.project_contributions(df_salaries,rate_contr,20)

print('Projection contributions : ', time.asctime( time.localtime(time.time())))
path = "../pop_projection/data/"

# Number of years to project
MAX_ANNEES = 50

# Loading data
employees = pd.read_csv(path + "employees.csv", sep=";", decimal=",")
spouses = pd.read_csv(path + "spouses.csv", sep=";", decimal=",")
children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

# Projection of population
numbers_ = eff.projectNumbers(employees,
                              spouses,
                              children,
                              'TV 88-90',
                              MAX_ANNEES,
                              (law_ret1, ['age', 'Year_employment']),
                              (law_resignation_1, ['age', 'sex']),
                              (law_mar1, ['age', 'sex', 'type']),
                              law_replacement_=None)

# Global numbers
Effectifs = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                              MAX_ANNEES)

Effectifs.to_csv('Effectifs_python.csv', sep=';', index=False, decimal=',')

# Number of actives leaving population : deaths, resignations, and new retired
Leaving = eff.leavingNumbers(numbers_[0], numbers_[4], MAX_ANNEES)

Leaving.to_csv('Sortants_python.csv', sep=';', index=False, decimal=',')
Exemple #8
0
# Path for input data
path ="./pop_projection/data/"

# Loading data
employees = pd.read_csv(path + "employees - Copie.csv",sep=";", decimal = ",")
spouses = pd.read_csv(path + "spouses.csv",sep=";", decimal = ",")
children = pd.read_csv(path + "children.csv",sep=";", decimal = ",")

# Diplay some data
# print('Employees :')
# print(employees.head(10))
# print('Spouses :')
# print(spouses.head(10))
# print('Children :')
# print(children.head(10))

# Projection of population
# Number of years to project
MAX_ANNEES = 100

# Projection
numbers_ = eff.projectNumbers(employees, spouses, children, 'TV 88-90', MAX_ANNEES, law_replacement_ = law_replacement1)

# global numbers
global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2], MAX_ANNEES)

# printing results
print(global_numb)

# print(eff.individual_employees_numbers(numbers_[0])[0])
Exemple #9
0
# Loading data
employees = pd.read_csv(path + "employees - Copie.csv",sep=";", decimal = ",")
spouses = pd.read_csv(path + "spouses.csv",sep=";", decimal = ",")
children = pd.read_csv(path + "children.csv",sep=";", decimal = ",")

# Diplay some data
# print('Employees :')
# print(employees.head(10))
# print('Spouses :')
# print(spouses.head(10))
# print('Children :')
# print(children.head(10))

# Projection of population
# Number of years to project
MAX_ANNEES = 30

# Projection
numbers_ = eff.projectNumbers(employees, spouses, children, 'TV 88-90', MAX_ANNEES, law_replacement_ = law_replacement1, max_child_age=23)

# global numbers
global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2], MAX_ANNEES)

# printing results
print(global_numb[['effectif_enfants_actifs', 'effectif_enfants_retraites', 
'effectif_enfants_ayant_cause',  'Total Children']])

# print(eff.individual_employees_numbers(numbers_[0])[0])
children_numbers = eff.individual_children_numbers(numbers_[2])
children_numbers[0].to_csv('./results/children-lives.csv', index=False, sep=';')
@author: a.teffal
"""

# Pyramides of spouses at years 1, 10, 20, ..., 50

from pop_projection import Effectifs as eff
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pop_projection import sample_laws as sl

# Path for input data
path = "./pop_projection/data/"

# Number of years to project
MAX_ANNEES = 50

# Loading data
employees = pd.read_csv(path + "employees.csv", sep=";", decimal=",")
spouses = pd.read_csv(path + "spouses.csv", sep=";", decimal=",")
children = pd.read_csv(path + "children.csv", sep=";", decimal=",")

# Projection of population
numbers_ = eff.projectNumbers(employees, spouses, children, 'TD 73-77', MAX_ANNEES,
                              law_replacement_=sl.law_replacement1, law_marriage_=sl.law_mar1)

# plot pyramides of spouses at years 1, 10, 20, ..., 50
y = [i*10 for i in range(1, 6)]
for j in y:
    eff.plot_pyramide_spouses(numbers_[1], j, MAX_ANNEES)
Exemple #11
0
# Diplay some data
print('Employees :')
print(employees.head(10))
print('Spouses :')
print(spouses.head(10))
print('Children :')
print(children.head(10))

# Projection of population
# Number of years to project
MAX_ANNEES = 50

# Projection
numbers_ = eff.projectNumbers(employees,
                              spouses,
                              children,
                              'TV 88-90',
                              MAX_ANNEES,
                              law_replacement_=None)

# global numbers
global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2], 50)

# departures
departures = eff.leavingNumbers(numbers_[0], numbers_[4], MAX_ANNEES)

# employees_walk
employees_walk = pd.merge(global_numb.loc[:, ['Year', 'effectif_actifs']],
                          departures,
                          on='Year')

# export results
Exemple #12
0
def test_simulerEffectif_1():

    # employees
    ids = ['id1', 'id2', 'id3']
    types = ['active', 'retired', 'active']
    sexes = ['male', 'female', 'male']
    familystatus = ['married', 'married', 'not married']
    ages = [30, 65, 45]
    Data = {
        'id': ids,
        'type': types,
        'sex': sexes,
        'familyStatus': familystatus,
        'age': ages
    }
    employees = pd.DataFrame(
        data=Data, columns=['id', 'type', 'sex', 'familyStatus', 'age'])

    # spouses
    ids = ['id1', 'id2']
    rangs = [1, 1]
    sexes = ['female', 'male']
    ages = [25, 65]
    types = ['active', 'retired']
    familystatus = ['married', 'married']
    Data = {
        'id': ids,
        'rang': rangs,
        'sex': sexes,
        'age': ages,
        'type': types,
        'familyStatus': familystatus
    }
    spouses = pd.DataFrame(
        data=Data,
        columns=['id', 'rang', 'sex', 'age', 'type', 'familyStatus'])

    # children
    ids = []
    rangs = []
    sexes = []
    ages = []
    types = []
    familystatus = []
    Data = {
        'id': ids,
        'rang': rangs,
        'sex': sexes,
        'age': ages,
        'type': types,
        'familyStatus': familystatus
    }
    children = pd.DataFrame(
        data=Data,
        columns=['id', 'rang', 'sex', 'age', 'type', 'familyStatus'])

    # Projection of population
    # Number of years to project
    MAX_ANNEES = 60

    # Projection
    numbers_ = eff.projectNumbers(employees,
                                  spouses,
                                  children,
                                  MAX_YEARS=MAX_ANNEES)

    # global numbers
    global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                    MAX_ANNEES)
Exemple #13
0
# print(spouses.head(10))
# print('Children :')
# print(children.head(10))

# Projection of population
# Number of years to project
MAX_ANNEES = 50

# Projection
cols_birth = [('age', 'employees'), ('age', 'spouses'), ('sex', 'employees'),
              ('sex', 'spouses')]
numbers_ = eff.projectNumbers(employees,
                              spouses,
                              children,
                              'TV 88-90',
                              MAX_ANNEES,
                              law_replacement_=law_replacement1,
                              law_marriage_=(law_mar_3, ['age', 'year_proj']),
                              law_birth_=loi_naiss_5,
                              law_resignation_=turnover)

# global numbers
global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                MAX_ANNEES)

# printing results
# print(global_numb)

# export global numbers
global_numb.to_csv(path_exp + "global_numbers.csv",
                   index=False,
Exemple #14
0
ages = []
types = []
familystatus = []
Data = {
    'id': ids,
    'rang': rangs,
    'sex': sexes,
    'age': ages,
    'type': types,
    'familyStatus': familystatus
}
children = pd.DataFrame(
    data=Data, columns=['id', 'rang', 'sex', 'age', 'type', 'familyStatus'])

# Projection of population
# Number of years to project
MAX_ANNEES = 60

# Projection
numbers_ = eff.simulerEffectif(employees,
                               spouses,
                               children,
                               MAX_YEARS=MAX_ANNEES)

# global numbers
global_numb = eff.globalNumbers(numbers_[0], numbers_[1], numbers_[2],
                                MAX_ANNEES)

global_numb.to_excel('./pop_projection/test/results/glob_num_toy.xlsx',
                     index=False)