def on_finish_entity(self, entity): super().on_finish_entity(entity) if not self.fetch_jq_timestamp: return # fill the timestamp for report published date the_data_list = get_data( data_schema=self.data_schema, provider=self.provider, entity_id=entity.id, order=self.data_schema.timestamp.asc(), return_type='domain', session=self.session, filters=[ self.data_schema.timestamp == self.data_schema.report_date, self.data_schema.timestamp >= to_pd_timestamp('2005-01-01') ]) if the_data_list: if self.data_schema == FinanceFactor: for the_data in the_data_list: self.fill_timestamp_with_jq(entity, the_data) else: df = get_finance_factor( entity_id=entity.id, columns=[ FinanceFactor.timestamp, FinanceFactor.report_date, FinanceFactor.id ], filters=[ FinanceFactor.timestamp != FinanceFactor.report_date, FinanceFactor.timestamp >= to_pd_timestamp('2005-01-01'), FinanceFactor.report_date >= the_data_list[0].report_date, FinanceFactor.report_date <= the_data_list[-1].report_date, ]) if pd_is_not_null(df): index_df(df, index='report_date', time_field='report_date') for the_data in the_data_list: if (df is not None) and ( not df.empty) and the_data.report_date in df.index: the_data.timestamp = df.at[the_data.report_date, 'timestamp'] self.logger.info( 'db fill {} {} timestamp:{} for report_date:{}'. format(self.data_schema, entity.id, the_data.timestamp, the_data.report_date)) self.session.commit() else: # self.logger.info( # 'waiting jq fill {} {} timestamp:{} for report_date:{}'.format(self.data_schema, # security_item.id, # the_data.timestamp, # the_data.report_date)) self.fill_timestamp_with_jq(entity, the_data)
def test_000001_finance_factor(): correct_timestamps = ['2018-09-30', '2018-06-30', '2018-03-31', '2017-12-31', '2017-09-30', '2017-06-30', '2017-03-31', '2016-12-31', '2016-09-30', '2016-06-30', '2016-03-31', '2015-12-31', '2015-09-30', '2015-06-30', '2015-03-31', '2014-12-31', '2014-09-30', '2014-06-30', '2014-03-31', '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31', '2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30', '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31', '2009-12-31', '2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30', '2008-06-30', '2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31', '2006-12-31', '2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30', '2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31', '2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30', '2002-06-30', '2002-03-31', '2001-12-31', '2001-09-30', '2001-06-30', '2001-03-31', '2000-12-31', '2000-06-30', '1999-12-31', '1999-06-30', '1998-12-31', '1998-06-30', '1997-12-31', '1997-06-30', '1996-12-31', '1996-06-30', '1995-12-31', '1995-06-30', '1994-12-31', '1994-06-30', '1993-12-31', '1993-06-30', '1992-12-31', '1991-12-31', '1990-12-31', '1989-12-31'] result = get_finance_factor(session=session, provider='eastmoney', return_type='domain', codes=['000001'], end_timestamp='2018-12-30', order=FinanceFactor.report_date.desc(), time_field='report_date') assert len(correct_timestamps) == len(result) timestamps = [to_time_str(item.report_date) for item in result] assert set(correct_timestamps) == set(timestamps) latest: FinanceFactor = result[0] assert latest.basic_eps == 1.14 assert latest.deducted_eps == 1.13 assert latest.diluted_eps == 1.14 assert latest.bps == 12.538 assert latest.capital_reserve_ps == 3.2886 assert latest.undistributed_profit_ps == 5.3566 assert latest.op_cash_flow_ps == -0.6587 assert latest.total_op_income == 86660000000 assert latest.net_profit == 20460000000 assert latest.deducted_net_profit == 20350000000 assert latest.op_income_growth_yoy == 0.0856 assert latest.net_profit_growth_yoy == 0.068 assert latest.deducted_net_profit_growth_yoy == 0.0636 assert latest.op_income_growth_qoq == 0.0336 assert latest.net_profit_growth_qoq == 0.0202 assert latest.deducted_net_profit_growth_qoq == 0.0168 assert latest.roe == 0.0948 assert latest.deducted_roe == 0.0943 assert latest.rota == 0.0062 assert latest.net_margin == 0.2360 assert latest.debt_asset_ratio == 0.9298 assert latest.em == 14.25 assert latest.equity_ratio == 13.25 assert latest.fi_total_deposit == 2130000000000 assert latest.fi_total_loan == 1920000000000 assert latest.fi_loan_deposit_ratio == 0.9004 assert latest.fi_npl_ratio == 0.0168 assert latest.fi_npl_provision_coverage == 1.6914
def test_000778_finance_factor(): correct_timestamps = [ '2018-09-30', '2018-06-30', '2018-03-31', '2017-12-31', '2017-09-30', '2017-06-30', '2017-03-31', '2016-12-31', '2016-09-30', '2016-06-30', '2016-03-31', '2015-12-31', '2015-09-30', '2015-06-30', '2015-03-31', '2014-12-31', '2014-09-30', '2014-06-30', '2014-03-31', '2013-12-31', '2013-09-30', '2013-06-30', '2013-03-31', '2012-12-31', '2012-09-30', '2012-06-30', '2012-03-31', '2011-12-31', '2011-09-30', '2011-06-30', '2011-03-31', '2010-12-31', '2010-09-30', '2010-06-30', '2010-03-31', '2009-12-31', '2009-09-30', '2009-06-30', '2009-03-31', '2008-12-31', '2008-09-30', '2008-06-30', '2008-03-31', '2007-12-31', '2007-09-30', '2007-06-30', '2007-03-31', '2006-12-31', '2006-09-30', '2006-06-30', '2006-03-31', '2005-12-31', '2005-09-30', '2005-06-30', '2005-03-31', '2004-12-31', '2004-09-30', '2004-06-30', '2004-03-31', '2003-12-31', '2003-09-30', '2003-06-30', '2003-03-31', '2002-12-31', '2002-09-30', '2002-06-30', '2002-03-31', '2001-12-31', '2001-06-30', '2000-12-31', '2000-06-30', '1999-12-31', '1999-06-30', '1998-12-31', '1998-06-30', '1997-12-31', '1997-06-30', '1996-12-31', '1995-12-31', '1994-12-31' ] result = get_finance_factor(session=session, provider='eastmoney', return_type='domain', codes=['000778'], end_timestamp='2018-12-30', order=FinanceFactor.report_date.desc(), time_field='report_date') assert len(correct_timestamps) == len(result) timestamps = [to_time_str(item.report_date) for item in result] assert set(correct_timestamps) == set(timestamps) latest: FinanceFactor = result[0] assert latest.basic_eps == 0.4537 assert latest.diluted_eps == 0.4537 assert latest.bps == 5.0919 assert latest.capital_reserve_ps == 2.1769 assert latest.undistributed_profit_ps == 1.8132 assert latest.op_cash_flow_ps == 1.0148 assert latest.total_op_income == 31710000000 assert latest.gross_profit == 5491000000 assert latest.net_profit == 1811000000 assert latest.deducted_net_profit == 1897000000 assert latest.op_income_growth_yoy == -0.1024 assert latest.net_profit_growth_yoy == 1.2404 assert latest.deducted_net_profit_growth_yoy == 1.4813 assert latest.op_income_growth_qoq == 0.0408 assert latest.net_profit_growth_qoq == 0.2143 assert latest.deducted_net_profit_growth_qoq == 0.2955 assert latest.roe == 0.0882 assert latest.rota == 0.0376 assert latest.gross_profit_margin == 0.1731 assert latest.net_margin == 0.0591 assert latest.advance_receipts_per_op_income == 0.1 assert latest.sales_net_cash_flow_per_op_income == 0.88 assert latest.op_net_cash_flow_per_op_income == 0.13 assert latest.actual_tax_rate == 0.2362 assert latest.current_ratio == 1 assert latest.quick_ratio == 0.84 assert latest.cash_flow_ratio == 0.17 assert latest.debt_asset_ratio == 0.5766 assert latest.em == 2.36 assert latest.equity_ratio == 1.43 assert latest.total_assets_turnover_days == 423.91 assert latest.inventory_turnover_days == 32.88 assert latest.receivables_turnover_days == 52.23 assert latest.total_assets_turnover == 0.64 assert latest.inventory_turnover == 8.21 assert latest.receivables_turnover == 5.17