public_analysis.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. from model.DateUtils import DateUtils
  2. from model.DataBaseUtils import *
  3. from model.log import logger
  4. from model.CommonUtils import *
  5. du = DateUtils()
  6. log = logger()
  7. def book_rank(start,end,book,page,page_size,order_by,order):
  8. db=MysqlUtils()
  9. op1=f" and book='{book}'" if book else ''
  10. op2 = f" and dt>='{start}' " if start else ''
  11. op3 = f" and dt<='{end}' " if end else ''
  12. op4 = f" order by {order_by} {order}" if order_by and order else ''
  13. sql=f"""select
  14. concat(min(dt),'~',max(dt)) date,
  15. pitcher,book,
  16. sum(cost) cost,
  17. sum(view_count) view_count,
  18. sum(click_count) click_count,
  19. round(sum(click_count)/sum(view_count),4) click_rate,
  20. round(sum(cost)*1000/sum(view_count),2) thousand_view_cost,
  21. sum(reg_order_user) reg_user,
  22. sum(reg_order_count) reg_count,
  23. sum(first_order_amount) first_amount,
  24. sum(reg_order_amount) reg_amount,
  25. round(sum(first_order_amount)/sum(cost),4) frist_roi,
  26. round(sum(reg_order_amount)/sum(cost),4) roi
  27. from dw_channel where 1=1 {op1} {op2} {op3} GROUP BY channel,book,pitcher
  28. {op4}"""
  29. print(sql)
  30. return getLimitData(db.dm,sql,page,page_size)