Skip to content

Instantly share code, notes, and snippets.

@yoyonel
Created June 19, 2019 21:57
Show Gist options
  • Select an option

  • Save yoyonel/64b28eaecf77bb10755646b3ffd51e86 to your computer and use it in GitHub Desktop.

Select an option

Save yoyonel/64b28eaecf77bb10755646b3ffd51e86 to your computer and use it in GitHub Desktop.

Revisions

  1. yoyonel created this gist Jun 19, 2019.
    80 changes: 80 additions & 0 deletions salary_range.ipynb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,80 @@
    {
    "cells": [
    {
    "cell_type": "code",
    "execution_count": 14,
    "metadata": {
    "scrolled": true
    },
    "outputs": [],
    "source": [
    "import numpy as np\n",
    "from typing import Iterable\n",
    "\n",
    "def gen_tranche_salary(\n",
    " nb_slices: int = 5, \n",
    " salary_start: int = 40,\n",
    " salary_end: int = 50,\n",
    ") -> Iterable[str]:\n",
    " coef_norm = 1.0 / float(nb_slices - 1)\n",
    " range_salaires = np.linspace(start=salary_start, stop=salary_end, num=nb_slices)\n",
    "\n",
    " def format_str_for_tranche_percent_range_salary(id_range_salary):\n",
    " i, (range_salary_min, range_salary_max) = id_range_salary\n",
    " # TODO: reformat with new style of string formatting `f{...}`\n",
    " return \"Tranche n°{} : {:>3.0%} - {:>4.0%} -> {:.2f}K - {:.2f}K\".format(\n",
    " i + 1, \n",
    " i * coef_norm,\n",
    " (i + 1) * coef_norm, \n",
    " range_salary_min,\n",
    " range_salary_max\n",
    " )\n",
    "\n",
    " for s in map(format_str_for_tranche_percent_range_salary,\n",
    " enumerate(zip(range_salaires[:-1:], range_salaires[1::]))):\n",
    " yield s"
    ]
    },
    {
    "cell_type": "code",
    "execution_count": 13,
    "metadata": {},
    "outputs": [
    {
    "name": "stdout",
    "output_type": "stream",
    "text": [
    "Tranche n°1 : 0% - 25% -> 45.00K - 46.25K\n",
    "Tranche n°2 : 25% - 50% -> 46.25K - 47.50K\n",
    "Tranche n°3 : 50% - 75% -> 47.50K - 48.75K\n",
    "Tranche n°4 : 75% - 100% -> 48.75K - 50.00K\n"
    ]
    }
    ],
    "source": [
    "print(\"\\n\".join(gen_tranche_salary(nb_slices=5, salary_start=45, salary_end=50)))"
    ]
    }
    ],
    "metadata": {
    "kernelspec": {
    "display_name": "Python 3",
    "language": "python",
    "name": "python3"
    },
    "language_info": {
    "codemirror_mode": {
    "name": "ipython",
    "version": 3
    },
    "file_extension": ".py",
    "mimetype": "text/x-python",
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
    "version": "3.6.7"
    }
    },
    "nbformat": 4,
    "nbformat_minor": 2
    }