{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import webbrowser" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "webbrowser.open(\"file://\" + os.path.realpath(\"bar.html\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fn = \"Darius-13-100m-Fly.txt\"\n", "\n", "import swimclub\n", "\n", "( swimmer, age, distance, stroke, _, _, _, _ ) = swimclub.get_swim_data(fn)\n", "\n", "title = swimmer + \" (Under \" + age + \") \" + distance + \" \" + stroke\n", "\n", "title" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "html = \"\" + title \n", "html = html + \"

\" + title + \"

\"\n", "\n", "html " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "first = \"Tim\"\n", "second = \"O'Reilly\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(\"Hi there, \" + first + \" \" + second + \"!\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(f\"Hi there, {first} {second}!\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "title = f\"{swimmer} (Under {age}) {distance} {stroke}\"\n", "\n", "title" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "html = f\"\"\"\n", "\n", " \n", " {title}\n", " \n", " \n", "

{title}

\n", "\"\"\"\n", "\n", "html" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(html)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import swimclub\n", "import hfpy_utils\n", "\n", "\n", "swimmer, age, distance, stroke, _, average_str, times, converts = swimclub.get_swim_data(fn)\n", "from_max = max(converts)\n", "svgs = \"\"\n", "times.reverse()\n", "converts.reverse()\n", "for n, t in enumerate(times):\n", " bar_width = hfpy_utils.convert2range(converts[n], 0, from_max, 0, 350)\n", " svgs = svgs + f\"\"\"\n", " \n", " \n", " {t}
\n", " \"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(svgs)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "footer = f\"\"\"\n", "

Average time: {average_str}

\n", " \n", "\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "page = html + svgs + footer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "with open(\"test.txt\", \"w\") as tf:\n", " print(\"This is a test.\", file=tf)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(fn)\n", "prefix = fn.removesuffix(\".txt\")\n", "print(prefix)\n", "print(f\"charts/{prefix}.html\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "save_to = f\"charts/{fn.removesuffix('.txt')}.html\"\n", "\n", "with open(save_to, \"w\") as sf:\n", " print(page, file=sf)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import swimclub\n", "import webbrowser" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "swimclub.produce_bar_chart(\"Darius-13-100m-Fly.txt\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart = swimclub.produce_bar_chart(\"Darius-13-100m-Fly.txt\")\n", "\n", "webbrowser.open(\"file://\" + os.path.realpath(chart))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart = swimclub.produce_bar_chart(\"Dave-17-100m-Free.txt\")\n", "\n", "webbrowser.open(\"file://\" + os.path.realpath(chart))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "swimclub.produce_bar_chart(\"Lizzie-14-100m-Back.txt\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "chart = swimclub.produce_bar_chart(\"Lizzie-14-100m-Back.txt\")\n", "\n", "webbrowser.open(\"file://\" + os.path.realpath(chart))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "swimclub.get_swim_data(\"Lizzie-14-100m-Back.txt\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "average = 8919.8" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(average)\n", "print(average / 100)\n", "print(round(average / 100, 2))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "f\"{(average / 100):.2f}\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "f\"{(average / 100):.2f}\".split(\".\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.11.2" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "5c7b89af1651d0b8571dde13640ecdccf7d5a6204171d6ab33e7c296e100e08a" } } }, "nbformat": 4, "nbformat_minor": 2 }