Exemple #1
0
def record_new_month(t,p,sn,sys,res,mar,month0tm):
    rc=(p.variable_rc*month0tm.aum/12)+p.fixed_rc #check calculation i. /12
    m=month.objects.filter(month_id=t.cm.month_id+1)
    if len(m) != 0:
        month1tm=TeamMonth(team=t,month=month.objects.get(month_id=t.cm.month_id+1),
                       strat_num=sn,
                       wc=month0tm.wc,aum=month0tm.aum,value=month0tm.value,mortgage=month0tm.mortgage,
                       revenue=0,monthly_profit=0,aum_change=0,
                       total_return=month0tm.total_return,total_revenue=month0tm.total_revenue,
                       running_costs=rc,
                       systems=sys,
                       research=res,
                       marketing=mar, fee=0.0,perf_fee=0.0,mgmt_fee=0.0,processed=False)
        t.cm=month1tm.month
        if t.cm.month_id==t.launch_month.month_id:
            month1tm.aum=t.saum
            month1tm.running_costs=(p.variable_rc*t.saum/12)+p.fixed_rc
            month1tm.wc+=month0tm.aum
        month1tm.save()
        record_boost(t,month1tm)
        t.save()
    else:
        t.game_stop=True
        t.save()
Exemple #2
0
def end_of_month(request,username,name):
    t=StudentTeam.objects.get(pk=name)
    p=ParameterSet.objects.get(pk=1)
    if t.session_limit:
        tz=datetime.datetime.now()+timedelta(minutes=0)
        tz=timezone.make_aware(tz, timezone.get_default_timezone())
        if tz>t.session_limit:
            t.game_stop=True
            t.save()
    mname=[]
    value=[]
    pre_launch=False
    zero=False
    if t.approve==False:
        return HttpResponseRedirect(BASE_URL+'%s/%s/game/details/'%(username,name))
    if t.cm.month_id==0:
        pre_launch=True
        zero=True
        if(t.swc is None or t.saum is None or t.mns is None or t.maxg is None):
            return HttpResponseRedirect(BASE_URL+'%s/%s/game/details/'%(username,name))
        else:
            chk=TeamMonth.objects.filter(team=t).filter(month=t.cm)#checking if a record for month 0 already exists
            if not t.launch_month:
                launch_info=False
                if chk:
                    chk.delete()
                #creating record of starting status
                month0=TeamMonth(team=t,month=month.objects.get(month_id=0),strat_num=0,wc=t.swc,aum=t.saum,value=100,revenue=0,
                                 monthly_profit=0,aum_change=0,total_return=0,total_revenue=0,running_costs=p.fixed_rc,systems=0,research=0,marketing=0,
                                 perf_fee=0.0,mgmt_fee=0.0,fee=0.0)
                month0.save()
                #choosing financial 'returns' scenario for the strategies
                change_scenario_set(t,p)
                t.cr=t.start_row +1
                #starting timer for the entire game
                t.session_limit=datetime.datetime.now() + timedelta(minutes=p.total_time_limit)
                t.save()
                #setting display information
                display_month=month0
            else:
                launch_info=True
                display_month=chk[0]
            mname,value=get_macro_indicators(t.start_row)
            event_list=events(mname[len(mname)-1],value[len(value)-1])
    else:
        launch_info=True
        if(t.cm.month_id<t.launch_month.month_id):
            pre_launch=True  
        display_month=TeamMonth.objects.filter(team=t).filter(month=t.cm)[0]
        if display_month.processed==False:
            if display_month.strat_num!=0:#crash check, if the machine crashes before entering the strategy details
                tss=TeamStrategy.objects.filter(team=t).filter(month=t.cm)
                if not tss:
                    return HttpResponseRedirect(BASE_URL+'%s/%s/game/3/'%(username,name))
            #return processing(t,p,display_month)
            display_month,boost=processing(t,p,display_month)
            t.fund_grade=update_grade(display_month)
            t.cr=t.cr+1
            if t.cr>p.max_row:
                t.cr=p.min_row+1
            t.save()
        if display_month.wc<0:
            t.game_stop=True
            t.save()
        mname,value=get_macro_indicators(t.cr)
        event_list=events(mname[len(mname)-1],value[len(value)-1])
    #setting macro display format
    macro=[]
    for x in range(0,len(mname)-1):
        macro.append([mname[x],value[x]])
        x+=1
    #rounding off the values for display
    display_month=rounding(display_month)
    strategies=TeamStrategy.objects.filter(team=t).filter(month=t.cm)
    if strategies:
        strategies=roundings(strategies)
    next_month=display_month.month.month_id+1
    #getting verbal description of micro event
    event=''
    if display_month.event!=0:
        event=MicroEvent.objects.get(pk=display_month.event).description
    if boost >0:
        event=event+' Recieve a boost due to robust spending on research,systems & marketing.'
    #calculating progress
    tl=Timeline.objects.get(pk=1)
    tledm=tl.end_date.month
    mdates=month.objects.filter(date__month=tledm)
    if not mdates:
        tledm=tledm-1
        mdates=month.objects.filter(date__month=tledm)
    lomd=len(mdates)#length of mdates
    maxrounds=mdates[lomd-1]
    progress= round((float(t.cm.month_id)/float(maxrounds.month_id))*100)
    #return HttpResponse(t.session_limit)
    #final display
    return render_to_response('game/default.html', {'name': name, 'username': username, 'status':t.approve, 'team':t,
                                                             'month':display_month,'next_month':next_month,
    'strategies':strategies,'macro':macro,'events':event_list, 'limit':t.session_limit,'lmonth':t.session_limit.strftime("%B"),
                                                    'progress':progress, 'maxround':maxrounds.month_id-1,
                                                    'launch_info':launch_info,'pre_launch':pre_launch,
          'game_over':t.game_stop,'zero':zero,'year':YEAR, 'event':event},RequestContext(request))