def get_share(): data_list_share = [] months_list = [] month_list_entity = ds.get_saved_months('month_list') if month_list_entity != None: #months_list is list, months_to_show is string months_list = month_list_entity.month_list months_to_show = months_list # months_to_show = json.dumps(months_list) else: months_to_show = '201501' if request.method == 'POST': month = request.form.get("month","") else: #use latest month when GET by default month = months_list[0] data_entities = ds.get_all_entities() for i in data_entities: data_list_share.append(json.dumps(i.to_dict())) monthly_total_pertype_dict_list = [] per_car_type_list = [] for car_type in TREND_TOP_V_TYPE: monthly_total_pertype_entities = ds.get_monthly_total_pertype_bytypemonth(car_type,month) for i in monthly_total_pertype_entities: per_car_type_list.append({car_type:i.monthly_total_no}) monthly_total_pertype_dict_list.append({'month':str(month), 'per_type_num':per_car_type_list}) # print monthly_total_pertype_dict_list monthly_total_perbrand_dict_list = [] per_car_brand_list = {} for car_brand in TREND_TOP_V_BRAND: monthly_total_perbrand_entities = ds.get_monthly_total_perbrand_bybrandmonth(car_brand,month) for i in monthly_total_perbrand_entities: per_car_brand_list[car_brand] = i.monthly_total_no monthly_total_perbrand_dict_list.append({'month':str(month), 'per_brand_num':per_car_brand_list}) # print monthly_total_perbrand_dict_list return render_template('market_share.html', data_list_share=data_list_share, months_show=months_to_show,\ cur_month = month, brands_all = TREND_TOP_V_BRAND, \ monthly_total_pertype_dict_list = monthly_total_pertype_dict_list, \ monthly_total_perbrand_dict_list = monthly_total_perbrand_dict_list)
def main(): month_list_entity = ds.get_saved_months('month_list') if month_list_entity != None: months_to_show = month_list_entity.month_list else: months_to_show = ["201501"] print "####months_to_show not found, use default:%s"%months_to_show if request.method == 'POST': month = request.form.get("month","") else: #use latest month when GET by default month = months_to_show[0] selling_data_list = [] selling_data_entities = ds.get_all_entities_bymonth(month) for i in selling_data_entities: selling_data_list.append(json.dumps(i.to_dict())) # print selling_data_list monthly_total_pertype_list = [] for car_type in TREND_TOP_V_TYPE: monthly_total_pertype_entities = ds.get_monthly_total_pertype_bytypemonth(car_type,month) for i in monthly_total_pertype_entities: monthly_total_pertype_list.append(i.monthly_total_no) # print monthly_total_pertype_list monthly_total_perbrand_list = [] for b in TREND_TOP_V_BRAND: monthly_total_perbrand_entities = ds.get_monthly_total_perbrand_bybrandmonth(b,month) for i in monthly_total_perbrand_entities: monthly_total_perbrand_list.append({str(i.brand):i.monthly_total_no}) # print monthly_total_perbrand_list return render_template('selling_num.html', data_list=selling_data_list,\ monthly_total_pertype_list = monthly_total_pertype_list,\ monthly_total_perbrand_list = monthly_total_perbrand_list, \ month=month, months_show=months_to_show)
def trends(): set_tab = 0 data_list_trends_brand = [] selling_data_list_trends = [] monthly_total_alltype_list = [] monthly_total_list = [] per_model_total_ytd = 0 per_brand_total_ytd = 0 models_to_show = TREND_TOP_V brands_to_show = TREND_TOP_V_BRAND tmp_months_to_show = [] tmp_month_list = [] month_list_entity = ds.get_saved_months('month_list') if month_list_entity != None: tmp_month_list = month_list_entity.month_list #default to use latest year current_year = tmp_month_list[0][:4] if current_year == None: current_year = '2015' if request.method == 'POST': model_full = request.form.get("model","") brand = request.form.get("brand","") current_year = request.form.get("year","") if model_full == "": model_full = models_to_show[0] if brand != "": set_tab = 1 else: brand = brands_to_show[0] else: model_full = models_to_show[0] brand = brands_to_show[0] tmp_months_to_show = [] if tmp_month_list != []: tmp_year_list = [] years_show_list = [] for m in tmp_month_list: tmp_year_list.append(m[:4]) if current_year in m: tmp_months_to_show.append(m) tmp_year_list = list(set(tmp_year_list)) tmp_year_list.sort(reverse=True) # print tmp_year_list years_show_list = tmp_year_list else: tmp_months_to_show = ['201501'] if model_full == "top 30 in total": per_model_total_ytd = 0 for tmp_month in reversed(tmp_months_to_show): data_dict_brand = {} brand_total = 0 data_dict_brand['month'] = str(tmp_month) data_entities_brand_a_month = ds.get_monthly_total_perbrand_bybrandmonth(brand, tmp_month) for i in data_entities_brand_a_month: brand_total += i.monthly_total_no per_brand_total_ytd += brand_total data_dict_brand['brand_total'] = brand_total data_list_trends_brand.append(data_dict_brand) if model_full == "top 30 in total": monthly_total_alltype_entities = ds.get_monthly_total_pertype_bytypemonth("all",tmp_month) for i in monthly_total_alltype_entities: monthly_total_alltype_list.append({'month':str(tmp_month),'monthly_total_no':i.monthly_total_no}) per_model_total_ytd += i.monthly_total_no # print data_list_trends_brand # print monthly_total_alltype_list model =' '.join(model_full.split()[1:]) for tmp_month in reversed(tmp_months_to_show): selling_data_entities_model = ds.get_all_entities_bymodelmonth(model, tmp_month) if selling_data_entities_model != None: for i in selling_data_entities_model: per_model_total_ytd = i.selling_no_ytd selling_data_list_trends.append(json.dumps(i.to_dict())) # print selling_data_list_trends return render_template('selling_trends.html', data_list_trends = selling_data_list_trends, \ monthly_total_list = monthly_total_alltype_list, model = model_full, models_show = models_to_show, \ per_model_total_ytd = per_model_total_ytd, per_brand_total_ytd = per_brand_total_ytd, \ data_list_trends_brand = data_list_trends_brand, brand = brand, brands_show = brands_to_show, \ years_show = years_show_list, year = current_year,set_tab = set_tab)