示例#1
0
文件: chat.py 项目: jrzb/WechatWoojuu
def generate_general_comparision(userid):
	# TODO better performance
	count_threshold = 10
	amount_threshold = 1000
	sql_format = "select left(date, 7) as date, sum(amount) as sum, count(1) as count, avg(amount) as avg" + \
				 " from expenses where userid='%s' " + \
				 "and amount < %d group by left(date, 7) order by left(date, 7) desc limit 2;"
	sql = sql_format % (userid, amount_threshold)
	out = Expense.query_sql(sql)
	if len(out) == 0:
		sum_this = 0
		count_this = 0
	else:
		sum_this = float(out[0][1])
		count_this = int(out[0][2])

	# if count_this > count_threshold:
	# 		msg = "本月共花了%s元。按这速度,本月会花掉%s元。" % \
	# 	  (util.format_float_str(sum_this), \
	# 	   util.format_float_str(util.predict_amount(sum_this)))
	# else:
	msg = "本月共花了%s元。" % \
	  (util.format_float_str(sum_this))

	if len(out) >= 2:
		sum_last = float(out[1][1])
		count_last = int(out[1][2])
		msg = "%s而上月共花了%s元。" % (msg, util.format_float_str(sum_last))
	return msg
示例#2
0
def generate_general_comparision(userid):
    # TODO better performance
    count_threshold = 10
    amount_threshold = 1000
    sql_format = "select left(date, 7) as date, sum(amount) as sum, count(1) as count, avg(amount) as avg" + \
        " from expenses where userid='%s' " + \
        "and amount < %d group by left(date, 7) order by left(date, 7) desc limit 2;"
    sql = sql_format % (userid, amount_threshold)
    out = Expense.query_sql(sql)
    if len(out) == 0:
        sum_this = 0
        count_this = 0
    else:
        sum_this = float(out[0][1])
        count_this = int(out[0][2])

    # if count_this > count_threshold:
    # 		msg = "本月共花了%s元。按这速度,本月会花掉%s元。" % \
    # 	  (util.format_float_str(sum_this), \
    # 	   util.format_float_str(util.predict_amount(sum_this)))
    # else:
    msg = "本月共花了%s元。" % \
      (util.format_float_str(sum_this))

    if len(out) >= 2:
        sum_last = float(out[1][1])
        count_last = int(out[1][2])
        msg = "%s而上月共花了%s元。" % (msg, util.format_float_str(sum_last))
    return msg
示例#3
0
文件: data.py 项目: jrzb/WechatWoojuu
def view_history(userid):
	(asset_amount, day_expense, week_expense, month_expense) = user_summary(userid)
	#print asset_amount, day_expense, week_expense, month_expense
	content = MSG.REPLAY_HISTORY % \
			  (format_float_str(str(day_expense)), \
			   format_float_str(str(week_expense)), \
			   format_float_str(str(month_expense)), \
			  format_float_str(str(asset_amount)), \
	   )
	return content.encode('utf-8', 'ignore')
示例#4
0
def view_history(userid):
    (asset_amount, day_expense, week_expense,
     month_expense) = user_summary(userid)
    #print asset_amount, day_expense, week_expense, month_expense
    content = MSG.REPLAY_HISTORY % \
        (format_float_str(str(day_expense)), \
         format_float_str(str(week_expense)), \
         format_float_str(str(month_expense)), \
        format_float_str(str(asset_amount)), \
       )
    return content.encode('utf-8', 'ignore')
示例#5
0
文件: chat.py 项目: jrzb/WechatWoojuu
def generate_expense_msg(userid, category):
	(user_count, user_amount, avg_count, avg_amount) \
			= Expense.get_expense_msg(userid, category)
	avg_count = avg_count * 3 # TODO: hack here
	category_msg = "你最近30天在'%s'上,一共消费%s元。" % \
				(category, util.format_float_str(user_amount * user_count))

	return category_msg
示例#6
0
def generate_expense_msg(userid, category):
    (user_count, user_amount, avg_count, avg_amount) \
      = Expense.get_expense_msg(userid, category)
    avg_count = avg_count * 3  # TODO: hack here
    category_msg = "你最近30天在'%s'上,一共消费%s元。" % \
       (category, util.format_float_str(user_amount * user_count))

    return category_msg