From fe5ea1a28491eb63ae950408808a5f40687b8cc4 Mon Sep 17 00:00:00 2001
From: Cricial <2911646453@qq.com>
Date: Tue, 24 Sep 2024 19:21:59 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0end=E5=A4=84=E7=90=86result?=
=?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=A1=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.idea/csv-editor.xml | 14 -----------
__pycache__/computation.cpython-38.pyc | Bin 1425 -> 1458 bytes
__pycache__/firm.cpython-38.pyc | Bin 11523 -> 11523 bytes
__pycache__/my_model.cpython-38.pyc | Bin 14682 -> 15574 bytes
computation.py | 6 ++---
main.py | 2 +-
my_model.py | 33 ++++++++++++++++++++++++-
7 files changed, 36 insertions(+), 19 deletions(-)
diff --git a/.idea/csv-editor.xml b/.idea/csv-editor.xml
index 29b9e5e..c176510 100644
--- a/.idea/csv-editor.xml
+++ b/.idea/csv-editor.xml
@@ -66,13 +66,6 @@
-
-
-
-
-
-
-
@@ -80,13 +73,6 @@
-
-
-
-
-
-
-
diff --git a/__pycache__/computation.cpython-38.pyc b/__pycache__/computation.cpython-38.pyc
index 7c87c9dd0d1100a22787bca18bec1f402e9dd429..7c722c738015d1fb2c5f882e776e0301c867149b 100644
GIT binary patch
delta 259
zcmbQpy@{JQl$V!_0SHdod`jE1k#{{KBmd;Rj1G*uCjVocqAF9%R>Qi0e<1@SLkV*Y
zTM1hh+XD8549!f8422VbG6Eo($@7^y7;jD1VAf-lpB&EY!OjRY&rMTs@-k*)elZ~X
z7Dq~ANoq-EZtAVcFPP<|C4gc@EFcNiqQt!P)LSgYC8-6sm{apoCd;rGs@!7D%}+_q
zxy6`S!~;?)0wQ=p>Y0m5^FX{}oymnPDqPGQj694Sj6#eYlV`KI$*F+Ufps7VkhUT=
aAi+ENKZ_)z^khlad`>1FAY@_WVFm!{2s~8)
delta 208
zcmdnQJ&~I?l$V!_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RcZ-}zmF}6=UUON_lZpD~CPmGMt
zi<`A|sbYgSY03@|sEW!WO622FEx;FOyt-@o8iefG$vYL`vNGr|H;^=pglSBhS}?zn
ztGPWZhSnTk$yGVja8Ud_F`rp-f5Hc>m;SsXQOx-|V942mQFk(j6-VK1(9
zX1AP`@B}H-$*V-fi5Z?XW+$D*B)Xt@g&U%wVPtC-OV1FX!RXHoN;`BXw=q|2^z)V8
z+%M%0G|m!`!?-MNGLVLGJG;3-F=w9(cv(;x1U1n}@Hj_FtYbH_#6-w@{KRIn?
z9Gdba9fy}}?MI@kWsn^ZGcB9c{a9>7EVb@)aVDgnd<{A`;`^BGId)bm`
zYU>U;XHFRkJ?w*{V!pCoG`Cmn@NnNbw&*!S?*RGYT%%>~6ptst89z;bC6#LyH`*5B
zGM2jyEb&NtRmpwbChYd@F}xsf*WL^GpEvHQW-)KIS0p=L>X9y`AM6*${!ogt
z(Y_7=*1Rjh@6xb0*SYa6#tw-OHyzmWV-hTT`0G$J!I{hEO03+#fR#+2G?IhE;+VFR
zy6TFydlM}AO~6k9C63-D*$73=Z;8Ka2YNnP`H)m5D>`CBSnxq%cW!7L2YnQP+ns+8
zkR!lB6mNDm_Ps{~J&O0JMB3!j^eo;}qFNeS4_OT4eD|c;|B=IZK8LIKJ~RKxIXqU#
zLA~n@W;KO35dC)${hjxff}k|U?WA;sRprW>
z)BKtk>e;BuK1${?JvSJ$a+`YttfqLMU7zikGbhBszCU7?mLd7&C%E#4au=194Ye;0IMz}>xV2zfJ@P?7r*MS?QIIEf!aVsinSWv43$j)
zWbFnrrt_IBKRqWO60SOv%os_V4~h1HeUEO0S`ttOkT;e*J8<#8d{g_U>A7o}gR~*}
S9SN|AC%_0e=TH`a*&
diff --git a/computation.py b/computation.py
index dba191f..1e847ff 100644
--- a/computation.py
+++ b/computation.py
@@ -2,7 +2,6 @@ import os
import datetime
from mesa import Model
-
from typing import TYPE_CHECKING
from my_model import MyModel
@@ -37,8 +36,9 @@ class Computation:
dct_sample_para = {'sample': sample_random,
'seed': sample_random.seed,
**dct_exp}
-
model = MyModel(dct_sample_para)
- for i in range(100):
+ for i in range(1):
model.step()
+ print(i, datetime.datetime.now())
+ model.end()
return False
diff --git a/main.py b/main.py
index 902ddfa..2ac6aa7 100644
--- a/main.py
+++ b/main.py
@@ -40,7 +40,7 @@ def do_computation(c_db):
exp = Computation(c_db)
while 1:
- time.sleep(random.uniform(0, 5))
+ time.sleep(random.uniform(0, 1))
is_all_done = exp.run()
if is_all_done:
break
diff --git a/my_model.py b/my_model.py
index 6b3d276..415826a 100644
--- a/my_model.py
+++ b/my_model.py
@@ -1,5 +1,6 @@
import json
from random import shuffle
+import platform
import networkx as nx
import pandas as pd
@@ -9,6 +10,7 @@ from mesa.datacollection import DataCollector
import numpy as np
from firm import FirmAgent
+from orm import db_session, Result
from product import ProductAgent
@@ -292,7 +294,8 @@ class MyModel(Model):
disrupted_products = [product for product in self.product_agents if product.unique_id in lst_product]
# 将公司与其受干扰的产品映射到字典中
- t_dct[firm] = disrupted_products
+ if firm is not None:
+ t_dct[firm] = disrupted_products
# 更新 self.dct_lst_init_disrupt_firm_prod 字典,存储公司及其受干扰的产品
self.dct_lst_init_disrupt_firm_prod = t_dct
@@ -478,3 +481,31 @@ class MyModel(Model):
# Increment the time step
self.t += 1
+
+ def end(self):
+ # print('/' * 20, 'output', '/' * 20)
+
+ qry_result = db_session.query(Result).filter_by(s_id=self.sample.id)
+ if qry_result.count() == 0:
+ lst_result_info = []
+ for firm in self.company_agents:
+ for prod, dct_status_supply in \
+ firm.dct_prod_up_prod_stat.items():
+ lst_is_normal = [stat == 'N' for stat, _
+ in dct_status_supply['p_stat']]
+ if not all(lst_is_normal):
+ # print(f"{firm.name} {prod.code}:")
+ # print(dct_status_supply['p_stat'])
+ for status, ts in dct_status_supply['p_stat']:
+ db_r = Result(s_id=self.sample.id,
+ id_firm=firm.unique_id,
+ id_product=prod.unique_id,
+ ts=ts,
+ status=status)
+ lst_result_info.append(db_r)
+ db_session.bulk_save_objects(lst_result_info)
+ db_session.commit()
+ self.sample.is_done_flag = 1
+ self.sample.computer_name = platform.node()
+ self.sample.stop_t = self.int_stop_ts
+ db_session.commit()