{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5dbfa7da-a2cc-4220-a0ef-ba521bd84905", "metadata": {}, "outputs": [], "source": [ "import os\n", "import numpy as np\n", "import pandas as pd\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 2, "id": "0aa63889-45cb-4145-bd6c-0077b1af008a", "metadata": {}, "outputs": [], "source": [ "from openpyxl import load_workbook" ] }, { "cell_type": "code", "execution_count": 3, "id": "439140e3-828b-4ddb-a9a4-66ee78f993ef", "metadata": {}, "outputs": [], "source": [ "path_to_sheet = r\"C:\\Users\\a.jurcenko\\Desktop\\Ralf Fischer\\Stempelzeiten Erding Oktober 2023.xlsx\"" ] }, { "cell_type": "code", "execution_count": 4, "id": "1787f5f5-ee30-4e41-b8c0-8c6209ae34ad", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "816\n" ] } ], "source": [ "wb = load_workbook(filename=path_to_sheet)\n", "ws = wb.active\n", "xl = pd.ExcelFile(path_to_sheet)\n", "nrows = xl.book.active.max_row\n", "print(nrows)" ] }, { "cell_type": "code", "execution_count": 5, "id": "d0f69c9c-e647-4d6f-abd4-e75d021014db", "metadata": {}, "outputs": [], "source": [ "def parse_time_string(time_string):\n", " come = time_string.endswith('K')\n", " time_string = time_string.replace('*', '').strip()[:5]\n", " return time_string, come" ] }, { "cell_type": "code", "execution_count": 16, "id": "7bb2e3ea-8a0a-4c68-92f3-151bdee96db9", "metadata": {}, "outputs": [], "source": [ "def parse_info(first_row, last_row, info):\n", " df_times = pd.read_excel(path_to_sheet, skiprows=first_row, skipfooter=nrows-last_row-1)\n", " user = info.split(':')\n", " user_id = user[1].strip()[:4]\n", " user_surname, user_name = user[0].split(',')\n", " user_name = user_name.split('-')[0].strip()\n", " user = user_surname[:8]\n", " # print(user_name)\n", " times = list()\n", " for index, row in df_times.iterrows():\n", " date = row['Datum']\n", " direction = 'Hinaus'\n", " for r in (row['Buchungen'], row['Unnamed: 5']):\n", " if str(r) != 'nan':\n", " if r.find('\\n') > -1:\n", " for s in r.split('\\n'):\n", " tm, come = parse_time_string(s)\n", " if come:\n", " direction = 'Herein'\n", " else:\n", " direction = 'Hinaus'\n", " times.append({'Benutzername': user, 'Vorname': user_name, 'Nachname': user_surname, 'Abteilung': 'Erding', \\\n", " 'Person': user_id, 'Wann': date + ' ' + tm + ':00', 'Gerät': 'Erding', 'Hinein/Hinaus': direction, 'Überprüfung': 'RFID'})\n", " \n", " else:\n", " tm, come = parse_time_string(r)\n", " if come:\n", " direction = 'Herein'\n", " else:\n", " direction = 'Hinaus'\n", " \n", " times.append({'Benutzername': user, 'Vorname': user_name, 'Nachname': user_surname, 'Abteilung': 'Erding', \\\n", " 'Person': user_id, 'Wann': date + ' ' + tm + ':00' , 'Gerät': 'Erding', 'Hinein/Hinaus': direction, 'Überprüfung': 'RFID'})\n", " # print(times)\n", " return times\n" ] }, { "cell_type": "code", "execution_count": 17, "id": "721ebf17-de2b-419f-a16d-997e8614a04d", "metadata": {}, "outputs": [], "source": [ "# info = \"Fischer, Achraf - P1: 1508 - Ausweis: 159 - VWG: Erding\"\n", "# first_cell = 273\n", "# last_cell = 305\n", "# time_table = parse_info(first_cell, last_cell, info)\n", "# print(time_table)" ] }, { "cell_type": "code", "execution_count": 18, "id": "8f675a0d-603f-4786-a89d-7e9d72213568", "metadata": {}, "outputs": [], "source": [ "rows = list(ws.rows)\n", "\n", "all_df = list()\n", "for row in rows:\n", " for cell in row: # Zellen\n", " if cell.value is None or type(cell.value) == float:\n", " continue\n", " elif cell.value.find('Ausweis') > -1:\n", " first_cell = cell.row\n", " info = cell.value\n", " elif cell.value.find('gesamt') > -1:\n", " last_cell = cell.row\n", " time_table = parse_info(first_cell, last_cell, info)\n", " if len(time_table) > 0:\n", " all_df.append(pd.DataFrame(time_table))" ] }, { "cell_type": "code", "execution_count": 19, "id": "c66a946a-0f75-479f-b27a-88de3a17757f", "metadata": {}, "outputs": [], "source": [ "df_cum = pd.concat(all_df)" ] }, { "cell_type": "code", "execution_count": 20, "id": "4eb98f8c-5630-4db7-93fa-6d1da3d7d081", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
|---|---|---|---|---|---|---|---|---|
| Benutzername | \n", "Vorname | \n", "Nachname | \n", "Abteilung | \n", "Person | \n", "Wann | \n", "Gerät | \n", "Hinein/Hinaus | \n", "Überprüfung | \n", "
| Braun | \n", "Tobias | \n", "Braun | \n", "Erding | \n", "1515 | \n", "02.10.2023 05:45:00 | \n", "Erding | \n", "Herein | \n", "RFID | \n", "
| 02.10.2023 07:17:00 | \n", "Erding | \n", "Hinaus | \n", "RFID | \n", "|||||
| 04.10.2023 09:42:00 | \n", "Erding | \n", "Herein | \n", "RFID | \n", "|||||
| 04.10.2023 09:43:00 | \n", "Erding | \n", "Hinaus | \n", "RFID | \n", "|||||
| 10.10.2023 06:00:00 | \n", "Erding | \n", "Herein | \n", "RFID | \n", "|||||
| ... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "... | \n", "
| Zingler | \n", "Markus | \n", "Zingler | \n", "Erding | \n", "1443 | \n", "27.10.2023 15:16:00 | \n", "Erding | \n", "Hinaus | \n", "RFID | \n", "
| 30.10.2023 05:57:00 | \n", "Erding | \n", "Herein | \n", "RFID | \n", "|||||
| 30.10.2023 10:49:00 | \n", "Erding | \n", "Hinaus | \n", "RFID | \n", "|||||
| Zweckstä | \n", "Carina | \n", "Zweckstätter | \n", "Erding | \n", "1527 | \n", "17.10.2023 07:15:00 | \n", "Erding | \n", "Herein | \n", "RFID | \n", "
| 17.10.2023 15:00:00 | \n", "Erding | \n", "Hinaus | \n", "RFID | \n", "
865 rows × 0 columns
\n", "