no message
This commit is contained in:
3869
GA_Agent_0925/risk_ay/count.csv
Normal file
3869
GA_Agent_0925/risk_ay/count.csv
Normal file
File diff suppressed because it is too large
Load Diff
5438
GA_Agent_0925/risk_ay/count_dcp.csv
Normal file
5438
GA_Agent_0925/risk_ay/count_dcp.csv
Normal file
File diff suppressed because it is too large
Load Diff
198
GA_Agent_0925/risk_ay/count_firm.csv
Normal file
198
GA_Agent_0925/risk_ay/count_firm.csv
Normal file
@@ -0,0 +1,198 @@
|
||||
id_firm,count
|
||||
214851100,453
|
||||
3111603340,453
|
||||
70634828,453
|
||||
532328014,227
|
||||
303926772,227
|
||||
395736790,216
|
||||
340093034,214
|
||||
29223617,208
|
||||
3330358736,177
|
||||
25980377,177
|
||||
2337727838,80
|
||||
2326722141,80
|
||||
331545755,80
|
||||
3191869223,61
|
||||
2327605629,61
|
||||
2336923756,61
|
||||
591350440,60
|
||||
728969035,59
|
||||
517675473,59
|
||||
16116663,54
|
||||
16210433,53
|
||||
471121089,52
|
||||
2349179532,52
|
||||
2349705416,50
|
||||
1452048,5
|
||||
515770253,3
|
||||
6,2
|
||||
2349345463,2
|
||||
5971532,2
|
||||
1,2
|
||||
5849940,2
|
||||
2424229017,2
|
||||
495782506,2
|
||||
420984285,2
|
||||
300186799,2
|
||||
37873062,2
|
||||
3392803162,2
|
||||
33822284,2
|
||||
3312358902,2
|
||||
2728939,2
|
||||
3226664625,2
|
||||
79938367,2
|
||||
78979697,2
|
||||
14913649,2
|
||||
80158773,2
|
||||
8,2
|
||||
11807506,2
|
||||
169978927,2
|
||||
4607820,1
|
||||
441623911,1
|
||||
367669349,1
|
||||
410030851,1
|
||||
395739442,1
|
||||
808524154,1
|
||||
38852110,1
|
||||
385766513,1
|
||||
8114841,1
|
||||
382080545,1
|
||||
466148111,1
|
||||
805940123,1
|
||||
675729777,1
|
||||
863973253,1
|
||||
35404067,1
|
||||
3462551351,1
|
||||
3429928077,1
|
||||
3420061649,1
|
||||
340603317,1
|
||||
872394725,1
|
||||
9032550,1
|
||||
907433543,1
|
||||
950849442,1
|
||||
3378606529,1
|
||||
3362063909,1
|
||||
3358892171,1
|
||||
961017,1
|
||||
9620005,1
|
||||
862404568,1
|
||||
493002466,1
|
||||
668539285,1
|
||||
507827038,1
|
||||
676597455,1
|
||||
688155470,1
|
||||
664591135,1
|
||||
648145286,1
|
||||
644252759,1
|
||||
643954924,1
|
||||
640700057,1
|
||||
6333996,1
|
||||
618469306,1
|
||||
696450846,1
|
||||
71271700,1
|
||||
733657390,1
|
||||
3268669333,1
|
||||
5979030,1
|
||||
737770776,1
|
||||
742704658,1
|
||||
596368303,1
|
||||
59234665,1
|
||||
756272716,1
|
||||
758879940,1
|
||||
578803019,1
|
||||
562681526,1
|
||||
551856519,1
|
||||
543470507,1
|
||||
762501019,1
|
||||
771821595,1
|
||||
518871190,1
|
||||
778745779,1
|
||||
78576577,1
|
||||
598808584,1
|
||||
314846874,1
|
||||
3226232,1
|
||||
2333843479,1
|
||||
2310534839,1
|
||||
2311838590,1
|
||||
2314659369,1
|
||||
2316150629,1
|
||||
2323069589,1
|
||||
2326520912,1
|
||||
2326655246,1
|
||||
2326903290,1
|
||||
2334430421,1
|
||||
225958786,1
|
||||
2337952436,1
|
||||
2341774429,1
|
||||
23421122,1
|
||||
2344471631,1
|
||||
2345982379,1
|
||||
2347561020,1
|
||||
2348894245,1
|
||||
2348987001,1
|
||||
2310406050,1
|
||||
205960791,1
|
||||
3222821993,1
|
||||
1524794108,1
|
||||
1160497810,1
|
||||
1171244159,1
|
||||
1208566436,1
|
||||
1247902451,1
|
||||
1253552935,1
|
||||
13854344,1
|
||||
1444449910,1
|
||||
1476953321,1
|
||||
157087137,1
|
||||
203314437,1
|
||||
1605495,1
|
||||
1651310523,1
|
||||
16715045,1
|
||||
1698501971,1
|
||||
178452970,1
|
||||
189427260,1
|
||||
193814549,1
|
||||
197362120,1
|
||||
2349349655,1
|
||||
2349588257,1
|
||||
2349742676,1
|
||||
3145389278,1
|
||||
2978926070,1
|
||||
2989649772,1
|
||||
29954548,1
|
||||
3010580773,1
|
||||
3011933107,1
|
||||
3031766093,1
|
||||
3118140206,1
|
||||
3135349256,1
|
||||
3147958370,1
|
||||
2349746655,1
|
||||
10437056,1
|
||||
3151377261,1
|
||||
31732840,1
|
||||
3195293647,1
|
||||
3196033145,1
|
||||
3203980088,1
|
||||
3220049148,1
|
||||
3222664794,1
|
||||
2962064709,1
|
||||
29452962,1
|
||||
2944593082,1
|
||||
290636928,1
|
||||
2350443114,1
|
||||
2350544061,1
|
||||
2351592628,1
|
||||
2352421906,1
|
||||
2353389310,1
|
||||
2353549582,1
|
||||
2382390052,1
|
||||
2448521375,1
|
||||
247297633,1
|
||||
25685135,1
|
||||
26487185,1
|
||||
265133300,1
|
||||
26895145,1
|
||||
27042865,1
|
||||
280281699,1
|
||||
286335813,1
|
||||
28667694,1
|
||||
9746245,1
|
||||
|
259
GA_Agent_0925/risk_ay/count_firm_prod.csv
Normal file
259
GA_Agent_0925/risk_ay/count_firm_prod.csv
Normal file
@@ -0,0 +1,259 @@
|
||||
id_firm,id_product,count
|
||||
303926772,99,227
|
||||
532328014,99,227
|
||||
395736790,95,216
|
||||
340093034,95,214
|
||||
29223617,95,208
|
||||
2326722141,90,80
|
||||
2337727838,90,80
|
||||
331545755,90,80
|
||||
3191869223,91,61
|
||||
2327605629,94,61
|
||||
2336923756,91,61
|
||||
591350440,91,60
|
||||
728969035,93,59
|
||||
517675473,92,59
|
||||
16210433,92,53
|
||||
2349179532,93,52
|
||||
471121089,93,52
|
||||
2349705416,94,50
|
||||
16116663,92,50
|
||||
70634828,51,49
|
||||
3111603340,51,49
|
||||
214851100,51,49
|
||||
214851100,53,48
|
||||
214851100,52,48
|
||||
3111603340,52,48
|
||||
3111603340,53,48
|
||||
70634828,52,48
|
||||
70634828,53,48
|
||||
3111603340,54,46
|
||||
70634828,55,46
|
||||
214851100,54,46
|
||||
214851100,55,46
|
||||
214851100,50,46
|
||||
70634828,54,46
|
||||
70634828,50,46
|
||||
3111603340,50,46
|
||||
3111603340,55,46
|
||||
25980377,38,32
|
||||
3330358736,38,32
|
||||
3330358736,39,31
|
||||
3330358736,43,31
|
||||
25980377,43,31
|
||||
25980377,39,31
|
||||
25980377,40,29
|
||||
3330358736,40,29
|
||||
3111603340,47,29
|
||||
70634828,47,29
|
||||
214851100,47,29
|
||||
214851100,49,28
|
||||
70634828,44,28
|
||||
25980377,41,28
|
||||
70634828,49,28
|
||||
3111603340,44,28
|
||||
3111603340,45,28
|
||||
3111603340,46,28
|
||||
3111603340,48,28
|
||||
3111603340,49,28
|
||||
70634828,48,28
|
||||
70634828,45,28
|
||||
70634828,46,28
|
||||
214851100,48,28
|
||||
3330358736,41,28
|
||||
214851100,46,28
|
||||
214851100,45,28
|
||||
214851100,44,28
|
||||
25980377,42,26
|
||||
3330358736,42,26
|
||||
1452048,9,3
|
||||
515770253,9,3
|
||||
33822284,9,2
|
||||
3392803162,9,2
|
||||
5971532,9,2
|
||||
37873062,9,2
|
||||
79938367,9,2
|
||||
8,37,2
|
||||
420984285,16,2
|
||||
495782506,19,2
|
||||
80158773,69,2
|
||||
6,10,2
|
||||
1,10,2
|
||||
14913649,9,2
|
||||
16116663,11,2
|
||||
2350443114,74,1
|
||||
5979030,9,1
|
||||
562681526,25,1
|
||||
578803019,10,1
|
||||
5849940,26,1
|
||||
5849940,36,1
|
||||
16116663,9,1
|
||||
59234665,65,1
|
||||
596368303,12,1
|
||||
598808584,15,1
|
||||
543470507,8,1
|
||||
16116663,10,1
|
||||
618469306,9,1
|
||||
6333996,66,1
|
||||
640700057,9,1
|
||||
643954924,9,1
|
||||
644252759,61,1
|
||||
648145286,35,1
|
||||
664591135,9,1
|
||||
551856519,33,1
|
||||
1651310523,9,1
|
||||
675729777,10,1
|
||||
518871190,9,1
|
||||
35404067,9,1
|
||||
367669349,31,1
|
||||
193814549,33,1
|
||||
382080545,9,1
|
||||
385766513,24,1
|
||||
38852110,10,1
|
||||
189427260,9,1
|
||||
395739442,9,1
|
||||
410030851,27,1
|
||||
178452970,25,1
|
||||
441623911,79,1
|
||||
4607820,9,1
|
||||
466148111,9,1
|
||||
169978927,9,1
|
||||
493002466,9,1
|
||||
169978927,66,1
|
||||
507827038,10,1
|
||||
1698501971,9,1
|
||||
16715045,10,1
|
||||
668539285,17,1
|
||||
676597455,68,1
|
||||
2350544061,9,1
|
||||
808524154,9,1
|
||||
778745779,9,1
|
||||
78576577,9,1
|
||||
78979697,61,1
|
||||
78979697,74,1
|
||||
11807506,36,1
|
||||
1171244159,32,1
|
||||
1160497810,12,1
|
||||
805940123,72,1
|
||||
8114841,9,1
|
||||
762501019,9,1
|
||||
862404568,11,1
|
||||
863973253,9,1
|
||||
872394725,70,1
|
||||
9032550,34,1
|
||||
907433543,10,1
|
||||
950849442,9,1
|
||||
961017,23,1
|
||||
9620005,9,1
|
||||
771821595,31,1
|
||||
758879940,65,1
|
||||
688155470,30,1
|
||||
13854344,9,1
|
||||
696450846,9,1
|
||||
1605495,9,1
|
||||
157087137,73,1
|
||||
1524794108,9,1
|
||||
1476953321,10,1
|
||||
1452048,30,1
|
||||
1452048,11,1
|
||||
1444449910,20,1
|
||||
1253552935,9,1
|
||||
756272716,32,1
|
||||
1247902451,9,1
|
||||
1208566436,62,1
|
||||
70634828,7,1
|
||||
71271700,27,1
|
||||
11807506,9,1
|
||||
733657390,10,1
|
||||
737770776,34,1
|
||||
742704658,9,1
|
||||
3462551351,13,1
|
||||
3429928077,9,1
|
||||
3420061649,9,1
|
||||
340603317,9,1
|
||||
280281699,60,1
|
||||
286335813,72,1
|
||||
28667694,10,1
|
||||
290636928,9,1
|
||||
2348987001,9,1
|
||||
2944593082,9,1
|
||||
29452962,9,1
|
||||
2962064709,9,1
|
||||
2978926070,8,1
|
||||
2989649772,71,1
|
||||
29954548,18,1
|
||||
300186799,10,1
|
||||
300186799,11,1
|
||||
3010580773,9,1
|
||||
3011933107,9,1
|
||||
3031766093,9,1
|
||||
2348894245,11,1
|
||||
2347561020,9,1
|
||||
2345982379,67,1
|
||||
2728939,71,1
|
||||
2728939,63,1
|
||||
27042865,9,1
|
||||
247297633,18,1
|
||||
2351592628,10,1
|
||||
2352421906,17,1
|
||||
2353389310,15,1
|
||||
2353549582,23,1
|
||||
2382390052,9,1
|
||||
2424229017,26,1
|
||||
2424229017,9,1
|
||||
2448521375,25,1
|
||||
25685135,11,1
|
||||
26895145,9,1
|
||||
2349746655,10,1
|
||||
2349742676,33,1
|
||||
2349588257,10,1
|
||||
2349349655,9,1
|
||||
2349345463,59,1
|
||||
2349345463,35,1
|
||||
26487185,62,1
|
||||
265133300,9,1
|
||||
2344471631,9,1
|
||||
23421122,9,1
|
||||
2341774429,9,1
|
||||
2310534839,64,1
|
||||
3226664625,13,1
|
||||
3226664625,28,1
|
||||
3268669333,67,1
|
||||
3312358902,59,1
|
||||
3312358902,79,1
|
||||
2316150629,10,1
|
||||
2314659369,20,1
|
||||
2311838590,97,1
|
||||
2310406050,60,1
|
||||
3222821993,9,1
|
||||
225958786,11,1
|
||||
214851100,7,1
|
||||
3358892171,64,1
|
||||
3362063909,10,1
|
||||
3378606529,9,1
|
||||
205960791,63,1
|
||||
203314437,22,1
|
||||
197362120,15,1
|
||||
3226232,10,1
|
||||
3222664794,9,1
|
||||
2337952436,24,1
|
||||
3135349256,9,1
|
||||
2334430421,73,1
|
||||
2333843479,70,1
|
||||
10437056,9,1
|
||||
2326903290,9,1
|
||||
2326655246,9,1
|
||||
2326520912,10,1
|
||||
3111603340,7,1
|
||||
3118140206,68,1
|
||||
3145389278,9,1
|
||||
3220049148,9,1
|
||||
3147958370,12,1
|
||||
314846874,11,1
|
||||
3151377261,29,1
|
||||
31732840,29,1
|
||||
2323069589,9,1
|
||||
3195293647,28,1
|
||||
3196033145,9,1
|
||||
3203980088,10,1
|
||||
9746245,97,1
|
||||
|
73
GA_Agent_0925/risk_ay/count_prod.csv
Normal file
73
GA_Agent_0925/risk_ay/count_prod.csv
Normal file
@@ -0,0 +1,73 @@
|
||||
id_product,count
|
||||
95,638
|
||||
99,454
|
||||
90,240
|
||||
91,182
|
||||
93,163
|
||||
92,162
|
||||
51,147
|
||||
53,144
|
||||
52,144
|
||||
50,138
|
||||
55,138
|
||||
54,138
|
||||
94,111
|
||||
47,87
|
||||
44,84
|
||||
9,84
|
||||
49,84
|
||||
46,84
|
||||
45,84
|
||||
48,84
|
||||
38,64
|
||||
43,62
|
||||
39,62
|
||||
40,58
|
||||
41,56
|
||||
42,52
|
||||
10,23
|
||||
11,9
|
||||
15,3
|
||||
12,3
|
||||
33,3
|
||||
7,3
|
||||
25,3
|
||||
69,2
|
||||
74,2
|
||||
68,2
|
||||
70,2
|
||||
71,2
|
||||
72,2
|
||||
73,2
|
||||
19,2
|
||||
79,2
|
||||
8,2
|
||||
66,2
|
||||
18,2
|
||||
17,2
|
||||
16,2
|
||||
13,2
|
||||
97,2
|
||||
67,2
|
||||
32,2
|
||||
65,2
|
||||
27,2
|
||||
34,2
|
||||
35,2
|
||||
36,2
|
||||
37,2
|
||||
31,2
|
||||
30,2
|
||||
29,2
|
||||
28,2
|
||||
26,2
|
||||
64,2
|
||||
24,2
|
||||
23,2
|
||||
20,2
|
||||
59,2
|
||||
60,2
|
||||
62,2
|
||||
63,2
|
||||
61,2
|
||||
22,1
|
||||
|
80
GA_Agent_0925/risk_ay/risk_sum.py
Normal file
80
GA_Agent_0925/risk_ay/risk_sum.py
Normal file
@@ -0,0 +1,80 @@
|
||||
import pickle
|
||||
|
||||
from sqlalchemy import text
|
||||
from orm import engine, connection
|
||||
import pandas as pd
|
||||
import networkx as nx
|
||||
import json
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# Prepare data
|
||||
Firm = pd.read_csv("../../input_data/input_firm_data/firm_amended.csv")
|
||||
Firm['Code'] = Firm['Code'].astype('string')
|
||||
Firm.fillna(0, inplace=True)
|
||||
BomNodes = pd.read_csv('../../input_data/input_product_data/BomNodes.csv', index_col=0)
|
||||
|
||||
# SQL query
|
||||
with open('../../SQL_analysis_risk.sql', 'r') as f:
|
||||
str_sql = text(f.read())
|
||||
|
||||
result = pd.read_sql(sql=str_sql, con=connection)
|
||||
result.to_csv('count.csv', index=False, encoding='utf-8-sig')
|
||||
print(result)
|
||||
|
||||
# Count firm product
|
||||
count_firm_prod = result.value_counts(subset=['id_firm', 'id_product'])
|
||||
count_firm_prod.name = 'count'
|
||||
count_firm_prod = count_firm_prod.to_frame().reset_index()
|
||||
count_firm_prod.to_csv('count_firm_prod.csv', index=False, encoding='utf-8-sig')
|
||||
print(count_firm_prod)
|
||||
|
||||
# Count firm
|
||||
count_firm = count_firm_prod.groupby('id_firm')['count'].sum()
|
||||
count_firm = count_firm.to_frame().reset_index()
|
||||
count_firm.sort_values('count', inplace=True, ascending=False)
|
||||
count_firm.to_csv('count_firm.csv', index=False, encoding='utf-8-sig')
|
||||
print(count_firm)
|
||||
|
||||
# Count product
|
||||
count_prod = count_firm_prod.groupby('id_product')['count'].sum()
|
||||
count_prod = count_prod.to_frame().reset_index()
|
||||
count_prod.sort_values('count', inplace=True, ascending=False)
|
||||
count_prod.to_csv('count_prod.csv', index=False, encoding='utf-8-sig')
|
||||
print(count_prod)
|
||||
|
||||
# DCP disruption causing probability
|
||||
result_disrupt_ts_above_0 = result[result['ts'] > 0]
|
||||
print(result_disrupt_ts_above_0)
|
||||
result_dcp = pd.DataFrame(columns=[
|
||||
's_id', 'up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product'
|
||||
])
|
||||
|
||||
result_dcp_list = [] # 用列表收集数据,避免DataFrame逐行增长的问题
|
||||
for sid, group in result.groupby('s_id'):
|
||||
ts_start = max(group['ts'])
|
||||
while ts_start >= 1:
|
||||
ts_end = ts_start - 1
|
||||
while ts_end >= 0:
|
||||
up = group.loc[group['ts'] == ts_end, ['id_firm', 'id_product']]
|
||||
down = group.loc[group['ts'] == ts_start, ['id_firm', 'id_product']]
|
||||
for _, up_row in up.iterrows():
|
||||
for _, down_row in down.iterrows():
|
||||
result_dcp_list.append([sid] + up_row.tolist() + down_row.tolist())
|
||||
ts_end -= 1
|
||||
ts_start -= 1
|
||||
|
||||
# 转换为DataFrame
|
||||
result_dcp = pd.DataFrame(result_dcp_list, columns=[
|
||||
's_id', 'up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product'
|
||||
])
|
||||
|
||||
# 统计
|
||||
count_dcp = result_dcp.value_counts(
|
||||
subset=['up_id_firm', 'up_id_product', 'down_id_firm', 'down_id_product']
|
||||
).reset_index(name='count')
|
||||
|
||||
# 保存文件
|
||||
count_dcp.to_csv('count_dcp.csv', index=False, encoding='utf-8-sig')
|
||||
|
||||
# 输出结果
|
||||
print(count_dcp)
|
||||
Reference in New Issue
Block a user