Skip to content

Commit

Permalink
Use Excel- and Google Sheets-readable formatting of durations in the …
Browse files Browse the repository at this point in the history
…notebook.

Fortunately, the format is human-readable as well and it just stops at the
"hours" level, i.e. instead of "2 days 3:00:00", it just says "51:00:00".
  • Loading branch information
ondrasej committed Nov 6, 2023
1 parent 3107090 commit 215a17e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions python/cfr/analysis/cfr-json-analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,12 @@
"# @title Aggregated vehicle statistics\n",
"\n",
"\n",
"def _format_duration(value) -> str:\n",
" total_seconds = int(value.total_seconds())\n",
" hours = total_seconds // 3600\n",
" remaining_seconds = total_seconds % 3600\n",
" return f\"{hours}:{remaining_seconds // 60:02d}:{remaining_seconds % 60:02d}\"\n",
"\n",
"def _safe_percentage(value, maximum) -> str:\n",
" if not maximum:\n",
" # The maximum is zero or a zero-like value (e.g. datetime.timedelta of zero\n",
Expand All @@ -797,6 +803,7 @@
" max_working_hours = datetime.timedelta()\n",
" soft_working_hours = datetime.timedelta()\n",
" actual_working_hours = datetime.timedelta()\n",
" wait_hours = datetime.timedelta()\n",
"\n",
" num_time_travel = 0\n",
" num_hard_time_travel = 0\n",
Expand All @@ -814,18 +821,21 @@
" num_hard_time_travel += cfr_json.get_num_decreasing_visit_times(\n",
" scenario.model, route, consider_visit_duration=False\n",
" )\n",
" wait_hours += max(datetime.timedelta(), analysis.get_vehicle_wait_hours(route))\n",
"\n",
" return {\n",
" \"# vehicles\": len(vehicles),\n",
" \"max working time\": str(max_working_hours),\n",
" \"soft working time\": str(soft_working_hours),\n",
" \"actual working time\": str(actual_working_hours),\n",
" \"max working time\": _format_duration(max_working_hours),\n",
" \"soft working time\": _format_duration(soft_working_hours),\n",
" \"actual working time\": _format_duration(actual_working_hours),\n",
" \"wait time\": _format_duration(wait_hours),\n",
" \"max working time %\": _safe_percentage(\n",
" actual_working_hours, max_working_hours\n",
" ),\n",
" \"soft working time %\": _safe_percentage(\n",
" actual_working_hours, soft_working_hours\n",
" ),\n",
" \"wait time %\": _safe_percentage(wait_hours, actual_working_hours),\n",
" \"# soft time travel\": str(num_time_travel),\n",
" \"# time travel\": str(num_hard_time_travel),\n",
" }\n",
Expand Down Expand Up @@ -1063,6 +1073,7 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "Im3WX2b6sP-V"
},
"outputs": [],
Expand Down

0 comments on commit 215a17e

Please sign in to comment.