Commit 3ed11d58 by Prayush Kumar

Update notebook to handle postdoc housing, still not complete though

parent 7b4b67a8
Showing with 176 additions and 77 deletions
...@@ -41,29 +41,12 @@ ...@@ -41,29 +41,12 @@
"source": [ "source": [
"# inputs = pd.read_csv(\"\")\n", "# inputs = pd.read_csv(\"\")\n",
"inputs = {}\n", "inputs = {}\n",
"inputs[\"name\"] = [\n", "inputs[\"name\"] = [\"person 1\", \"person 2\", \"person 3\"]\n",
" \"person 1\",\n", "inputs[\"year\"] = [1, 3, 2]\n",
" \"person 2\",\n", "inputs[\"student_or_postdoc\"] = [\"student\", \"student\", \"postdoc\"]\n",
" \"person 3\"\n", "inputs[\"course\"] = [\"iphd\", \"phd\", \"postdoc\"]\n",
"]\n", "inputs[\"female\"] = [1, 0, 0]\n",
"inputs[\"year\"] = [\n", "inputs[\"preferences\"] = [[0, 5, 1, 2, 3], [0, 5, 1, 2, 3], [0, 5, 1, 2, 3]]"
" 1, 3, 2\n",
"]\n",
"inputs[\"student_or_postdoc\"] = [\n",
" \"student\", \"student\", \"postdoc\"\n",
"]\n",
"inputs[\"course\"] = [\n",
" \"iphd\", \"phd\", \"postdoc\"\n",
"]\n",
"\n",
"inputs[\"female\"] = [\n",
" 1, 0, 0\n",
"]\n",
"inputs[\"preferences\"] = [\n",
" [0,5,1,2,3],\n",
" [0,5,1,2,3],\n",
" [0,5,1,2,3]\n",
"]"
] ]
}, },
{ {
...@@ -72,14 +55,9 @@ ...@@ -72,14 +55,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"availability = {\n", "availability = {}\n",
" 0: 15,\n", "availability[\"student\"] = {0: 15, 1: 23, 2: 25, 3: 35, 4: 40, 5: 18}\n",
" 1: 23,\n", "availability[\"postdoc\"] = {0: 4, 1: 23, 2: 0, 3: 0, 4: 0, 5: 10}"
" 2: 25,\n",
" 3: 35,\n",
" 4: 40,\n",
" 5: 18\n",
"}\n"
] ]
}, },
{ {
...@@ -91,33 +69,50 @@ ...@@ -91,33 +69,50 @@
"def get_info_for_person(person_name, col_name):\n", "def get_info_for_person(person_name, col_name):\n",
" if person_name not in inputs[\"name\"]:\n", " if person_name not in inputs[\"name\"]:\n",
" raise IOError(f\"We do not recognize name: {person_name}\")\n", " raise IOError(f\"We do not recognize name: {person_name}\")\n",
" \n", "\n",
" if col_name not in inputs:\n", " if col_name not in inputs:\n",
" raise IOError(f\"We were not provided with info: {col_name}\")\n", " raise IOError(f\"We were not provided with info: {col_name}\")\n",
" \n", "\n",
" idx_of_person = inputs[\"name\"].index(person_name)\n", " idx_of_person = inputs[\"name\"].index(person_name)\n",
" return inputs[col_name][idx_of_person]\n", " return inputs[col_name][idx_of_person]\n",
"\n", "\n",
"def get_pool_number(person_name):\n", "\n",
"def get_pool_number_for_student(person_name):\n",
" pool_number = 3\n", " pool_number = 3\n",
" if (get_info_for_person(person_name, \"female\") == 1) and (\n", " if (get_info_for_person(person_name, \"female\") == 1) and (\n",
" get_info_for_person(person_name, \"year\") == 1\n", " get_info_for_person(person_name, \"year\") == 1\n",
" ):\n", " ):\n",
" pool_number = 1\n", " pool_number = 1\n",
" elif (get_info_for_person(person_name, \"year\") == 1) or (\n", " elif (get_info_for_person(person_name, \"year\") == 1) or (\n",
" (get_info_for_person(person_name, \"year\") == 5 and get_info_for_person(\n", " (\n",
" person_name, \"course\") == \"phd\") or (\n", " get_info_for_person(person_name, \"year\") == 5\n",
" get_info_for_person(person_name, \"year\") == 6 and get_info_for_person(\n", " and get_info_for_person(person_name, \"course\") == \"phd\"\n",
" person_name, \"course\") == \"iphd\")\n", " )\n",
" ):\n", " or (\n",
" get_info_for_person(person_name, \"year\") == 6\n",
" and get_info_for_person(person_name, \"course\") == \"iphd\"\n",
" )\n",
" ):\n",
" pool_number = 2\n", " pool_number = 2\n",
" return pool_number\n", " return pool_number\n",
"\n", "\n",
"def get_pool_number_for_postdoc(person_name):\n",
" # FIXME: Everyone is equal?\n",
" return 1\n",
"\n",
"\n",
"def get_possible_pools():\n", "def get_possible_pools():\n",
" return [1, 2, 3]" " return [1, 2, 3]"
] ]
}, },
{ {
"cell_type": "markdown",
"metadata": {},
"source": [
"Check if inputs look okay"
]
},
{
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": {}, "metadata": {},
...@@ -135,9 +130,11 @@ ...@@ -135,9 +130,11 @@
"\n", "\n",
"for col_name in inputs:\n", "for col_name in inputs:\n",
" if len(inputs[col_name]) != total_number_of_people:\n", " if len(inputs[col_name]) != total_number_of_people:\n",
" raise IOError(\"There are {} entries for column {}. We need {}.\".format(\n", " raise IOError(\n",
" len(inputs[col_name]), col_name, total_number_of_people\n", " \"There are {} entries for column {}. We need {}.\".format(\n",
" ))\n", " len(inputs[col_name]), col_name, total_number_of_people\n",
" )\n",
" )\n",
"\n", "\n",
"print(f\"Inputs look good. We got {total_number_of_people} entries.\")" "print(f\"Inputs look good. We got {total_number_of_people} entries.\")"
] ]
...@@ -153,6 +150,15 @@ ...@@ -153,6 +150,15 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 6,
"metadata": {}, "metadata": {},
"outputs": [],
"source": [
"all_pools = {}"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
...@@ -164,7 +170,46 @@ ...@@ -164,7 +170,46 @@
"In pool 2, we have:\n", "In pool 2, we have:\n",
" []\n", " []\n",
"In pool 3, we have:\n", "In pool 3, we have:\n",
" ['person 2', 'person 3']\n" " ['person 2']\n"
]
}
],
"source": [
"housing_pools = {}\n",
"\n",
"for pool_id in get_possible_pools():\n",
" _pool = []\n",
" for person_name in inputs[\"name\"]:\n",
" # FIXME: Change the next line for postdocs\n",
" if get_info_for_person(person_name, \"student_or_postdoc\") == \"student\":\n",
" if get_pool_number_for_student(person_name) == pool_id:\n",
" _pool.append(person_name)\n",
" housing_pools[pool_id] = _pool\n",
"\n",
"print(\"Here are our assignments:\")\n",
"\n",
"for pool_id in housing_pools:\n",
" print(f\"In pool {pool_id}, we have:\\n {housing_pools[pool_id]}\")\n",
"\n",
"all_pools[\"student\"] = copy.deepcopy(housing_pools)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here are our assignments:\n",
"In pool 1, we have:\n",
" ['person 3']\n",
"In pool 2, we have:\n",
" []\n",
"In pool 3, we have:\n",
" []\n"
] ]
} }
], ],
...@@ -174,14 +219,39 @@ ...@@ -174,14 +219,39 @@
"for pool_id in get_possible_pools():\n", "for pool_id in get_possible_pools():\n",
" _pool = []\n", " _pool = []\n",
" for person_name in inputs[\"name\"]:\n", " for person_name in inputs[\"name\"]:\n",
" if get_pool_number(person_name) == pool_id:\n", " # FIXME: Change the next line for postdocs\n",
" _pool.append(person_name)\n", " if get_info_for_person(person_name, \"student_or_postdoc\") == \"postdoc\":\n",
" if get_pool_number_for_postdoc(person_name) == pool_id:\n",
" _pool.append(person_name)\n",
" housing_pools[pool_id] = _pool\n", " housing_pools[pool_id] = _pool\n",
"\n", "\n",
"print(\"Here are our assignments:\")\n", "print(\"Here are our assignments:\")\n",
"\n", "\n",
"for pool_id in housing_pools:\n", "for pool_id in housing_pools:\n",
" print(f\"In pool {pool_id}, we have:\\n {housing_pools[pool_id]}\")" " print(f\"In pool {pool_id}, we have:\\n {housing_pools[pool_id]}\")\n",
"\n",
"all_pools[\"postdoc\"] = copy.deepcopy(housing_pools)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'student': {1: ['person 1'], 2: [], 3: ['person 2']},\n",
" 'postdoc': {1: ['person 3'], 2: [], 3: []}}"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"all_pools"
] ]
}, },
{ {
...@@ -193,57 +263,86 @@ ...@@ -193,57 +263,86 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"housing_allocations = {}"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"------------------------\n",
"Processing housing allotments for: student\n",
"\n", "\n",
"As per a randomized lottery, we will allocate in the following order:['person 1']\n", "As per a randomized lottery, we will allocate pool 1 in the following order:['person 1']\n",
"...assigning housing 0 to person 1 as it has 15 vacancies still.\n", "...assigning housing 0 to person 1 as it has 15 vacancies still.\n",
"\n", "\n",
"As per a randomized lottery, we will allocate in the following order:[]\n", "As per a randomized lottery, we will allocate pool 2 in the following order:[]\n",
"\n", "\n",
"As per a randomized lottery, we will allocate in the following order:['person 2', 'person 3']\n", "As per a randomized lottery, we will allocate pool 3 in the following order:['person 2']\n",
"...assigning housing 0 to person 2 as it has 14 vacancies still.\n", "...assigning housing 0 to person 2 as it has 14 vacancies still.\n",
"...assigning housing 0 to person 3 as it has 13 vacancies still.\n" "------------------------\n",
"------------------------\n",
"Processing housing allotments for: postdoc\n",
"\n",
"As per a randomized lottery, we will allocate pool 1 in the following order:['person 3']\n",
"...assigning housing 0 to person 3 as it has 4 vacancies still.\n",
"\n",
"As per a randomized lottery, we will allocate pool 2 in the following order:[]\n",
"\n",
"As per a randomized lottery, we will allocate pool 3 in the following order:[]\n",
"------------------------\n"
] ]
} }
], ],
"source": [ "source": [
"housing_allocations = {}\n", "for pool_type in [\"student\", \"postdoc\"]:\n",
"current_availability = copy.deepcopy(availability)\n", " print(\"------------------------\")\n",
" print(f\"Processing housing allotments for: {pool_type}\")\n",
" current_availability = copy.deepcopy(availability[pool_type])\n",
" current_pool = all_pools[pool_type]\n",
"\n", "\n",
"for pool_id in get_possible_pools():\n", " for pool_id in get_possible_pools():\n",
" # randomly assign ranks, and sort according to it\n", " # randomly assign ranks, and sort according to it\n",
" this_pool = housing_pools[pool_id]\n", " this_pool = current_pool[pool_id]\n",
" random.shuffle(this_pool)\n", " random.shuffle(this_pool)\n",
" \n", "\n",
" print(f\"\\nAs per a randomized lottery, we will allocate in the following order:\"\n", " print(\n",
" f\"{this_pool}\") \n", " f\"\\nAs per a randomized lottery, we will allocate pool {pool_id} in the following order:\"\n",
" \n", " f\"{this_pool}\"\n",
" # now we go over the ranked list, and assign housing based on availability\n", " )\n",
" for person_name in this_pool:\n", "\n",
" their_preferences = get_info_for_person(person_name, \"preferences\")\n", " # now we go over the ranked list, and assign housing based on availability\n",
" for pref in their_preferences:\n", " for person_name in this_pool:\n",
" if current_availability[pref] > 0:\n", " their_preferences = get_info_for_person(person_name, \"preferences\")\n",
" # Allot NOW!\n", " for pref in their_preferences:\n",
" print(f\"\"\"...assigning housing {pref} to {\n", " if current_availability[pref] > 0:\n",
" person_name} as it has {\n", " # Allot NOW!\n",
" current_availability[pref]} vacancies still.\"\"\")\n", " print(\n",
" housing_allocations[person_name] = pref\n", " f\"\"\"...assigning housing {pref} to {\n",
" current_availability[pref] = current_availability[pref] - 1\n", " person_name} as it has {\n",
" break\n", " current_availability[pref]} vacancies still.\"\"\"\n",
" else:\n", " )\n",
" print(f\"For {person_name}, acco {pref} is full. Moving on...\")\n", " housing_allocations[person_name] = pref\n",
" continue" " current_availability[pref] = current_availability[pref] - 1\n",
" break\n",
" else:\n",
" print(f\"For {person_name}, acco {pref} is full. Moving on...\")\n",
" continue\n",
" print(\"------------------------\")"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 12,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment