{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Tweaking the profilers parameters"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-09-21T08:55:56.365935Z",
     "start_time": "2022-09-21T08:55:54.238909Z"
    }
   },
   "outputs": [],
   "source": [
    "import tslumen\n",
    "import pandas as pd\n",
    "from pprint import pprint"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-09-21T08:55:56.373117Z",
     "start_time": "2022-09-21T08:55:56.368413Z"
    },
    "nbsphinx": "hidden"
   },
   "outputs": [],
   "source": [
    "# patch it\n",
    "_read_csv = pd.read_csv\n",
    "pd.read_csv = lambda fpath, *args, **kwargs: _read_csv(fpath.split('/')[-1], *args, **kwargs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-09-21T08:55:57.089316Z",
     "start_time": "2022-09-21T08:55:56.375361Z"
    }
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv(\n",
    "    'https://datahub.io/core/gdp/r/gdp.csv', \n",
    "    parse_dates=[2], \n",
    "    date_parser=lambda dt: pd.to_datetime(f'{dt}-12-31'),\n",
    ")\n",
    "df = df[df['Country Code'].isin(['WLD', 'EUU', 'USA', 'HIC', 'MIC', 'LIC'])]\\\n",
    "    .set_index(['Year', 'Country Code'])['Value'].unstack(1)\n",
    "meta = {\n",
    "    'frame': {\n",
    "        'Description': 'Country, regional and world GDP in current US Dollars ($).',\n",
    "        'Source': '<a href=\"https://datahub.io/core/gold-prices\">DataHub</a>',\n",
    "    },\n",
    "    'series': {\n",
    "        'WLD': 'World GDP in current USD',        \n",
    "        'EUU': 'European Union GDP in current USD',\n",
    "        'USA': 'United States GDP in current USD',\n",
    "        'HIC': 'High income GDP in current USD',\n",
    "        'MIC': 'Middle income GDP in current USD',\n",
    "        'LIC': 'Low income GDP in current USD',\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Unless explicitly provided, *tslumen*'s `HtmlReport` uses the `DefaultProfiler` to profile the time series data.  \n",
    "A dictionary with all the configurations can be obtained by calling its class method `get_config_defaults`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-09-21T08:55:57.097897Z",
     "start_time": "2022-09-21T08:55:57.092559Z"
    }
   },
   "outputs": [],
   "source": [
    "pprint(tslumen.DefaultProfiler.get_config_defaults())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this example we'll be changing the confidence level of the statistical tests."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-09-21T08:55:57.103288Z",
     "start_time": "2022-09-21T08:55:57.100141Z"
    }
   },
   "outputs": [],
   "source": [
    "profiler_config = {\n",
    "    'adfuller_stationarity': {'confidence_level': 0.17},\n",
    "    'jarque_bera_normality': {'confidence_level': 0.17},\n",
    "    'kpss_stationarity': {'confidence_level': 0.17},\n",
    "    'levene_constant_variance': {'confidence_level': 0.17},\n",
    "    'ljungbox_autocorrelation': {'confidence_level': 0.17},\n",
    "    'omnibus_normality': {'confidence_level': 0.17},\n",
    "}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "After rendering the report, you can see on the *Stats* tab, *Confidence* column, that all values are now set to `0.17`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2022-09-21T08:55:57.109990Z",
     "start_time": "2022-09-21T08:55:57.105360Z"
    }
   },
   "outputs": [],
   "source": [
    "report = tslumen.HtmlReport(df, meta, profiler_config=profiler_config)\n",
    "report.SECTIONS = report.SECTIONS[1:2]\n",
    "report"
   ]
  }
 ],
 "metadata": {
  "celltoolbar": "Edit Metadata",
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.7"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": false,
   "skip_h1_title": true,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
