<commit_before>{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "import collections\n",
      "import copy\n",
      "import json\n",
      "import urllib2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "base_scenario = dict(\n",
      "    familles = [\n",
      "        dict(\n",
      "            parents = ['ind0', 'ind1'],\n",
      "            enfants = ['ind2'],\n",
      "            ),\n",
      "        ],\n",
      "    foyers_fiscaux = [\n",
      "        dict(\n",
      "            declarants = ['ind0'],\n",
      "            personnes_a_charge = ['ind2'],\n",
      "            ),\n",
      "        dict(\n",
      "            declarants = ['ind1'],\n",
      "            ),\n",
      "        ],\n",
      "    individus = [\n",
      "        dict(\n",
      "            birth = '1970-01-01',\n",
      "            id = 'ind0',\n",
      "            sali = 16000,\n",
      "            ),\n",
      "        dict(\n",
      "            birth = '1970-01-02',\n",
      "            id = 'ind1',\n",
      "            sali = 12500,\n",
      "            ),\n",
      "        dict(\n",
      "            birth = '2000-01-03',\n",
      "            id = 'ind2',\n",
      "            ),\n",
      "        ],\n",
      "    legislation_url = 'http://api.openfisca.fr/api/1/default-legislation',\n",
      "    menages = [\n",
      "        dict(\n",
      "            personne_de_reference = 'ind0',\n",
      "            conjoint = 'ind1',\n",
      "            enfants = ['ind2'],\n",
      "            ),\n",
      "        ],\n",
      "    )\n",
      "years = [2013]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "scenarios = []\n",
      "for year in years:\n",
      "    scenario = copy.deepcopy(base_scenario)\n",
      "    scenario['year'] = year\n",
      "    scenarios.append(scenario)\n",
      "\n",
      "simulation = dict(\n",
      "    scenarios = scenarios,\n",
      "    )\n",
      "\n",
      "request = urllib2.Request('http://api.openfisca.fr/api/1/simulate', headers = {\n",
      "    'Content-Type': 'application/json',\n",
      "    'User-Agent': 'OpenFisca-Notebook',\n",
      "    })\n",
      "try:\n",
      "    response = urllib2.urlopen(request, json.dumps(simulation))\n",
      "except urllib2.HTTPError as response:\n",
      "    print response.read()\n",
      "    raise\n",
      "response_dict = json.loads(response.read(), object_pairs_hook = collections.OrderedDict)\n",
      "trees = response_dict['value']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def iter_columns_from_tree(node, base_value = 0, code = None):\n",
      "    children = node.get('children')\n",
      "    if children:\n",
      "        child_base_value = base_value\n",
      "        for child_code, child in children.iteritems():\n",
      "            for column in iter_columns_from_tree(child, base_value = child_base_value, code = child_code):\n",
      "                yield column\n",
      "            child_base_value += child['values'][value_index]\n",
      "\n",
      "    value = node['values'][value_index]\n",
      "    if value != 0 and code is not None:\n",
      "        column = dict(\n",
      "            base_value = base_value,\n",
      "            code = code,\n",
      "            value = value,\n",
      "            )\n",
      "        column.update(node)\n",
      "        yield column"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "value_index = 0\n",
      "tree = trees[0]\n",
      "for column_index, column in enumerate(iter_columns_from_tree(tree)):\n",
      "    base_value = column['base_value']\n",
      "    value = column['value']\n",
      "    print u'{:20s} | {:10.2f} | {:10.2f}'.format(column['name'], column['base_value'], column['value'])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Co\u00fbt travail         |       0.00 |   41390.40\n",
        "Cotsoc pat           |   41390.40 |  -15648.99\n",
        "All\u00e8g. sal.          |   25741.40 |    7957.64\n",
        "CICE                 |   33699.04 |    1404.13\n",
        "Sal. bruts           |       0.00 |   35103.17\n",
        "Cotsoc sal           |   35103.17 |   -4844.24\n",
        "CSG deduc            |   30258.93 |   -1758.93\n",
        "Sal. impos.          |       0.00 |   28500.00\n",
        "CSG imp. sal.        |   28500.00 |    -827.73\n",
        "CRDS sal.            |   27672.27 |    -172.44\n",
        "Sal. nets            |       0.00 |   27499.82\n",
        "Rev. travail         |       0.00 |   27499.82\n",
        "Rev. nets            |       0.00 |   27499.82\n",
        "Rev. disp.           |       0.00 |   27499.82\n"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}<commit_msg>Change "salaire" to "chomage" for one family member.<commit_after>{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "\n",
      "import collections\n",
      "import copy\n",
      "import json\n",
      "import urllib2"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": true,
     "input": [
      "base_scenario = dict(\n",
      "    familles = [\n",
      "        dict(\n",
      "            parents = ['ind0', 'ind1'],\n",
      "            enfants = ['ind2'],\n",
      "            ),\n",
      "        ],\n",
      "    foyers_fiscaux = [\n",
      "        dict(\n",
      "            declarants = ['ind0'],\n",
      "            personnes_a_charge = ['ind2'],\n",
      "            ),\n",
      "        dict(\n",
      "            declarants = ['ind1'],\n",
      "            ),\n",
      "        ],\n",
      "    individus = [\n",
      "        dict(\n",
      "            birth = '1970-01-01',\n",
      "            id = 'ind0',\n",
      "            sali = 16000,\n",
      "            ),\n",
      "        dict(\n",
      "            birth = '1970-01-02',\n",
      "            id = 'ind1',\n",
      "            choi = 12500,\n",
      "            ),\n",
      "        dict(\n",
      "            birth = '2000-01-03',\n",
      "            id = 'ind2',\n",
      "            ),\n",
      "        ],\n",
      "    legislation_url = 'http://api.openfisca.fr/api/1/default-legislation',\n",
      "    menages = [\n",
      "        dict(\n",
      "            personne_de_reference = 'ind0',\n",
      "            conjoint = 'ind1',\n",
      "            enfants = ['ind2'],\n",
      "            ),\n",
      "        ],\n",
      "    )\n",
      "years = [2013]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "scenarios = []\n",
      "for year in years:\n",
      "    scenario = copy.deepcopy(base_scenario)\n",
      "    scenario['year'] = year\n",
      "    scenarios.append(scenario)\n",
      "\n",
      "simulation = dict(\n",
      "    scenarios = scenarios,\n",
      "    )\n",
      "\n",
      "request = urllib2.Request('http://api.openfisca.fr/api/1/simulate', headers = {\n",
      "    'Content-Type': 'application/json',\n",
      "    'User-Agent': 'OpenFisca-Notebook',\n",
      "    })\n",
      "try:\n",
      "    response = urllib2.urlopen(request, json.dumps(simulation))\n",
      "except urllib2.HTTPError as response:\n",
      "    print response.read()\n",
      "    raise\n",
      "response_dict = json.loads(response.read(), object_pairs_hook = collections.OrderedDict)\n",
      "trees = response_dict['value']"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def iter_columns_from_tree(node, base_value = 0, code = None):\n",
      "    children = node.get('children')\n",
      "    if children:\n",
      "        child_base_value = base_value\n",
      "        for child_code, child in children.iteritems():\n",
      "            for column in iter_columns_from_tree(child, base_value = child_base_value, code = child_code):\n",
      "                yield column\n",
      "            child_base_value += child['values'][value_index]\n",
      "\n",
      "    value = node['values'][value_index]\n",
      "    if value != 0 and code is not None:\n",
      "        column = dict(\n",
      "            base_value = base_value,\n",
      "            code = code,\n",
      "            value = value,\n",
      "            )\n",
      "        column.update(node)\n",
      "        yield column"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "value_index = 0\n",
      "tree = trees[0]\n",
      "for column_index, column in enumerate(iter_columns_from_tree(tree)):\n",
      "    base_value = column['base_value']\n",
      "    value = column['value']\n",
      "    print u'{:20s} | {:10.2f} | {:10.2f}'.format(column['name'], column['base_value'], column['value'])\n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Co\u00fbt travail         |       0.00 |   24072.83\n",
        "Cotsoc pat           |   24072.83 |   -8785.40\n",
        "All\u00e8g. sal.          |   15287.43 |    3631.33\n",
        "CICE                 |   18918.76 |     788.28\n",
        "Sal. bruts           |       0.00 |   19707.04\n",
        "Cotsoc sal           |   19707.04 |   -2719.57\n",
        "CSG deduc            |   16987.47 |    -987.47\n",
        "Sal. impos.          |       0.00 |   16000.00\n",
        "CSG imp. sal.        |   16000.00 |    -464.69\n",
        "CRDS sal.            |   15535.31 |     -96.81\n",
        "Sal. nets            |       0.00 |   15438.50\n",
        "Rev. travail         |       0.00 |   15438.50\n",
        "Ch\u00f4mage brut         |   15438.50 |   12500.00\n",
        "Ch\u00f4mage decl.        |   15438.50 |   12500.00\n",
        "Ch\u00f4mage net          |   15438.50 |   12500.00\n",
        "Pensions             |   15438.50 |   12500.00\n",
        "Rev. nets            |       0.00 |   27938.50\n",
        "Rev. disp.           |       0.00 |   27938.50\n"
       ]
      }
     ],
     "prompt_number": 5
    }
   ],
   "metadata": {}
  }
 ]
}
{'fraction_non_alphanumeric': 0.19102386717398823, 'fraction_numerical': 0.046783120027672084, 'mean_word_length': 1.3148518815052042, 'pattern_counts': {'":': 90, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7249244', 'n_tokens_mistral': 4331, 'n_tokens_neox': 3989, 'n_words': 662}