Skip to content

Commit

Permalink
added duration to 2020-06-16 exam
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidLeoni committed Jun 16, 2020
1 parent 825b3db commit 43921f9
Showing 1 changed file with 62 additions and 30 deletions.
92 changes: 62 additions & 30 deletions exams/2020-06-16/exam-2020-06-16-solution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,41 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### A3 calc_stats\n",
"### A3.1 duration\n",
"\n",
"Given two times as strings `a` and `b` in format like `17:34`, RETURN the duration in minutes between them as an integer. \n",
"\n",
"To calculate gap durations, **we assume a meeting NEVER ends after midnight**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"def duration(a, b):\n",
" #jupman-raise\n",
" last_time = a.split(':')\n",
" new_time = b.split(':')\n",
" gap = (int(new_time[0]) - int(last_time[0]))*60\n",
" gap += (int(new_time[1]) - int(last_time[1]))\n",
" return gap\n",
" #/jupman-raise\n",
" \n",
"assert duration('15:00','15:34') == 34\n",
"assert duration('15:00','17:34') == 120 + 34\n",
"assert duration('15:50','16:12') == 22\n",
"assert duration('09:55','11:06') == 5 + 60 + 6\n",
"assert duration('00:00','00:01') == 1\n",
"#assert duration('11:58','00:01') == 3 # no need to support this case !!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### A3.2 calc_stats\n",
"\n",
"We want to know something about the time each participant has been disconnected from the exam. We call such intervals `gaps`, which are the difference between a session leave time and successive session join time.\n",
"\n",
Expand All @@ -460,7 +494,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
Expand All @@ -473,7 +507,7 @@
" 'Wario': {'gaps': 4, 'max_gap': 15, 'time_away': 25}}"
]
},
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -504,12 +538,8 @@
" } \n",
" \n",
" if participant in last_sessions:\n",
" last_leave_time = last_sessions[participant][5] \n",
" last_time = last_leave_time.split(':')\n",
" new_time = join_time.split(':')\n",
" gap = (int(new_time[0]) - int(last_time[0]))*60\n",
" gap += (int(new_time[1]) - int(last_time[1]))\n",
"\n",
" last_leave_time = last_sessions[participant][5] \n",
" gap = duration(last_leave_time, join_time) \n",
" ret[participant]['max_gap'] = max(gap, ret[participant]['max_gap'])\n",
" ret[participant]['gaps'] += 1\n",
" ret[participant]['time_away'] += gap\n",
Expand All @@ -529,7 +559,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -562,7 +592,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -707,7 +737,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -716,7 +746,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -732,7 +762,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand All @@ -756,7 +786,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -765,7 +795,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 12,
"metadata": {},
"outputs": [
{
Expand All @@ -789,7 +819,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 13,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -820,7 +850,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 14,
"metadata": {},
"outputs": [
{
Expand All @@ -844,7 +874,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 15,
"metadata": {},
"outputs": [
{
Expand All @@ -868,7 +898,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 16,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -966,7 +996,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -976,7 +1006,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -997,7 +1027,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 19,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1026,7 +1056,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1035,7 +1065,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -1058,7 +1088,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -1067,7 +1097,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 23,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -1109,7 +1139,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 26,
"metadata": {
"nbsphinx": "hidden"
},
Expand All @@ -1120,18 +1150,20 @@
"text": [
"...................\n",
"----------------------------------------------------------------------\n",
"Ran 19 tests in 0.022s\n",
"Ran 19 tests in 0.016s\n",
"\n",
"OK\n",
"................\n",
"----------------------------------------------------------------------\n",
"Ran 16 tests in 0.032s\n",
"Ran 16 tests in 0.018s\n",
"\n",
"OK\n"
]
}
],
"source": [
"import sys\n",
"sys.path.append('../../')\n",
"import jupman\n",
"import linked_list_test\n",
"import bin_tree_test\n",
Expand Down

0 comments on commit 43921f9

Please sign in to comment.