|
@@ -585,9 +585,11 @@ def ad_cost_day_mp(account_id, access_token, st, et):
|
|
|
if i['cost'] > 0:
|
|
|
li.append(
|
|
|
(
|
|
|
- i['date'], i['ad_id'], i['adgroup_id'], i['cost'] / 100, i['view_count'],
|
|
|
+ i['date'], i['ad_id'], i['adgroup_id'],
|
|
|
+ i['cost'] / 100, i['view_count'],
|
|
|
i['valid_click_count'],
|
|
|
- i['official_account_follow_count'], i['order_count'], i['order_amount'] / 100, account_id,
|
|
|
+ i['official_account_follow_count'],
|
|
|
+ i['order_count'], i['order_amount'] / 100, account_id,
|
|
|
'MP'
|
|
|
)
|
|
|
)
|
|
@@ -601,15 +603,21 @@ def ad_cost_day_mp(account_id, access_token, st, et):
|
|
|
# exit()
|
|
|
if len(li) > 0:
|
|
|
# TODO:询问一下adgroup_id,campaign_id作用
|
|
|
+ # 对一下ad的数据
|
|
|
li_df = pandas.DataFrame(li)
|
|
|
li_df_g = li_df.groupby([0, 1, 9, 10])
|
|
|
li_new = []
|
|
|
+ adgroup_id_dict = {}
|
|
|
+ for index, group in li_df_g:
|
|
|
+ adgroup_id_dict[index] = ','.join([str(i) for i in group[2].tolist()])
|
|
|
for index, row in li_df_g.agg('sum').iterrows():
|
|
|
new_row = row.tolist()
|
|
|
- new_row = list(index[0:2]) + new_row[1:] + list(index[2:])
|
|
|
+ new_row = list(index[0:2]) + new_row + list(index[2:])
|
|
|
+ new_row[2] = adgroup_id_dict[index]
|
|
|
li_new.append(tuple(new_row))
|
|
|
logging.info(f"{account_id} have ad cost :{len(li_new)} ")
|
|
|
- db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', li_new)
|
|
|
+ db.quchen_text.executeMany('replace into ad_cost_day values(%s,%s,%s,%s,%s,'
|
|
|
+ '%s,%s,%s,%s,%s,%s)', li_new)
|
|
|
db.close()
|
|
|
|
|
|
|