Explorar o código

add jupyterlab files

hanojiang %!s(int64=2) %!d(string=hai) anos
pai
achega
957976e9ef
Modificáronse 1 ficheiros con 251 adicións e 0 borrados
  1. 251 0
      jupyter/getUsefulInfo.ipynb

+ 251 - 0
jupyter/getUsefulInfo.ipynb

@@ -0,0 +1,251 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 10,
+   "id": "983238bd-b699-4167-a27d-c94886211672",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "import pandas as pd\n",
+    "from pandas import DataFrame\n",
+    "import numpy as np\n",
+    "import dtale"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "id": "79d66d27-c2c8-465e-b57b-45be76a69422",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def get_agg_pdu_info_by_controller(pdu_name: str, pdu_triggering_df: DataFrame):\n",
+    "    # select pdu_name releated pdus in Pdu Triggering \n",
+    "    pdu_triggering_df.fillna('', inplace=True)\n",
+    "    criterion_select_pdus = pdu_triggering_df['Pdu Name'].str.contains(pdu_name)\n",
+    "    releated_pdus = pdu_triggering_df[criterion_select_pdus]\n",
+    "\n",
+    "    pdu_info_agg = releated_pdus \\\n",
+    "        .groupby('Controller') \\\n",
+    "        .agg(\n",
+    "                PduName = ('Pdu Name', lambda x: ','.join(x.unique())),\n",
+    "                PortDirection = ('Port Direction', lambda x: ','.join(x.unique())),\n",
+    "                signal=('Signal Trigger', lambda x: ','.join(x))\n",
+    "            ) \\\n",
+    "        .reset_index()\n",
+    "\n",
+    "    return pdu_info_agg"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "id": "8b1d1ccc-1587-48c3-908b-b602858bc017",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def get_normal_or_contained_pdu(pdu_name: str, aggregated_pdu_info: DataFrame, container_df: DataFrame):\n",
+    "    unique_pdu_list = aggregated_pdu_info['PduName'].unique()\n",
+    "\n",
+    "    # get contained pdu's name, and add pdu name as normal can pdu name.\n",
+    "    cri_is_contained = container_df['Contained PDU'].apply(lambda x: x[5:]).isin(unique_pdu_list) # trip head 'PduTr'\n",
+    "    normal_contained_pdus = np.append(container_df[cri_is_contained]['PDU Name'].unique(), pdu_name)\n",
+    "\n",
+    "    return normal_contained_pdus"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 13,
+   "id": "e0e4ec16-1d39-4545-a130-e45af798a5a5",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def get_frame_info_by_pdu_name_list(normal_contained_pdus, frame_df: DataFrame):\n",
+    "    cri_has_frame_info = frame_df['Pdu Trigger'].apply(lambda x: x[5:]).isin(normal_contained_pdus) # trip head 'PduTr'\n",
+    "    frame_info = frame_df[cri_has_frame_info]\n",
+    "    return frame_info"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 14,
+   "id": "16c7b4dd-acf7-4476-a626-993a670df6c4",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def get_useful_info_by_pdu_name(pdu_name: str, frame_df, pdu_triggering_df, container_df):\n",
+    "    pdu_info_agg = get_agg_pdu_info_by_controller(pdu_name, pdu_triggering_df)\n",
+    "    # print(pdu_info_agg)\n",
+    "    normal_contained_pdus = get_normal_or_contained_pdu(pdu_name, pdu_info_agg, container_df)\n",
+    "    # print(normal_contained_pdus)\n",
+    "    frame_info = get_frame_info_by_pdu_name_list(normal_contained_pdus, frame_df)\n",
+    "    # print(frame_info.loc[:, ['Controller', 'Frame Name', 'Frame ID', 'Pdu Trigger']])\n",
+    "    # pdu_info_merged = pd.merge(pdu_info_agg, frame_info.loc[:, ['Frame Name', 'Frame ID', 'Pdu Trigger']], on='Controller')\n",
+    "    pdu_info_merged = pd.merge(pdu_info_agg, frame_info.loc[:, ['Controller', 'Frame Name', 'Frame ID', 'Pdu Trigger']], on='Controller')\n",
+    "    return pdu_info_merged"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 19,
+   "id": "cd35de4a-9be7-4be0-86f7-0ab9d09cc4f1",
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "def test():\n",
+    "    xlsx = pd.ExcelFile('OutputFile_Attributes_20220524-zw5_EC32_EP_V02_GW.xlsx')\n",
+    "    # print(xlsx.sheet_names)\n",
+    "    df_idpu = pd.read_excel(xlsx, sheet_name='IPdu', index_col=0)\n",
+    "    df_frame = pd.read_excel(xlsx, sheet_name='FrameTriggering', index_col=0)\n",
+    "    df_pdu_trig = pd.read_excel(xlsx, sheet_name='PduTriggering', index_col=0)\n",
+    "    df_container = pd.read_excel(xlsx, sheet_name='ContainerPdu', index_col=0)\n",
+    "    \n",
+    "    # pdu_name = 'CCP_020ms_PDU02'\n",
+    "    pdu_name = 'FVCM_020ms_PDU01'\n",
+    "    # pdu_name = 'FVCM_ADCANFD_Sporadic_Container12'\n",
+    "    # pdu_name = 'SCS_020ms_PDU04'\n",
+    "\n",
+    "    search_info = get_useful_info_by_pdu_name(pdu_name, df_frame, df_pdu_trig, df_container)\n",
+    "    # dtale.show(search_info,open_browser=True)#\n",
+    "    print(search_info)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 20,
+   "id": "b037682f-207c-497c-83c6-e943d96d957b",
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "         Controller                 PduName PortDirection  \\\n",
+      "0  ADCANFDConnector        FVCM_020ms_PDU01   IPduPort_In   \n",
+      "1    CFCANConnector        FVCM_020ms_PDU01  IPduPort_Out   \n",
+      "2  CHCANFDConnector  FVCM_020ms_PDU01_SGWCH  IPduPort_Out   \n",
+      "3  PTCANFDConnector  FVCM_020ms_PDU01_SGWPT  IPduPort_Out   \n",
+      "\n",
+      "                                              signal               Frame Name  \\\n",
+      "0  ISTrisLDWLKARVsulznReq_0_7,ISTrisLDWSysSts_0_7...       FVCM_ADCANFD_FrP00   \n",
+      "1                                                        CCP_CFCAN_FVCM_FrP01   \n",
+      "2  ISTrisLDWLKARVsulznReq_1_2,ISTrisLDWSysSts_1_2...  CCP_CHCANFD_PDUGW_FrP10   \n",
+      "3  ISTrisLDWLKARVsulznReq_2_1,ISTrisLDWSysSts_2_1...   CCP_PTCANFD_FVCM_FrP00   \n",
+      "\n",
+      "  Frame ID                          Pdu Trigger  \n",
+      "0    0x1da  PduTrFVCM_ADCANFD_020ms_Container00  \n",
+      "1    0x1b1                PduTrFVCM_020ms_PDU01  \n",
+      "2    0x14d   PduTrCCP_CHCANFD_020ms_Container10  \n",
+      "3    0x1da   PduTrCCP_PTCANFD_020ms_Container02  \n",
+      "Executing shutdown due to inactivity...\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2022-10-04 19:24:23,346 - INFO     - Executing shutdown due to inactivity...\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Executing shutdown...\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2022-10-04 19:24:23,356 - INFO     - Executing shutdown...\n"
+     ]
+    },
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      "Exception on /shutdown [GET]\n",
+      "Traceback (most recent call last):\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 2525, in wsgi_app\n",
+      "    response = self.full_dispatch_request()\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 1822, in full_dispatch_request\n",
+      "    rv = self.handle_user_exception(e)\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 1820, in full_dispatch_request\n",
+      "    rv = self.dispatch_request()\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 1796, in dispatch_request\n",
+      "    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/dtale/app.py\", line 435, in shutdown\n",
+      "    shutdown_server()\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/dtale/app.py\", line 421, in shutdown_server\n",
+      "    raise RuntimeError(\"Not running with the Werkzeug Server\")\n",
+      "RuntimeError: Not running with the Werkzeug Server\n"
+     ]
+    },
+    {
+     "name": "stderr",
+     "output_type": "stream",
+     "text": [
+      "2022-10-04 19:24:23,357 - ERROR    - Exception on /shutdown [GET]\n",
+      "Traceback (most recent call last):\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 2525, in wsgi_app\n",
+      "    response = self.full_dispatch_request()\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 1822, in full_dispatch_request\n",
+      "    rv = self.handle_user_exception(e)\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 1820, in full_dispatch_request\n",
+      "    rv = self.dispatch_request()\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/flask/app.py\", line 1796, in dispatch_request\n",
+      "    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/dtale/app.py\", line 435, in shutdown\n",
+      "    shutdown_server()\n",
+      "  File \"/opt/conda/lib/python3.9/site-packages/dtale/app.py\", line 421, in shutdown_server\n",
+      "    raise RuntimeError(\"Not running with the Werkzeug Server\")\n",
+      "RuntimeError: Not running with the Werkzeug Server\n"
+     ]
+    }
+   ],
+   "source": [
+    "test()"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "b038e2c7-1494-44d9-b8f1-de1c3b1cb120",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "id": "3a10d610-1a1b-4691-bdbd-8fbdc4520102",
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "kernelspec": {
+   "display_name": "Python 3 (ipykernel)",
+   "language": "python",
+   "name": "python3"
+  },
+  "language_info": {
+   "codemirror_mode": {
+    "name": "ipython",
+    "version": 3
+   },
+   "file_extension": ".py",
+   "mimetype": "text/x-python",
+   "name": "python",
+   "nbconvert_exporter": "python",
+   "pygments_lexer": "ipython3",
+   "version": "3.9.7"
+  }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}