Spaces:
Runtime error
Runtime error
Upload control_chart_test.ipynb
Browse files- control_chart_test.ipynb +1 -1
control_chart_test.ipynb
CHANGED
@@ -1 +1 @@
|
|
1 |
-
{"cells":[{"cell_type":"raw","metadata":{},"source":["---\n","title: Gráficos de proceso\n","description: Se requiere cargar un archivo con la data y otro con los límites\n","show-code: False\n","params:\n"," select_area:\n"," label: Seleccione el nombre del área\n"," input: select\n"," value: Bioenergia\n"," choices: ['Bioenergia', 'Blanqueo SF1', 'Blanqueo SF2',\n"," 'Caldera Biomasa SF1', 'Caldera Biomasa SF2',\n"," 'Caldera Recuperadora 2', 'Caldera Recuperadora SF1',\n"," 'Caldera Recuperadora SF2', 'Causitificacion y Horno SF2',\n"," 'Caustificacion SF1', 'Caustificacion SF2', 'Clasificacion',\n"," 'Coccion SF1', 'Coccion SF2', 'Compresores SF1', 'Compresores SF2',\n"," 'Efluentes', 'Erco', 'Erco R10', 'Evaporadores SF1',\n"," 'Evaporadores SF2', 'Horno de Cal SF1', 'Horno de Cal SF2',\n"," 'Lavado SF1', 'Lavado SF2', 'Lavado y Blanqueo SF2', 'Maderas',\n"," 'Maquina SF1', 'Maquina SF2', 'Planta', 'Planta de agua',\n"," 'Planta de Agua', 'Planta demi SF1', 'Planta demi SF2',\n"," 'Secado SF1', 'Secado SF2', 'TG1', 'TG2', 'TG3', 'TG4']\n"," multi: False\n"," filename1:\n"," label: Ingrese archivo con los datos\n"," input: file\n"," maxFileSize: 100MB\n"," filename2:\n"," label: Ingrese archivo con los límites\n"," input: file\n"," maxFileSize: 100MB\n","\n","---"]},{"cell_type":"code","execution_count":9,"metadata":{},"outputs":[],"source":["select_area = select_area\n","#select_area = \"Caldera Recuperadora SF1\"\n","\n","filename1 = filename1\n","#filename1 = \"15_dias.xlsx\"\n","\n","filename2 = filename2\n","#filename2 = \"SDCA Google Sheet.xlsx\""]},{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["Requirement already satisfied: openpyxl in c:\\users\\oquilodran\\anaconda3\\lib\\site-packages (3.0.9)\n","Requirement already satisfied: et-xmlfile in c:\\users\\oquilodran\\anaconda3\\lib\\site-packages (from openpyxl) (1.1.0)\n"]},{"name":"stderr","output_type":"stream","text":["WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n"]}],"source":["#!pip install openpyxl"]},{"cell_type":"code","execution_count":7,"metadata":{"executionInfo":{"elapsed":1793,"status":"ok","timestamp":1674579356775,"user":{"displayName":"Carlos Sandoval Ormeño","userId":"08254748332068667609"},"user_tz":180},"id":"OvnKztF5hBlh"},"outputs":[],"source":["import pandas as pd\n","import numpy as np\n","import pickle\n","import warnings\n","import matplotlib.pyplot as plt\n","import seaborn as sns\n","from scipy.stats import norm\n","\n","warnings.filterwarnings(\"ignore\")"]},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[],"source":["#%load_ext watermark"]},{"cell_type":"code","execution_count":4,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["sys : 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]\n","matplotlib: 3.5.1\n","pandas : 1.4.2\n","seaborn : 0.11.2\n","numpy : 1.21.5\n","\n"]}],"source":["#%watermark --iversions "]},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["openpyxl 3.0.9\n"]},{"name":"stderr","output_type":"stream","text":["WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n","WARNING: Ignoring invalid distribution -rotobuf (c:\\users\\oquilodran\\anaconda3\\lib\\site-packages)\n"]}],"source":["#!pip3 list | findstr openpyxl"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sIiZd8tijLAm"},"outputs":[],"source":["# Conexión y carga de datos"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ydai0pFWjM2T"},"outputs":[],"source":["#Conectarse a google drive para cargar datos\n","#from google.colab import drive\n","#drive.mount('/content/drive')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bpV5VAuR6Klh"},"outputs":[],"source":["## Archivo 1: Datos\n","\n","#Posee todos los datos en un periodo de tiempo definido. Primera fila debe ser el nombre de la Variable"]},{"cell_type":"code","execution_count":27,"metadata":{"id":"wnkX8PRujP-m"},"outputs":[{"data":{"text/plain":["(1153, 692)"]},"execution_count":27,"metadata":{},"output_type":"execute_result"}],"source":["#path data googledrive\n","path_data_processed = filename1\n","\n","#leer data processed\n","data_processed = pd.read_excel(path_data_processed,sheet_name='15_dias')\n","data_processed.shape"]},{"cell_type":"code","execution_count":28,"metadata":{"id":"yB55dhn5j2zB"},"outputs":[],"source":["data = data_processed.copy()"]},{"cell_type":"code","execution_count":29,"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>Fecha</th>\n"," <th>TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2</th>\n"," <th>TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2</th>\n"," <th>TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2</th>\n"," <th>TEMPERATURA SALA RACK 1</th>\n"," <th>TEMPERATURA SALA MEDIO TENSION 2</th>\n"," <th>TEMPERATURA SALA MEDIO TENSION 3</th>\n"," <th>Desviación estandar kappa L1</th>\n"," <th>Soda Caustica Blanqueo L1 SF1</th>\n"," <th>Oxigeno Blanqueo L1 SF1</th>\n"," <th>...</th>\n"," <th>Generación TG4</th>\n"," <th>Traspaso vapor alta presion</th>\n"," <th>Flujo condensado de vapor 2</th>\n"," <th>Flujo condensado de vapor 1</th>\n"," <th>Potencia Media AGA SF2</th>\n"," <th>Potencia Media AMSA SF1</th>\n"," <th>Potencia Media SF1+AMSA</th>\n"," <th>Potencia Media SF2+AGA</th>\n"," <th>Generación TG2</th>\n"," <th>Solidos alimentados Evap SF2</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>2023-01-02 00:00:00</td>\n"," <td>22.380388</td>\n"," <td>22.280931</td>\n"," <td>22.333216</td>\n"," <td>22.086191</td>\n"," <td>22.149839</td>\n"," <td>22.045614</td>\n"," <td>0.231715</td>\n"," <td>8.086400</td>\n"," <td>1.217000</td>\n"," <td>...</td>\n"," <td>45.800533</td>\n"," <td>-16.403118</td>\n"," <td>55.111847</td>\n"," <td>1.320719</td>\n"," <td>3596.615723</td>\n"," <td>238.051071</td>\n"," <td>28787.296875</td>\n"," <td>-10226.526367</td>\n"," <td>44.311375</td>\n"," <td>15.029305</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>2023-01-02 00:30:00</td>\n"," <td>22.380516</td>\n"," <td>22.281185</td>\n"," <td>22.332581</td>\n"," <td>22.086889</td>\n"," <td>22.149967</td>\n"," <td>22.046375</td>\n"," <td>0.275171</td>\n"," <td>8.045627</td>\n"," <td>1.140499</td>\n"," <td>...</td>\n"," <td>47.174568</td>\n"," <td>-25.001226</td>\n"," <td>54.472202</td>\n"," <td>1.295107</td>\n"," <td>3626.050293</td>\n"," <td>238.147842</td>\n"," <td>28451.166016</td>\n"," <td>-12912.736328</td>\n"," <td>44.399441</td>\n"," <td>15.029305</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>2023-01-02 01:00:00</td>\n"," <td>22.380642</td>\n"," <td>22.281439</td>\n"," <td>22.331945</td>\n"," <td>22.087587</td>\n"," <td>22.150095</td>\n"," <td>22.047138</td>\n"," <td>0.275171</td>\n"," <td>8.060355</td>\n"," <td>1.103316</td>\n"," <td>...</td>\n"," <td>41.501835</td>\n"," <td>-32.346756</td>\n"," <td>54.868324</td>\n"," <td>1.320784</td>\n"," <td>3760.971191</td>\n"," <td>235.034882</td>\n"," <td>28733.126953</td>\n"," <td>-10815.240234</td>\n"," <td>44.359051</td>\n"," <td>15.301791</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>2023-01-02 01:30:00</td>\n"," <td>22.38077</td>\n"," <td>22.281693</td>\n"," <td>22.33131</td>\n"," <td>22.088285</td>\n"," <td>22.150221</td>\n"," <td>22.047899</td>\n"," <td>0.275171</td>\n"," <td>8.340420</td>\n"," <td>1.223614</td>\n"," <td>...</td>\n"," <td>50.031181</td>\n"," <td>-11.782591</td>\n"," <td>55.122517</td>\n"," <td>1.340983</td>\n"," <td>3732.642334</td>\n"," <td>243.157639</td>\n"," <td>28331.724609</td>\n"," <td>-13846.183594</td>\n"," <td>44.499325</td>\n"," <td>15.301791</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>2023-01-02 02:00:00</td>\n"," <td>22.380896</td>\n"," <td>22.281946</td>\n"," <td>22.330677</td>\n"," <td>22.088984</td>\n"," <td>22.150349</td>\n"," <td>22.048662</td>\n"," <td>0.275171</td>\n"," <td>8.446277</td>\n"," <td>1.248739</td>\n"," <td>...</td>\n"," <td>42.183971</td>\n"," <td>-37.520939</td>\n"," <td>59.148407</td>\n"," <td>1.364929</td>\n"," <td>3719.249023</td>\n"," <td>238.37941</td>\n"," <td>28454.082031</td>\n"," <td>-12041.871094</td>\n"," <td>44.042847</td>\n"," <td>15.301791</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>1148</th>\n"," <td>2023-01-25 22:00:00</td>\n"," <td>20.509975</td>\n"," <td>20.69157</td>\n"," <td>20.480833</td>\n"," <td>20.200678</td>\n"," <td>20.314024</td>\n"," <td>20.057224</td>\n"," <td>0.400087</td>\n"," <td>9.184175</td>\n"," <td>1.327102</td>\n"," <td>...</td>\n"," <td>0</td>\n"," <td>-6.052447</td>\n"," <td>58.167320</td>\n"," <td>1.659870</td>\n"," <td>3779.910156</td>\n"," <td>431.451935</td>\n"," <td>29560.935547</td>\n"," <td>-3510.351562</td>\n"," <td>43.572365</td>\n"," <td>15.575074</td>\n"," </tr>\n"," <tr>\n"," <th>1149</th>\n"," <td>2023-01-25 22:30:00</td>\n"," <td>20.509588</td>\n"," <td>20.69138</td>\n"," <td>20.480579</td>\n"," <td>20.200933</td>\n"," <td>20.313135</td>\n"," <td>20.054491</td>\n"," <td>0.400087</td>\n"," <td>8.738999</td>\n"," <td>1.282202</td>\n"," <td>...</td>\n"," <td>0</td>\n"," <td>-6.071373</td>\n"," <td>59.485466</td>\n"," <td>1.659870</td>\n"," <td>3745.52002</td>\n"," <td>450.862396</td>\n"," <td>30219.025391</td>\n"," <td>-5982.137207</td>\n"," <td>43.621933</td>\n"," <td>15.575074</td>\n"," </tr>\n"," <tr>\n"," <th>1150</th>\n"," <td>2023-01-25 23:00:00</td>\n"," <td>20.509201</td>\n"," <td>20.691189</td>\n"," <td>20.480326</td>\n"," <td>20.201187</td>\n"," <td>20.312244</td>\n"," <td>20.053791</td>\n"," <td>0.400087</td>\n"," <td>8.750358</td>\n"," <td>1.234370</td>\n"," <td>...</td>\n"," <td>0</td>\n"," <td>-6.266962</td>\n"," <td>59.564442</td>\n"," <td>1.659870</td>\n"," <td>3743.449463</td>\n"," <td>342.854919</td>\n"," <td>29341.095703</td>\n"," <td>-8177.477539</td>\n"," <td>43.528225</td>\n"," <td>15.849157</td>\n"," </tr>\n"," <tr>\n"," <th>1151</th>\n"," <td>2023-01-25 23:30:00</td>\n"," <td>20.508814</td>\n"," <td>20.690998</td>\n"," <td>20.48007</td>\n"," <td>20.201443</td>\n"," <td>20.31152</td>\n"," <td>20.053093</td>\n"," <td>0.400087</td>\n"," <td>8.998313</td>\n"," <td>1.248112</td>\n"," <td>...</td>\n"," <td>0</td>\n"," <td>-6.236718</td>\n"," <td>59.191444</td>\n"," <td>1.659870</td>\n"," <td>3582.329834</td>\n"," <td>421.524902</td>\n"," <td>30061.484375</td>\n"," <td>-7916.760254</td>\n"," <td>43.369431</td>\n"," <td>15.849157</td>\n"," </tr>\n"," <tr>\n"," <th>1152</th>\n"," <td>2023-01-26 00:00:00</td>\n"," <td>20.508425</td>\n"," <td>20.690807</td>\n"," <td>20.479816</td>\n"," <td>20.201696</td>\n"," <td>20.311775</td>\n"," <td>20.052395</td>\n"," <td>0.311225</td>\n"," <td>8.629993</td>\n"," <td>1.102960</td>\n"," <td>...</td>\n"," <td>0</td>\n"," <td>-6.123524</td>\n"," <td>57.916817</td>\n"," <td>1.561509</td>\n"," <td>3582.556152</td>\n"," <td>381.4758</td>\n"," <td>29213.257812</td>\n"," <td>-3081.311035</td>\n"," <td>43.577621</td>\n"," <td>15.849157</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>1153 rows × 692 columns</p>\n","</div>"],"text/plain":[" Fecha TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2 \\\n","0 2023-01-02 00:00:00 22.380388 \n","1 2023-01-02 00:30:00 22.380516 \n","2 2023-01-02 01:00:00 22.380642 \n","3 2023-01-02 01:30:00 22.38077 \n","4 2023-01-02 02:00:00 22.380896 \n","... ... ... \n","1148 2023-01-25 22:00:00 20.509975 \n","1149 2023-01-25 22:30:00 20.509588 \n","1150 2023-01-25 23:00:00 20.509201 \n","1151 2023-01-25 23:30:00 20.508814 \n","1152 2023-01-26 00:00:00 20.508425 \n","\n"," TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2 \\\n","0 22.280931 \n","1 22.281185 \n","2 22.281439 \n","3 22.281693 \n","4 22.281946 \n","... ... \n","1148 20.69157 \n","1149 20.69138 \n","1150 20.691189 \n","1151 20.690998 \n","1152 20.690807 \n","\n"," TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2 TEMPERATURA SALA RACK 1 \\\n","0 22.333216 22.086191 \n","1 22.332581 22.086889 \n","2 22.331945 22.087587 \n","3 22.33131 22.088285 \n","4 22.330677 22.088984 \n","... ... ... \n","1148 20.480833 20.200678 \n","1149 20.480579 20.200933 \n","1150 20.480326 20.201187 \n","1151 20.48007 20.201443 \n","1152 20.479816 20.201696 \n","\n"," TEMPERATURA SALA MEDIO TENSION 2 TEMPERATURA SALA MEDIO TENSION 3 \\\n","0 22.149839 22.045614 \n","1 22.149967 22.046375 \n","2 22.150095 22.047138 \n","3 22.150221 22.047899 \n","4 22.150349 22.048662 \n","... ... ... \n","1148 20.314024 20.057224 \n","1149 20.313135 20.054491 \n","1150 20.312244 20.053791 \n","1151 20.31152 20.053093 \n","1152 20.311775 20.052395 \n","\n"," Desviación estandar kappa L1 Soda Caustica Blanqueo L1 SF1 \\\n","0 0.231715 8.086400 \n","1 0.275171 8.045627 \n","2 0.275171 8.060355 \n","3 0.275171 8.340420 \n","4 0.275171 8.446277 \n","... ... ... \n","1148 0.400087 9.184175 \n","1149 0.400087 8.738999 \n","1150 0.400087 8.750358 \n","1151 0.400087 8.998313 \n","1152 0.311225 8.629993 \n","\n"," Oxigeno Blanqueo L1 SF1 ... Generación TG4 \\\n","0 1.217000 ... 45.800533 \n","1 1.140499 ... 47.174568 \n","2 1.103316 ... 41.501835 \n","3 1.223614 ... 50.031181 \n","4 1.248739 ... 42.183971 \n","... ... ... ... \n","1148 1.327102 ... 0 \n","1149 1.282202 ... 0 \n","1150 1.234370 ... 0 \n","1151 1.248112 ... 0 \n","1152 1.102960 ... 0 \n","\n"," Traspaso vapor alta presion Flujo condensado de vapor 2 \\\n","0 -16.403118 55.111847 \n","1 -25.001226 54.472202 \n","2 -32.346756 54.868324 \n","3 -11.782591 55.122517 \n","4 -37.520939 59.148407 \n","... ... ... \n","1148 -6.052447 58.167320 \n","1149 -6.071373 59.485466 \n","1150 -6.266962 59.564442 \n","1151 -6.236718 59.191444 \n","1152 -6.123524 57.916817 \n","\n"," Flujo condensado de vapor 1 Potencia Media AGA SF2 \\\n","0 1.320719 3596.615723 \n","1 1.295107 3626.050293 \n","2 1.320784 3760.971191 \n","3 1.340983 3732.642334 \n","4 1.364929 3719.249023 \n","... ... ... \n","1148 1.659870 3779.910156 \n","1149 1.659870 3745.52002 \n","1150 1.659870 3743.449463 \n","1151 1.659870 3582.329834 \n","1152 1.561509 3582.556152 \n","\n"," Potencia Media AMSA SF1 Potencia Media SF1+AMSA \\\n","0 238.051071 28787.296875 \n","1 238.147842 28451.166016 \n","2 235.034882 28733.126953 \n","3 243.157639 28331.724609 \n","4 238.37941 28454.082031 \n","... ... ... \n","1148 431.451935 29560.935547 \n","1149 450.862396 30219.025391 \n","1150 342.854919 29341.095703 \n","1151 421.524902 30061.484375 \n","1152 381.4758 29213.257812 \n","\n"," Potencia Media SF2+AGA Generación TG2 Solidos alimentados Evap SF2 \n","0 -10226.526367 44.311375 15.029305 \n","1 -12912.736328 44.399441 15.029305 \n","2 -10815.240234 44.359051 15.301791 \n","3 -13846.183594 44.499325 15.301791 \n","4 -12041.871094 44.042847 15.301791 \n","... ... ... ... \n","1148 -3510.351562 43.572365 15.575074 \n","1149 -5982.137207 43.621933 15.575074 \n","1150 -8177.477539 43.528225 15.849157 \n","1151 -7916.760254 43.369431 15.849157 \n","1152 -3081.311035 43.577621 15.849157 \n","\n","[1153 rows x 692 columns]"]},"execution_count":29,"metadata":{},"output_type":"execute_result"}],"source":["data"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_0cSzbEa6YNx"},"outputs":[],"source":["## Archivo 2: Variables\n","'''\n","Archivo debe tener\n","\n","\n","* Tag\n","* Nombre de la Variable\n","'''\n"]},{"cell_type":"code","execution_count":12,"metadata":{"id":"KisA0eitjwPF"},"outputs":[{"data":{"text/plain":["(691, 2)"]},"execution_count":12,"metadata":{},"output_type":"execute_result"}],"source":["#path data googledrive\n","path_data_processed = filename1\n","\n","#leer data processed\n","variables = pd.read_excel(path_data_processed,sheet_name='variables')\n","variables.shape"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DqWBrBGU5o6d"},"outputs":[],"source":["## Archivo 3: Listado límites\n","'''\n","Archivo debe contar con lo siguiente:\n","\n","\n","* Tag\n","* Variable\n","* Unidad\n","* Min\n","* Max\n","* Proceso\n","* Tipo\n","'''\n"]},{"cell_type":"code","execution_count":13,"metadata":{"id":"gWnno7CNne6K"},"outputs":[],"source":["#path data googledrive\n","path_data_processed = filename2\n","\n","#leer data processed\n","rangos = pd.read_excel(path_data_processed, sheet_name='SDCA GoogleSheet')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"57Kw2wK4oWGY"},"outputs":[],"source":["# Funciones"]},{"cell_type":"code","execution_count":14,"metadata":{"id":"ZWQinDfNmFSg"},"outputs":[],"source":["def Cp(USL,LSL,STD,sigma):\n"," if STD==0:\n"," STD=0.001\n"," Cp = (USL - LSL)/(sigma*STD)\n"," return Cp"]},{"cell_type":"code","execution_count":15,"metadata":{"id":"t7qGarFapCkw"},"outputs":[],"source":["def Cpk(USL,LSL,mean_x,STD,sigma):\n"," if STD==0:\n"," STD=0.001\n"," Cpk_sup = (USL - mean_x)/(sigma*STD)\n"," Cpk_inf = (mean_x - LSL)/(sigma*STD)\n","\n"," minimum = min(Cpk_sup,Cpk_inf)\n","\n"," return minimum"]},{"cell_type":"code","execution_count":16,"metadata":{"id":"IY8viMz147FF"},"outputs":[],"source":["def process_capability(data,variables,rangos,sigma):\n"," ##\n"," ## Función para obtener la capacidad del proceso para un set de variables\n"," ##\n"," \n"," capacidad_proc = pd.DataFrame(columns=['Tag','Variable','Promedio','STD','LSL','USL','CP','CPK','% bajo LSL','% sobre USL'])\n"," for j in range(len(variables.iloc[:,0])):\n"," \n"," # Var selection\n"," tag = variables.iloc[j,0]\n"," var = variables.iloc[j,1]\n"," \n"," # Cp y CPk\n"," mean_var = data[var].mean()\n"," std_var = data[var].std()\n","\n"," if pd.isna(rangos[rangos['Variable']==var].loc[j,'Max'])==False:\n"," USL = rangos[rangos['Variable']==var].loc[j,'Max']\n"," else:\n"," USL = mean_var+3*std_var\n"," LSL = rangos[rangos['Variable']==var].loc[j,'Min']\n","\n"," Cp_1 = Cp(USL,LSL,std_var,sigma)\n"," Cpk_1 = Cpk(USL,LSL,mean_var,std_var,sigma/2)\n","\n"," pct_below_LSL = len(data[var][data[var] < LSL])/len(data[var])*100\n"," pct_above_USL = len(data[var][data[var] > USL])/len(data[var])*100\n","\n"," # Creación Dataframe\n"," row_append = pd.DataFrame([[tag,var,mean_var,std_var,LSL,USL,Cp_1,Cpk_1,pct_below_LSL,pct_above_USL]],columns=['Tag','Variable','Promedio','STD','LSL','USL','CP','CPK','% bajo LSL','% sobre USL'])\n"," capacidad_proc = pd.concat([capacidad_proc,row_append],ignore_index=True)\n"," \n"," cap_process = capacidad_proc.merge(rangos[['Variable','Proceso']],on='Variable').drop_duplicates('Variable').reset_index(drop=True).round(2)\n","\n"," return cap_process"]},{"cell_type":"code","execution_count":17,"metadata":{"id":"aKMNAGyb8ka-"},"outputs":[],"source":["def outlier_removal(data,variables):\n"," ## data: dataset completo\n"," ## vairables: lista con el nombre de las variables\n"," # Outlier removal\n"," for i in range(len(variables)):\n"," var = variables.iloc[i]\n","\n"," q75 = data[var].quantile(0.75)\n"," q25 = data[var].quantile(0.25)\n"," intr_qr = q75-q25\n","\n"," maxi = q75+(1.5*intr_qr)\n"," mini = q25-(1.5*intr_qr)\n","\n"," data[var].loc[data[var] < mini] = np.nan\n"," data[var].loc[data[var] > maxi] = np.nan\n","\n"," return data"]},{"cell_type":"code","execution_count":18,"metadata":{"id":"TAjvxICXDQQ7"},"outputs":[],"source":["def process_hist_plot(data,USL,LSL,target):\n"," #\n"," # Solo para análisis univariado \n"," # hist plot\n"," \n"," from scipy.stats import norm\n"," x = np.linspace(min(data), max(data), 1000)\n","\n"," # call first \n"," # from scipy.stats import norm\n"," y = norm.pdf(x, loc=5, scale=1)\n","\n"," # Plot histogram for data along with probability density functions and specification limits\n"," plt.figure(figsize=(15,10))\n"," plt.hist(data, color=\"lightgrey\", edgecolor=\"black\", density=True)\n"," sns.kdeplot(data, color=\"blue\", label=\"Density ST\")\n"," plt.plot(x, y, linestyle=\"--\", color=\"black\", label=\"Theorethical Density ST\")\n"," plt.axvline(LSL, linestyle=\"--\", color=\"red\", label=\"LSL\")\n"," plt.axvline(USL, linestyle=\"--\", color=\"orange\", label=\"USL\")\n"," plt.axvline(target, linestyle=\"--\", color=\"green\", label=\"Target\")\n"," plt.title('Process Capability Analysis')\n"," plt.xlabel(\"Measure\")\n"," plt.ylabel(\"\")\n"," plt.yticks([])\n"," plt.legend()\n"," plt.show()\n","\n"," # % data outside\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," print('')\n"," print('Estadística descriptiva')\n"," print(' ')\n"," print('Promedio : {0:.2f}'.format(data.mean()))\n"," print('Desv Estandar : {0:.2f}'.format(data.std()))\n"," print('Mínimo: {0:.2f}'.format(data.min()))\n"," print('25%: {0:.2f}'.format(data.quantile(0.25)))\n"," print('50%: {0:.2f}'.format(data.quantile(0.5)))\n"," print('75%: {0:.2f}'.format(data.quantile(0.75)))\n"," print('Máximo: {0:.2f}'.format(data.max()))\n"," print('IQR : {0:.2f}'.format(data.quantile(0.75)-data.quantile(0.25)))\n"," print('Asimetría: {0:.2f}'.format(data.skew()))\n"," print('Kurtosis: {0:.2f}'.format(data.kurt()))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Límites')\n"," print(' ')\n"," print('Límite control superior: {0:.2f}'.format((data.mean())+3*data.std()))\n"," print('Límite control inferior: {0:.2f}'.format((data.mean())-3*data.std()))\n"," print('Límite especificación superior: {0:.2f}'.format(USL))\n"," print('Límite especificación inferior: {0:.2f}'.format(LSL))\n"," print('')\n"," print('--------')\n"," print('')\n"," print('Datos fuera rangos')\n"," print(' ') \n"," print('Porcentaje de datos bajo LSL ({0:.2f}): {1:.2f}%'.format(LSL,pct_below_LSL))\n"," print('Porcentaje de datos sobre USL ({0:.2f}): {1:.2f}%'.format(USL,pct_above_USL))\n"," print(' ') \n"," print(' ')"]},{"cell_type":"code","execution_count":19,"metadata":{"id":"CPGTpoP1YBvf"},"outputs":[],"source":["def plot_control_chart(data,fecha,USL,LSL,sigma):\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.axhline(((data.mean())+3*data.std()), color='red', linestyle='dashed',label='UCL')\n"," ax.axhline(((data.mean())-3*data.std()), color='red', linestyle='dashed',label='LCL')\n"," ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n"," print('')\n"," print('Estadística descriptiva')\n"," print(' ')\n"," print('Promedio : {0:.2f}'.format(data.mean()))\n"," print('Desv Estandar : {0:.2f}'.format(data.std()))\n"," print('Mínimo: {0:.2f}'.format(data.min()))\n"," print('25%: {0:.2f}'.format(data.quantile(0.25)))\n"," print('50%: {0:.2f}'.format(data.quantile(0.5)))\n"," print('75%: {0:.2f}'.format(data.quantile(0.75)))\n"," print('Máximo: {0:.2f}'.format(data.max()))\n"," print('IQR : {0:.2f}'.format(data.quantile(0.75)-data.quantile(0.25)))\n"," print('Asimetría: {0:.2f}'.format(data.skew()))\n"," print('Kurtosis: {0:.2f}'.format(data.kurt()))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Control de Procesos')\n"," print('')\n"," print('Cp: {0:.2f}'.format(Cp_1))\n"," print('Cpk: {0:.2f}'.format(Cpk_1))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Límites')\n"," print(' ')\n"," print('Límite control superior: {0:.2f}'.format((data.mean())+3*data.std()))\n"," print('Límite control inferior: {0:.2f}'.format((data.mean())-3*data.std()))\n"," print('Límite especificación superior: {0:.2f}'.format(USL))\n"," print('Límite especificación inferior: {0:.2f}'.format(LSL))\n"," print('')\n"," print('--------')\n"," print('')\n"," print('Datos fuera rangos')\n"," print(' ') \n"," print('Porcentaje de datos bajo LSL ({0:.2f}): {1:.2f}%'.format(LSL,pct_below_LSL))\n"," print('Porcentaje de datos sobre USL ({0:.2f}): {1:.2f}%'.format(USL,pct_above_USL))\n"," print(' ') \n"," print(' ') "]},{"cell_type":"code","execution_count":20,"metadata":{"id":"LBBubqXxt006"},"outputs":[],"source":["def plot_control_chart_week(data,fecha,USL,LSL,sigma,semana):\n"," control_columns = pd.DataFrame(columns=['Fecha','LCL','UCL','Mean','Semana'])\n"," control_columns['Fecha'] = fecha.copy()\n"," control_columns['Semana'] = semana.copy()\n"," for i in semana.unique():\n"," control_columns.loc[control_columns['Semana']==i,'LCL'] = (data.loc[semana==i].mean())-3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'UCL'] = (data.loc[semana==i].mean())+3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'Mean'] = (data.loc[semana==i].mean())\n","\n","\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.plot(fecha,control_columns['LCL'], color='red', linestyle='dashed',label='LCL')\n"," ax.plot(fecha,control_columns['UCL'], color='red', linestyle='dashed',label='UCL')\n"," ax.plot(fecha,control_columns['Mean'], color='green', linestyle='dashed',label='UCL')\n"," # ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n"," print('')\n"," print('Estadística descriptiva')\n"," print(' ')\n"," print('Promedio : {0:.2f}'.format(data.mean()))\n"," print('Desv Estandar : {0:.2f}'.format(data.std()))\n"," print('Mínimo: {0:.2f}'.format(data.min()))\n"," print('25%: {0:.2f}'.format(data.quantile(0.25)))\n"," print('50%: {0:.2f}'.format(data.quantile(0.5)))\n"," print('75%: {0:.2f}'.format(data.quantile(0.75)))\n"," print('Máximo: {0:.2f}'.format(data.max()))\n"," print('IQR : {0:.2f}'.format(data.quantile(0.75)-data.quantile(0.25)))\n"," print('Asimetría: {0:.2f}'.format(data.skew()))\n"," print('Kurtosis: {0:.2f}'.format(data.kurt()))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Control de Procesos')\n"," print('')\n"," print('Cp: {0:.2f}'.format(Cp_1))\n"," print('Cpk: {0:.2f}'.format(Cpk_1))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Límites')\n"," print(' ')\n"," print('Límite control superior: {0:.2f}'.format((data.mean())+3*data.std()))\n"," print('Límite control inferior: {0:.2f}'.format((data.mean())-3*data.std()))\n"," print('Límite especificación superior: {0:.2f}'.format(USL))\n"," print('Límite especificación inferior: {0:.2f}'.format(LSL))\n"," print('')\n"," print('--------')\n"," print('')\n"," print('Datos fuera rangos')\n"," print(' ') \n"," print('Porcentaje de datos bajo LSL ({0:.2f}): {1:.2f}%'.format(LSL,pct_below_LSL))\n"," print('Porcentaje de datos sobre USL ({0:.2f}): {1:.2f}%'.format(USL,pct_above_USL))\n"," print(' ') \n"," print(' ') "]},{"cell_type":"code","execution_count":21,"metadata":{"id":"kz6_yThe5hXe"},"outputs":[],"source":["def plot_control_chart_weekb(data,fecha,USL,LSL,sigma,semana):\n"," control_columns = pd.DataFrame(columns=['Fecha','LCL','UCL','Mean','Semana'])\n"," control_columns['Fecha'] = fecha.copy()\n"," control_columns['Semana'] = semana.copy()\n"," for i in semana.unique():\n"," control_columns.loc[control_columns['Semana']==i,'LCL'] = (data.loc[semana==i].mean())-3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'UCL'] = (data.loc[semana==i].mean())+3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'Mean'] = (data.loc[semana==i].mean())\n","\n","\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.plot(fecha,control_columns['LCL'], color='red', linestyle='dashed',label='LCL')\n"," ax.plot(fecha,control_columns['UCL'], color='red', linestyle='dashed',label='UCL')\n"," ax.plot(fecha,control_columns['Mean'], color='green', linestyle='dashed',label='UCL')\n"," # ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n"," "]},{"cell_type":"code","execution_count":22,"metadata":{"id":"CTQEHuDJ9zbk"},"outputs":[],"source":["def plot_control_chart_weekc(data,fecha,USL,LSL,sigma,semana):\n"," control_columns = pd.DataFrame(columns=['Fecha','LCL','UCL','Mean','Semana'])\n"," control_columns['Fecha'] = fecha.copy()\n"," control_columns['Semana'] = semana.copy()\n"," for i in semana.unique():\n"," control_columns.loc[control_columns['Semana']==i,'LCL'] = (data.loc[semana==i].mean())-3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'UCL'] = (data.loc[semana==i].mean())+3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'Mean'] = (data.loc[semana==i].mean())\n","\n","\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.plot(fecha,control_columns['LCL'], color='red', linestyle='dashed',label='LCL')\n"," ax.plot(fecha,control_columns['UCL'], color='red', linestyle='dashed',label='UCL')\n"," ax.plot(fecha,control_columns['Mean'], color='green', linestyle='dashed',label='Promedio')\n"," # ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n","\n"," process_hist_plot(data,USL,LSL,USL - (USL - LSL)/2)\n","\n"," print('Control de Procesos Generales')\n"," print('')\n"," print('Cp: {0:.2f}'.format(Cp_1))\n"," print('Cpk: {0:.2f}'.format(Cpk_1))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pUVMHNz6kuJF"},"outputs":[],"source":["# Transformaciones"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_hZY-BrCkyCw"},"outputs":[],"source":["## fechas"]},{"cell_type":"code","execution_count":24,"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>Tag</th>\n"," <th>Nombre</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>369TI441.PNT</td>\n"," <td>TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>369TI442.PNT</td>\n"," <td>TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>369TI443.PNT</td>\n"," <td>TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>369TI987.PNT</td>\n"," <td>TEMPERATURA SALA RACK 1</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>369TI993.PNT</td>\n"," <td>TEMPERATURA SALA MEDIO TENSION 2</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>686</th>\n"," <td>CaeAmsaP</td>\n"," <td>Potencia Media AMSA SF1</td>\n"," </tr>\n"," <tr>\n"," <th>687</th>\n"," <td>CaeStfel1P</td>\n"," <td>Potencia Media SF1+AMSA</td>\n"," </tr>\n"," <tr>\n"," <th>688</th>\n"," <td>CaeStfel2P</td>\n"," <td>Potencia Media SF2+AGA</td>\n"," </tr>\n"," <tr>\n"," <th>689</th>\n"," <td>CAESTFETG2P.C</td>\n"," <td>Generación TG2</td>\n"," </tr>\n"," <tr>\n"," <th>690</th>\n"," <td>S267ALE036</td>\n"," <td>Solidos alimentados Evap SF2</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>691 rows × 2 columns</p>\n","</div>"],"text/plain":[" Tag Nombre\n","0 369TI441.PNT TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2\n","1 369TI442.PNT TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2\n","2 369TI443.PNT TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2\n","3 369TI987.PNT TEMPERATURA SALA RACK 1\n","4 369TI993.PNT TEMPERATURA SALA MEDIO TENSION 2\n",".. ... ...\n","686 CaeAmsaP Potencia Media AMSA SF1\n","687 CaeStfel1P Potencia Media SF1+AMSA\n","688 CaeStfel2P Potencia Media SF2+AGA\n","689 CAESTFETG2P.C Generación TG2\n","690 S267ALE036 Solidos alimentados Evap SF2\n","\n","[691 rows x 2 columns]"]},"execution_count":24,"metadata":{},"output_type":"execute_result"}],"source":["#data"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"L3FgCue8kt2f"},"outputs":[],"source":["data['dia'] = pd.to_datetime(data['Fecha']).dt.day\n","data['mes'] = pd.to_datetime(data['Fecha']).dt.month\n","data['anio'] = pd.to_datetime(data['Fecha']).dt.year\n","data['semana'] = pd.to_datetime(data['Fecha']).dt.isocalendar().week"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"x9TQiN6T38L_"},"outputs":[],"source":["## fill nan cuando Min no tiene valor"]},{"cell_type":"code","execution_count":16,"metadata":{"id":"14MhjxzM3-KL"},"outputs":[],"source":["rangos['Min'] = rangos['Min'].fillna(0)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pwVpudFKBaO5"},"outputs":[],"source":["## textos en nan"]},{"cell_type":"code","execution_count":17,"metadata":{"id":"9k1p7s2lBc2y"},"outputs":[],"source":["data.iloc[:,1:] = data.iloc[:,1:].applymap(lambda x: x if not isinstance(x, str) else np.nan)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"PpCcVczm__1j"},"outputs":[],"source":["## Outlier removal"]},{"cell_type":"code","execution_count":18,"metadata":{"id":"bo7bIAgu-avh"},"outputs":[],"source":["data_clean = outlier_removal(data,variables.iloc[:,1])\n","dataset_process = data_clean.copy()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"itP8KpJV29ji"},"outputs":[],"source":["# Capacidad del proceso\n","'''\n","Se utiliza sigma=4\n","'''"]},{"cell_type":"code","execution_count":19,"metadata":{"id":"zjdpRymv2dsH"},"outputs":[],"source":["sigma_proc = 4"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LPBPaz2S3BxF"},"outputs":[],"source":["## Dataset Completo"]},{"cell_type":"code","execution_count":20,"metadata":{"id":"Z_kmjmA77Sqv"},"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>Tag</th>\n"," <th>Variable</th>\n"," <th>Promedio</th>\n"," <th>STD</th>\n"," <th>LSL</th>\n"," <th>USL</th>\n"," <th>CP</th>\n"," <th>CPK</th>\n"," <th>% bajo LSL</th>\n"," <th>% sobre USL</th>\n"," <th>Proceso</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>369TI441.PNT</td>\n"," <td>TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2</td>\n"," <td>22.399166</td>\n"," <td>0.012986</td>\n"," <td>0.0</td>\n"," <td>30.0</td>\n"," <td>577.549864</td>\n"," <td>292.657388</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>Bioenergia</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>369TI442.PNT</td>\n"," <td>TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2</td>\n"," <td>22.303206</td>\n"," <td>0.011622</td>\n"," <td>0.0</td>\n"," <td>28.0</td>\n"," <td>602.311126</td>\n"," <td>245.088756</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>Bioenergia</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>369TI443.PNT</td>\n"," <td>TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2</td>\n"," <td>22.352765</td>\n"," <td>0.01338</td>\n"," <td>0.0</td>\n"," <td>34.0</td>\n"," <td>635.298659</td>\n"," <td>435.263103</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>Bioenergia</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>369TI987.PNT</td>\n"," <td>TEMPERATURA SALA RACK 1</td>\n"," <td>22.117785</td>\n"," <td>0.014267</td>\n"," <td>0.0</td>\n"," <td>24.0</td>\n"," <td>420.553047</td>\n"," <td>65.964257</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>Bioenergia</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>369TI993.PNT</td>\n"," <td>TEMPERATURA SALA MEDIO TENSION 2</td>\n"," <td>22.176624</td>\n"," <td>0.014079</td>\n"," <td>0.0</td>\n"," <td>30.0</td>\n"," <td>532.69445</td>\n"," <td>277.831263</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>Bioenergia</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>618</th>\n"," <td>CaeAmsaP</td>\n"," <td>Potencia Media AMSA SF1</td>\n"," <td>1440.957608</td>\n"," <td>739.24912</td>\n"," <td>0.0</td>\n"," <td>1834743298.0</td>\n"," <td>620475.306622</td>\n"," <td>0.974609</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>NaN</td>\n"," </tr>\n"," <tr>\n"," <th>619</th>\n"," <td>CaeStfel1P</td>\n"," <td>Potencia Media SF1+AMSA</td>\n"," <td>30295.740066</td>\n"," <td>903.221376</td>\n"," <td>0.0</td>\n"," <td>8758034661.0</td>\n"," <td>2424110.769948</td>\n"," <td>16.770938</td>\n"," <td>0.0</td>\n"," <td>0.0</td>\n"," <td>NaN</td>\n"," </tr>\n"," <tr>\n"," <th>620</th>\n"," <td>CaeStfel2P</td>\n"," <td>Potencia Media SF2+AGA</td>\n"," <td>-7844.02693</td>\n"," <td>3120.760784</td>\n"," <td>0.0</td>\n"," <td>-6503232001.0</td>\n"," <td>-520965.275088</td>\n"," <td>-1041929.293427</td>\n"," <td>96.61752</td>\n"," <td>97.051171</td>\n"," <td>NaN</td>\n"," </tr>\n"," <tr>\n"," <th>621</th>\n"," <td>CAESTFETG2P.C</td>\n"," <td>Generación TG2</td>\n"," <td>43.93403</td>\n"," <td>0.454022</td>\n"," <td>43.0</td>\n"," <td>45.296094</td>\n"," <td>1.264309</td>\n"," <td>1.028618</td>\n"," <td>0.780572</td>\n"," <td>0.0</td>\n"," <td>NaN</td>\n"," </tr>\n"," <tr>\n"," <th>622</th>\n"," <td>S267ALE036</td>\n"," <td>Solidos alimentados Evap SF2</td>\n"," <td>15.204944</td>\n"," <td>0.390561</td>\n"," <td>13.5</td>\n"," <td>14.5</td>\n"," <td>0.640105</td>\n"," <td>-0.902477</td>\n"," <td>0.0</td>\n"," <td>95.836947</td>\n"," <td>NaN</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>623 rows × 11 columns</p>\n","</div>"],"text/plain":[" Tag Variable \\\n","0 369TI441.PNT TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2 \n","1 369TI442.PNT TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2 \n","2 369TI443.PNT TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2 \n","3 369TI987.PNT TEMPERATURA SALA RACK 1 \n","4 369TI993.PNT TEMPERATURA SALA MEDIO TENSION 2 \n",".. ... ... \n","618 CaeAmsaP Potencia Media AMSA SF1 \n","619 CaeStfel1P Potencia Media SF1+AMSA \n","620 CaeStfel2P Potencia Media SF2+AGA \n","621 CAESTFETG2P.C Generación TG2 \n","622 S267ALE036 Solidos alimentados Evap SF2 \n","\n"," Promedio STD LSL USL CP \\\n","0 22.399166 0.012986 0.0 30.0 577.549864 \n","1 22.303206 0.011622 0.0 28.0 602.311126 \n","2 22.352765 0.01338 0.0 34.0 635.298659 \n","3 22.117785 0.014267 0.0 24.0 420.553047 \n","4 22.176624 0.014079 0.0 30.0 532.69445 \n",".. ... ... ... ... ... \n","618 1440.957608 739.24912 0.0 1834743298.0 620475.306622 \n","619 30295.740066 903.221376 0.0 8758034661.0 2424110.769948 \n","620 -7844.02693 3120.760784 0.0 -6503232001.0 -520965.275088 \n","621 43.93403 0.454022 43.0 45.296094 1.264309 \n","622 15.204944 0.390561 13.5 14.5 0.640105 \n","\n"," CPK % bajo LSL % sobre USL Proceso \n","0 292.657388 0.0 0.0 Bioenergia \n","1 245.088756 0.0 0.0 Bioenergia \n","2 435.263103 0.0 0.0 Bioenergia \n","3 65.964257 0.0 0.0 Bioenergia \n","4 277.831263 0.0 0.0 Bioenergia \n",".. ... ... ... ... \n","618 0.974609 0.0 0.0 NaN \n","619 16.770938 0.0 0.0 NaN \n","620 -1041929.293427 96.61752 97.051171 NaN \n","621 1.028618 0.780572 0.0 NaN \n","622 -0.902477 0.0 95.836947 NaN \n","\n","[623 rows x 11 columns]"]},"execution_count":20,"metadata":{},"output_type":"execute_result"}],"source":["#@title Capacidad del proceso\n","\n","# capacidad_proc = process_capability(dataset_process[dataset_process['semana']==2],variables,rangos,sigma_proc)\n","capacidad_proc = process_capability(dataset_process,variables,rangos,sigma_proc)\n","capacidad_proc\n","\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NYyHAdOBxdPW"},"outputs":[],"source":["# Análisis Univariado - Mes movil"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"kefb2Sjm9UPN"},"outputs":[],"source":["## Seleccionamos la variable"]},{"cell_type":"code","execution_count":21,"metadata":{"id":"pfO9fE2Mxi3R"},"outputs":[],"source":["var_analizar='Kappa Salida Deslignificacion'\n","USL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['USL']\n","LSL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['LSL']\n","target_process = USL_process - (USL_process - LSL_process)/2"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"iwKZhYJ1x-yQ"},"outputs":[],"source":["## Control Chart"]},{"cell_type":"code","execution_count":22,"metadata":{"id":"yMpj1Ve1sUUQ"},"outputs":[],"source":["variables_analizar = capacidad_proc['Variable'].unique()\n","proceso_analizar = capacidad_proc['Proceso'].unique()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Q1vqJS9qb-6H"},"outputs":[],"source":["# plot_control_chart(data=dataset_process[var_analizar],fecha=dataset_process['Fecha'],USL=USL_process,LSL=LSL_process,sigma=sigma_proc)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Qv5jYHOMtplz"},"outputs":[],"source":["# plot_control_chart_weekc(data=dataset_process[var_analizar],fecha=dataset_process['Fecha'],USL=USL_process,LSL=LSL_process,sigma=sigma_proc,semana=dataset_process['semana'])"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"zvzLzW4hDv3O"},"outputs":[],"source":["# process_hist_plot(dataset_process[var_analizar],USL=USL_process,LSL= LSL_process,target=target_process)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ATZtJ8db0d5V"},"outputs":[],"source":["# Análisis Semanal"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ISuNOi4xMogR"},"outputs":[],"source":["## Generación de información"]},{"cell_type":"code","execution_count":23,"metadata":{"id":"MTl57ZB-0bst"},"outputs":[],"source":["analisis_semanal = pd.DataFrame(columns=capacidad_proc.columns)\n","analisis_semanal['semana'] = np.nan\n","for i in data_clean['semana'].unique():\n"," process_concat = process_capability(dataset_process[dataset_process['semana']==i],variables,rangos,sigma = sigma_proc)\n"," process_concat['semana'] = i\n"," analisis_semanal = analisis_semanal.append(process_concat,ignore_index=True)"]},{"cell_type":"code","execution_count":24,"metadata":{"id":"-hkW05igCv0g"},"outputs":[],"source":["semana_analisis = analisis_semanal[analisis_semanal['Variable']==var_analizar]['semana']\n","cp_analisis = analisis_semanal[analisis_semanal['Variable']==var_analizar]['CP']\n","cpk_analisis = analisis_semanal[analisis_semanal['Variable']==var_analizar]['CPK']"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"nCk1_tAnMvnO"},"outputs":[],"source":["## Evolución capacidad del proceso 4 últimas semanas"]},{"cell_type":"code","execution_count":31,"metadata":{},"outputs":[{"data":{"text/plain":["array(['Bioenergia', 'Blanqueo SF1', 'Blanqueo SF2',\n"," 'Caldera Biomasa SF1', 'Caldera Biomasa SF2',\n"," 'Caldera Recuperadora 2', 'Caldera Recuperadora SF1',\n"," 'Caldera Recuperadora SF2', 'Causitificacion y Horno SF2',\n"," 'Caustificacion SF1', 'Caustificacion SF2', 'Clasificacion',\n"," 'Coccion SF1', 'Coccion SF2', 'Compresores SF1', 'Compresores SF2',\n"," 'Efluentes', 'Erco', 'Erco R10', 'Evaporadores SF1',\n"," 'Evaporadores SF2', 'Horno de Cal SF1', 'Horno de Cal SF2',\n"," 'Lavado SF1', 'Lavado SF2', 'Lavado y Blanqueo SF2', 'Maderas',\n"," 'Maquina SF1', 'Maquina SF2', 'Planta', 'Planta de agua',\n"," 'Planta de Agua', 'Planta demi SF1', 'Planta demi SF2',\n"," 'Secado SF1', 'Secado SF2', 'TG1', 'TG2', 'TG3', 'TG4', nan],\n"," dtype=object)"]},"execution_count":31,"metadata":{},"output_type":"execute_result"}],"source":["analisis_semanal['Proceso'].unique()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Oj7BK98t8EHm"},"outputs":[],"source":["for i in analisis_semanal[analisis_semanal['Proceso']== select_area]['Variable'].unique():\n"," try:\n"," var_analizar=i\n"," USL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['USL']\n"," LSL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['LSL']\n"," target_process = USL_process - (USL_process - LSL_process)/2\n"," print('')\n"," print('')\n"," print(var_analizar)\n"," print('')\n"," print(analisis_semanal[analisis_semanal['Variable']==var_analizar])\n"," print('')\n"," plot_control_chart_weekc(data=dataset_process[var_analizar],fecha=dataset_process['Fecha'],USL=USL_process,LSL=LSL_process,sigma=sigma_proc,semana=dataset_process['semana'])\n"," except:\n"," pass\n"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMK24vRsdKQ5F9deXxFJUL4","provenance":[]},"kernelspec":{"display_name":"Python 3.9.12 ('base')","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.12"},"vscode":{"interpreter":{"hash":"499f128a82e2b79451131852586e0bb06fce5014f717125641f9cae50119434e"}}},"nbformat":4,"nbformat_minor":0}
|
|
|
1 |
+
{"cells":[{"cell_type":"raw","metadata":{},"source":["---\n","title: Gráficos de proceso\n","description: Se requiere cargar un archivo con la data y otro con los límites\n","show-code: False\n","params:\n"," select_area:\n"," label: Seleccione el nombre del área\n"," input: select\n"," value: Bioenergia\n"," choices: ['Bioenergia', 'Blanqueo SF1', 'Blanqueo SF2',\n"," 'Caldera Biomasa SF1', 'Caldera Biomasa SF2',\n"," 'Caldera Recuperadora 2', 'Caldera Recuperadora SF1',\n"," 'Caldera Recuperadora SF2', 'Causitificacion y Horno SF2',\n"," 'Caustificacion SF1', 'Caustificacion SF2', 'Clasificacion',\n"," 'Coccion SF1', 'Coccion SF2', 'Compresores SF1', 'Compresores SF2',\n"," 'Efluentes', 'Erco', 'Erco R10', 'Evaporadores SF1',\n"," 'Evaporadores SF2', 'Horno de Cal SF1', 'Horno de Cal SF2',\n"," 'Lavado SF1', 'Lavado SF2', 'Lavado y Blanqueo SF2', 'Maderas',\n"," 'Maquina SF1', 'Maquina SF2', 'Planta', 'Planta de agua',\n"," 'Planta de Agua', 'Planta demi SF1', 'Planta demi SF2',\n"," 'Secado SF1', 'Secado SF2', 'TG1', 'TG2', 'TG3', 'TG4']\n"," multi: False\n"," filename1:\n"," label: Ingrese archivo con los datos\n"," input: file\n"," maxFileSize: 100MB\n"," filename2:\n"," label: Ingrese archivo con los límites\n"," input: file\n"," maxFileSize: 100MB\n","\n","---"]},{"cell_type":"code","execution_count":9,"metadata":{},"outputs":[],"source":["select_area = select_area\n","#select_area = \"Caldera Recuperadora SF1\"\n","\n","filename1 = filename1\n","#filename1 = \"15_dias.xlsx\"\n","\n","filename2 = filename2\n","#filename2 = \"SDCA Google Sheet.xlsx\""]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["#!pip install openpyxl"]},{"cell_type":"code","execution_count":7,"metadata":{"executionInfo":{"elapsed":1793,"status":"ok","timestamp":1674579356775,"user":{"displayName":"Carlos Sandoval Ormeño","userId":"08254748332068667609"},"user_tz":180},"id":"OvnKztF5hBlh"},"outputs":[],"source":["import pandas as pd\n","import numpy as np\n","import pickle\n","import warnings\n","import matplotlib.pyplot as plt\n","import seaborn as sns\n","from scipy.stats import norm\n","\n","warnings.filterwarnings(\"ignore\")"]},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[],"source":["#%load_ext watermark"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["#%watermark --iversions "]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["#!pip3 list | findstr openpyxl"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"sIiZd8tijLAm"},"outputs":[],"source":["# Conexión y carga de datos"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ydai0pFWjM2T"},"outputs":[],"source":["#Conectarse a google drive para cargar datos\n","#from google.colab import drive\n","#drive.mount('/content/drive')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"bpV5VAuR6Klh"},"outputs":[],"source":["## Archivo 1: Datos\n","\n","#Posee todos los datos en un periodo de tiempo definido. Primera fila debe ser el nombre de la Variable"]},{"cell_type":"code","execution_count":27,"metadata":{"id":"wnkX8PRujP-m"},"outputs":[{"data":{"text/plain":["(1153, 692)"]},"execution_count":27,"metadata":{},"output_type":"execute_result"}],"source":["#path data googledrive\n","path_data_processed = filename1\n","\n","#leer data processed\n","data_processed = pd.read_excel(path_data_processed,sheet_name='15_dias')\n","#data_processed.shape"]},{"cell_type":"code","execution_count":28,"metadata":{"id":"yB55dhn5j2zB"},"outputs":[],"source":["data = data_processed.copy()"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["#data"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_0cSzbEa6YNx"},"outputs":[],"source":["## Archivo 2: Variables\n","\n","#Archivo debe tener\n","\n","\n","#* Tag\n","#* Nombre de la Variable\n"]},{"cell_type":"code","execution_count":12,"metadata":{"id":"KisA0eitjwPF"},"outputs":[{"data":{"text/plain":["(691, 2)"]},"execution_count":12,"metadata":{},"output_type":"execute_result"}],"source":["#path data googledrive\n","path_data_processed = filename1\n","\n","#leer data processed\n","variables = pd.read_excel(path_data_processed,sheet_name='variables')\n","#variables.shape"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"DqWBrBGU5o6d"},"outputs":[],"source":["## Archivo 3: Listado límites\n","\n","#Archivo debe contar con lo siguiente:\n","\n","\n","#* Tag\n","#* Variable\n","#* Unidad\n","#* Min\n","#* Max\n","#* Proceso\n","#* Tipo\n","\n"]},{"cell_type":"code","execution_count":13,"metadata":{"id":"gWnno7CNne6K"},"outputs":[],"source":["#path data googledrive\n","path_data_processed = filename2\n","\n","#leer data processed\n","rangos = pd.read_excel(path_data_processed, sheet_name='SDCA GoogleSheet')"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"57Kw2wK4oWGY"},"outputs":[],"source":["# Funciones"]},{"cell_type":"code","execution_count":14,"metadata":{"id":"ZWQinDfNmFSg"},"outputs":[],"source":["def Cp(USL,LSL,STD,sigma):\n"," if STD==0:\n"," STD=0.001\n"," Cp = (USL - LSL)/(sigma*STD)\n"," return Cp"]},{"cell_type":"code","execution_count":15,"metadata":{"id":"t7qGarFapCkw"},"outputs":[],"source":["def Cpk(USL,LSL,mean_x,STD,sigma):\n"," if STD==0:\n"," STD=0.001\n"," Cpk_sup = (USL - mean_x)/(sigma*STD)\n"," Cpk_inf = (mean_x - LSL)/(sigma*STD)\n","\n"," minimum = min(Cpk_sup,Cpk_inf)\n","\n"," return minimum"]},{"cell_type":"code","execution_count":16,"metadata":{"id":"IY8viMz147FF"},"outputs":[],"source":["def process_capability(data,variables,rangos,sigma):\n"," ##\n"," ## Función para obtener la capacidad del proceso para un set de variables\n"," ##\n"," \n"," capacidad_proc = pd.DataFrame(columns=['Tag','Variable','Promedio','STD','LSL','USL','CP','CPK','% bajo LSL','% sobre USL'])\n"," for j in range(len(variables.iloc[:,0])):\n"," \n"," # Var selection\n"," tag = variables.iloc[j,0]\n"," var = variables.iloc[j,1]\n"," \n"," # Cp y CPk\n"," mean_var = data[var].mean()\n"," std_var = data[var].std()\n","\n"," if pd.isna(rangos[rangos['Variable']==var].loc[j,'Max'])==False:\n"," USL = rangos[rangos['Variable']==var].loc[j,'Max']\n"," else:\n"," USL = mean_var+3*std_var\n"," LSL = rangos[rangos['Variable']==var].loc[j,'Min']\n","\n"," Cp_1 = Cp(USL,LSL,std_var,sigma)\n"," Cpk_1 = Cpk(USL,LSL,mean_var,std_var,sigma/2)\n","\n"," pct_below_LSL = len(data[var][data[var] < LSL])/len(data[var])*100\n"," pct_above_USL = len(data[var][data[var] > USL])/len(data[var])*100\n","\n"," # Creación Dataframe\n"," row_append = pd.DataFrame([[tag,var,mean_var,std_var,LSL,USL,Cp_1,Cpk_1,pct_below_LSL,pct_above_USL]],columns=['Tag','Variable','Promedio','STD','LSL','USL','CP','CPK','% bajo LSL','% sobre USL'])\n"," capacidad_proc = pd.concat([capacidad_proc,row_append],ignore_index=True)\n"," \n"," cap_process = capacidad_proc.merge(rangos[['Variable','Proceso']],on='Variable').drop_duplicates('Variable').reset_index(drop=True).round(2)\n","\n"," return cap_process"]},{"cell_type":"code","execution_count":17,"metadata":{"id":"aKMNAGyb8ka-"},"outputs":[],"source":["def outlier_removal(data,variables):\n"," ## data: dataset completo\n"," ## vairables: lista con el nombre de las variables\n"," # Outlier removal\n"," for i in range(len(variables)):\n"," var = variables.iloc[i]\n","\n"," q75 = data[var].quantile(0.75)\n"," q25 = data[var].quantile(0.25)\n"," intr_qr = q75-q25\n","\n"," maxi = q75+(1.5*intr_qr)\n"," mini = q25-(1.5*intr_qr)\n","\n"," data[var].loc[data[var] < mini] = np.nan\n"," data[var].loc[data[var] > maxi] = np.nan\n","\n"," return data"]},{"cell_type":"code","execution_count":18,"metadata":{"id":"TAjvxICXDQQ7"},"outputs":[],"source":["def process_hist_plot(data,USL,LSL,target):\n"," #\n"," # Solo para análisis univariado \n"," # hist plot\n"," \n"," from scipy.stats import norm\n"," x = np.linspace(min(data), max(data), 1000)\n","\n"," # call first \n"," # from scipy.stats import norm\n"," y = norm.pdf(x, loc=5, scale=1)\n","\n"," # Plot histogram for data along with probability density functions and specification limits\n"," plt.figure(figsize=(15,10))\n"," plt.hist(data, color=\"lightgrey\", edgecolor=\"black\", density=True)\n"," sns.kdeplot(data, color=\"blue\", label=\"Density ST\")\n"," plt.plot(x, y, linestyle=\"--\", color=\"black\", label=\"Theorethical Density ST\")\n"," plt.axvline(LSL, linestyle=\"--\", color=\"red\", label=\"LSL\")\n"," plt.axvline(USL, linestyle=\"--\", color=\"orange\", label=\"USL\")\n"," plt.axvline(target, linestyle=\"--\", color=\"green\", label=\"Target\")\n"," plt.title('Process Capability Analysis')\n"," plt.xlabel(\"Measure\")\n"," plt.ylabel(\"\")\n"," plt.yticks([])\n"," plt.legend()\n"," plt.show()\n","\n"," # % data outside\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," print('')\n"," print('Estadística descriptiva')\n"," print(' ')\n"," print('Promedio : {0:.2f}'.format(data.mean()))\n"," print('Desv Estandar : {0:.2f}'.format(data.std()))\n"," print('Mínimo: {0:.2f}'.format(data.min()))\n"," print('25%: {0:.2f}'.format(data.quantile(0.25)))\n"," print('50%: {0:.2f}'.format(data.quantile(0.5)))\n"," print('75%: {0:.2f}'.format(data.quantile(0.75)))\n"," print('Máximo: {0:.2f}'.format(data.max()))\n"," print('IQR : {0:.2f}'.format(data.quantile(0.75)-data.quantile(0.25)))\n"," print('Asimetría: {0:.2f}'.format(data.skew()))\n"," print('Kurtosis: {0:.2f}'.format(data.kurt()))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Límites')\n"," print(' ')\n"," print('Límite control superior: {0:.2f}'.format((data.mean())+3*data.std()))\n"," print('Límite control inferior: {0:.2f}'.format((data.mean())-3*data.std()))\n"," print('Límite especificación superior: {0:.2f}'.format(USL))\n"," print('Límite especificación inferior: {0:.2f}'.format(LSL))\n"," print('')\n"," print('--------')\n"," print('')\n"," print('Datos fuera rangos')\n"," print(' ') \n"," print('Porcentaje de datos bajo LSL ({0:.2f}): {1:.2f}%'.format(LSL,pct_below_LSL))\n"," print('Porcentaje de datos sobre USL ({0:.2f}): {1:.2f}%'.format(USL,pct_above_USL))\n"," print(' ') \n"," print(' ')"]},{"cell_type":"code","execution_count":19,"metadata":{"id":"CPGTpoP1YBvf"},"outputs":[],"source":["def plot_control_chart(data,fecha,USL,LSL,sigma):\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.axhline(((data.mean())+3*data.std()), color='red', linestyle='dashed',label='UCL')\n"," ax.axhline(((data.mean())-3*data.std()), color='red', linestyle='dashed',label='LCL')\n"," ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n"," print('')\n"," print('Estadística descriptiva')\n"," print(' ')\n"," print('Promedio : {0:.2f}'.format(data.mean()))\n"," print('Desv Estandar : {0:.2f}'.format(data.std()))\n"," print('Mínimo: {0:.2f}'.format(data.min()))\n"," print('25%: {0:.2f}'.format(data.quantile(0.25)))\n"," print('50%: {0:.2f}'.format(data.quantile(0.5)))\n"," print('75%: {0:.2f}'.format(data.quantile(0.75)))\n"," print('Máximo: {0:.2f}'.format(data.max()))\n"," print('IQR : {0:.2f}'.format(data.quantile(0.75)-data.quantile(0.25)))\n"," print('Asimetría: {0:.2f}'.format(data.skew()))\n"," print('Kurtosis: {0:.2f}'.format(data.kurt()))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Control de Procesos')\n"," print('')\n"," print('Cp: {0:.2f}'.format(Cp_1))\n"," print('Cpk: {0:.2f}'.format(Cpk_1))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Límites')\n"," print(' ')\n"," print('Límite control superior: {0:.2f}'.format((data.mean())+3*data.std()))\n"," print('Límite control inferior: {0:.2f}'.format((data.mean())-3*data.std()))\n"," print('Límite especificación superior: {0:.2f}'.format(USL))\n"," print('Límite especificación inferior: {0:.2f}'.format(LSL))\n"," print('')\n"," print('--------')\n"," print('')\n"," print('Datos fuera rangos')\n"," print(' ') \n"," print('Porcentaje de datos bajo LSL ({0:.2f}): {1:.2f}%'.format(LSL,pct_below_LSL))\n"," print('Porcentaje de datos sobre USL ({0:.2f}): {1:.2f}%'.format(USL,pct_above_USL))\n"," print(' ') \n"," print(' ') "]},{"cell_type":"code","execution_count":20,"metadata":{"id":"LBBubqXxt006"},"outputs":[],"source":["def plot_control_chart_week(data,fecha,USL,LSL,sigma,semana):\n"," control_columns = pd.DataFrame(columns=['Fecha','LCL','UCL','Mean','Semana'])\n"," control_columns['Fecha'] = fecha.copy()\n"," control_columns['Semana'] = semana.copy()\n"," for i in semana.unique():\n"," control_columns.loc[control_columns['Semana']==i,'LCL'] = (data.loc[semana==i].mean())-3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'UCL'] = (data.loc[semana==i].mean())+3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'Mean'] = (data.loc[semana==i].mean())\n","\n","\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.plot(fecha,control_columns['LCL'], color='red', linestyle='dashed',label='LCL')\n"," ax.plot(fecha,control_columns['UCL'], color='red', linestyle='dashed',label='UCL')\n"," ax.plot(fecha,control_columns['Mean'], color='green', linestyle='dashed',label='UCL')\n"," # ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n"," print('')\n"," print('Estadística descriptiva')\n"," print(' ')\n"," print('Promedio : {0:.2f}'.format(data.mean()))\n"," print('Desv Estandar : {0:.2f}'.format(data.std()))\n"," print('Mínimo: {0:.2f}'.format(data.min()))\n"," print('25%: {0:.2f}'.format(data.quantile(0.25)))\n"," print('50%: {0:.2f}'.format(data.quantile(0.5)))\n"," print('75%: {0:.2f}'.format(data.quantile(0.75)))\n"," print('Máximo: {0:.2f}'.format(data.max()))\n"," print('IQR : {0:.2f}'.format(data.quantile(0.75)-data.quantile(0.25)))\n"," print('Asimetría: {0:.2f}'.format(data.skew()))\n"," print('Kurtosis: {0:.2f}'.format(data.kurt()))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Control de Procesos')\n"," print('')\n"," print('Cp: {0:.2f}'.format(Cp_1))\n"," print('Cpk: {0:.2f}'.format(Cpk_1))\n"," print(' ')\n"," print('--------')\n"," print('')\n"," print('Límites')\n"," print(' ')\n"," print('Límite control superior: {0:.2f}'.format((data.mean())+3*data.std()))\n"," print('Límite control inferior: {0:.2f}'.format((data.mean())-3*data.std()))\n"," print('Límite especificación superior: {0:.2f}'.format(USL))\n"," print('Límite especificación inferior: {0:.2f}'.format(LSL))\n"," print('')\n"," print('--------')\n"," print('')\n"," print('Datos fuera rangos')\n"," print(' ') \n"," print('Porcentaje de datos bajo LSL ({0:.2f}): {1:.2f}%'.format(LSL,pct_below_LSL))\n"," print('Porcentaje de datos sobre USL ({0:.2f}): {1:.2f}%'.format(USL,pct_above_USL))\n"," print(' ') \n"," print(' ') "]},{"cell_type":"code","execution_count":21,"metadata":{"id":"kz6_yThe5hXe"},"outputs":[],"source":["def plot_control_chart_weekb(data,fecha,USL,LSL,sigma,semana):\n"," control_columns = pd.DataFrame(columns=['Fecha','LCL','UCL','Mean','Semana'])\n"," control_columns['Fecha'] = fecha.copy()\n"," control_columns['Semana'] = semana.copy()\n"," for i in semana.unique():\n"," control_columns.loc[control_columns['Semana']==i,'LCL'] = (data.loc[semana==i].mean())-3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'UCL'] = (data.loc[semana==i].mean())+3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'Mean'] = (data.loc[semana==i].mean())\n","\n","\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.plot(fecha,control_columns['LCL'], color='red', linestyle='dashed',label='LCL')\n"," ax.plot(fecha,control_columns['UCL'], color='red', linestyle='dashed',label='UCL')\n"," ax.plot(fecha,control_columns['Mean'], color='green', linestyle='dashed',label='UCL')\n"," # ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n"," "]},{"cell_type":"code","execution_count":22,"metadata":{"id":"CTQEHuDJ9zbk"},"outputs":[],"source":["def plot_control_chart_weekc(data,fecha,USL,LSL,sigma,semana):\n"," control_columns = pd.DataFrame(columns=['Fecha','LCL','UCL','Mean','Semana'])\n"," control_columns['Fecha'] = fecha.copy()\n"," control_columns['Semana'] = semana.copy()\n"," for i in semana.unique():\n"," control_columns.loc[control_columns['Semana']==i,'LCL'] = (data.loc[semana==i].mean())-3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'UCL'] = (data.loc[semana==i].mean())+3*data.loc[semana==i].std()\n"," control_columns.loc[control_columns['Semana']==i,'Mean'] = (data.loc[semana==i].mean())\n","\n","\n"," import matplotlib.dates as mdates\n"," fig, ax = plt.subplots(figsize=(15, 10))\n","\n"," #year_month_formatter = mdates.DateFormatter(\"%Y-%m\")\n"," #ax.xaxis.set_major_formatter(year_month_formatter) # formatter for major axis only\n","\n"," ax.plot(fecha,data)\n","\n"," ax.plot(fecha,control_columns['LCL'], color='red', linestyle='dashed',label='LCL')\n"," ax.plot(fecha,control_columns['UCL'], color='red', linestyle='dashed',label='UCL')\n"," ax.plot(fecha,control_columns['Mean'], color='green', linestyle='dashed',label='Promedio')\n"," # ax.axhline((data.mean()), color='green', linestyle='dashed',label='Promedio')\n"," ax.axhline(USL, color='orange', linestyle='dashed',label='USL')\n"," ax.axhline(LSL, color='orange', linestyle='dashed',label='LSL')\n"," ax.legend()\n"," plt.title('Control Chart')\n","\n"," pct_below_LSL = len(data[data < LSL])/len(data)*100\n"," pct_above_USL = len(data[data > USL])/len(data)*100\n","\n"," Cp_1 = Cp(USL,LSL,data.std(),sigma)\n"," Cpk_1 = Cpk(USL,LSL,data.mean(),data.std(),sigma/2)\n","\n"," fig.autofmt_xdate()\n"," plt.show()\n","\n"," process_hist_plot(data,USL,LSL,USL - (USL - LSL)/2)\n","\n"," print('Control de Procesos Generales')\n"," print('')\n"," print('Cp: {0:.2f}'.format(Cp_1))\n"," print('Cpk: {0:.2f}'.format(Cpk_1))"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pUVMHNz6kuJF"},"outputs":[],"source":["# Transformaciones"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"_hZY-BrCkyCw"},"outputs":[],"source":["## fechas"]},{"cell_type":"code","execution_count":24,"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>Tag</th>\n"," <th>Nombre</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>369TI441.PNT</td>\n"," <td>TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>369TI442.PNT</td>\n"," <td>TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>369TI443.PNT</td>\n"," <td>TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>369TI987.PNT</td>\n"," <td>TEMPERATURA SALA RACK 1</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>369TI993.PNT</td>\n"," <td>TEMPERATURA SALA MEDIO TENSION 2</td>\n"," </tr>\n"," <tr>\n"," <th>...</th>\n"," <td>...</td>\n"," <td>...</td>\n"," </tr>\n"," <tr>\n"," <th>686</th>\n"," <td>CaeAmsaP</td>\n"," <td>Potencia Media AMSA SF1</td>\n"," </tr>\n"," <tr>\n"," <th>687</th>\n"," <td>CaeStfel1P</td>\n"," <td>Potencia Media SF1+AMSA</td>\n"," </tr>\n"," <tr>\n"," <th>688</th>\n"," <td>CaeStfel2P</td>\n"," <td>Potencia Media SF2+AGA</td>\n"," </tr>\n"," <tr>\n"," <th>689</th>\n"," <td>CAESTFETG2P.C</td>\n"," <td>Generación TG2</td>\n"," </tr>\n"," <tr>\n"," <th>690</th>\n"," <td>S267ALE036</td>\n"," <td>Solidos alimentados Evap SF2</td>\n"," </tr>\n"," </tbody>\n","</table>\n","<p>691 rows × 2 columns</p>\n","</div>"],"text/plain":[" Tag Nombre\n","0 369TI441.PNT TEMPERATURA SALA RAC MEDIO TENSION BIOMASA 2\n","1 369TI442.PNT TEMPERATURA SALA RAC UNO BAJA TENSION BIOMASA 2\n","2 369TI443.PNT TEMPERATURA SALA RAC DOS BAJA TENSION BIOMASA 2\n","3 369TI987.PNT TEMPERATURA SALA RACK 1\n","4 369TI993.PNT TEMPERATURA SALA MEDIO TENSION 2\n",".. ... ...\n","686 CaeAmsaP Potencia Media AMSA SF1\n","687 CaeStfel1P Potencia Media SF1+AMSA\n","688 CaeStfel2P Potencia Media SF2+AGA\n","689 CAESTFETG2P.C Generación TG2\n","690 S267ALE036 Solidos alimentados Evap SF2\n","\n","[691 rows x 2 columns]"]},"execution_count":24,"metadata":{},"output_type":"execute_result"}],"source":["#data"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"L3FgCue8kt2f"},"outputs":[],"source":["data['dia'] = pd.to_datetime(data['Fecha']).dt.day\n","data['mes'] = pd.to_datetime(data['Fecha']).dt.month\n","data['anio'] = pd.to_datetime(data['Fecha']).dt.year\n","data['semana'] = pd.to_datetime(data['Fecha']).dt.isocalendar().week"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"x9TQiN6T38L_"},"outputs":[],"source":["## fill nan cuando Min no tiene valor"]},{"cell_type":"code","execution_count":16,"metadata":{"id":"14MhjxzM3-KL"},"outputs":[],"source":["rangos['Min'] = rangos['Min'].fillna(0)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pwVpudFKBaO5"},"outputs":[],"source":["## textos en nan"]},{"cell_type":"code","execution_count":17,"metadata":{"id":"9k1p7s2lBc2y"},"outputs":[],"source":["data.iloc[:,1:] = data.iloc[:,1:].applymap(lambda x: x if not isinstance(x, str) else np.nan)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"PpCcVczm__1j"},"outputs":[],"source":["## Outlier removal"]},{"cell_type":"code","execution_count":18,"metadata":{"id":"bo7bIAgu-avh"},"outputs":[],"source":["data_clean = outlier_removal(data,variables.iloc[:,1])\n","dataset_process = data_clean.copy()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"itP8KpJV29ji"},"outputs":[],"source":["# Capacidad del proceso\n","\n","#Se utiliza sigma=4\n"]},{"cell_type":"code","execution_count":19,"metadata":{"id":"zjdpRymv2dsH"},"outputs":[],"source":["sigma_proc = 4"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"LPBPaz2S3BxF"},"outputs":[],"source":["## Dataset Completo"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Z_kmjmA77Sqv"},"outputs":[],"source":["#@title Capacidad del proceso\n","\n","# capacidad_proc = process_capability(dataset_process[dataset_process['semana']==2],variables,rangos,sigma_proc)\n","capacidad_proc = process_capability(dataset_process,variables,rangos,sigma_proc)\n","capacidad_proc\n","\n","\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"NYyHAdOBxdPW"},"outputs":[],"source":["# Análisis Univariado - Mes movil"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"kefb2Sjm9UPN"},"outputs":[],"source":["## Seleccionamos la variable"]},{"cell_type":"code","execution_count":21,"metadata":{"id":"pfO9fE2Mxi3R"},"outputs":[],"source":["var_analizar='Kappa Salida Deslignificacion'\n","USL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['USL']\n","LSL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['LSL']\n","target_process = USL_process - (USL_process - LSL_process)/2"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"iwKZhYJ1x-yQ"},"outputs":[],"source":["## Control Chart"]},{"cell_type":"code","execution_count":22,"metadata":{"id":"yMpj1Ve1sUUQ"},"outputs":[],"source":["variables_analizar = capacidad_proc['Variable'].unique()\n","proceso_analizar = capacidad_proc['Proceso'].unique()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Q1vqJS9qb-6H"},"outputs":[],"source":["# plot_control_chart(data=dataset_process[var_analizar],fecha=dataset_process['Fecha'],USL=USL_process,LSL=LSL_process,sigma=sigma_proc)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Qv5jYHOMtplz"},"outputs":[],"source":["# plot_control_chart_weekc(data=dataset_process[var_analizar],fecha=dataset_process['Fecha'],USL=USL_process,LSL=LSL_process,sigma=sigma_proc,semana=dataset_process['semana'])"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"zvzLzW4hDv3O"},"outputs":[],"source":["# process_hist_plot(dataset_process[var_analizar],USL=USL_process,LSL= LSL_process,target=target_process)"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ATZtJ8db0d5V"},"outputs":[],"source":["# Análisis Semanal"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"ISuNOi4xMogR"},"outputs":[],"source":["## Generación de información"]},{"cell_type":"code","execution_count":23,"metadata":{"id":"MTl57ZB-0bst"},"outputs":[],"source":["analisis_semanal = pd.DataFrame(columns=capacidad_proc.columns)\n","analisis_semanal['semana'] = np.nan\n","for i in data_clean['semana'].unique():\n"," process_concat = process_capability(dataset_process[dataset_process['semana']==i],variables,rangos,sigma = sigma_proc)\n"," process_concat['semana'] = i\n"," analisis_semanal = analisis_semanal.append(process_concat,ignore_index=True)"]},{"cell_type":"code","execution_count":24,"metadata":{"id":"-hkW05igCv0g"},"outputs":[],"source":["semana_analisis = analisis_semanal[analisis_semanal['Variable']==var_analizar]['semana']\n","cp_analisis = analisis_semanal[analisis_semanal['Variable']==var_analizar]['CP']\n","cpk_analisis = analisis_semanal[analisis_semanal['Variable']==var_analizar]['CPK']"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"nCk1_tAnMvnO"},"outputs":[],"source":["## Evolución capacidad del proceso 4 últimas semanas"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["#analisis_semanal['Proceso'].unique()"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"Oj7BK98t8EHm"},"outputs":[],"source":["for i in analisis_semanal[analisis_semanal['Proceso']== select_area]['Variable'].unique():\n"," try:\n"," var_analizar=i\n"," USL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['USL']\n"," LSL_process = capacidad_proc[capacidad_proc['Variable']==var_analizar].iloc[0]['LSL']\n"," target_process = USL_process - (USL_process - LSL_process)/2\n"," print('')\n"," print('')\n"," print(var_analizar)\n"," print('')\n"," print(analisis_semanal[analisis_semanal['Variable']==var_analizar])\n"," print('')\n"," plot_control_chart_weekc(data=dataset_process[var_analizar],fecha=dataset_process['Fecha'],USL=USL_process,LSL=LSL_process,sigma=sigma_proc,semana=dataset_process['semana'])\n"," except:\n"," pass\n"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMK24vRsdKQ5F9deXxFJUL4","provenance":[]},"kernelspec":{"display_name":"Python 3.9.12 ('base')","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.12"},"vscode":{"interpreter":{"hash":"499f128a82e2b79451131852586e0bb06fce5014f717125641f9cae50119434e"}}},"nbformat":4,"nbformat_minor":0}
|