def get_dividend_financing_data(provider: Provider, sleep, desc, pc, lock, region, batch): # 除权概览表 DividendFinancing.record_data(provider=provider, share_para=(desc, pc, lock, True, region), sleeping_time=sleep, batch_size=batch)
def on_finish(self): last_year = str(now_pd_timestamp().year) codes = [item.code for item in self.entities] need_filleds = DividendFinancing.query_data( provider=self.provider, codes=codes, return_type="domain", session=self.session, filters=[DividendFinancing.rights_raising_fund.is_(None)], end_timestamp=last_year, ) for item in need_filleds: df = RightsIssueDetail.query_data( provider=self.provider, entity_id=item.entity_id, columns=[ RightsIssueDetail.timestamp, RightsIssueDetail.rights_raising_fund ], start_timestamp=item.timestamp, end_timestamp="{}-12-31".format(item.timestamp.year), ) if pd_is_not_null(df): item.rights_raising_fund = df["rights_raising_fund"].sum() self.session.commit() super().on_finish()
def on_finish(self): last_year = str(now_pd_timestamp(self.region).year) codes = [item.code for item in self.entities] need_filleds = DividendFinancing.query_data(region=self.region, provider=self.provider, codes=codes, return_type='domain', filters=[DividendFinancing.rights_raising_fund.is_(None)], end_timestamp=last_year) desc = RightsIssueDetail.__name__ + ": update relevant table" with tqdm(total=len(need_filleds), ncols=90, desc=desc, position=2, leave=True) as pbar: from sqlalchemy import func session = get_db_session(region=self.region, provider=self.provider, data_schema=self.data_schema) for item in need_filleds: result = RightsIssueDetail.query_data( region=self.region, provider=self.provider, entity_id=item.entity_id, start_timestamp=item.timestamp, end_timestamp="{}-12-31".format(item.timestamp.year), return_type='func', func=func.sum(RightsIssueDetail.rights_raising_fund)) if isinstance(result, (int, float)): item.rights_raising_fund = result session.commit() pbar.update() super().on_finish()
def test_000778_dividend_financing(): result = DividendFinancing.query_data( session=session, provider='eastmoney', return_type='domain', codes=['000778'], end_timestamp='2018-09-30', order=DividendFinancing.timestamp.desc()) assert len(result) == 22 latest: DividendFinancing = result[1] assert latest.timestamp == to_pd_timestamp('2017') assert latest.dividend_money == 598632026.4 assert latest.spo_issues == 347572815.0 assert latest.rights_issues == 0 assert latest.ipo_issues == 0
def test_000778_dividend_financing(): result = DividendFinancing.query_data( session=session, provider="eastmoney", return_type="domain", codes=["000778"], end_timestamp="2018-09-30", order=DividendFinancing.timestamp.desc(), ) assert len(result) == 22 latest: DividendFinancing = result[1] assert latest.timestamp == to_pd_timestamp("2017") assert latest.dividend_money == 598632026.4 assert latest.spo_issues == 347572815.0 assert latest.rights_issues == 0 assert latest.ipo_issues == 0
def on_finish(self): last_year = str(now_pd_timestamp(Region.CHN).year) codes = [item.code for item in self.entities] need_filleds = DividendFinancing.query_data( region=self.region, provider=self.provider, codes=codes, return_type='domain', session=self.session, filters=[DividendFinancing.spo_raising_fund.is_(None)], end_timestamp=last_year) for item in need_filleds: df = SpoDetail.query_data( region=self.region, provider=self.provider, entity_id=item.entity_id, columns=[SpoDetail.timestamp, SpoDetail.spo_raising_fund], start_timestamp=item.timestamp, end_timestamp="{}-12-31".format(item.timestamp.year)) if pd_is_not_null(df): item.spo_raising_fund = df['spo_raising_fund'].sum() self.session.commit() super().on_finish()
def test_dividend_financing(): try: DividendFinancing.record_data(provider='eastmoney', codes=SAMPLE_STOCK_CODES) except: assert False