예제 #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