Commit c3b68a4d authored by rico.liu's avatar rico.liu

update

parent a87c2a18
......@@ -20,7 +20,7 @@ def get_test_data():
conn = pymssql.connect('123.56.115.207','zgcindex','jiayou2017+2018','ZI_DataBase')
cursor = conn.cursor()
#cursor.execute("select * from vw_electricity_source_price where ProductCode in "+ code_list +" and periods = (select top 1 periods from vw_entry_source_price order by periods desc)")
cursor.execute("select * from Product_Api_Data where batch = '20191224' and source = 'JD' and state = 4")
cursor.execute("select * from Product_Api_Data where batch = '2020-02-153' and state = 4")
test_df = pd.DataFrame([v for v in cursor.fetchall()],columns=[tuple[0] for tuple in cursor.description])
cursor.close()
......@@ -70,7 +70,7 @@ def get_db_data(zgc_category_code):
if db_file_name in file_list:
print('获取本地已存数据库数据')
db_attr_data = pd.read_csv(file_path,converters={'productcode':str,'SubCategoryCode':str,'BrandCode':str})
db_attr_data = pd.read_csv(file_path,converters={'ProductCode':str,'SubCategoryCode':str,'BrandCode':str})
db_attr_data = db_attr_data.rename(columns={"productcode": "ProductCode","productname":"ProductName","subtitle":"SubTitle","state":"State","value":"Value"})
return db_attr_data
......@@ -121,11 +121,14 @@ def match_with_db(params_df):
match_res['productName'] = [list(params_df[params_df['productId'] == _id]['productName'])[0] for _id in list(match_res['productId'])]
match_res['source'] = [list(params_df[params_df['productId'] == _id]['source'])[0] for _id in list(match_res['productId'])]
match_res['batch'] = [list(params_df[params_df['productId'] == _id]['batch'])[0] for _id in list(match_res['productId'])]
match_res['subcategorycode'] = [list(params_df[params_df['productId'] == _id]['subcategorycode'])[0] for _id in list(match_res['productId'])]
match_res.sort_values("subcategorycode",inplace=True)
match_code_list = []
match_name_list = []
#classify data
category_list = params_df['subcategorycode'].unique().tolist()
category_list = match_res['subcategorycode'].unique().tolist()
for category_code in category_list:
print('开始匹配'+category_code+'数据')
......@@ -136,7 +139,7 @@ def match_with_db(params_df):
#get brand list
brand_list = single_df['brandCode'].unique().tolist()
#get productid
productid_list = single_df['productId'].unique().tolist()
productid_list = match_res[match_res['subcategorycode']==category_code]['productId'].unique().tolist()
#get db data
db_attr_data = get_db_data(category_code)
......@@ -144,6 +147,7 @@ def match_with_db(params_df):
#match
for productid in productid_list:
#productid = '46262229631'
matched_productcode_list = []
matched_productname_list = []
......@@ -173,6 +177,7 @@ def match_with_db(params_df):
match_name_list.append(matched_productname_list)
match_res['match_code'] = match_code_list
match_res['match_name'] = match_name_list
del match_res['subcategorycode']
return match_res
......@@ -181,3 +186,4 @@ def match(df):
params_df = get_params_df(df)
res = match_with_db(params_df)
return res
......@@ -10,13 +10,14 @@ import match_program
import pandas as pd
import pymssql
import pymysql
'''
test data load
'''
def get_test_data():
'''
conn = pymssql.connect('123.56.115.207','zgcindex','jiayou2017+2018','ZI_DataBase')
cursor = conn.cursor()
#cursor.execute("select * from vw_electricity_source_price where ProductCode in "+ code_list +" and periods = (select top 1 periods from vw_entry_source_price order by periods desc)")
......@@ -25,6 +26,16 @@ def get_test_data():
cursor.close()
conn.close()
'''
conn = pymysql.connect('59.110.219.171','root','qwertyuiop1','product_chongqin')
cursor = conn.cursor()
#cursor.execute("select * from vw_electricity_source_price where ProductCode in "+ code_list +" and periods = (select top 1 periods from vw_entry_source_price order by periods desc)")
cursor.execute("select * from product")
test_df = pd.DataFrame([v for v in cursor.fetchall()],columns=[tuple[0] for tuple in cursor.description])
cursor.close()
conn.close()
return test_df
test_df = get_test_data()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment