From 6fdf7b7a70d87e913af94f9f31ed8b4fda41d8b1 Mon Sep 17 00:00:00 2001 From: laixingyu Date: Sun, 6 Aug 2023 20:02:40 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=8C=E6=88=90=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transferIndustrySatistics_python.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/transferIndustrySatistics_python.py b/transferIndustrySatistics_python.py index 7b26175..220ba77 100644 --- a/transferIndustrySatistics_python.py +++ b/transferIndustrySatistics_python.py @@ -131,6 +131,18 @@ def getPeriodDiff(dbconfig,dbcursor,startDate,endDate): def getPreData(dbconfig,dbcursor,date): preDataMap = {} + sql_trade_period_qurey = 'select business_date,security_code,turnover,turnover5,turnover10,turnover20,turnover30,turnover_sort,turnover5_sort,turnover10_sort,turnover20_sort,turnover30_sort,turnover_ratio,turnover5_ratio,turnover10_ratio,turnover20_ratio,turnover30_ratio,rise_number,rise5_number,rise10_number,rise20_number,rise30_number,losses_number,losses5_number,losses10_number,losses20_number,losses30_number,flat_number,flat5_number,flat10_number,flat20_number,flat30_number from dong_cai_secondary_industry_statistics where business_date = %s' + dbcursor.execute(sql_trade_period_qurey,date) + datas = dbcursor.fetchall() + for row in datas: + business_date,security_code,turnover,turnover5,turnover10,turnover20,turnover30,turnover_sort,turnover5_sort,turnover10_sort,turnover20_sort,turnover30_sort,turnover_ratio,turnover5_ratio,turnover10_ratio,turnover20_ratio,turnover30_ratio,rise_number,rise5_number,rise10_number,rise20_number,rise30_number,losses_number,losses5_number,losses10_number,losses20_number,losses30_number,flat_number,flat5_number,flat10_number,flat20_number,flat30_number = row + preDataMap[security_code] = {'business_date':business_date,'security_code':security_code, + 'turnover':turnover,'turnover5':turnover5,'turnover10':turnover10,'turnover20':turnover20,'turnover30':turnover30, + 'turnover_sort':turnover_sort,'turnover5_sort':turnover5_sort,'turnover10_sort':turnover10_sort,'turnover20_sort':turnover20_sort,'turnover30_sort':turnover30_sort, + 'turnover_ratio':turnover_ratio,'turnover5_ratio':turnover5_ratio,'turnover10_ratio':turnover10_ratio,'turnover20_ratio':turnover20_ratio,'turnover30_ratio':turnover30_ratio, + 'rise_number':rise_number,'rise5_number':rise5_number,'rise10_number':rise10_number,'rise20_number':rise20_number,'rise30_number':rise30_number, + 'losses_number':losses_number,'losses5_number':losses5_number,'losses10_number':losses10_number,'losses20_number':losses20_number,'losses30_number':losses30_number, + 'flat_number':flat_number,'flat5_number':flat5_number,'flat10_number':flat10_number,'flat20_number':flat20_number,'flat30_number':flat30_number} return preDataMap @@ -234,8 +246,9 @@ def main(): print('start transfer statistics ',trading_date , ' data.') # 获取前一日数据 - preIndustryDataMap = getPreData(db_a_conn,db_a_cursor,period_trading_dateMap['1']) - + prevIndustryDataMap = getPreData(db_a_conn,db_a_cursor,period_trading_dateMap['1']) + hasPrevIndustryData = len(prevIndustryDataMap) + # 获取多日成交额汇总数据 turnOver5 = getPeriodTurnOver(db_a_conn,db_a_cursor,period_trading_dateMap['5'],trading_date) for data in turnOver5: @@ -279,7 +292,7 @@ def main(): security_name = name turnover = amount turnover_sort = sortIndex - turnover_change = '' #todo 从交易数据中获取然后计算 ,一日、多日 + turnover_change = turnover - prevIndustryDataMap[code]['turnover'] if hasPrevIndustryData else turnover #todo 从交易数据中获取然后计算 ,一日、多日 sortIndex +=1 rise_number = risenum flat_number = flatnum @@ -297,25 +310,25 @@ def main(): # turnover_ratio_change = '' #todo # turnover_sort_change = ''#todo turnover5 = turnOver5[code]['turnover'] #todo - turnover5_change = '' #todo + turnover5_change = turnover5 - prevIndustryDataMap[code]['turnover5'] if hasPrevIndustryData else turnover5 #todo turnover5_ratio = (turnover5*Decimal('100.00') )/ turnOver5[code]['total'] #todo turnover5_ratio_change = '' #todo turnover5_sort = '' #todo turnover5_sort_change = ''#todo turnover10 = turnOver10[code]['turnover'] #todo - turnover10_change = '' #todo + turnover10_change = turnover10 - prevIndustryDataMap[code]['turnover10'] if hasPrevIndustryData else turnover10 #todo turnover10_ratio = (turnover10*Decimal('100.00') )/ turnOver10[code]['total'] #todo turnover10_ratio_change = '' #todo turnover10_sort = '' #todo turnover10_sort_change = ''#todo turnover20 = turnOver20[code]['turnover'] #todo - turnover20_change = '' #todo + turnover20_change = turnover20 - prevIndustryDataMap[code]['turnover20'] if hasPrevIndustryData else turnover20 #todo turnover20_ratio = (turnover20*Decimal('100.00') )/ turnOver20[code]['total'] #todo turnover20_ratio_change = '' #todo turnover20_sort = '' #todo turnover20_sort_change = ''#todo turnover30 = turnOver30[code]['turnover'] #todo - turnover30_change = '' #todo + turnover30_change = turnover30 - prevIndustryDataMap[code]['turnover30'] if hasPrevIndustryData else turnover30 #todo turnover30_ratio = (turnover30*Decimal('100.00') )/ turnOver30[code]['total'] #todo turnover30_ratio_change = '' #todo turnover30_sort = '' #todo