From 84828272e2e55b3282ebb24b9e2f4c594bb70828 Mon Sep 17 00:00:00 2001 From: HaoYizhi Date: Sun, 2 Jul 2023 20:44:06 +0800 Subject: [PATCH] log status of every firm product in every time step + mysql --- __pycache__/controller_db.cpython-38.pyc | Bin 7908 -> 7908 bytes __pycache__/firm.cpython-38.pyc | Bin 8626 -> 8760 bytes __pycache__/model.cpython-38.pyc | Bin 12254 -> 13017 bytes __pycache__/orm.cpython-38.pyc | Bin 3728 -> 3700 bytes firm.py | 11 ++- model.py | 91 +++++++++++------------ orm.py | 3 +- test.ipynb | 40 ++++++++++ 8 files changed, 92 insertions(+), 53 deletions(-) diff --git a/__pycache__/controller_db.cpython-38.pyc b/__pycache__/controller_db.cpython-38.pyc index 7c1cb9727e6b758edf78cb826d2686189b6b25e2..84efc0861813012ebfd97bb19ca01540fb28f362 100644 GIT binary patch delta 19 ZcmaE2`^1(jl$V!_0SE$JHgesP0{}M~1r7iJ delta 19 ZcmaE2`^1(jl$V!_0SF>AHgesP0{}L-1o;2} diff --git a/__pycache__/firm.cpython-38.pyc b/__pycache__/firm.cpython-38.pyc index b90941022575c608169dade22bc0e4c60ead138c..c41df1570e4b0100fed6d737ecf5bffda9d235ca 100644 GIT binary patch delta 1751 zcmaJ?O>7%Q6yBM&owc{NH%{u>ZW7ypif&xmioYUg15KMWg~}9Y1q6cSdN-;QJ2qnz z5VD032PDLy(p)%jNGkOZ4k!>+a6qVMj(|X{gt*c>5^xIhy|t4%{8;kmH}Ac9`QGU`{KG#b&=CosF=gr+}_{l-qQwC1R9M_W!F*1CrJ)s}PX`HtZjDGhi?+u+@B zd$JRLpE+zryTQa`4wLWkW(VfVeynyu_xqJ3+z2cX!lhlZmMOV`wro zg?K?`4L5aCnR6nnP(@Sl2LS>3iIHNaylv!JRQ_b-SVaD5Or9B6K~Jx_t6~yXsB*ng zt+-+YdxinW0TYO^wij%Q>S~+l*ayTB`BJ!U9Yq2WcobG)`-kwBZopwPFD>un((+c+ zGVR^8g1i%*X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w_Ce=15>{~{fblR!{ygvOjt>3KB8=#=?QzofGrU%? zVkkRtOHlmc0`pjST~N=gY`nuyb{k6oT4PF+M5`K|+YcMKA9+4$rmc#QmvJ z1-TOq2J zO!8Obo!xR&R)~B{#!!fMOH+cxk8C!OD5)lXSti=r&A1}hJ60Y0i_l`Ye)3QI2YX%; z>tn)(FaP{vHanMbot+c>Q-aL%{fTGm@3>`rQ!s^B#wGsa!~j|0HKTRjU0|Hy|4!ui z2ZP#@Q!fGt6J-$yiLhN4&F&(MwfJHt{^xy}0Xr zcx$To)!f@2d}LRgB~q@J$wsYn5;ri`wW^b)D*n=jj@e1qSCOkj#vahm$j+qZ=3yO- z7qH>xYdtsT!ApAA6EfwS$*1x&FJ>GFrfNhl<;}FY2=3y-!rVEY8;rL8P-G_xQHcc6 zTnc)r8ng*%QPzGw_)mf^e|OU|xyknoT~aULoRJp@w!V((Uxct|I+X-(sZvt@oABGX z!v8z;2>BkL7#<_XxiuUgF~FXxo6eZ2)AKZwN}HxJb7IlVj9Owr7=k;%CA zILCiK+(%yEpAC=g7O9-_EXG4rt=2HVoIxMJ!>52r$+mN*R_SYw3(eZP8n%_W%Pmn0WD*L@&Et; diff --git a/__pycache__/orm.cpython-38.pyc b/__pycache__/orm.cpython-38.pyc index e9f3b53cc7ccae6dfe356d2e13ac7cbec5b301e9..03a14041e99c63abb358cd0d722294bac46de5e3 100644 GIT binary patch delta 225 zcmbOr`$dK?l$V!_0SHp_7N%Sh*vPkxQ{)y;W^sHfD-wFIj;G6{&!TKoH?E`2mOV9$S%6W1k%v)W O^E{rnjI4rOKp6lIX+87+ delta 253 zcmew&GeMRwl$V!_0SFol7o@NWZsc3WDH6q#Ssb5|pO+e+mXnxX!~v9zntXy&jWKHS zd(LT$b0*JYcbR;OOUIBug(-!-mnljhl{FQ{7EBdN;Y{I5VN2oeWsVX~;Ys0bVTck* z;R|NanQ{vMyi*lp5 zfQ*8o{FKt 0: for firm in self.a_lst_total_firms: for prod in firm.dct_prod_up_prod_stat.keys(): - status, ts = firm.dct_prod_up_prod_stat[prod]['status'][-1] - if status == 'D' and ts != 0: + status, _ = firm.dct_prod_up_prod_stat[prod]['status'][-1] + is_init = \ + firm in self.dct_lst_init_disrupt_firm_prod.keys() \ + and prod in self.dct_lst_init_disrupt_firm_prod[firm] + if status == 'D' and not is_init: print("not stop because", firm.name, prod.code) break else: @@ -422,45 +432,30 @@ class Model(ap.Model): def end(self): print('/' * 20, 'output', '/' * 20) - for firm in self.a_lst_total_firms: - is_size = False - for prod, dct_status_supply in firm.dct_prod_up_prod_stat.items(): - if len(dct_status_supply['status']) > 1: - is_size = True - print(f"{firm.name} {prod.code}:") - print(dct_status_supply['status']) - if is_size: - print(firm.size_stat) - - # qry_result = db_session.query(Result).filter_by(s_id=self.sample.id) - # if qry_result.count() == 0: - # lst_result_info = [] - # for t, dct in self.lst_dct_lst_disrupt_firm_prod: - # for firm, a_lst_product in dct.items(): - # for product in a_lst_product: - # db_r = Result(s_id=self.sample.id, - # id_firm=firm.code, - # id_product=product.code, - # ts=t, - # is_disrupted=True) - # lst_result_info.append(db_r) - # db_session.bulk_save_objects(lst_result_info) - # db_session.commit() - # for t, dct in self.lst_dct_lst_disrupt_firm_prod: - # for firm, a_lst_product in dct.items(): - # for product in a_lst_product: - # # only firm disrupted can be removed theoretically - # qry_f_p = db_session.query(Result).filter( - # Result.s_id == self.sample.id, - # Result.id_firm == firm.code, - # Result.id_product == product.code) - # if qry_f_p.count() == 1: - # qry_f_p.update({"is_removed": True}) - # 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() + 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.a_lst_total_firms: + for prod, dct_status_supply in \ + firm.dct_prod_up_prod_stat.items(): + lst_is_normal = [stat == 'N' for stat, _ + in dct_status_supply['status']] + if not all(lst_is_normal): + print(f"{firm.name} {prod.code}:") + print(dct_status_supply['status']) + for status, ts in dct_status_supply['status']: + db_r = Result(s_id=self.sample.id, + id_firm=firm.code, + id_product=prod.code, + 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() def draw_network(self): import matplotlib.pyplot as plt diff --git a/orm.py b/orm.py index a955bf1..649bff0 100644 --- a/orm.py +++ b/orm.py @@ -105,8 +105,7 @@ class Result(Base): id_firm = Column(String(10), nullable=False) id_product = Column(String(10), nullable=False) ts = Column(Integer, nullable=False) - is_disrupted = Column(Boolean, nullable=True) - is_removed = Column(Boolean, nullable=True) + status = Column(String(5), nullable=False) sample = relationship('Sample', back_populates='result', uselist=False) diff --git a/test.ipynb b/test.ipynb index 83d5656..e52427d 100644 --- a/test.ipynb +++ b/test.ipynb @@ -317,6 +317,46 @@ "print(27 / (4 * 3))\n", "print(27 / 4 / 3)" ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "for i in range(1,1):\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n" + ] + }, + { + "data": { + "text/plain": [ + "[6, 7, 8, 9, 10]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = list(range(1,11))\n", + "print(lst)\n", + "\n", + "lst[-5:]" + ] } ], "metadata": {