Exemple #1
0
def pace_waiting():
    # extract info
    day_index = game.get_day_index(current_user, models.Game)
    current_par = game.get_current_parameters(current_user, models.Parameter)
    # users for unpaced sessions are not allowed
    if not current_par.consistent_pace:
        return redirect('/stats')
    # users for paced sessions are allowed but returns depend on conditions
    try:
        # instructor not yet opened the paced session if exception raised
        current_pace = models.Pace.query.filter_by(
            session_code=current_user.session_code).all()[-1]
        # id in collection
        if current_user.id in [
                int(x) for x in current_pace.session_id_collection.split(',')
        ]:
            pass
        else:  # id not in collection
            return redirect(url_for('pace_loading'))
    except:
        return redirect(url_for('pace_loading'))
    # pace control
    condition = day_index - 1 != min([
        len(models.Game.query.filter_by(id=y).all()) for y in
        [int(x) for x in current_pace.session_id_collection.split(',')]
    ])
    return render_template('pace_wait.html', condition=condition)
Exemple #2
0
def pace_day():
    form = forms.InputForm()
    day_index = game.get_day_index(current_user, models.Game)
    current_par = game.get_current_parameters(current_user, models.Parameter)
    # users for unpaced sessions are not allowed
    if not current_par.consistent_pace:
        return redirect('/stats')
    # users for paced sessions are allowed but returns depend on conditions
    try:
        # instructor not yet opened the paced session if exception raised
        current_pace = game.get_current_pace(current_user, models.Pace)
        # id in collection
        if current_user.id in [
                int(x) for x in current_pace.session_id_collection.split(',')
        ]:
            pass
        else:  # id not in collection
            return redirect(url_for('pace_loading'))
    except:
        return redirect(url_for('pace_loading'))
    # pace control
    if day_index - 1 != min([
            len(models.Game.query.filter_by(id=y).all()) for y in
        [int(x) for x in current_pace.session_id_collection.split(',')]
    ]):
        return redirect(url_for('pace_loading'))
    # protect from finished user coming back and make new orders
    if day_index > current_par.nrounds:
        return redirect(url_for('pace_game_end'))

    if form.validate_on_submit():
        return end_round(form, 'pace_day_end.html')
    else:
        return start_round(form, 'pace_day_start.html')
Exemple #3
0
def start_round(form, dest):
    day_index = game.get_day_index(current_user, models.Game)
    current_par = game.get_current_parameters(current_user, models.Parameter)
    current_demand = game.get_current_demand(current_user, models.Demand)
    # redirect consistent pace users
    history = ''
    previous = ''
    demand_range = ''
    demand_mean = ''
    demand_std_dev = ''
    demand_peak = ''
    if current_par.demand_pattern != DistributionType.SAMPLE_POOL:
        history = current_demand.demand_past
        for x in current_demand.demand_new.split(',')[:day_index - 1]:
            previous = previous + str(x)
        demand_range = str(current_par.distribution_all_lower_bound) \
                       + ' to ' + str(current_par.distribution_all_upper_bound)
    if current_par.demand_pattern == DistributionType.NORMAL:
        demand_mean = current_par.distribution_normal_mean
        demand_std_dev = current_par.distribution_normal_std
    if current_par.demand_pattern == DistributionType.TRIANGULAR:
        demand_peak = current_par.distribution_triangular_peak
    return render_template(dest,
                           form=form,
                           day_index=day_index,
                           current_par=current_par,
                           current_demand=current_demand,
                           history=history,
                           demand_range=demand_range,
                           demand_mean=demand_mean,
                           demand_std_dev=demand_std_dev,
                           demand_peak=demand_peak)
Exemple #4
0
def game_start():
    form = forms.InputForm()
    day_index = game.get_day_index(current_user, models.Game)
    current_par = game.get_current_parameters(current_user, models.Parameter)
    if current_par.consistent_pace:
        return redirect('/paceloading')
    # protect from finished user coming back and make new orders
    if day_index > current_par.nrounds:
        return redirect(url_for('game_end'))
    if form.validate_on_submit():
        return end_round(form, 'roundend.html')
    else:
        return start_round(form, 'game.html')
Exemple #5
0
def end_round(form, dest):
    day_index = game.get_day_index(current_user, models.Game)
    current_par = game.get_current_parameters(current_user, models.Parameter)
    current_demand = game.get_current_demand(current_user, models.Demand)
    norder = int(form.input.data)
    ndemand = int(current_demand.demand_new.split(',')[day_index - 1])
    nsold = min(norder, ndemand)
    nlost = max(0, ndemand - norder)
    rev = round(nsold * round(float(current_par.retail_price), 2), 2)
    cost = round(norder * round(float(current_par.wholesale_price), 2), 2)
    profit = round(rev - cost, 2)
    if day_index == 1:
        total_profit = round(profit, 2)
    else:
        total_profit = round(
            profit + models.Game.query.filter_by(
                id=current_user.id,
                day_index=day_index - 1).first().total_profit, 2)
    # insert into db
    current_game_rec = models.Game(session_code=current_user.session_code,
                                   id=current_user.id,
                                   pname=current_user.pname,
                                   day_index=day_index,
                                   norder=norder,
                                   ndemand=ndemand,
                                   nsold=nsold,
                                   nlost=nlost,
                                   rev=rev,
                                   cost=cost,
                                   profit=profit,
                                   total_profit=total_profit)
    db.session.add(current_game_rec)
    db.session.commit()
    return render_template(dest,
                           norder=norder,
                           ndemand=ndemand,
                           nsold=nsold,
                           nlost=nlost,
                           rev=rev,
                           cost=cost,
                           current_par=current_par,
                           profit=profit,
                           tot_profit=total_profit)
Exemple #6
0
def pace_day_start(form):
    day_index = game.get_day_index(current_user, models.Game)
    current_par = game.get_current_parameters(current_user, models.Parameter)
    current_demand = game.get_current_demand(current_user, models.Demand)
    # users for unpaced sessions are not allowed
    if not current_par.consistent_pace:
        return redirect('/stats')
    # users for paced sessions are allowed but returns depend on conditions
    try:
        # instructor not yet opened the paced session if exception raised
        current_pace = game.get_current_pace(current_user, models.Pace)
        # id in collection
        if current_user.id in [
                int(x) for x in current_pace.session_id_collection.split(',')
        ]:
            pass
        else:  # id not in collection
            return redirect('/paceloading')
    except:
        return redirect('/paceloading')
    # pace control
    if day_index - 1 != min([
            len(models.Game.query.filter_by(id=y).all()) for y in
        [int(x) for x in current_pace.session_id_collection.split(',')]
    ]):
        return redirect('/pacewaiting')
        # protect from finished user coming back and make new orders
    if day_index > current_par.nrounds:
        return redirect(url_for('pace_game_end'))
    nrounds = int(current_par.nrounds)
    wholesale_price = round(float(current_par.wholesale_price), 2)
    retail_sale_price = round(float(current_par.retail_price), 2)
    demand_pattern = 'FROM ' + str(
        current_par.demand_pattern).split('.')[1].replace('_', ' ')
    distri_null = '' if current_par.demand_pattern == DistributionType.SAMPLE_POOL else 'DISTRIBUTION'
    history = '<p>Historical Demand Samples: {}</p>'.format(
        current_demand.demand_past
    ) if current_par.demand_pattern == DistributionType.SAMPLE_POOL else ''
    previous = '<p>Demands From Previous Rounds: {}</p>'.format(
        str([int(x) for x in current_demand.demand_new.split(',')][:day_index - 1])[1:-1]) \
                   if current_par.demand_pattern == DistributionType.SAMPLE_POOL else '',
    demand_range = '' if current_par.demand_pattern == DistributionType.SAMPLE_POOL \
                       else '<p>Demand Range: {}</p>'.format(
                        str(current_par.distribution_all_lower_bound) +
                        ' to ' + str(current_par.distribution_all_upper_bound)),
    demand_mean = '<p>Demand Mean: {}</p>'.format(
        current_par.distribution_normal_mean
    ) if current_par.demand_pattern == DistributionType.NORMAL else '',
    demand_std = '<p>Demand Standard Deviation: {}</p>'.format(
        current_par.distribution_normal_std
    ) if current_par.demand_pattern == DistributionType.NORMAL else '',
    demand_peak = '<p>Demand Peak: {}</p>'.format(
        current_par.distribution_triangular_peak
    ) if current_par.demand_pattern == DistributionType.TRIANGULAR else '',
    day = day_index
    return render_template('pace_day_start.html',
                           form=form,
                           nrounds=nrounds,
                           wholesale_price=wholesale_price,
                           retail_sale_price=retail_sale_price,
                           demand_pattern=demand_pattern,
                           distri_null=distri_null,
                           history=history,
                           previous=previous,
                           demand_range=demand_range,
                           demand_mean=demand_mean,
                           demand_std=demand_std,
                           demand_peak=demand_peak,
                           day=day)