{ "cells": [ { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Using custom data configuration tappyness1--causion-f0c7d8cb97d796fc\n", "Found cached dataset parquet (C:/Users/neoce/.cache/huggingface/datasets/tappyness1___parquet/tappyness1--causion-f0c7d8cb97d796fc/0.0.0/2a3b91fbd88a2c90d1dbbb32b460cf621d31bd5b05b934492fdef7d8d6f236ec)\n", "100%|██████████| 1/1 [00:00<00:00, 144.77it/s]\n" ] } ], "source": [ "from datasets import load_dataset\n", "import pandas as pd\n", "import os\n", "import yaml\n", "import sys\n", "sys.path.append(\"..\")\n", "from src.pred_plot import prep_data_pred_plot, data_split\n", "%load_ext autoreload\n", "%autoreload 2\n", "\n", "token_file = open(\"../token_secret.yaml\")\n", "token_obj = yaml.load(token_file, Loader=yaml.FullLoader)\n", "dataset = load_dataset(\"tappyness1/causion\", use_auth_token=token_obj['TOKEN'])\n", "counts_df = pd.DataFrame(dataset['train'])" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datetimeviewcarmotorcyclelarge_vehicle
02023-02-1422:36:03View_from_Second_Link_at_Tuas001
12023-02-1422:36:03View_from_Tuas_Checkpoint200
22023-02-1422:36:03View_from_Woodlands_Causeway_Towards_Johor200
32023-02-1422:36:03View_from_Woodlands_Checkpoint_Towards_BKE301
42023-02-1423:14:34View_from_Second_Link_at_Tuas006
\n", "
" ], "text/plain": [ " date time view car \\\n", "0 2023-02-14 22:36:03 View_from_Second_Link_at_Tuas 0 \n", "1 2023-02-14 22:36:03 View_from_Tuas_Checkpoint 2 \n", "2 2023-02-14 22:36:03 View_from_Woodlands_Causeway_Towards_Johor 2 \n", "3 2023-02-14 22:36:03 View_from_Woodlands_Checkpoint_Towards_BKE 3 \n", "4 2023-02-14 23:14:34 View_from_Second_Link_at_Tuas 0 \n", "\n", " motorcycle large_vehicle \n", "0 0 1 \n", "1 0 0 \n", "2 0 0 \n", "3 0 1 \n", "4 0 6 " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "counts_df.head()" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "g:\\My Drive\\DataScience\\OMSA GaTech\\08_CSE6242\\Project\\Org_Space\\Causion\\notebooks\\..\\src\\pred_plot.py:117: SettingWithCopyWarning:\n", "\n", "\n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", "\n", "g:\\My Drive\\DataScience\\OMSA GaTech\\08_CSE6242\\Project\\Org_Space\\Causion\\notebooks\\..\\src\\pred_plot.py:118: SettingWithCopyWarning:\n", "\n", "\n", "A value is trying to be set on a copy of a slice from a DataFrame.\n", "Try using .loc[row_indexer,col_indexer] = value instead\n", "\n", "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n", "\n", "g:\\My Drive\\DataScience\\OMSA GaTech\\08_CSE6242\\Project\\Org_Space\\Causion\\notebooks\\..\\src\\pred_plot.py:120: FutureWarning:\n", "\n", "The default value of numeric_only in DataFrameGroupBy.sum is deprecated. In a future version, numeric_only will default to False. Either specify numeric_only or select only columns which should be valid for the function.\n", "\n" ] } ], "source": [ "from src.pred_plot import prep_data_pred_plot, data_split, train_model, predicted_figure, get_today, convert_date, gen_fig\n", "from datetime import date, datetime, timedelta\n", "from jupyter_dash import JupyterDash\n", "import dash\n", "from dash import Dash, html, dcc, Input, Output\n", "final_table = prep_data_pred_plot(counts_df)\n", "x_train, x_test, y_train, y_test = data_split(final_table)\n", "clf = train_model(x_train, y_train)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "starter_variables = [x_train, str(date.today()), \"07:00\", \"Tuas-Johor\"]\n", "figs = gen_fig()\n", "fig = predicted_figure(clf, starter_variables, figs)\n", "today = get_today()" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [], "source": [ "app = JupyterDash(__name__)\n", "\n", "app.title = 'CSE6242 Dashboard'\n", "app.layout = html.Div([\n", " html.Div([\n", " dcc.DatePickerSingle(\n", " id='my_date_picker_single',\n", " min_date_allowed=date(2023, 4, 11),\n", " max_date_allowed=date(2024, 4, 11),\n", " initial_visible_month=date(today[0],today[1], today[2]),\n", " date=date(today[0],today[1], today[2])\n", " ),\n", " html.Div(id='output-container-date-picker-single')],\n", " style={'width':'20%','height':'0px', 'padding-left':'2%',\n", " 'display':'inline-block'}),\n", " html.Div([dcc.Dropdown(id='hours_dropdown_id',\n", " options=['00:00', '01:00', '02:00', '03:00', '04:00', '05:00', '06:00', '07:00', '08:00', '09:00', \n", " '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00','19:00',\n", " '20:00', '21:00', '22:00', '23:00'],\n", " value='07:00', clearable=False),html.Label(\"Estimated Leave Time\")],\n", " style={'width':'20%','height':'60px', 'padding-left':'2%',\n", " 'display':'inline-block'}),\n", " html.Div([dcc.Dropdown(id='direction_id',\n", " options=['Johor-Tuas','Johor-Woodlands',\n", " 'Tuas-Johor', 'Woodlands-Johor'],\n", " value=\"Tuas-Johor\", clearable=False),html.Label(\"Direction\")],\n", " style={'width':'20%','height':'60px', 'padding-left':'2%',\n", " 'display':'inline-block'}),\n", " html.Div(dcc.Graph(id='final_output', figure=fig))])\n", "\n", "\n", "@app.callback(Output('output-container-date-picker-single', 'children'),\n", " Input('my_date_picker_single', 'date'))\n", "def update_output(date_value):\n", " string_prefix = 'Travel Day: '\n", " if date_value is not None:\n", " date_object = date.fromisoformat(date_value)\n", " date_string = convert_date(date_value)\n", " return string_prefix + date_string\n", " \n", "@app.callback(Output('final_output', \"figure\"),\n", " Input('my_date_picker_single', 'date'),\n", " Input('hours_dropdown_id', 'value'),\n", " Input('direction_id', 'value'))\n", "def update_final_output_hour(my_date_picker_single, hours_dropdown_id, direction_id):\n", " starter_variables[0] = x_train\n", " starter_variables[1] = str(my_date_picker_single)\n", " starter_variables[2] = str(hours_dropdown_id)\n", " starter_variables[3] = str(direction_id)\n", " fig = predicted_figure(clf, starter_variables, figs)\n", " return fig" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Dash is running on http://127.0.0.1:8050/\n", "\n" ] } ], "source": [ "app.run_server(mode='inline')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'2023-04-14'" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from datetime import date\n", "\n", "str(date.today())" ] } ], "metadata": { "kernelspec": { "display_name": "causion", "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.8.16" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }