def set_init_data(self,today_pre,today): revenue_list=self.get(True) if revenue_list is not None: if today_pre not in revenue_list: sqlres=DB_G.query("select sum(total_num) as num from ad_stats.ad_daily_report where sta_date>='%s' and sta_date<'%s' and ad_status=14 and campaign_id<1000000" % (today_pre,today)) qres=sqlres[0] m_ins=int(qres['num']) sqlres=DB_G.query("select sum(total_num) as num from ad_stats.ad_daily_report where sta_date>='%s' and sta_date<'%s' and ad_status=14" % (today_pre,today)) qres=sqlres[0] t_ins=int(qres['num']) sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s'" % (today_pre,today)) qres=sqlres[0] t_cov=qres['num'] t_rev=qres['rev'] sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s' and campaign_id<1000000" % (today_pre,today)) qres=sqlres[0] m_cov=qres['num'] m_rev=qres['rev'] m_cov_r=CUtils.rate_it(m_cov,m_ins) a_cov_r=CUtils.rate_it(t_cov-m_cov,t_ins-m_ins) revenue_list[today_pre]={"t_rev":t_rev,"a_rev":t_rev-m_rev,"m_rev":m_rev,"t_cov":t_cov,"a_cov":t_cov-m_cov,"m_cov":m_cov,"m_cov_r":m_cov_r,"a_cov_r":a_cov_r,"t_ins":t_ins,"a_ins":t_ins-m_ins,"m_ins":m_ins} else: revenue_list={} sqlres=DB_G.query("select sum(total_num) as num from ad_stats.ad_daily_report where sta_date>='%s' and sta_date<'%s' and ad_status=14 and campaign_id<1000000" % (today_pre,today)) qres=sqlres[0] m_ins=int(qres['num']) sqlres=DB_G.query("select sum(total_num) as num from ad_stats.ad_daily_report where sta_date>='%s' and sta_date<'%s' and ad_status=14" % (today_pre,today)) qres=sqlres[0] t_ins=int(qres['num']) sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s'" % (today_pre,today)) qres=sqlres[0] t_cov=qres['num'] t_rev=qres['rev'] sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s' and campaign_id<1000000" % (today_pre,today)) qres=sqlres[0] m_cov=qres['num'] m_rev=qres['rev'] m_cov_r=CUtils.rate_it(m_cov,m_ins) a_cov_r=CUtils.rate_it(t_cov-m_cov,t_ins-m_ins) revenue_list[today_pre]={"t_rev":t_rev,"a_rev":t_rev-m_rev,"m_rev":m_rev,"t_cov":t_cov,"a_cov":t_cov-m_cov,"m_cov":m_cov,"m_cov_r":m_cov_r,"a_cov_r":a_cov_r,"t_ins":t_ins,"a_ins":t_ins-m_ins,"m_ins":m_ins} self.set(revenue_list)
def get_report_data(self): report_data={} #revenue_list=DailyRevenue().get(True) revenue_hist={} for interval in xrange(15): timespan=timedelta(days=interval) histime=(datetime.strptime(self.report_date,"%Y-%m-%d")-timespan).strftime("%Y-%m-%d") histime_pre=(datetime.strptime(self.report_date,"%Y-%m-%d")-timespan-timedelta(days=1)).strftime("%Y-%m-%d") if histime_pre=="2015-12-06": break appid_report=DateReport_APPID(histime,self.app_id).get() if not "rob_conversion" in appid_report: appid_report["rob_conversion"]=0 appid_report["rob_rev"]=0 if "manual_rev" in appid_report: avg_rev=0; m_avg_rev=0; a_avg_rev=0; if appid_report["active_user"]>0: avg_rev=round(100000.0/appid_report["active_user"]*(float(appid_report["auto_rev"])+float(appid_report["manual_rev"])),1) m_avg_rev=round(100000.0/appid_report["active_user"]*float(appid_report["manual_rev"]),1) a_avg_rev=round(100000.0/appid_report["active_user"]*float(appid_report["auto_rev"]),1) revenue_hist[histime_pre]={"m_ins":appid_report["manual_install"],\ "m_cov":appid_report["manual_conversion"],\ "m_cov_r":CUtils.rate_it(appid_report["manual_conversion"],appid_report["manual_install"]),\ "m_rev":appid_report["manual_rev"],\ "m_100_rev":m_avg_rev,\ "a_ins":appid_report["auto_install"],\ "a_cov":appid_report["auto_conversion"],\ "a_cov_r":CUtils.rate_it(appid_report["auto_conversion"],appid_report["auto_install"]),\ "a_rev":appid_report["auto_rev"],\ "a_100_rev":a_avg_rev,\ "t_rev":appid_report["auto_rev"]+appid_report["manual_rev"],\ "avg_rev":avg_rev,\ "r_cov":appid_report["rob_conversion"],\ "r_rev":appid_report["rob_rev"]} else: revenue_hist[histime_pre]={"m_ins":0,"m_cov":0,"m_cov_r":0,"m_rev":0,"m_100_rev":0,"a_ins":0,"a_cov":0,"m_cov_r":0,"a_rev":0,"a_100_rev":0,"t_rev":0,"avg_rev":0,"r_cov":0,"r_rev":0} report_data['hist']=revenue_hist return report_data
def get_report_data(self): report_data={} today=self.report_date report_data["report_date"]=self.report_date if datetime.strptime(self.report_date,"%Y-%m-%d")<=datetime.today(): print today offers_dict=OfferActiveList(today).get() report_data["offers"]=[] for package_name,offer_info in offers_dict.items(): offer_info_out=offer_info offer_info_out['package_name']=package_name offer_info_out['cov_r']=CUtils.rate_it(offer_info_out['cov'],offer_info_out['ins']) offer_info_out['bid_avg']=CUtils.rate_it(offer_info_out['rev'],offer_info_out['cov']) report_data["offers"].append(offer_info_out) return report_data
def read_from_db(self,subwhere=None): today=self.date timespan=timedelta(days=1) today_date=datetime.strptime(today, "%Y-%m-%d") today_pre=(today_date-timespan).strftime("%Y-%m-%d") print today sqlres=DB_G.query("select sum(total_num) as num from ad_stats.ad_daily_report where sta_date>='%s' and sta_date<'%s' and ad_status=14 and campaign_id<1000000" % (today_pre,today)) qres=sqlres[0] m_ins=int(CUtils.none2zero(qres['num'])) sqlres=DB_G.query("select sum(total_num) as num from ad_stats.ad_daily_report where sta_date>='%s' and sta_date<'%s' and ad_status=14" % (today_pre,today)) qres=sqlres[0] t_ins=int(CUtils.none2zero(qres['num'])) sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s'" % (today_pre,today)) qres=sqlres[0] t_cov=int(CUtils.none2zero(qres['num'])) t_rev=CUtils.none2zero(qres['rev']) sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s' and campaign_id<1000000" % (today_pre,today)) qres=sqlres[0] m_cov=int(CUtils.none2zero(qres['num'])) m_rev=CUtils.none2zero(qres['rev']) sqlres=DB3_G.query("select count(DISTINCT(guid)) as num,sum(bid) as rev from adex_postback_partner where create_time>'%s' and create_time<'%s' and source_type=1" % (today_pre,today)) qres=sqlres[0] r_cov=int(CUtils.none2zero(qres['num'])) r_rev=CUtils.none2zero(qres['rev']) m_cov_r=CUtils.rate_it(m_cov,m_ins) a_cov_r=CUtils.rate_it(t_cov-m_cov,t_ins-m_ins) revenue_report={"t_rev":t_rev,"a_rev":t_rev-m_rev,"m_rev":m_rev,"r_rev":r_rev,"t_cov":t_cov,"a_cov":t_cov-m_cov,"m_cov":m_cov,"r_cov":r_cov,"m_cov_r":m_cov_r,"a_cov_r":a_cov_r,"t_ins":t_ins,"a_ins":t_ins-m_ins,"m_ins":m_ins} return revenue_report