def init(datetime): global articles,products,order_product_counts,cart_product_counts,tags product_df=da.getDataFrame('product',datetime) article_df=da.getDataFrame('article',datetime) tags_df=da.getDataFrame('product_list',datetime) products=da.rowGroupCount(product_df[pd.notnull(product_df['device_id'])],'values') articles=da.rowGroupCount(article_df[pd.notnull(article_df['device_id'])],'values') tags=da.rowGroupCount(tags_df[pd.notnull(tags_df['device_id'])],'values') order_product_counts=da.getOrderCounts(datetime) cart_product_counts=da.getCartCount(datetime)
def init(datetime): global articles, products, order_product_counts, cart_product_counts, tags product_df = da.getDataFrame('product', datetime) article_df = da.getDataFrame('article', datetime) tags_df = da.getDataFrame('product_list', datetime) products = da.rowGroupCount( product_df[pd.notnull(product_df['device_id'])], 'values') articles = da.rowGroupCount( article_df[pd.notnull(article_df['device_id'])], 'values') tags = da.rowGroupCount(tags_df[pd.notnull(tags_df['device_id'])], 'values') order_product_counts = da.getOrderCounts(datetime) cart_product_counts = da.getCartCount(datetime)
def init(datetime): global articles,products,order_product_counts,cart_product_counts,tags,\ product_unique_visitor,article_unique_visitor,tag_unique_visitor product_df=da.getDataFrame('product',datetime) article_df=da.getDataFrame('article',datetime) tags_df=da.getDataFrame('product_list',datetime) products=da.rowGroupCount(product_df,'values') articles=da.rowGroupCount(article_df,'values') tags=da.rowGroupCount(tags_df,'values') order_product_counts=da.getOrderCounts(datetime) cart_product_counts=da.getCartCount(datetime) product_unique_visitor=da.getDfUniqueDevice(product_df,'values') article_unique_visitor=da.getDfUniqueDevice(article_df,'values') tag_unique_visitor=da.getDfUniqueDevice(tags_df,'values')
def init(datetime): global articles,products,order_product_counts,cart_product_counts,tags,\ product_unique_visitor,article_unique_visitor,tag_unique_visitor product_df = da.getDataFrame('product', datetime) article_df = da.getDataFrame('article', datetime) tags_df = da.getDataFrame('product_list', datetime) products = da.rowGroupCount(product_df, 'values') articles = da.rowGroupCount(article_df, 'values') tags = da.rowGroupCount(tags_df, 'values') order_product_counts = da.getOrderCounts(datetime) cart_product_counts = da.getCartCount(datetime) product_unique_visitor = da.getDfUniqueDevice(product_df, 'values') article_unique_visitor = da.getDfUniqueDevice(article_df, 'values') tag_unique_visitor = da.getDfUniqueDevice(tags_df, 'values')
def getShopStatics(datetime): print datetime data = '' result = da.getUniqueDevice(datetime, 'home', 'app_id') result_dict = dict((key, result[key]) for key in result.keys()) sorted_dict = OrderedDict( sorted(result_dict.items(), key=lambda item: item[1], reverse=True)) app_names = db.getAppNames(sorted_dict.keys()[:LIMIT]) device_df = da.getDataFrame('device', datetime) new_devices = da.getUniqueDevice(datetime, 'device', 'app_id') articles = da.getApiCountByApp(datetime, 'article') products = da.getApiCountByApp(datetime, 'product') products_lists = da.getApiCountByApp(datetime, 'product_list') orders = da.getApiCountByApp(datetime, 'order') carts = da.getApiCountByApp(datetime, 'cart') data += pr_format.format('app_id', 'active_user', 'new_user', 'article', 'product', 'product_list', 'cart', 'order') for key, value in sorted_dict.items()[:LIMIT]: data+=pr_format.format(app_names.get(key,''),value,new_devices.get(key,0),\ articles.get(key,0),products.get(key,0),\ products_lists.get(key,0), carts.get(key,0),\ orders.get(key,0)) data += 'sum\n' data+=pr_format.format(len(sorted_dict),sum(sorted_dict.values()),sum(new_devices),\ sum(articles),sum(products),sum(products_lists),\ sum(carts),sum(orders)) da.write2CsvFile(datetime, 'shop', data)
def getShopStatics(datetime): print datetime data='' result=da.getUniqueDevice(datetime,'home','app_id') result_dict=dict((key,result[key])for key in result.keys()) sorted_dict=OrderedDict(sorted(result_dict.items(),key=lambda item:item[1],reverse=True)) app_names=db.getAppNames(sorted_dict.keys()[:LIMIT]) device_df=da.getDataFrame('device',datetime) new_devices=da.getUniqueDevice(datetime,'device','app_id') articles=da.getApiCountByApp(datetime,'article') products=da.getApiCountByApp(datetime,'product') products_lists=da.getApiCountByApp(datetime,'product_list') orders=da.getApiCountByApp(datetime,'order') carts=da.getApiCountByApp(datetime,'cart') data+=pr_format.format('app_id','active_user','new_user','article','product','product_list','cart','order') for key,value in sorted_dict.items()[:LIMIT]: data+=pr_format.format(app_names.get(key,''),value,new_devices.get(key,0),\ articles.get(key,0),products.get(key,0),\ products_lists.get(key,0), carts.get(key,0),\ orders.get(key,0)) data+='sum\n' data+=pr_format.format(len(sorted_dict),sum(sorted_dict.values()),sum(new_devices),\ sum(articles),sum(products),sum(products_lists),\ sum(carts),sum(orders)) da.write2CsvFile(datetime,'shop',data)
def save_data(datetime,limit): product_view_counts=da.rowGroupCount(da.getDataFrame('product',datetime),'values') order_product_counts=da.getOrderCounts(datetime) cart_product_counts=da.getCartCount(datetime) result=da.rowGroupCount(da.getDataFrame('article',datetime),'values') article_ids=result.keys()[:limit] for article_id in article_ids: product_ids=api_util.getProductIdInArticle(article_id) if product_ids: for product_id in product_ids: db.save_article_data(datetime,id_util.decode_article(article_id),result[article_id],product_id,\ da.getProductCounts(product_view_counts,id_util.encode_product(product_id)),\ da.getProductCounts(cart_product_counts,id_util.encode_product(product_id)),\ da.getProductCounts(order_product_counts,id_util.encode_product(product_id))) else: db.save_article_data(datetime,id_util.decode_article(article_id),result[article_id],0,0,0,0)
def every_report(date): product_df=da.getDataFrame('product',date) print_patter='{5},{0},{1},{2},{3},{4}' print print_patter.format('pv','order_all','order_rate','dealed_order','avg_order_price','date') datetime = dt.datetime.strptime(date,'%Y%m%d') order_all=db.get_all_order_sum(datetime) order_dealed=db.get_dealed_order_sum(datetime) print print_patter.format(len(product_df),order_all,\ order_dealed/float(order_all),order_dealed,\ db.avg_dealed_order_price(datetime,datetime),date)
def article_statics(datetime,limit): print datetime product_view_counts=da.rowGroupCount(da.getDataFrame('product',datetime),'values') order_product_counts=da.getOrderCounts(datetime) cart_product_counts=da.getCartCount(datetime) result=da.rowGroupCount(da.getDataFrame('article',datetime),'values') article_ids=result[:limit].keys() article_unique_device_counts=da.getUniqueDevice(datetime,'article','values') for article_id in article_ids: product_ids=api_util.getProductIdInArticle(article_id) unique_device_num=article_unique_device_counts.get(article_id,0) if product_ids: for product_id in product_ids: print show_format.format(id_util.decode_article(article_id),result[article_id],product_id,\ da.getProductCounts(product_view_counts,id_util.encode_product(product_id)),\ da.getProductCounts(cart_product_counts,id_util.encode_product(product_id)),\ da.getProductCounts(order_product_counts,id_util.encode_product(product_id)),\ unique_device_num) else: print show_format.format(id_util.decode_article(article_id),result[article_id],0,0,0,0,unique_device_num)
def every_report(date): product_df = da.getDataFrame('product', date) print_patter = '{5},{0},{1},{2},{3},{4}' print print_patter.format('pv', 'order_all', 'order_rate', 'dealed_order', 'avg_order_price', 'date') datetime = dt.datetime.strptime(date, '%Y%m%d') order_all = db.get_all_order_sum(datetime) order_dealed = db.get_dealed_order_sum(datetime) print print_patter.format(len(product_df),order_all,\ order_dealed/float(order_all),order_dealed,\ db.avg_dealed_order_price(datetime,datetime),date)
def product_statics(datetime,limit): print datetime data='' product_df=da.getDataFrame('product',datetime) condition=pd.notnull(product_df['device_id']) result=da.rowGroupCount(product_df[condition],'values') order_product_counts=da.getOrderCounts(datetime) cart_product_counts=da.getCartCount(datetime) unique_visitor=da.getUniqueDevice(datetime,'product','values') product_ids=result.keys() data+=pr_format.format('date','product_id','product_pv','cart_count','order_count','unique_visitor') for product_id in product_ids: data+=pr_format.format(datetime,id_util.decode_product(product_id),result.get(product_id,0),\ cart_product_counts.get(product_id,0),\ order_product_counts.get(product_id,0),\ unique_visitor.get(product_id,0)) data+=all_pr_format.format('sum',len(result.keys()),sum(result),\ sum(cart_product_counts),\ sum(order_product_counts),\ da.getActiveUser(datetime),\ da.getAllUser(datetime),\ len(product_df['device_id'].unique())) da.write2CsvFile(datetime,'product',data)
def product_statics(datetime, limit): print datetime data = '' product_df = da.getDataFrame('product', datetime) condition = pd.notnull(product_df['device_id']) result = da.rowGroupCount(product_df[condition], 'values') order_product_counts = da.getOrderCounts(datetime) cart_product_counts = da.getCartCount(datetime) unique_visitor = da.getUniqueDevice(datetime, 'product', 'values') product_ids = result.keys() data += pr_format.format('date', 'product_id', 'product_pv', 'cart_count', 'order_count', 'unique_visitor') for product_id in product_ids: data+=pr_format.format(datetime,id_util.decode_product(product_id),result.get(product_id,0),\ cart_product_counts.get(product_id,0),\ order_product_counts.get(product_id,0),\ unique_visitor.get(product_id,0)) data+=all_pr_format.format('sum',len(result.keys()),sum(result),\ sum(cart_product_counts),\ sum(order_product_counts),\ da.getActiveUser(datetime),\ da.getAllUser(datetime),\ len(product_df['device_id'].unique())) da.write2CsvFile(datetime, 'product', data)
def getCartedDeviceIds(datetime): cart_df=da.getDataFrame('cart',datetime) return cart_df['device_id'].unique()
def product_list_record(date): list_df=da.getDataFrame('product_list',str(date).replace('-','')) tags=da.rowGroupCount(list_df,'values') for tag in tags.keys()[:10]: print tag,tags.get(tag,0)
def getOrderedDeviceIds(datetime): order_df = da.getDataFrame('order', datetime) return order_df['device_id'].unique()
def getNewUser(date): device_df = da.getDataFrame('device', date) return device_df['device_id'].unique()
def getCartedDeviceIds(datetime): cart_df = da.getDataFrame('cart', datetime) return cart_df['device_id'].unique()
def init(datetime): global list_df,like_df,follow_df,create_df,view_df,reply_df,privateMsg_df list_df,view_df,create_df,privateMsg_df,reply_df,like_df,follow_df=map(lambda x:da.getDataFrame(x,datetime),\ ['topic_list','topic_view','topic_create','private_msg','reply','topic_like','topic_follow'])
def getOrderedDeviceIds(datetime): order_df=da.getDataFrame('order',datetime) return order_df['device_id'].unique()
def getNewUser(date): device_df=da.getDataFrame('device',date) return device_df['device_id'].unique()
def product_list_record(date): list_df = da.getDataFrame('product_list', str(date).replace('-', '')) tags = da.rowGroupCount(list_df, 'values') for tag in tags.keys()[:10]: print tag, tags.get(tag, 0)