Sfoglia il codice sorgente

广告消耗排行榜

DZW 4 anni fa
parent
commit
964fff46a6
3 ha cambiato i file con 82 aggiunte e 2 eliminazioni
  1. 54 1
      data_manage/public_analysis.py
  2. 25 0
      handlers/PublicAnalysisHandler.py
  3. 3 1
      urls.py

+ 54 - 1
data_manage/public_analysis.py

@@ -409,4 +409,57 @@ def image_rank(start, end, type,book, page, page_size, order_by, order):
             from dm_image_cost_day where 1=1 {op1} {op2} {op3} {op4} GROUP BY image_id,preview_url 
             {op5} """
 
-    return getLimitData(db, sql, page, page_size)
+    return getLimitData(db, sql, page, page_size)
+
+
+"""广告排行榜"""
+def advertisement_rank(start,end,ad_id,channel,pitcher,stage,site,type,page,page_size,order,order_by):
+    op1=f" and ad_id='{ad_id}' " if ad_id else ''
+    op2=f" and dt>='{start}' " if start else ''
+    op3=f" and dt<='{end}' " if end else ''
+    op4=f" and channel='{channel}' " if channel else ''
+    op5=f" and pitcher='{pitcher}' " if pitcher else ''
+    op6=f" and stage='{stage}'" if stage else ''
+    op7=f" and site='{site}'" if site else ''
+    op8=f" and type='{type}'" if type else ''
+    op9=f" order by {order_by} {order}" if order_by and order else ''
+    db =MysqlUtils().dm
+
+    sql=f"""select 
+    dt,channel,pitcher,stage,platform,book,ad_name,ad_id,`type`,site, cost,
+    view_count,
+    click_count,
+    follow_count,
+    round((cost/view_count)*1000,4) cpm, 
+    round(click_count/view_count,4) ctr,
+    round(cost/click_count,2) cpc,
+    order_count,
+    order_amount,
+    round(order_count/click_count,4)  order_rate,
+    round(order_amount/order_count,2) unit_price,
+    round(cost/order_count,2) order_cost,
+    round(order_amount/cost,4) roi,
+    title,
+    description,
+    image_id,
+    preview_url
+    from dw_ad_day
+    where 1=1 {op1} {op2} {op3} {op4} {op5} {op6} {op7} {op8} {op9}  
+    """
+    sum_sql = f"""select '总计' as pitcher,
+                      sum(cost) cost,
+                      sum(view_count) view_count,
+                      sum(click_count) click_count,
+                      sum(follow_count) follow_count,
+                      round((sum(cost)/sum(view_count))*1000,4) cpm,
+                      round(sum(click_count)/sum(view_count),4) ctr,
+                      round(sum(cost)/sum(click_count),2) cpc,
+                      sum(order_count),
+                      sum(order_amount),
+                      round(sum(order_count)/sum(click_count),4) order_rate,
+                      round(sum(order_amount)/sum(order_count),2) unit_price,
+                      round(sum(cost)/sum(order_count),2) order_cost,
+                      round(sum(order_amount)/sum(cost),4) ROI
+                      from ({sql}) a 
+      """
+    return getLimitSumData(db,sql,sum_sql, page, page_size)

+ 25 - 0
handlers/PublicAnalysisHandler.py

@@ -149,3 +149,28 @@ class ImageRank(BaseHandler):
             book = arg.get('book')
             data, total = image_rank(start, end, type,book, page, page_size, order_by, order)
             self.write_json(data=data, total=total)
+
+
+
+
+"""广告排行榜"""
+class AdvertisementRank(BaseHandler):
+    def post(self):
+        if not self._au:
+            self.write_fial(msg='auth error')
+        else:
+            arg = self.get_args()
+            start = arg.get("start")
+            end = arg.get("end")
+            ad_id = arg.get("ad_id")
+            page = arg.get("page",1)
+            page_size = arg.get("page_size")
+            order_by = arg.get("order_by", 'dt')
+            order = arg.get("order", 'desc')
+            channel = arg.get("channel")
+            pitcher = arg.get("pitcher")
+            stage = arg.get("stage")
+            site =arg.get("site")
+            type =arg.get("type")
+            data, total,total_data = advertisement_rank(start, end, ad_id, channel, pitcher, stage,site,type,page,page_size,order,order_by)
+            self.write_json(data=data, total=total,total_data=total_data)

+ 3 - 1
urls.py

@@ -40,6 +40,8 @@ urls = [
 
     # web hook
     (r'/api/git_hook/data_center', DataCenerHook),
-    (r'/api/git_hook/qc_web', QcWebHook)
+    (r'/api/git_hook/qc_web', QcWebHook),
 
+    #广告排行榜
+    (r'/data/advertisement/ad_rank',AdvertisementRank), #广告点击数
 ]