ck 4 rokov pred
rodič
commit
884a919aa7
1 zmenil súbory, kde vykonal 82 pridanie a 43 odobranie
  1. 82 43
      data_manage/pitcher_panel.py

+ 82 - 43
data_manage/pitcher_panel.py

@@ -187,28 +187,67 @@ def get_channel_again_order_trend(channel,date,pitcher):
     json1=get_dict_list(key1,get_round(data))[0]
     # print(json1)
     sql2=f"""select
-               dateDiff(day,toDate('{date}'),date)+1 ddf,
-               count(1) c1,
-               sum(if(count>1,1,0)) c2,
-               sum(if(count>2,1,0)) c3,
-               sum(if(count>3,1,0)) c4,
-               sum(if(count>4,1,0)) c5,
-               sum(if(count>5,1,0)) c6
-        
+        1 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
+        from (select count(1) count
+            from order where channel='观云书海' and date='{date}'
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id,date) a
+union all
+select
+        2 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
         from (
-        
-        select count(1) count,date
-            from order where channel='{channel}' and date>='{date}' and date<=addDays(toDate('{date}'),6)
-                         and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id,date
-            ) a group by date"""
+        select count(1) count
+            from order where channel='观云书海' and date>='{date}' and date<=addDays(toDate('{date}'),1)
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id) a
+union all
+select
+        3 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
+        from (
+        select count(1) count
+            from order where channel='观云书海' and date>='{date}' and date<=addDays(toDate('{date}'),2)
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id) a
+union all
+select
+        4 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
+        from (
+        select count(1) count
+            from order where channel='观云书海' and date>='{date}' and date<=addDays(toDate('{date}'),3)
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id) a
+union all
+select
+        5 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
+        from (
+        select count(1) count
+            from order where channel='观云书海' and date>='{date}' and date<=addDays(toDate('{date}'),4)
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id) a
+union all
+select
+        6 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
+        from (
+        select count(1) count
+            from order where channel='观云书海' and date>='{date}' and date<=addDays(toDate('{date}'),5)
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id) a
+union all
+select
+        7 as ddf,count(1) c1,sum(if(count>1,1,0)) c2,sum(if(count>2,1,0)) c3,
+        sum(if(count>3,1,0)) c4,sum(if(count>4,1,0)) c5,sum(if(count>5,1,0)) c6
+        from (
+        select count(1) count
+            from order where channel='观云书海' and date>='{date}' and date<=addDays(toDate('{date}'),6)
+            and formatDateTime(reg_time,'%Y-%m-%d')='{date}'  group by user_id) a"""
 
     df=ck.execute(sql2)
     print(df)
     # 补全
-    xx=[i[0] for i in df]
-    for i in range(1,8):
-        if i not in xx:
-            df.append((i,0,0,0,0,0,0))
+    # xx=[i[0] for i in df]
+    # for i in range(1,8):
+    #     if i not in xx:
+    #         df.append((i,0,0,0,0,0,0))
     # 排序
     import operator
     df.sort(key=operator.itemgetter(0))
@@ -225,55 +264,55 @@ def get_channel_again_order_trend(channel,date,pitcher):
         d1["new"]=0
         d1["move"]=df[0][i+1]
         d1["now"]=d1["origin"]+d1['new']-d1["move"]
-        d1["follow_order_rate"]=round(d1["now"]/reg_user,2) if reg_user!=0 else 0
+        d1["follow_order_rate"]=round(d1["now"]/df[0][i],2) if df[0][i]!=0 else 0
         d['d1'] = d1
 
         d2={}
         d2["origin"] = d1["now"]
-        d2["new"] = df[1][i]
-        d2["move"] = df[1][i+1]
-        d2["now"] = d2["origin"] +d2['new']- d2["move"]
-        d2["follow_order_rate"] = round(d2["now"] / reg_user, 2) if reg_user!=0 else 0
+        d2["new"] = df[1][i]-df[0][i]
+        d2["move"] = df[1][i+1]-df[0][i+1]
+        d2["now"] = df[1][i]-df[1][i+1]
+        d2["follow_order_rate"] = round(d2["now"] /df[1][i], 2) if df[1][i]!=0 else 0
         d['d2'] = d2
 
         d3={}
         d3["origin"] = d2["now"]
-        d3["new"] = df[2][i]
-        d3["move"] =df[2][i+1]
-        d3["now"] = d3["origin"] +d3['new']- d3["move"]
-        d3["follow_order_rate"] = round(d3["now"] / reg_user, 2) if reg_user!=0 else 0
+        d3["new"] = df[2][i]-df[1][i]
+        d3["move"] =df[2][i+1]-df[1][i+1]
+        d3["now"] = df[2][i]-df[2][i+1]
+        d3["follow_order_rate"] = round(d3["now"] / df[2][i], 2) if df[2][i]!=0 else 0
         d['d3'] = d3
 
         d4={}
         d4["origin"] = d3["now"]
-        d4["new"] = df[3][i]
-        d4["move"] = df[3][i+1]
-        d4["now"] = d4["origin"] +d4['new']- d4["move"]
-        d4["follow_order_rate"] = round(d4["now"] / reg_user, 2) if reg_user!=0 else 0
+        d4["new"] = df[3][i]-df[2][i]
+        d4["move"] = df[3][i+1]-df[2][i+1]
+        d4["now"] = df[3][i]-df[3][i+1]
+        d4["follow_order_rate"] = round(d4["now"] / df[3][i], 2) if df[3][i]!=0 else 0
         d['d4'] = d4
 
         d5={}
         d5["origin"] = d4["now"]
-        d5["new"] = df[4][i]
-        d5["move"] = df[4][i+1]
-        d5["now"] = d5["origin"] +d5['new']- d5["move"]
-        d5["follow_order_rate"] = round(d4["now"] / reg_user, 2) if reg_user!=0 else 0
+        d5["new"] = df[4][i]-df[3][i]
+        d5["move"] = df[4][i+1]-df[3][i+1]
+        d5["now"] =  df[4][i]-df[4][i+1]
+        d5["follow_order_rate"] = round(d4["now"] / df[4][i], 2) if df[3][i]!=0 else 0
         d['d5'] = d5
 
         d6 = {}
         d6["origin"] = d5["now"]
-        d6["new"] = df[5][i]
-        d6["move"] = df[5][i+1]
-        d6["now"] = d6["origin"] +d6['new']- d6["move"]
-        d6["follow_order_rate"] = round(d6["now"] / reg_user, 2) if reg_user!=0 else 0
+        d6["new"] = df[5][i]-df[4][i]
+        d6["move"] = df[5][i+1]-df[4][i+1]
+        d6["now"] =  df[5][i]-df[5][i+1]
+        d6["follow_order_rate"] = round(d6["now"] / df[5][i], 2) if df[5][i]!=0 else 0
         d['d6'] = d6
 
         d7 = {}
         d7["origin"] = d6["now"]
-        d7["new"] = df[6][i]
-        d7["move"] = df[6][i+1]
-        d7["now"] = d7["origin"] +d7['new']- d7["move"]
-        d7["follow_order_rate"] = round(d7["now"] / reg_user, 2) if reg_user!=0 else 0
+        d7["new"] = df[6][i]-df[5][i]
+        d7["move"] = df[6][i+1]-df[5][i+1]
+        d7["now"] = df[6][i]-df[6][i+1]
+        d7["follow_order_rate"] = round(d7["now"] / df[6][i], 2) if df[6][i]!=0 else 0
         d['d7'] = d7
 
         li.append(d)
@@ -639,7 +678,7 @@ from order where  channel='{channel}' and dt>='{start}' group by formatDateTime(
             if x>=11:
                 i[x]=parse(y)
     print(data)
-    key=['date','channel','book','cost','reg_amount','roi','new_follow_user','new_follow_per_cost','order_user','order_count',
+    key=['channel','date','book','cost','reg_amount','roi','new_follow_user','new_follow_per_cost','order_user','order_count',
          'order_user_per_cost','d1','d2','d3','d4','d5','d6','d7','d8','d9','d10','d11','d12','d13','d14','d15','d16','d17','d18',
          'd19','d20','d21','d22','d23','d24','d25','d26','d27','d28','d29','d30','d31','d32','d33','d34','d35','d36','d37','d38',
          'd39','d40','d41','d42','d43','d44','d45','d46','d47','d48','d49','d50','d51','d52','d53','d54','d55','d56','d57','d58','d59',