Commit 3ed11d58 by Prayush Kumar

Update notebook to handle postdoc housing, still not complete though

parent 7b4b67a8
Showing with 159 additions and 60 deletions
......@@ -41,29 +41,12 @@
"source": [
"# inputs = pd.read_csv(\"\")\n",
"inputs = {}\n",
"inputs[\"name\"] = [\n",
" \"person 1\",\n",
" \"person 2\",\n",
" \"person 3\"\n",
"]\n",
"inputs[\"year\"] = [\n",
" 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",
"]"
"inputs[\"name\"] = [\"person 1\", \"person 2\", \"person 3\"]\n",
"inputs[\"year\"] = [1, 3, 2]\n",
"inputs[\"student_or_postdoc\"] = [\"student\", \"student\", \"postdoc\"]\n",
"inputs[\"course\"] = [\"iphd\", \"phd\", \"postdoc\"]\n",
"inputs[\"female\"] = [1, 0, 0]\n",
"inputs[\"preferences\"] = [[0, 5, 1, 2, 3], [0, 5, 1, 2, 3], [0, 5, 1, 2, 3]]"
]
},
{
......@@ -72,14 +55,9 @@
"metadata": {},
"outputs": [],
"source": [
"availability = {\n",
" 0: 15,\n",
" 1: 23,\n",
" 2: 25,\n",
" 3: 35,\n",
" 4: 40,\n",
" 5: 18\n",
"}\n"
"availability = {}\n",
"availability[\"student\"] = {0: 15, 1: 23, 2: 25, 3: 35, 4: 40, 5: 18}\n",
"availability[\"postdoc\"] = {0: 4, 1: 23, 2: 0, 3: 0, 4: 0, 5: 10}"
]
},
{
......@@ -91,33 +69,50 @@
"def get_info_for_person(person_name, col_name):\n",
" if person_name not in inputs[\"name\"]:\n",
" raise IOError(f\"We do not recognize name: {person_name}\")\n",
" \n",
"\n",
" if col_name not in inputs:\n",
" raise IOError(f\"We were not provided with info: {col_name}\")\n",
" \n",
"\n",
" idx_of_person = inputs[\"name\"].index(person_name)\n",
" return inputs[col_name][idx_of_person]\n",
"\n",
"def get_pool_number(person_name):\n",
"\n",
"def get_pool_number_for_student(person_name):\n",
" pool_number = 3\n",
" if (get_info_for_person(person_name, \"female\") == 1) and (\n",
" get_info_for_person(person_name, \"year\") == 1\n",
" ):\n",
" pool_number = 1\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",
" person_name, \"course\") == \"phd\") or (\n",
" get_info_for_person(person_name, \"year\") == 6 and get_info_for_person(\n",
" person_name, \"course\") == \"iphd\")\n",
" (\n",
" get_info_for_person(person_name, \"year\") == 5\n",
" and get_info_for_person(person_name, \"course\") == \"phd\"\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",
" return pool_number\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",
" return [1, 2, 3]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Check if inputs look okay"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
......@@ -135,9 +130,11 @@
"\n",
"for col_name in inputs:\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",
" \"There are {} entries for column {}. We need {}.\".format(\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.\")"
]
......@@ -153,6 +150,15 @@
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"all_pools = {}"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
......@@ -164,7 +170,7 @@
"In pool 2, we have:\n",
" []\n",
"In pool 3, we have:\n",
" ['person 2', 'person 3']\n"
" ['person 2']\n"
]
}
],
......@@ -174,14 +180,78 @@
"for pool_id in get_possible_pools():\n",
" _pool = []\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",
" 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]}\")"
" 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"
]
}
],
"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\") == \"postdoc\":\n",
" if get_pool_number_for_postdoc(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[\"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 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"housing_allocations = {}"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"------------------------\n",
"Processing housing allotments for: student\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",
"\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",
"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 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": [
"housing_allocations = {}\n",
"current_availability = copy.deepcopy(availability)\n",
"for pool_type in [\"student\", \"postdoc\"]:\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",
"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",
" this_pool = housing_pools[pool_id]\n",
" this_pool = current_pool[pool_id]\n",
" random.shuffle(this_pool)\n",
" \n",
" print(f\"\\nAs per a randomized lottery, we will allocate in the following order:\"\n",
" f\"{this_pool}\") \n",
" \n",
"\n",
" print(\n",
" f\"\\nAs per a randomized lottery, we will allocate pool {pool_id} in the following order:\"\n",
" f\"{this_pool}\"\n",
" )\n",
"\n",
" # now we go over the ranked list, and assign housing based on availability\n",
" for person_name in this_pool:\n",
" their_preferences = get_info_for_person(person_name, \"preferences\")\n",
" for pref in their_preferences:\n",
" if current_availability[pref] > 0:\n",
" # Allot NOW!\n",
" print(f\"\"\"...assigning housing {pref} to {\n",
" print(\n",
" f\"\"\"...assigning housing {pref} to {\n",
" person_name} as it has {\n",
" current_availability[pref]} vacancies still.\"\"\")\n",
" current_availability[pref]} vacancies still.\"\"\"\n",
" )\n",
" housing_allocations[person_name] = pref\n",
" 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"
" continue\n",
" print(\"------------------------\")"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"metadata": {},
"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