before proactive

This commit is contained in:
HaoYizhi 2023-06-04 18:43:49 +08:00
parent 228a066cf6
commit af0d1dd2c3
9 changed files with 33 additions and 31 deletions

4
.vscode/launch.json vendored
View File

@ -12,8 +12,8 @@
"console": "integratedTerminal",
"justMyCode": true,
"args": [
"--exp", "with_exp",
"--job", "24",
"--exp", "test",
"--reset_db", "True"
]
}
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 531 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

@ -1,7 +1,6 @@
import pandas as pd
import matplotlib.pyplot as plt
import networkx as nx
import math
plt.rcParams['font.sans-serif'] = 'SimHei'
@ -65,9 +64,11 @@ for _, row in count_dcp.iterrows():
pos = nx.nx_agraph.graphviz_layout(G_firm, prog="dot", args="")
node_label = nx.get_node_attributes(G_firm, 'Name')
# node_degree = dict(G_firm.out_degree())
# desensitize
node_label = {
# key: f"{node_label[key]} {node_degree[key]}"
key: f"{node_label[key]}"
# key: f"{node_label[key]}"
key: key
for key in node_label.keys()
}
node_size = list(nx.get_node_attributes(G_firm, 'Revenue_Log').values())
@ -87,7 +88,7 @@ nx.draw(G_firm,
node_size=node_size,
labels=node_label,
font_size=6,
width = 3,
width=3,
edge_color=colors,
edge_cmap=cmap,
edge_vmin=vmin,
@ -95,7 +96,7 @@ nx.draw(G_firm,
nx.draw_networkx_edge_labels(G_firm, pos, edge_label, font_size=6)
sm = plt.cm.ScalarMappable(cmap=cmap, norm=plt.Normalize(vmin=vmin, vmax=vmax))
sm._A = []
position=fig.add_axes([0.9, 0.05, 0.01, 0.3])
position = fig.add_axes([0.9, 0.05, 0.01, 0.3])
plt.colorbar(sm, fraction=0.01, cax=position)
# plt.savefig("analysis\\count_dcp_network")
plt.savefig("analysis\\count_dcp_network20230526_de")
plt.close()

Binary file not shown.

View File

@ -1 +1 @@
db_name_prefix: with_exp
db_name_prefix: test

View File

@ -75,7 +75,7 @@ class ControllerDB:
# list_dct = [{'133': ['1.4.4.1']}]
# list_dct = [{'2': ['1.1.3']}]
# list_dct = [{'135': ['1.3.2.1']}]
# list_dct = [{'79': ['2.1.3.4']}]
list_dct = [{'79': ['2.1.3.4']}]
# fill g_bom
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)

View File

@ -10,21 +10,20 @@ Firm['Code'] = Firm['Code'].astype('string')
Firm.fillna(0, inplace=True)
BomNodes = pd.read_csv('BomNodes.csv', index_col=0)
result = pd.read_sql(sql='select * from iiabmdb.not_test_result where ts > 0;',
result = pd.read_sql(sql='select * from iiabmdb_dissertation.not_test_result where ts > 0;',
con=engine)
lst_s_id = list(set(result['s_id'].to_list()))
for s_id in lst_s_id:
query = pd.read_sql(
sql=
f'select * from iiabmdb.not_test_result where ts = 0 and s_id = {s_id};',
sql=f'select * from iiabmdb_dissertation.not_test_result where ts = 0 and s_id = {s_id};',
con=engine)
result = pd.concat([result, query])
result.set_index('id', inplace=True)
result.sort_index(inplace=True)
result['id_firm'] = result['id_firm'].astype('string')
result.to_csv('analysis\\count.csv',
index=False,
encoding='utf-8-sig')
# result.to_csv('analysis\\count.csv',
# index=False,
# encoding='utf-8-sig')
print(result)
# G bom
@ -32,7 +31,7 @@ plt.rcParams['font.sans-serif'] = 'SimHei'
exp_id = 1
G_bom_str = pd.read_sql(
sql=f'select g_bom from iiabmdb.not_test_experiment where id = {exp_id};',
sql=f'select g_bom from iiabmdb_dissertation.not_test_experiment where id = {exp_id};',
con=engine)['g_bom'].tolist()[0]
G_bom = nx.adjacency_graph(json.loads(G_bom_str))
pos = nx.nx_agraph.graphviz_layout(G_bom, prog="twopi", args="")
@ -41,7 +40,8 @@ plt.figure(figsize=(12, 12), dpi=300)
nx.draw_networkx_nodes(G_bom, pos)
nx.draw_networkx_edges(G_bom, pos)
nx.draw_networkx_labels(G_bom, pos, labels=node_labels, font_size=6)
plt.savefig(f"analysis\\g_bom_exp_id_{exp_id}.png")
# plt.show()
# plt.savefig(f"analysis\\g_bom_exp_id_{exp_id}.png")
plt.close()
# G firm
@ -49,14 +49,14 @@ plt.rcParams['font.sans-serif'] = 'SimHei'
sample_id = 1
G_firm_str = pd.read_sql(
sql=f'select g_firm from iiabmdb.not_test_sample where id = {exp_id};',
sql=f'select g_firm from iiabmdb_dissertation.not_test_sample where id = {exp_id};',
con=engine)['g_firm'].tolist()[0]
G_firm = nx.adjacency_graph(json.loads(G_firm_str))
pos = nx.nx_agraph.graphviz_layout(G_firm, prog="twopi", args="")
node_label = nx.get_node_attributes(G_firm, 'Name')
node_degree = dict(G_firm.out_degree())
# desensitize
node_label = {
key: f"{node_label[key]} {node_degree[key]}"
key: key
for key in node_label.keys()
}
node_size = list(nx.get_node_attributes(G_firm, 'Revenue_Log').values())
@ -66,7 +66,8 @@ edge_label = {(n1, n2): label for (n1, n2, _), label in edge_label.items()}
plt.figure(figsize=(12, 12), dpi=300)
nx.draw(G_firm, pos, node_size=node_size, labels=node_label, font_size=6)
nx.draw_networkx_edge_labels(G_firm, pos, edge_label, font_size=4)
plt.savefig(f"analysis\\g_firm_sample_id_{exp_id}.png")
# plt.show()
plt.savefig(f"analysis\\g_firm_sample_id_{exp_id}_de.png")
plt.close()
# count firm product
@ -90,9 +91,9 @@ count_firm_prod.rename(columns={'Name': 'name_product'}, inplace=True)
count_firm_prod = count_firm_prod[[
'id_firm', 'name_firm', 'id_product', 'name_product', 'count'
]]
count_firm_prod.to_csv('analysis\\count_firm_prod.csv',
index=False,
encoding='utf-8-sig')
# count_firm_prod.to_csv('analysis\\count_firm_prod.csv',
# index=False,
# encoding='utf-8-sig')
print(count_firm_prod)
# count firm
@ -106,9 +107,9 @@ count_firm = pd.merge(count_firm,
count_firm.drop('Code', axis=1, inplace=True)
count_firm.sort_values('count', inplace=True, ascending=False)
count_firm = count_firm[['id_firm', 'Name', 'count']]
count_firm.to_csv('analysis\\count_firm.csv',
index=False,
encoding='utf-8-sig')
# count_firm.to_csv('analysis\\count_firm.csv',
# index=False,
# encoding='utf-8-sig')
print(count_firm)
# count product
@ -122,9 +123,9 @@ count_prod = pd.merge(count_prod,
count_prod.drop('Code', axis=1, inplace=True)
count_prod.sort_values('count', inplace=True, ascending=False)
count_prod = count_prod[['id_product', 'Name', 'count']]
count_prod.to_csv('analysis\\count_prod.csv',
index=False,
encoding='utf-8-sig')
# count_prod.to_csv('analysis\\count_prod.csv',
# index=False,
# encoding='utf-8-sig')
print(count_prod)
# DCP disruption causing probability
@ -187,5 +188,5 @@ count_dcp = count_dcp[[
'down_id_firm', 'down_name_firm', 'down_id_product', 'down_name_product',
'count'
]]
count_dcp.to_csv('analysis\\count_dcp.csv', index=False, encoding='utf-8-sig')
# count_dcp.to_csv('analysis\\count_dcp.csv', index=False, encoding='utf-8-sig')
print(count_dcp)