{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# **Analyse 3**\n",
    "\n",
    "## Merkmal 2 - Zeitbezüge innerhalb der Vorgänge\n",
    "\n",
    "### Strategie & Fokus\n",
    "\n",
    "- Untersuchung der Datumszusammenhänge\n",
    "- Anlage von Datumsangaben:\n",
    "    1. ``ErstellungsDatum``\n",
    "    1. ``VorgangsDatum`` (Plan)\n",
    "    1. ``Arbeitsbeginn``\n",
    "    1. ``ErledigungsDatum``"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "\n",
    "sns.set()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 129020 entries, 0 to 129019\n",
      "Data columns (total 20 columns):\n",
      " #   Column                   Non-Null Count   Dtype         \n",
      "---  ------                   --------------   -----         \n",
      " 0   VorgangsID               129020 non-null  int64         \n",
      " 1   ObjektID                 129020 non-null  int64         \n",
      " 2   HObjektText              129003 non-null  object        \n",
      " 3   ObjektArtID              129020 non-null  int64         \n",
      " 4   ObjektArtText            128372 non-null  object        \n",
      " 5   VorgangsTypID            129020 non-null  int64         \n",
      " 6   VorgangsTypName          129020 non-null  object        \n",
      " 7   VorgangsDatum            129020 non-null  datetime64[ns]\n",
      " 8   VorgangsStatusId         129020 non-null  int64         \n",
      " 9   VorgangsPrioritaet       129020 non-null  int64         \n",
      " 10  VorgangsBeschreibung     124087 non-null  object        \n",
      " 11  VorgangsOrt              507 non-null     object        \n",
      " 12  VorgangsArtText          129020 non-null  object        \n",
      " 13  ErledigungsDatum         129020 non-null  datetime64[ns]\n",
      " 14  ErledigungsArtText       128474 non-null  object        \n",
      " 15  ErledigungsBeschreibung  118135 non-null  object        \n",
      " 16  MPMelderArbeitsplatz     6359 non-null    object        \n",
      " 17  MPAbteilungBezeichnung   6359 non-null    object        \n",
      " 18  Arbeitsbeginn            123538 non-null  datetime64[ns]\n",
      " 19  ErstellungsDatum         129020 non-null  datetime64[ns]\n",
      "dtypes: datetime64[ns](4), int64(6), object(10)\n",
      "memory usage: 19.7+ MB\n"
     ]
    }
   ],
   "source": [
    "# load dataset\n",
    "FILE_PATH = '01_2_Rohdaten_neu/Export4.csv'\n",
    "date_cols = ['VorgangsDatum', 'ErledigungsDatum', 'Arbeitsbeginn', 'ErstellungsDatum']\n",
    "raw = pd.read_csv(filepath_or_buffer=FILE_PATH, sep=';', encoding='cp1252', parse_dates=date_cols, dayfirst=True)\n",
    "raw.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "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>VorgangsID</th>\n",
       "      <th>ObjektID</th>\n",
       "      <th>HObjektText</th>\n",
       "      <th>ObjektArtID</th>\n",
       "      <th>ObjektArtText</th>\n",
       "      <th>VorgangsTypID</th>\n",
       "      <th>VorgangsTypName</th>\n",
       "      <th>VorgangsDatum</th>\n",
       "      <th>VorgangsStatusId</th>\n",
       "      <th>VorgangsPrioritaet</th>\n",
       "      <th>VorgangsBeschreibung</th>\n",
       "      <th>VorgangsOrt</th>\n",
       "      <th>VorgangsArtText</th>\n",
       "      <th>ErledigungsDatum</th>\n",
       "      <th>ErledigungsArtText</th>\n",
       "      <th>ErledigungsBeschreibung</th>\n",
       "      <th>MPMelderArbeitsplatz</th>\n",
       "      <th>MPAbteilungBezeichnung</th>\n",
       "      <th>Arbeitsbeginn</th>\n",
       "      <th>ErstellungsDatum</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>11</td>\n",
       "      <td>114</td>\n",
       "      <td>427 C , Webmaschine, DL 280 EMS Breite 280</td>\n",
       "      <td>3</td>\n",
       "      <td>Luft-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-06</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kettbaum kaputt</td>\n",
       "      <td>2019-03-06</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2019-03-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>17</td>\n",
       "      <td>124</td>\n",
       "      <td>621 C , Webmaschine, DL 280 EMS Breite 280</td>\n",
       "      <td>3</td>\n",
       "      <td>Luft-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-11</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>asgasdg</td>\n",
       "      <td>2019-03-11</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Elektrowerkstatt</td>\n",
       "      <td>Elektrowerkstatt</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2019-03-11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>53</td>\n",
       "      <td>244</td>\n",
       "      <td>285 C, Webmaschine, SG 220 EMS</td>\n",
       "      <td>5</td>\n",
       "      <td>Greifer-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-19</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Kupplung schleift</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kupplung defekt</td>\n",
       "      <td>2019-03-20</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>NaT</td>\n",
       "      <td>2019-03-19</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>58</td>\n",
       "      <td>257</td>\n",
       "      <td>107, Webmaschine, OM 220 EOS</td>\n",
       "      <td>3</td>\n",
       "      <td>Luft-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Gegengewicht wieder anbringen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gegengewicht an der Webmaschine abgefallen</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Schraube ausgebohrt\\nGegengewicht wieder angeb...</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>2019-03-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>81</td>\n",
       "      <td>138</td>\n",
       "      <td>00138, Schärmaschine 9,</td>\n",
       "      <td>16</td>\n",
       "      <td>Schärmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>da ist etwas gebrochen. (Herr Heininger)</td>\n",
       "      <td>NaN</td>\n",
       "      <td>zentrale Bremsenverstellung linke Gatterseite ...</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Bolzen gebrochen. Bolzen neu angefertig und di...</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   VorgangsID  ObjektID                                  HObjektText  \\\n",
       "0          11       114  427 C , Webmaschine, DL 280 EMS Breite 280    \n",
       "1          17       124  621 C , Webmaschine, DL 280 EMS Breite 280    \n",
       "2          53       244               285 C, Webmaschine, SG 220 EMS   \n",
       "3          58       257                 107, Webmaschine, OM 220 EOS   \n",
       "4          81       138                     00138, Schärmaschine 9,    \n",
       "\n",
       "   ObjektArtID        ObjektArtText  VorgangsTypID            VorgangsTypName  \\\n",
       "0            3     Luft-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "1            3     Luft-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "2            5  Greifer-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "3            3     Luft-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "4           16        Schärmaschine              3  Reparaturauftrag (Portal)   \n",
       "\n",
       "  VorgangsDatum  VorgangsStatusId  VorgangsPrioritaet  \\\n",
       "0    2019-03-06                 4                   0   \n",
       "1    2019-03-11                 5                   0   \n",
       "2    2019-03-19                 5                   0   \n",
       "3    2019-03-21                 5                   0   \n",
       "4    2019-03-25                 5                   0   \n",
       "\n",
       "                       VorgangsBeschreibung VorgangsOrt  \\\n",
       "0                                       NaN         NaN   \n",
       "1                                       NaN         NaN   \n",
       "2                         Kupplung schleift         NaN   \n",
       "3             Gegengewicht wieder anbringen         NaN   \n",
       "4  da ist etwas gebrochen. (Herr Heininger)         NaN   \n",
       "\n",
       "                                     VorgangsArtText ErledigungsDatum  \\\n",
       "0                                    Kettbaum kaputt       2019-03-06   \n",
       "1                                            asgasdg       2019-03-11   \n",
       "2                                    Kupplung defekt       2019-03-20   \n",
       "3         Gegengewicht an der Webmaschine abgefallen       2019-03-21   \n",
       "4  zentrale Bremsenverstellung linke Gatterseite ...       2019-03-25   \n",
       "\n",
       "  ErledigungsArtText                            ErledigungsBeschreibung  \\\n",
       "0                NaN                                                NaN   \n",
       "1                NaN                                                NaN   \n",
       "2      Reparatur UTT                                                NaN   \n",
       "3      Reparatur UTT  Schraube ausgebohrt\\nGegengewicht wieder angeb...   \n",
       "4      Reparatur UTT  Bolzen gebrochen. Bolzen neu angefertig und di...   \n",
       "\n",
       "  MPMelderArbeitsplatz MPAbteilungBezeichnung Arbeitsbeginn ErstellungsDatum  \n",
       "0              Weberei                Weberei           NaT       2019-03-06  \n",
       "1     Elektrowerkstatt       Elektrowerkstatt           NaT       2019-03-11  \n",
       "2              Weberei                Weberei           NaT       2019-03-19  \n",
       "3              Weberei                Weberei    2019-03-21       2019-03-21  \n",
       "4              Vorwerk                Vorwerk    2019-03-25       2019-03-25  "
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "raw.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Anzahl Features: 20\n"
     ]
    }
   ],
   "source": [
    "print(f\"Anzahl Features: {len(raw.columns)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Duplikate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "duplicates_filt = raw.duplicated()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Anzahl Duplikate: 84\n"
     ]
    }
   ],
   "source": [
    "print(f\"Anzahl Duplikate: {duplicates_filt.sum()}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "filt_data = raw[duplicates_filt]\n",
    "uni_obj_id_dupl = filt_data['ObjektID'].unique()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Anzahl einzigartiger Objekt-IDs unter Duplikaten: 47\n"
     ]
    }
   ],
   "source": [
    "print(f\"Anzahl einzigartiger Objekt-IDs unter Duplikaten: {len(uni_obj_id_dupl)}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 128936 entries, 0 to 128935\n",
      "Data columns (total 20 columns):\n",
      " #   Column                   Non-Null Count   Dtype         \n",
      "---  ------                   --------------   -----         \n",
      " 0   VorgangsID               128936 non-null  int64         \n",
      " 1   ObjektID                 128936 non-null  int64         \n",
      " 2   HObjektText              128920 non-null  object        \n",
      " 3   ObjektArtID              128936 non-null  int64         \n",
      " 4   ObjektArtText            128289 non-null  object        \n",
      " 5   VorgangsTypID            128936 non-null  int64         \n",
      " 6   VorgangsTypName          128936 non-null  object        \n",
      " 7   VorgangsDatum            128936 non-null  datetime64[ns]\n",
      " 8   VorgangsStatusId         128936 non-null  int64         \n",
      " 9   VorgangsPrioritaet       128936 non-null  int64         \n",
      " 10  VorgangsBeschreibung     124008 non-null  object        \n",
      " 11  VorgangsOrt              507 non-null     object        \n",
      " 12  VorgangsArtText          128936 non-null  object        \n",
      " 13  ErledigungsDatum         128936 non-null  datetime64[ns]\n",
      " 14  ErledigungsArtText       128402 non-null  object        \n",
      " 15  ErledigungsBeschreibung  118086 non-null  object        \n",
      " 16  MPMelderArbeitsplatz     6337 non-null    object        \n",
      " 17  MPAbteilungBezeichnung   6337 non-null    object        \n",
      " 18  Arbeitsbeginn            123480 non-null  datetime64[ns]\n",
      " 19  ErstellungsDatum         128936 non-null  datetime64[ns]\n",
      "dtypes: datetime64[ns](4), int64(6), object(10)\n",
      "memory usage: 19.7+ MB\n"
     ]
    }
   ],
   "source": [
    "wo_duplicates = raw.drop_duplicates(ignore_index=True)\n",
    "wo_duplicates.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### NA vals"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['VorgangsDatum', 'ErledigungsDatum', 'Arbeitsbeginn', 'ErstellungsDatum']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_cols"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Feature VorgangsDatum: number of NA vals 0, relative 0.00%\n",
      "Feature ErledigungsDatum: number of NA vals 0, relative 0.00%\n",
      "Feature Arbeitsbeginn: number of NA vals 5456, relative 4.23%\n",
      "Feature ErstellungsDatum: number of NA vals 0, relative 0.00%\n"
     ]
    }
   ],
   "source": [
    "for col in date_cols:\n",
    "    na_count = wo_duplicates[col].isna().sum()\n",
    "    rel_count = na_count / len(wo_duplicates)\n",
    "    print(f'Feature {col}: number of NA vals {na_count}, relative {rel_count:.2%}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [],
   "source": [
    "wo_na = wo_duplicates.dropna(how='any', subset=date_cols).reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 123480 entries, 0 to 123479\n",
      "Data columns (total 20 columns):\n",
      " #   Column                   Non-Null Count   Dtype         \n",
      "---  ------                   --------------   -----         \n",
      " 0   VorgangsID               123480 non-null  int64         \n",
      " 1   ObjektID                 123480 non-null  int64         \n",
      " 2   HObjektText              123464 non-null  object        \n",
      " 3   ObjektArtID              123480 non-null  int64         \n",
      " 4   ObjektArtText            122932 non-null  object        \n",
      " 5   VorgangsTypID            123480 non-null  int64         \n",
      " 6   VorgangsTypName          123480 non-null  object        \n",
      " 7   VorgangsDatum            123480 non-null  datetime64[ns]\n",
      " 8   VorgangsStatusId         123480 non-null  int64         \n",
      " 9   VorgangsPrioritaet       123480 non-null  int64         \n",
      " 10  VorgangsBeschreibung     120389 non-null  object        \n",
      " 11  VorgangsOrt              445 non-null     object        \n",
      " 12  VorgangsArtText          123480 non-null  object        \n",
      " 13  ErledigungsDatum         123480 non-null  datetime64[ns]\n",
      " 14  ErledigungsArtText       123428 non-null  object        \n",
      " 15  ErledigungsBeschreibung  117900 non-null  object        \n",
      " 16  MPMelderArbeitsplatz     6110 non-null    object        \n",
      " 17  MPAbteilungBezeichnung   6110 non-null    object        \n",
      " 18  Arbeitsbeginn            123480 non-null  datetime64[ns]\n",
      " 19  ErstellungsDatum         123480 non-null  datetime64[ns]\n",
      "dtypes: datetime64[ns](4), int64(6), object(10)\n",
      "memory usage: 18.8+ MB\n"
     ]
    }
   ],
   "source": [
    "wo_na.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Unlogische Einträge\n",
    "\n",
    "- nach Prozessablauf Datumsangaben, die in anderer chronologischer Reihenfolge erscheinen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Planung vor Erstellung, Treffer 3966\n",
      "Arbeitsbeginn vor Erstellung, Treffer 4118\n",
      "Arbeitsbeginn vor Planung, Treffer 9356\n",
      "Erledigung vor Erstellung, Treffer 3681\n",
      "Erledigung vor Planung, Treffer 8142\n",
      "Erledigung vor Arbeitsbeginn, Treffer 1\n"
     ]
    }
   ],
   "source": [
    "# Planung des Vorgangs vor Erstellung\n",
    "matches = (wo_na['VorgangsDatum'] < wo_na['ErstellungsDatum']).sum()\n",
    "print(f'Planung vor Erstellung, Treffer {matches}')\n",
    "\n",
    "# Arbeitsbeginn vor Erstellung\n",
    "matches = (wo_na['Arbeitsbeginn'] < wo_na['ErstellungsDatum']).sum()\n",
    "print(f'Arbeitsbeginn vor Erstellung, Treffer {matches}')\n",
    "\n",
    "# Arbeitsbeginn vor Planung\n",
    "matches = (wo_na['Arbeitsbeginn'] < wo_na['VorgangsDatum']).sum()\n",
    "print(f'Arbeitsbeginn vor Planung, Treffer {matches}')\n",
    "\n",
    "# Erledigung vor Erstellung\n",
    "matches = (wo_na['ErledigungsDatum'] < wo_na['ErstellungsDatum']).sum()\n",
    "print(f'Erledigung vor Erstellung, Treffer {matches}')\n",
    "\n",
    "# Erledigung vor Planung\n",
    "matches = (wo_na['ErledigungsDatum'] < wo_na['VorgangsDatum']).sum()\n",
    "print(f'Erledigung vor Planung, Treffer {matches}')\n",
    "\n",
    "# Erledigung vor Arbeitsbeginn\n",
    "matches = (wo_na['ErledigungsDatum'] < wo_na['Arbeitsbeginn']).sum()\n",
    "print(f'Erledigung vor Arbeitsbeginn, Treffer {matches}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Number of illogical entries: 13215\n"
     ]
    }
   ],
   "source": [
    "filter_illogical = (\n",
    "    (wo_na['VorgangsDatum'] < wo_na['ErstellungsDatum']) |\n",
    "    (wo_na['Arbeitsbeginn'] < wo_na['ErstellungsDatum']) |\n",
    "    (wo_na['Arbeitsbeginn'] < wo_na['VorgangsDatum']) |\n",
    "    (wo_na['ErledigungsDatum'] < wo_na['ErstellungsDatum']) |\n",
    "    (wo_na['ErledigungsDatum'] < wo_na['VorgangsDatum']) |\n",
    "    (wo_na['ErledigungsDatum'] < wo_na['Arbeitsbeginn'])\n",
    ")\n",
    "print(f'Number of illogical entries: {filter_illogical.sum()}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "logical = wo_na.loc[~filter_illogical,:].reset_index(drop=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 110265 entries, 0 to 110264\n",
      "Data columns (total 20 columns):\n",
      " #   Column                   Non-Null Count   Dtype         \n",
      "---  ------                   --------------   -----         \n",
      " 0   VorgangsID               110265 non-null  int64         \n",
      " 1   ObjektID                 110265 non-null  int64         \n",
      " 2   HObjektText              110252 non-null  object        \n",
      " 3   ObjektArtID              110265 non-null  int64         \n",
      " 4   ObjektArtText            109788 non-null  object        \n",
      " 5   VorgangsTypID            110265 non-null  int64         \n",
      " 6   VorgangsTypName          110265 non-null  object        \n",
      " 7   VorgangsDatum            110265 non-null  datetime64[ns]\n",
      " 8   VorgangsStatusId         110265 non-null  int64         \n",
      " 9   VorgangsPrioritaet       110265 non-null  int64         \n",
      " 10  VorgangsBeschreibung     108683 non-null  object        \n",
      " 11  VorgangsOrt              441 non-null     object        \n",
      " 12  VorgangsArtText          110265 non-null  object        \n",
      " 13  ErledigungsDatum         110265 non-null  datetime64[ns]\n",
      " 14  ErledigungsArtText       110215 non-null  object        \n",
      " 15  ErledigungsBeschreibung  106105 non-null  object        \n",
      " 16  MPMelderArbeitsplatz     6029 non-null    object        \n",
      " 17  MPAbteilungBezeichnung   6029 non-null    object        \n",
      " 18  Arbeitsbeginn            110265 non-null  datetime64[ns]\n",
      " 19  ErstellungsDatum         110265 non-null  datetime64[ns]\n",
      "dtypes: datetime64[ns](4), int64(6), object(10)\n",
      "memory usage: 16.8+ MB\n"
     ]
    }
   ],
   "source": [
    "logical.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Date Diffs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- Differenzen von:\n",
    "    - VorgangsDatum und Arbeitsbeginn (Plan zu Ist)\n",
    "    - Arbeitsbeginn zu ErledigungsDatum (Dauer im Ist)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Planabweichungen"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "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>VorgangsID</th>\n",
       "      <th>ObjektID</th>\n",
       "      <th>HObjektText</th>\n",
       "      <th>ObjektArtID</th>\n",
       "      <th>ObjektArtText</th>\n",
       "      <th>VorgangsTypID</th>\n",
       "      <th>VorgangsTypName</th>\n",
       "      <th>VorgangsDatum</th>\n",
       "      <th>VorgangsStatusId</th>\n",
       "      <th>VorgangsPrioritaet</th>\n",
       "      <th>VorgangsBeschreibung</th>\n",
       "      <th>VorgangsOrt</th>\n",
       "      <th>VorgangsArtText</th>\n",
       "      <th>ErledigungsDatum</th>\n",
       "      <th>ErledigungsArtText</th>\n",
       "      <th>ErledigungsBeschreibung</th>\n",
       "      <th>MPMelderArbeitsplatz</th>\n",
       "      <th>MPAbteilungBezeichnung</th>\n",
       "      <th>Arbeitsbeginn</th>\n",
       "      <th>ErstellungsDatum</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>58</td>\n",
       "      <td>257</td>\n",
       "      <td>107, Webmaschine, OM 220 EOS</td>\n",
       "      <td>3</td>\n",
       "      <td>Luft-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Gegengewicht wieder anbringen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gegengewicht an der Webmaschine abgefallen</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Schraube ausgebohrt\\nGegengewicht wieder angeb...</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>2019-03-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>81</td>\n",
       "      <td>138</td>\n",
       "      <td>00138, Schärmaschine 9,</td>\n",
       "      <td>16</td>\n",
       "      <td>Schärmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>da ist etwas gebrochen. (Herr Heininger)</td>\n",
       "      <td>NaN</td>\n",
       "      <td>zentrale Bremsenverstellung linke Gatterseite ...</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Bolzen gebrochen. Bolzen neu angefertig und di...</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>82</td>\n",
       "      <td>0</td>\n",
       "      <td>Warenschau allgemein</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Klappbügel Portalkran H31 defekt</td>\n",
       "      <td>Warenschau allgemein</td>\n",
       "      <td>Allgemeine Reparaturarbeiten</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Feder ausgetauscht</td>\n",
       "      <td>Warenschau</td>\n",
       "      <td>Warenschau</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>76</td>\n",
       "      <td>0</td>\n",
       "      <td>Neben der Türe</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-22</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Schraube nix mer gut</td>\n",
       "      <td>Neben der Türe</td>\n",
       "      <td>Kettbaum</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Schrauben ausgebohrt\\t\\nGewinde nachgeschnitten\\t</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>111</td>\n",
       "      <td>241</td>\n",
       "      <td>294 C, Webmaschine, SG 240 EMS</td>\n",
       "      <td>5</td>\n",
       "      <td>Greifer-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-04-01</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>KBK tauschen\\nUrsache vermutlich mechanisch</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kupplung-Brems-Kombination</td>\n",
       "      <td>2019-04-08</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>da derzeit Keine Ersatzteile da Reparatur mit ...</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>2019-04-02</td>\n",
       "      <td>2019-04-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   VorgangsID  ObjektID                     HObjektText  ObjektArtID  \\\n",
       "0          58       257    107, Webmaschine, OM 220 EOS            3   \n",
       "1          81       138        00138, Schärmaschine 9,            16   \n",
       "2          82         0            Warenschau allgemein            0   \n",
       "3          76         0                  Neben der Türe            0   \n",
       "4         111       241  294 C, Webmaschine, SG 240 EMS            5   \n",
       "\n",
       "         ObjektArtText  VorgangsTypID            VorgangsTypName  \\\n",
       "0     Luft-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "1        Schärmaschine              3  Reparaturauftrag (Portal)   \n",
       "2                  NaN              3  Reparaturauftrag (Portal)   \n",
       "3                  NaN              3  Reparaturauftrag (Portal)   \n",
       "4  Greifer-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "\n",
       "  VorgangsDatum  VorgangsStatusId  VorgangsPrioritaet  \\\n",
       "0    2019-03-21                 5                   0   \n",
       "1    2019-03-25                 5                   0   \n",
       "2    2019-03-25                 5                   0   \n",
       "3    2019-03-22                 5                   0   \n",
       "4    2019-04-01                 5                   0   \n",
       "\n",
       "                          VorgangsBeschreibung           VorgangsOrt  \\\n",
       "0                Gegengewicht wieder anbringen                   NaN   \n",
       "1     da ist etwas gebrochen. (Herr Heininger)                   NaN   \n",
       "2             Klappbügel Portalkran H31 defekt  Warenschau allgemein   \n",
       "3                         Schraube nix mer gut        Neben der Türe   \n",
       "4  KBK tauschen\\nUrsache vermutlich mechanisch                   NaN   \n",
       "\n",
       "                                     VorgangsArtText ErledigungsDatum  \\\n",
       "0         Gegengewicht an der Webmaschine abgefallen       2019-03-21   \n",
       "1  zentrale Bremsenverstellung linke Gatterseite ...       2019-03-25   \n",
       "2                      Allgemeine Reparaturarbeiten        2019-03-25   \n",
       "3                                           Kettbaum       2019-03-25   \n",
       "4                         Kupplung-Brems-Kombination       2019-04-08   \n",
       "\n",
       "  ErledigungsArtText                            ErledigungsBeschreibung  \\\n",
       "0      Reparatur UTT  Schraube ausgebohrt\\nGegengewicht wieder angeb...   \n",
       "1      Reparatur UTT  Bolzen gebrochen. Bolzen neu angefertig und di...   \n",
       "2      Reparatur UTT                                 Feder ausgetauscht   \n",
       "3      Reparatur UTT  Schrauben ausgebohrt\\t\\nGewinde nachgeschnitten\\t   \n",
       "4      Reparatur UTT  da derzeit Keine Ersatzteile da Reparatur mit ...   \n",
       "\n",
       "  MPMelderArbeitsplatz MPAbteilungBezeichnung Arbeitsbeginn ErstellungsDatum  \n",
       "0              Weberei                Weberei    2019-03-21       2019-03-21  \n",
       "1              Vorwerk                Vorwerk    2019-03-25       2019-03-25  \n",
       "2           Warenschau             Warenschau    2019-03-25       2019-03-25  \n",
       "3              Vorwerk                Vorwerk    2019-03-25       2019-03-22  \n",
       "4              Weberei                Weberei    2019-04-02       2019-04-01  "
      ]
     },
     "execution_count": 137,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logical.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "metadata": {},
   "outputs": [],
   "source": [
    "MAX_DATE_DIFF = 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 142,
   "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_diff</th>\n",
       "      <th>days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3 days</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1 days</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  date_diff  days\n",
       "0    0 days     0\n",
       "1    0 days     0\n",
       "2    0 days     0\n",
       "3    3 days     3\n",
       "4    1 days     1"
      ]
     },
     "execution_count": 142,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_diff = logical['Arbeitsbeginn'] - logical['VorgangsDatum']\n",
    "date_diff = date_diff.to_frame()\n",
    "date_diff.columns = ['date_diff']\n",
    "date_diff['days'] = date_diff['date_diff'].apply(lambda x: x.days)\n",
    "date_diff = date_diff.loc[((date_diff['days'] <= MAX_DATE_DIFF) & \n",
    "                           (date_diff['days'] >= -MAX_DATE_DIFF)), :]\n",
    "#date_diff = date_diff.reset_index(drop=True)\n",
    "date_diff.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 143,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "Index: 110265 entries, 0 to 110264\n",
      "Data columns (total 2 columns):\n",
      " #   Column     Non-Null Count   Dtype          \n",
      "---  ------     --------------   -----          \n",
      " 0   date_diff  110265 non-null  timedelta64[ns]\n",
      " 1   days       110265 non-null  int64          \n",
      "dtypes: int64(1), timedelta64[ns](1)\n",
      "memory usage: 2.5 MB\n"
     ]
    }
   ],
   "source": [
    "date_diff.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 144,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "count    110265.000000\n",
       "mean          0.994939\n",
       "std           6.599087\n",
       "min           0.000000\n",
       "25%           0.000000\n",
       "50%           0.000000\n",
       "75%           0.000000\n",
       "max         392.000000\n",
       "Name: days, dtype: float64"
      ]
     },
     "execution_count": 144,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_diff['days'].describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "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_diff</th>\n",
       "      <th>days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>296</th>\n",
       "      <td>392 days</td>\n",
       "      <td>392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5982</th>\n",
       "      <td>358 days</td>\n",
       "      <td>358</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>109336</th>\n",
       "      <td>303 days</td>\n",
       "      <td>303</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       date_diff  days\n",
       "296     392 days   392\n",
       "5982    358 days   358\n",
       "109336  303 days   303"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_diff.loc[date_diff['days'] > 300]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 147,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "VorgangsID                                                            136387\n",
       "ObjektID                                                                1820\n",
       "HObjektText                      01821, Phenolphtaleinindikatorlösung 0,1%, \n",
       "ObjektArtID                                                              105\n",
       "ObjektArtText                                           Chemische Prüfmittel\n",
       "VorgangsTypID                                                              1\n",
       "VorgangsTypName                                                      Wartung\n",
       "VorgangsDatum                                            2022-02-28 00:00:00\n",
       "VorgangsStatusId                                                           5\n",
       "VorgangsPrioritaet                                                         0\n",
       "VorgangsBeschreibung       Jährliche Kontrolle des Mindeshaltbarkeitsdatum\\n\n",
       "VorgangsOrt                                                              NaN\n",
       "VorgangsArtText                               Prüfmittelüberwachung jährlich\n",
       "ErledigungsDatum                                         2023-03-27 00:00:00\n",
       "ErledigungsArtText                          Intern UTT - Prüfmittelkontrolle\n",
       "ErledigungsBeschreibung                                        laut Prüfplan\n",
       "MPMelderArbeitsplatz                                                     NaN\n",
       "MPAbteilungBezeichnung                                                   NaN\n",
       "Arbeitsbeginn                                            2023-03-27 00:00:00\n",
       "ErstellungsDatum                                         2021-08-27 00:00:00\n",
       "Name: 296, dtype: object"
      ]
     },
     "execution_count": 147,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logical.loc[296,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 145,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: xlabel='days', ylabel='Density'>"
      ]
     },
     "execution_count": 145,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 19252 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.kdeplot(data=date_diff, x='days')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### Ist-Dauer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 156,
   "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>VorgangsID</th>\n",
       "      <th>ObjektID</th>\n",
       "      <th>HObjektText</th>\n",
       "      <th>ObjektArtID</th>\n",
       "      <th>ObjektArtText</th>\n",
       "      <th>VorgangsTypID</th>\n",
       "      <th>VorgangsTypName</th>\n",
       "      <th>VorgangsDatum</th>\n",
       "      <th>VorgangsStatusId</th>\n",
       "      <th>VorgangsPrioritaet</th>\n",
       "      <th>VorgangsBeschreibung</th>\n",
       "      <th>VorgangsOrt</th>\n",
       "      <th>VorgangsArtText</th>\n",
       "      <th>ErledigungsDatum</th>\n",
       "      <th>ErledigungsArtText</th>\n",
       "      <th>ErledigungsBeschreibung</th>\n",
       "      <th>MPMelderArbeitsplatz</th>\n",
       "      <th>MPAbteilungBezeichnung</th>\n",
       "      <th>Arbeitsbeginn</th>\n",
       "      <th>ErstellungsDatum</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>58</td>\n",
       "      <td>257</td>\n",
       "      <td>107, Webmaschine, OM 220 EOS</td>\n",
       "      <td>3</td>\n",
       "      <td>Luft-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Gegengewicht wieder anbringen</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Gegengewicht an der Webmaschine abgefallen</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Schraube ausgebohrt\\nGegengewicht wieder angeb...</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>2019-03-21</td>\n",
       "      <td>2019-03-21</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>81</td>\n",
       "      <td>138</td>\n",
       "      <td>00138, Schärmaschine 9,</td>\n",
       "      <td>16</td>\n",
       "      <td>Schärmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>da ist etwas gebrochen. (Herr Heininger)</td>\n",
       "      <td>NaN</td>\n",
       "      <td>zentrale Bremsenverstellung linke Gatterseite ...</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Bolzen gebrochen. Bolzen neu angefertig und di...</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>82</td>\n",
       "      <td>0</td>\n",
       "      <td>Warenschau allgemein</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Klappbügel Portalkran H31 defekt</td>\n",
       "      <td>Warenschau allgemein</td>\n",
       "      <td>Allgemeine Reparaturarbeiten</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Feder ausgetauscht</td>\n",
       "      <td>Warenschau</td>\n",
       "      <td>Warenschau</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>76</td>\n",
       "      <td>0</td>\n",
       "      <td>Neben der Türe</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-03-22</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>Schraube nix mer gut</td>\n",
       "      <td>Neben der Türe</td>\n",
       "      <td>Kettbaum</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>Schrauben ausgebohrt\\t\\nGewinde nachgeschnitten\\t</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>Vorwerk</td>\n",
       "      <td>2019-03-25</td>\n",
       "      <td>2019-03-22</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>111</td>\n",
       "      <td>241</td>\n",
       "      <td>294 C, Webmaschine, SG 240 EMS</td>\n",
       "      <td>5</td>\n",
       "      <td>Greifer-Webmaschine</td>\n",
       "      <td>3</td>\n",
       "      <td>Reparaturauftrag (Portal)</td>\n",
       "      <td>2019-04-01</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>KBK tauschen\\nUrsache vermutlich mechanisch</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Kupplung-Brems-Kombination</td>\n",
       "      <td>2019-04-08</td>\n",
       "      <td>Reparatur UTT</td>\n",
       "      <td>da derzeit Keine Ersatzteile da Reparatur mit ...</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>Weberei</td>\n",
       "      <td>2019-04-02</td>\n",
       "      <td>2019-04-01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   VorgangsID  ObjektID                     HObjektText  ObjektArtID  \\\n",
       "0          58       257    107, Webmaschine, OM 220 EOS            3   \n",
       "1          81       138        00138, Schärmaschine 9,            16   \n",
       "2          82         0            Warenschau allgemein            0   \n",
       "3          76         0                  Neben der Türe            0   \n",
       "4         111       241  294 C, Webmaschine, SG 240 EMS            5   \n",
       "\n",
       "         ObjektArtText  VorgangsTypID            VorgangsTypName  \\\n",
       "0     Luft-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "1        Schärmaschine              3  Reparaturauftrag (Portal)   \n",
       "2                  NaN              3  Reparaturauftrag (Portal)   \n",
       "3                  NaN              3  Reparaturauftrag (Portal)   \n",
       "4  Greifer-Webmaschine              3  Reparaturauftrag (Portal)   \n",
       "\n",
       "  VorgangsDatum  VorgangsStatusId  VorgangsPrioritaet  \\\n",
       "0    2019-03-21                 5                   0   \n",
       "1    2019-03-25                 5                   0   \n",
       "2    2019-03-25                 5                   0   \n",
       "3    2019-03-22                 5                   0   \n",
       "4    2019-04-01                 5                   0   \n",
       "\n",
       "                          VorgangsBeschreibung           VorgangsOrt  \\\n",
       "0                Gegengewicht wieder anbringen                   NaN   \n",
       "1     da ist etwas gebrochen. (Herr Heininger)                   NaN   \n",
       "2             Klappbügel Portalkran H31 defekt  Warenschau allgemein   \n",
       "3                         Schraube nix mer gut        Neben der Türe   \n",
       "4  KBK tauschen\\nUrsache vermutlich mechanisch                   NaN   \n",
       "\n",
       "                                     VorgangsArtText ErledigungsDatum  \\\n",
       "0         Gegengewicht an der Webmaschine abgefallen       2019-03-21   \n",
       "1  zentrale Bremsenverstellung linke Gatterseite ...       2019-03-25   \n",
       "2                      Allgemeine Reparaturarbeiten        2019-03-25   \n",
       "3                                           Kettbaum       2019-03-25   \n",
       "4                         Kupplung-Brems-Kombination       2019-04-08   \n",
       "\n",
       "  ErledigungsArtText                            ErledigungsBeschreibung  \\\n",
       "0      Reparatur UTT  Schraube ausgebohrt\\nGegengewicht wieder angeb...   \n",
       "1      Reparatur UTT  Bolzen gebrochen. Bolzen neu angefertig und di...   \n",
       "2      Reparatur UTT                                 Feder ausgetauscht   \n",
       "3      Reparatur UTT  Schrauben ausgebohrt\\t\\nGewinde nachgeschnitten\\t   \n",
       "4      Reparatur UTT  da derzeit Keine Ersatzteile da Reparatur mit ...   \n",
       "\n",
       "  MPMelderArbeitsplatz MPAbteilungBezeichnung Arbeitsbeginn ErstellungsDatum  \n",
       "0              Weberei                Weberei    2019-03-21       2019-03-21  \n",
       "1              Vorwerk                Vorwerk    2019-03-25       2019-03-25  \n",
       "2           Warenschau             Warenschau    2019-03-25       2019-03-25  \n",
       "3              Vorwerk                Vorwerk    2019-03-25       2019-03-22  \n",
       "4              Weberei                Weberei    2019-04-02       2019-04-01  "
      ]
     },
     "execution_count": 156,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logical.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 157,
   "metadata": {},
   "outputs": [],
   "source": [
    "MAX_DATE_DIFF = 1000"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 158,
   "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_diff</th>\n",
       "      <th>days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0 days</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>6 days</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  date_diff  days\n",
       "0    0 days     0\n",
       "1    0 days     0\n",
       "2    0 days     0\n",
       "3    0 days     0\n",
       "4    6 days     6"
      ]
     },
     "execution_count": 158,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_diff = logical['ErledigungsDatum'] - logical['Arbeitsbeginn']\n",
    "date_diff = date_diff.to_frame()\n",
    "date_diff.columns = ['date_diff']\n",
    "date_diff['days'] = date_diff['date_diff'].apply(lambda x: x.days)\n",
    "date_diff = date_diff.loc[((date_diff['days'] <= MAX_DATE_DIFF) & \n",
    "                           (date_diff['days'] >= -MAX_DATE_DIFF)), :]\n",
    "#date_diff = date_diff.reset_index(drop=True)\n",
    "date_diff.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 159,
   "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_diff</th>\n",
       "      <th>days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>110265</td>\n",
       "      <td>110265.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>0 days 04:03:16.283498843</td>\n",
       "      <td>0.168938</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>3 days 09:12:15.416163344</td>\n",
       "      <td>3.383512</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0 days 00:00:00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0 days 00:00:00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>0 days 00:00:00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>0 days 00:00:00</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>486 days 00:00:00</td>\n",
       "      <td>486.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       date_diff           days\n",
       "count                     110265  110265.000000\n",
       "mean   0 days 04:03:16.283498843       0.168938\n",
       "std    3 days 09:12:15.416163344       3.383512\n",
       "min              0 days 00:00:00       0.000000\n",
       "25%              0 days 00:00:00       0.000000\n",
       "50%              0 days 00:00:00       0.000000\n",
       "75%              0 days 00:00:00       0.000000\n",
       "max            486 days 00:00:00     486.000000"
      ]
     },
     "execution_count": 159,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_diff.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 160,
   "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_diff</th>\n",
       "      <th>days</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>106054</th>\n",
       "      <td>486 days</td>\n",
       "      <td>486</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       date_diff  days\n",
       "106054  486 days   486"
      ]
     },
     "execution_count": 160,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "date_diff.loc[date_diff['days'] > 300]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 161,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "VorgangsID                                                             65407\n",
       "ObjektID                                                                  55\n",
       "HObjektText                503 C , Webmaschine, DL 280 EMS Breite 280 Bj....\n",
       "ObjektArtID                                                                3\n",
       "ObjektArtText                                               Luft-Webmaschine\n",
       "VorgangsTypID                                                              3\n",
       "VorgangsTypName                                    Reparaturauftrag (Portal)\n",
       "VorgangsDatum                                            2020-11-19 00:00:00\n",
       "VorgangsStatusId                                                           5\n",
       "VorgangsPrioritaet                                                         0\n",
       "VorgangsBeschreibung       Schaltschrank ausrichten ist angefahren worden...\n",
       "VorgangsOrt                                                              NaN\n",
       "VorgangsArtText                                       Maschineninfrastruktur\n",
       "ErledigungsDatum                                         2022-03-21 00:00:00\n",
       "ErledigungsArtText                                   Intern UTT - Reparatur \n",
       "ErledigungsBeschreibung                                  Schanier eingebaut \n",
       "MPMelderArbeitsplatz                                                 Weberei\n",
       "MPAbteilungBezeichnung                                               Weberei\n",
       "Arbeitsbeginn                                            2020-11-20 00:00:00\n",
       "ErstellungsDatum                                         2020-11-19 00:00:00\n",
       "Name: 106054, dtype: object"
      ]
     },
     "execution_count": 161,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "logical.loc[106054,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 162,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Axes: xlabel='days', ylabel='Density'>"
      ]
     },
     "execution_count": 162,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "[encoded data, 23392 characters]",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "sns.kdeplot(data=date_diff, x='days')"
   ]
  },
  {
   "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.4"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
