|
|
@@ -4,28 +4,6 @@
|
|
4
|
4
|
# In[1]:
|
|
5
|
5
|
|
|
6
|
6
|
|
|
7
|
|
-import os
|
|
8
|
|
-import array
|
|
9
|
|
-import math
|
|
10
|
|
-import pickle
|
|
11
|
|
-# import joblib
|
|
12
|
|
-import sys
|
|
13
|
|
-import argparse
|
|
14
|
|
-import pandas as pd
|
|
15
|
|
-import numpy as np
|
|
16
|
|
-import matplotlib.pyplot as plt
|
|
17
|
|
-from datetime import datetime
|
|
18
|
|
-from pprint import pprint
|
|
19
|
|
-import ssl
|
|
20
|
|
-from elasticsearch.connection import create_ssl_context
|
|
21
|
|
-from elasticsearch import Elasticsearch
|
|
22
|
|
-from elasticsearch import helpers
|
|
23
|
|
-import urllib3
|
|
24
|
|
-
|
|
25
|
|
-
|
|
26
|
|
-# In[3]:
|
|
27
|
|
-
|
|
28
|
|
-
|
|
29
|
7
|
import pandas as pd
|
|
30
|
8
|
import numpy as np
|
|
31
|
9
|
from mlxtend.preprocessing import TransactionEncoder
|
|
|
@@ -33,103 +11,6 @@ from mlxtend.frequent_patterns import association_rules, fpgrowth
|
|
33
|
11
|
from prefixspan import PrefixSpan
|
|
34
|
12
|
|
|
35
|
13
|
|
|
36
|
|
-# In[4]:
|
|
37
|
|
-
|
|
38
|
|
-
|
|
39
|
|
-ssl_context = create_ssl_context()
|
|
40
|
|
-ssl_context.check_hostname = False
|
|
41
|
|
-ssl_context.verify_mode = ssl.CERT_NONE
|
|
42
|
|
-
|
|
43
|
|
-
|
|
44
|
|
-# In[12]:
|
|
45
|
|
-
|
|
46
|
|
-
|
|
47
|
|
-es = Elasticsearch(hosts=[{'host': '223.194.92.152', 'port': 9200}], scheme="http",verify_certs=False, timeout=300, ssl_context=ssl_context, http_auth=("elasticsearch", "hadoop2019@!@#$"))
|
|
48
|
|
-urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
49
|
|
-
|
|
50
|
|
-
|
|
51
|
|
-# In[347]:
|
|
52
|
|
-
|
|
53
|
|
-
|
|
54
|
|
-######## 2020, 1 year ########
|
|
55
|
|
-######## There are no MTM data in 2018, 2019 ########
|
|
56
|
|
-
|
|
57
|
|
-body = {
|
|
58
|
|
- "size" : 10000,
|
|
59
|
|
- "query": {
|
|
60
|
|
- "range":{
|
|
61
|
|
- "TW_COLLECT_DT":{
|
|
62
|
|
- "gte":"2020-01-01T00:00:00.625+09:00",
|
|
63
|
|
- "lte":"2020-12-31T00:00:00.625+09:00" ################
|
|
64
|
|
- }
|
|
65
|
|
- }
|
|
66
|
|
- },
|
|
67
|
|
- "sort":[{
|
|
68
|
|
- "_id":"asc"
|
|
69
|
|
- }]
|
|
70
|
|
-}
|
|
71
|
|
-
|
|
72
|
|
-res = es.search(index = 'ts_data_accident-2020', body=body)
|
|
73
|
|
-data = res['hits']['hits']
|
|
74
|
|
-nxt=res["hit"]["hit"][-1]["sort"][0]
|
|
75
|
|
-total = res['hits']['total']
|
|
76
|
|
-
|
|
77
|
|
-# print(total)
|
|
78
|
|
-
|
|
79
|
|
-accident = []
|
|
80
|
|
-for da in data:
|
|
81
|
|
- att_type = da['_source']
|
|
82
|
|
- # att_type["POL_NM"]=att_type["SCEN_INFOS"][0]["POL_NM"]
|
|
83
|
|
- accident.append(att_type)
|
|
84
|
|
-
|
|
85
|
|
-# df = pd.DataFrame(accident,dtype=str)
|
|
86
|
|
-df_10000 = pd.DataFrame(accident)
|
|
87
|
|
-
|
|
88
|
|
-print(df_10000.head())
|
|
89
|
|
-
|
|
90
|
|
-
|
|
91
|
|
-# In[ ]:
|
|
92
|
|
-
|
|
93
|
|
-
|
|
94
|
|
-######## 2020, 1 year ########
|
|
95
|
|
-######## There are no MTM data in 2018, 2019 ########
|
|
96
|
|
-
|
|
97
|
|
-body = {
|
|
98
|
|
- "size" : 10000,
|
|
99
|
|
- "search_after":[nxt],
|
|
100
|
|
- "query": {
|
|
101
|
|
- "range":{
|
|
102
|
|
- "TW_COLLECT_DT":{
|
|
103
|
|
- "gte":"2020-01-01T00:00:00.625+09:00",
|
|
104
|
|
- "lte":"2020-12-31T00:00:00.625+09:00" ################
|
|
105
|
|
- }
|
|
106
|
|
- }
|
|
107
|
|
- },
|
|
108
|
|
- "sort":[{
|
|
109
|
|
- "_id":"asc"
|
|
110
|
|
- }]
|
|
111
|
|
-}
|
|
112
|
|
-
|
|
113
|
|
-res = es.search(index = 'ts_data_accident-2020', body=body)
|
|
114
|
|
-data = res['hits']['hits']
|
|
115
|
|
-nxt=res["hit"]["hit"][-1]["sort"][0]
|
|
116
|
|
-total = res['hits']['total']
|
|
117
|
|
-
|
|
118
|
|
-# print(total)
|
|
119
|
|
-
|
|
120
|
|
-accident = []
|
|
121
|
|
-for da in data:
|
|
122
|
|
- att_type = da['_source']
|
|
123
|
|
- # att_type["POL_NM"]=att_type["SCEN_INFOS"][0]["POL_NM"]
|
|
124
|
|
- accident.append(att_type)
|
|
125
|
|
-
|
|
126
|
|
-# df = pd.DataFrame(accident,dtype=str)
|
|
127
|
|
-df_20000 = pd.DataFrame(accident)
|
|
128
|
|
-
|
|
129
|
|
-print(df_20000.head())
|
|
130
|
|
-
|
|
131
|
|
-
|
|
132
|
|
-# In[348]:
|
|
133
|
14
|
|
|
134
|
15
|
|
|
135
|
16
|
df=df[['RISK_V2','INST_NM','DRULE_ATT_TYPE_CODE1','TW_ATT_IP','TW_ATT_PORT','TW_DMG_IP','TW_DMG_PORT','ACCD_DMG_PROTO_NM','TW_ATT_CT_NM','ACCD_FIND_MTD_CODE','DRULE_NM']].dropna()
|