lmstack 3 年之前
父节点
当前提交
cee953c246

+ 1 - 1
LIB/MIDDLE/SaftyCenter/Low_Soc_Alarm/low_soc_alarm_sta.py

@@ -26,7 +26,7 @@ def low_soc_alarm_sta(df_sns, db_qxcas_engine, conn, db_sp_engine):
 
     # 遍历昨日报警和报警列表,如果 1:sn存在于昨日报警,但不存在与报警allinfo里,则添加一条新的报警记录到allinfo里;
     #                           2:如果sn存在于allinfo但不存在于昨日报警,也不存在于昨日离线,则记录故障为结束;
-    #                           3: 如果sn在两个表中都存在,但级别不同,则更新级别(离线暂时不考虑级别)。
+    #                           3: 如果sn在两个表中都存在,但级别不同,则更新级别(离线暂rr时不考虑级别)。
     sn_new = list(set(sn_lowsoc)-set(sn_allalarm))
     sn_close = list(set(sn_allalarm)-set(sn_lowsoc)-set(sn_offline))
     # sn_cross = list(set(sn_lowsoc) & set(sn_allalarm))

+ 20 - 0
LIB/OTHER/ca-cert

@@ -0,0 +1,20 @@
+-----BEGIN CERTIFICATE-----
+MIIDPDCCAqWgAwIBAgIJAMRsb0DLM1fsMA0GCSqGSIb3DQEBBQUAMHIxCzAJBgNV
+BAYTAkNOMQswCQYDVQQIEwJIWjELMAkGA1UEBxMCSFoxCzAJBgNVBAoTAkFCMRAw
+DgYDVQQDEwdLYWZrYUNBMSowKAYJKoZIhvcNAQkBFht6aGVuZG9uZ2xpdS5semRA
+YWxpYmFiYS5jb20wIBcNMTcwMzA5MTI1MDUyWhgPMjEwMTAyMTcxMjUwNTJaMHIx
+CzAJBgNVBAYTAkNOMQswCQYDVQQIEwJIWjELMAkGA1UEBxMCSFoxCzAJBgNVBAoT
+AkFCMRAwDgYDVQQDEwdLYWZrYUNBMSowKAYJKoZIhvcNAQkBFht6aGVuZG9uZ2xp
+dS5semRAYWxpYmFiYS5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBALZV
+bbIO1ULQQN853BTBgRfPiRJaAOWf38u8GC0TNp/E9qtI88A+79ywAP17k5WYJ7XS
+wXMOJ3h1qkQT2TYJVetZ6E69CUJq4BsOvNlNRvmnW6eFymh5QZsEz2MTooxJjVjC
+JQPlI2XRDjIrTVYEQWUDxj2JhB8VVPEed+6u4KQVAgMBAAGjgdcwgdQwHQYDVR0O
+BBYEFHFlOoiqQxXanVi2GUoDiKDD33ujMIGkBgNVHSMEgZwwgZmAFHFlOoiqQxXa
+nVi2GUoDiKDD33ujoXakdDByMQswCQYDVQQGEwJDTjELMAkGA1UECBMCSFoxCzAJ
+BgNVBAcTAkhaMQswCQYDVQQKEwJBQjEQMA4GA1UEAxMHS2Fma2FDQTEqMCgGCSqG
+SIb3DQEJARYbemhlbmRvbmdsaXUubHpkQGFsaWJhYmEuY29tggkAxGxvQMszV+ww
+DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQBTSz04p0AJXKl30sHw+UM/
+/k1jGFJzI5p0Z6l2JzKQYPP3PfE/biE8/rmiGYEenNqWNy1ZSniEHwa8L/Ux98ci
+4H0ZSpUrMo2+6bfuNW9X35CFPp5vYYJqftilJBKIJX3C3J1ruOuBR28UxE42xx4K
+pQ70wChNi914c4B+SxkGUg==
+-----END CERTIFICATE-----

文件差异内容过多而无法显示
+ 66 - 0
LIB/OTHER/hz_kafka_cosumer.ipynb


+ 234 - 0
LIB/OTHER/hz_kafka_cosumer_packmodel.ipynb

@@ -0,0 +1,234 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      " 27存储成功"
+     ]
+    }
+   ],
+   "source": [
+    "import ssl\n",
+    "from kafka import KafkaProducer, KafkaConsumer\n",
+    "from kafka.errors import kafka_errors\n",
+    "import traceback\n",
+    "import json\n",
+    "import pdb\n",
+    "import os\n",
+    "import pandas as pd\n",
+    "context = ssl.create_default_context()\n",
+    "context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n",
+    "## The new python(2.7.8+) may cannot ignore the hostname check,\n",
+    "## you could set to ssl.CERT_NONE to walk around the problem,\n",
+    "## or you can change the client to confluent-python-demo \n",
+    "\n",
+    "# context.verify_mode = ssl.CERT_NONE\n",
+    "context.verify_mode = ssl.CERT_REQUIRED\n",
+    "topic = 'sys_battery_module_model_topic_temp'\n",
+    "# context.check_hostname = True\n",
+    "context.load_verify_locations(\"ca-cert\")\n",
+    "consumer = KafkaConsumer(topic, bootstrap_servers=['alikafka-pre-cn-8ed2kw57901x-1.alikafka.aliyuncs.com:9093',\n",
+    "                                            'alikafka-pre-cn-8ed2kw57901x-2.alikafka.aliyuncs.com:9093',\n",
+    "                                            'alikafka-pre-cn-8ed2kw57901x-3.alikafka.aliyuncs.com:9093'],\n",
+    "                         sasl_mechanism=\"PLAIN\",\n",
+    "                         ssl_context=context,\n",
+    "                         security_protocol='SASL_SSL',\n",
+    "                         api_version = (2,2),\n",
+    "                         sasl_plain_username='alikafka_pre-cn-8ed2kw57901x',\n",
+    "                         sasl_plain_password='hlQsApgUUdUxcWEr1uQoM9BeuF8t8vMF',\n",
+    "                         consumer_timeout_ms= 100000000, # 如果10秒内kafka中没有可供消费的数据,自动退出\n",
+    "                         client_id='consumer-python3',\n",
+    "                         auto_offset_reset='earliest',# 消费kafka中最近的数据,如果设置为earliest则消费最早的数据,不管这些数据是否消费\n",
+    "                         enable_auto_commit=True, # 自动提交消费者的offset\n",
+    "                         auto_commit_interval_ms=3000, ## 自动提交消费者offset的时间间隔,\n",
+    "\n",
+    ")\n",
+    "i = 0\n",
+    "\n",
+    "for message in consumer:\n",
+    "    # df = pd.DataFrame(columns=['code','child_code','create_time','id','model_type'])\n",
+    "    if topic+'.csv' not in os.listdir():\n",
+    "        pd.DataFrame(json.loads(str(message.value,'utf-8')),index=[0]).to_csv(topic+'.csv', index=False)\n",
+    "    else:\n",
+    "        pd.DataFrame(json.loads(str(message.value,'utf-8')),index=[0]).to_csv(topic+'.csv', mode='a', index=False, header=None)\n",
+    "    i = i + 1\n",
+    "    print(\"\\r\",str(i)+\"存储成功\",end=\"\",flush=True)\n",
+    "    "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 15,
+   "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>code</th>\n",
+       "      <th>child_code</th>\n",
+       "      <th>create_time</th>\n",
+       "      <th>id</th>\n",
+       "      <th>model_type</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>2101TAB</td>\n",
+       "      <td>J9</td>\n",
+       "      <td>2021-01-07 10:19:28</td>\n",
+       "      <td>01d0d517da13492f9255cc34ef5f8d1c</td>\n",
+       "      <td>M</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "      code child_code          create_time                                id  \\\n",
+       "0  2101TAB         J9  2021-01-07 10:19:28  01d0d517da13492f9255cc34ef5f8d1c   \n",
+       "\n",
+       "  model_type  \n",
+       "0          M  "
+      ]
+     },
+     "execution_count": 15,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df = df.append(json.loads(str(message.value,'utf-8')),ignore_index=True)\n",
+    "df"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 12,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "df = pd.DataFrame(columns=['code','child_code','create_time','id','model_type'])"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 11,
+   "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>code</th>\n",
+       "      <th>child_code</th>\n",
+       "      <th>create_time</th>\n",
+       "      <th>id</th>\n",
+       "      <th>model_type</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>J9</td>\n",
+       "      <td>2101TAB</td>\n",
+       "      <td>2021-01-07 10:19:28</td>\n",
+       "      <td>01d0d517da13492f9255cc34ef5f8d1c</td>\n",
+       "      <td>M</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "  code child_code          create_time                                id  \\\n",
+       "0   J9    2101TAB  2021-01-07 10:19:28  01d0d517da13492f9255cc34ef5f8d1c   \n",
+       "\n",
+       "  model_type  \n",
+       "0          M  "
+      ]
+     },
+     "execution_count": 11,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "df"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "5ac93a79b26608c768d42fbd754dd4f69161017bfc4d38cb4b18d60e5198dbca"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.6.2 ('ana_py36')",
+   "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.6.2"
+  },
+  "orig_nbformat": 4
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

+ 183 - 0
LIB/OTHER/hz_kafka_cosumer_tbox.ipynb

@@ -0,0 +1,183 @@
+{
+ "cells": [
+  {
+   "cell_type": "code",
+   "execution_count": 1,
+   "metadata": {},
+   "outputs": [
+    {
+     "name": "stdout",
+     "output_type": "stream",
+     "text": [
+      " 14901存储成功储成功190存储成功192存储成功398存储成功450存储成功476存储成功858存储成功938存储成功1006存储成功1123存储成功1150存储成功1397存储成功1890存储成功2224存储成功2320存储成功2368存储成功2516存储成功2679存储成功2798存储成功3379存储成功3426存储成功3590存储成功3934存储成功4153存储成功4360存储成功4990存储成功5340存储成功5461存储成功5470存储成功5579存储成功5667存储成功6201存储成功6202存储成功6613存储成功7014存储成功7057存储成功7440存储成功7504存储成功7562存储成功7947存储成功7965存储成功8273存储成功8553存储成功8696存储成功8887存储成功8888存储成功9148存储成功9259存储成功9433存储成功10072存储成功10073存储成功10299存储成功10485存储成功10513存储成功10834存储成功10870存储成功11058存储成功11311存储成功11517存储成功11587存储成功11700存储成功11757存储成功12391存储成功12591存储成功12888存储成功12943存储成功13051存储成功13067存储成功13667存储成功14073存储成功14127存储成功14533存储成功14593存储成功"
+     ]
+    }
+   ],
+   "source": [
+    "import ssl\n",
+    "from kafka import KafkaProducer, KafkaConsumer\n",
+    "from kafka.errors import kafka_errors\n",
+    "import traceback\n",
+    "import json\n",
+    "import pdb\n",
+    "import os\n",
+    "import pandas as pd\n",
+    "context = ssl.create_default_context()\n",
+    "context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)\n",
+    "## The new python(2.7.8+) may cannot ignore the hostname check,\n",
+    "## you could set to ssl.CERT_NONE to walk around the problem,\n",
+    "## or you can change the client to confluent-python-demo \n",
+    "\n",
+    "# context.verify_mode = ssl.CERT_NONE\n",
+    "context.verify_mode = ssl.CERT_REQUIRED\n",
+    "topic = 's_kafka_tbox_analysis_hh_delta_ext_topic'\n",
+    "# context.check_hostname = True\n",
+    "context.load_verify_locations(\"ca-cert\")\n",
+    "consumer = KafkaConsumer(topic, bootstrap_servers=['alikafka-pre-cn-8ed2kw57901x-1.alikafka.aliyuncs.com:9093',\n",
+    "                                            'alikafka-pre-cn-8ed2kw57901x-2.alikafka.aliyuncs.com:9093',\n",
+    "                                            'alikafka-pre-cn-8ed2kw57901x-3.alikafka.aliyuncs.com:9093'],\n",
+    "                         sasl_mechanism=\"PLAIN\",\n",
+    "                         ssl_context=context,\n",
+    "                         security_protocol='SASL_SSL',\n",
+    "                         api_version = (2,2),\n",
+    "                         sasl_plain_username='alikafka_pre-cn-8ed2kw57901x',\n",
+    "                         sasl_plain_password='hlQsApgUUdUxcWEr1uQoM9BeuF8t8vMF',\n",
+    "                         consumer_timeout_ms= 100000000, # 如果10秒内kafka中没有可供消费的数据,自动退出\n",
+    "                         client_id='consumer-python3',\n",
+    "                         auto_offset_reset='earliest',# 消费kafka中最近的数据,如果设置为earliest则消费最早的数据,不管这些数据是否消费\n",
+    "                         enable_auto_commit=True, # 自动提交消费者的offset\n",
+    "                         auto_commit_interval_ms=3000, ## 自动提交消费者offset的时间间隔,\n",
+    "\n",
+    ")\n",
+    "\n",
+    "i = 1\n",
+    "for message in consumer:\n",
+    "    if i == 1:\n",
+    "        i = i + 1\n",
+    "        continue\n",
+    "    if topic+'.csv' not in os.listdir():\n",
+    "        pd.DataFrame(json.loads(str(message.value,'utf-8')),index=[0]).to_csv(topic+'.csv', index=False)\n",
+    "    else:\n",
+    "        pd.DataFrame(json.loads(str(message.value,'utf-8')),index=[0]).to_csv(topic+'.csv', mode='a', index=False, header=None)\n",
+    "    i = i + 1\n",
+    "    print(\"\\r\",str(i)+\"存储成功\",end=\"\",flush=True)\n",
+    "    "
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 2,
+   "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>code</th>\n",
+       "      <th>create_time</th>\n",
+       "      <th>id</th>\n",
+       "      <th>model_id</th>\n",
+       "      <th>vin</th>\n",
+       "    </tr>\n",
+       "  </thead>\n",
+       "  <tbody>\n",
+       "    <tr>\n",
+       "      <th>0</th>\n",
+       "      <td>0CZPE007DN0111B2P0000010</td>\n",
+       "      <td>2021-03-31 16:05:38</td>\n",
+       "      <td>000038a9f8c745a19da116d82085e54c</td>\n",
+       "      <td>2101TAB</td>\n",
+       "      <td>LUZAGAAA4MA008178</td>\n",
+       "    </tr>\n",
+       "  </tbody>\n",
+       "</table>\n",
+       "</div>"
+      ],
+      "text/plain": [
+       "                       code          create_time  \\\n",
+       "0  0CZPE007DN0111B2P0000010  2021-03-31 16:05:38   \n",
+       "\n",
+       "                                 id model_id                vin  \n",
+       "0  000038a9f8c745a19da116d82085e54c  2101TAB  LUZAGAAA4MA008178  "
+      ]
+     },
+     "execution_count": 2,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "pd.DataFrame(json.loads(str(message.value,'utf-8')),index=[0]).to_csv(topic+'.csv', index=False)"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": 5,
+   "metadata": {},
+   "outputs": [
+    {
+     "data": {
+      "text/plain": [
+       "ConsumerRecord(topic='sys_battery_pack_entity_storage_topic', partition=0, offset=1, timestamp=1645586299071, timestamp_type=0, key=None, value=b'{\"code\":\"0CZPE007DN0111B2P0000010\",\"create_time\":\"2021-03-31 16:05:38\",\"id\":\"000038a9f8c745a19da116d82085e54c\",\"model_id\":\"2101TAB\",\"vin\":\"LUZAGAAA4MA008178\"}', headers=[], checksum=None, serialized_key_size=-1, serialized_value_size=158, serialized_header_size=-1)"
+      ]
+     },
+     "execution_count": 5,
+     "metadata": {},
+     "output_type": "execute_result"
+    }
+   ],
+   "source": [
+    "message"
+   ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": []
+  }
+ ],
+ "metadata": {
+  "interpreter": {
+   "hash": "5ac93a79b26608c768d42fbd754dd4f69161017bfc4d38cb4b18d60e5198dbca"
+  },
+  "kernelspec": {
+   "display_name": "Python 3.6.2 ('ana_py36')",
+   "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.6.2"
+  },
+  "orig_nbformat": 4
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}

部分文件因为文件数量过多而无法显示