Spaces:
Sleeping
Sleeping
File size: 11,294 Bytes
79daedf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
{
"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": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>time</th>\n",
" <th>view</th>\n",
" <th>car</th>\n",
" <th>motorcycle</th>\n",
" <th>large_vehicle</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2023-02-14</td>\n",
" <td>22:36:03</td>\n",
" <td>View_from_Second_Link_at_Tuas</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2023-02-14</td>\n",
" <td>22:36:03</td>\n",
" <td>View_from_Tuas_Checkpoint</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>2023-02-14</td>\n",
" <td>22:36:03</td>\n",
" <td>View_from_Woodlands_Causeway_Towards_Johor</td>\n",
" <td>2</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>2023-02-14</td>\n",
" <td>22:36:03</td>\n",
" <td>View_from_Woodlands_Checkpoint_Towards_BKE</td>\n",
" <td>3</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>2023-02-14</td>\n",
" <td>23:14:34</td>\n",
" <td>View_from_Second_Link_at_Tuas</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>6</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"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
}
|