{ "cells": [ { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import time\n", "from datetime import datetime\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "%matplotlib qt5\n", "\n", "def unpack_line(str):\n", " time_format = \"%d.%m.%Y %H:%M:%S.%f\"\n", " index_1 = str.find(';')\n", " index_2 = str.find(';',index_1+1)\n", " index_3 = str.find(';',index_2+1)\n", " index_4 = str.find(';',index_3+1)\n", " index_5 = str.find(';',index_4+1)\n", " parameter = str[0:index_1]\n", " value = float(str[index_2+1:index_3])\n", " timestamp = time.mktime(datetime.strptime(str[index_5+1:-2],time_format).timetuple())\n", " return parameter,value,timestamp\n", "\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "M1_LA_df = pd.DataFrame(columns=['Timestamp','M1-LA'])\n", "M2_LA_df = pd.DataFrame(columns=['Timestamp','M2-LA'])\n", "M1_Druck_df = pd.DataFrame(columns=['Timestamp','M1-Druck'])\n", "M2_Druck_df = pd.DataFrame(columns=['Timestamp','M2-Druck'])\n", "\n", "\n", "parameter_old = ''\n", "value_list = []\n", "timestamp_list = []\n", "with open('Juni_1_22.txt') as txt_file:\n", " for line in txt_file:\n", " parameter_new, value_new, timestamp_new = unpack_line(line)\n", " if parameter_new != parameter_old:\n", " if 'M1' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", " M1_LA_df['Timestamp'] = timestamp_list[:]\n", " M1_LA_df['M1-LA'] = value_list[:]\n", " if 'M1' in parameter_old and 'Spiraldruck' in parameter_old:\n", " M1_Druck_df['Timestamp'] = timestamp_list[:]\n", " M1_Druck_df['M1-Druck'] = value_list[:]\n", " if 'M2' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", " M2_LA_df['Timestamp'] = timestamp_list[:]\n", " M2_LA_df['M2-LA'] = value_list[:]\n", " if 'M2' in parameter_old and 'Spiraldruck' in parameter_old:\n", " M2_Druck_df['Timestamp'] = timestamp_list[:]\n", " M2_Druck_df['M2-Druck'] = value_list[:]\n", " \n", " value_list = []\n", " timestamp_list = []\n", " value_list.append(value_new)\n", " timestamp_list.append(timestamp_new)\n", "\n", " parameter_old = parameter_new\n", " else:\n", " if value_new != value_list[-1]:\n", " value_list.append(value_new)\n", " timestamp_list.append(timestamp_new) \n", "\n", " if 'M1' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", " M1_LA_df['Timestamp'] = timestamp_list[:]\n", " M1_LA_df['M1-LA'] = value_list[:]\n", " if 'M1' in parameter_old and 'Spiraldruck' in parameter_old:\n", " M1_Druck_df['Timestamp'] = timestamp_list[:]\n", " M1_Druck_df['M1-Druck'] = value_list[:]\n", " if 'M2' in parameter_old and 'Stell_Leitapparat' in parameter_old:\n", " M2_LA_df['Timestamp'] = timestamp_list[:]\n", " M2_LA_df['M2-LA'] = value_list[:]\n", " if 'M2' in parameter_old and 'Spiraldruck' in parameter_old:\n", " M2_Druck_df['Timestamp'] = timestamp_list[:]\n", " M2_Druck_df['M2-Druck'] = value_list[:]\n", "\n", "M1_LA_df.set_index(['Timestamp'],inplace=True)\n", "M1_Druck_df.set_index(['Timestamp'],inplace=True)\n", "M2_LA_df.set_index(['Timestamp'],inplace=True)\n", "M2_Druck_df.set_index(['Timestamp'],inplace=True)\n" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig1=plt.figure()\n", "plt.plot(M1_LA_df['M1-LA'])\n", "fig2=plt.figure()\n", "plt.plot(M1_Druck_df['M1-Druck'])\n", "fig3=plt.figure()\n", "plt.plot(M2_LA_df['M2-LA'])\n", "fig4=plt.figure()\n", "plt.plot(M2_Druck_df['M2-Druck'])" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "df = M1_LA_df.join([M2_LA_df,M1_Druck_df,M2_Druck_df],how='outer')\n", "df.sort_index(axis=0,inplace=True)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig1=plt.figure()\n", "plt.plot(df['M1-LA'])\n", "fig2=plt.figure()\n", "plt.plot(df['M1-Druck'])\n", "fig3=plt.figure()\n", "plt.plot(df['M2-LA'])\n", "fig4=plt.figure()\n", "plt.plot(df['M2-Druck'])" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "t_vec = df.index.to_numpy()\n", "M1_LA = df['M1-LA'].to_numpy() " ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fig5=plt.figure()\n", "plt.plot(t_vec,M1_LA)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.8.13 ('Georg_DT_Slot3')", "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.13" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "84fb123bdc47ab647d3782661abcbe80fbb79236dd2f8adf4cef30e8755eb2cd" } } }, "nbformat": 4, "nbformat_minor": 2 }