def result(): if g.user: report = Report.get_by_user_id(g.user.id) if not report or report.is_deprecated: wxplan = session.get('wxplan') if not wxplan: return redirect(url_for('.info')) plan = PlanData.from_dict(wxplan) plan = plan.assign_to_user(g.user.id) formula = Formula(plan=plan) report = formula.gen_report() else: plan = PlanData.get_by_user_id(g.user.id) if not plan: return redirect(url_for('.info')) weekly_annual_rates = [] latest_rate = 0 if report.pocket_money > 0: dashboard = PublicDashboard.today() weekly_annual_rates = [(unicode(r.date), round_half_up(r.annual_rate, 2)) for r in dashboard.weekly_annual_rates] latest_rate = round_half_up( dashboard.latest_annual_rate.annual_rate, 2) return render_template( 'plan/detail_result.html', report=report, plan=plan, weekly_annual_rates=weekly_annual_rates, latest_rate=latest_rate, monthly_mortgages=report.get_monthly_mortgages(), rent_data=report.get_rent_data()) return redirect(url_for('.brief'))
def test_gen_report(self): account = self.add_account() user_id = account.id plan = PlanData.add(gender=1, user_id=user_id, age=25, province_code=u'110000', stock=1, rent=1000, mpayment=1000, insurance=1, tour=1, has_children=1, savings=10000, mincome=10000) formula = Formula(plan=plan) report = formula.gen_report() assert formula.get_theory_children_tour_factor() == 1600 assert formula.get_practice_children_tour_factor() == 1600 assert abs(formula.get_this_year_norm_dist() - 0.564386647) < 0.00001 assert abs(formula.get_raise_quota() - Decimal(0.07233586)) < Decimal(0.00001) assert report is not None assert report.erfund == 16859
def info(): redo = request.args.get('redo') if not redo: if g.user: report = Report.get_by_user_id(g.user.id) plan = PlanData.get_by_user_id(g.user.id) if report and not report.is_deprecated: return redirect(url_for('.result')) if plan: session['wxplan'] = plan.to_dict() return redirect(url_for('.brief')) wxplan = session.get('wxplan') if wxplan: return redirect(url_for('.brief')) if g.user: report = Report.get_by_user_id(g.user.id) if report: report.deprecate() show_mask = request.args.get('mask') china = location.Location.get('100000') user_count = get_user_count() wxplan = session.get('wxplan') return render_template('plan/info.html', location=china, user_count=user_count, wxplan=wxplan, show_mask=show_mask)
def add(): gender = request.form.get('info_gender', type=int) age = request.form.get('info_age', type=int) province = request.form.get('info_province') stock = request.form.get('info_stock', type=int) insurance = request.form.get('info_ins', type=int) travel = request.form.get('info_travel', type=int) children = request.form.get('info_children', type=int) monthly = request.form.get('info_monthly', type=int) rent = request.form.get('info_rent', type=int) income = request.form.get('info_income', type=int) savings = request.form.get('info_savings', type=int) plan = PlanData(id_=None, gender=gender, user_id=None, age=age, province_code=province, stock=stock, rent=rent, mpayment=monthly, insurance=insurance, tour=travel, has_children=children, savings=savings, mincome=income, create_time=None, update_time=None) validator = Formula(plan=plan).validate() if validator['code'] == errors.err_ok: session['wxplan'] = plan.to_dict() if g.user: PlanData.add_or_update(gender=gender, user_id=g.user.id, age=age, province_code=province, stock=stock, rent=rent, mpayment=monthly, insurance=insurance, tour=travel, has_children=children, savings=savings, mincome=income) return jsonify(r=True) return jsonify(r=False, d=validator)
def brief(): wxplan = session.get('wxplan') if not wxplan: return redirect(url_for('.info')) plan = PlanData.from_dict(wxplan) formula = Formula(plan=plan) raise_quota = round_half_up(formula.get_raise_quota() * 100, 2) norm_dist = [min(99, int(n * 100)) for n in formula.get_ten_norm_dist()] income_msg = formula.get_income_msg() province = ProvinceSalary.get_by_province_code(plan.province_code) return render_template('plan/brief_result.html', province=province, raise_quota=raise_quota, norm_dist=norm_dist, income_msg=income_msg)
def test_add_wxplan(self): account = self.add_account() user_id = account.id plan = PlanData.add(gender=1, user_id=user_id, age=30, province_code=u'110000', stock=1, rent=123, mpayment=123, insurance=1, tour=1, has_children=1, savings=10000, mincome=2000) assert plan is not None assert plan.user_id == user_id
def test_savings_money(self): account = self.add_account() user_id = account.id plan = PlanData.add(gender=1, user_id=user_id, age=30, province_code=u'110000', stock=1, rent=123, mpayment=123, insurance=1, tour=1, has_children=1, savings=10000, mincome=10000) formula = Formula(plan=plan) assert 75100 in formula.get_five_savings_money()[0]
def test_validation(self): account = self.add_account() user_id = account.id plan = PlanData(id_=None, gender=1, user_id=user_id, age=30, province_code=u'110000', stock=1, rent=123, mpayment=123, insurance=1, tour=1, has_children=1, savings=10000, mincome=2000, create_time=None, update_time=None) formula = Formula(plan=plan) validator = formula.validate() assert validator == {'name': 'result', 'code': errors.err_ok}
def test_gen_simple_report(self): plan = PlanData(id_=None, gender=1, user_id=None, age=30, province_code=u'110000', stock=-1, rent=1, mpayment=-1, insurance=-1, tour=-1, has_children=-1, savings=20, mincome=20, update_time=None, create_time=None) formula = Formula(plan=plan) assert formula.get_practice_need_msavings_factor() == 0 assert formula.get_practice_pocket_money_factor() == 19 assert formula.get_theory_children_tour_factor() == 0 assert formula.get_practice_children_tour_factor() == 0 assert abs(formula.get_this_year_norm_dist() - 0.401612399) < 0.00001 assert abs(formula.get_raise_quota() - Decimal(0.0365)) < Decimal(0.00001)