Example #1
0
    def vars_for_template(self):
        # Filling the data for HighCharts graph

        series = []

        transaction_prices = [g.sale_price for g in self.group.in_all_rounds()]
        series.append({
            'name': 'Transaction Price',
            'data': transaction_prices
        })

        for player in self.group.get_players():
            payoffs = [p.payoff for p in player.in_all_rounds()]
            series.append({
                'name':
                'Earnings for %s' % player.role().capitalize(),
                'data':
                payoffs
            })
        highcharts_series = safe_json(series)

        round_numbers = safe_json(list(range(1, Constants.num_rounds + 1)))

        return {
            'highcharts_series': highcharts_series,
            'round_numbers': round_numbers
        }
Example #2
0
 def vars_for_template(self):
     return {
         'fixed_pay': self.group.agent_fixed_pay,
         'EFFORT_TO_RETURN': safe_json(Constants.EFFORT_TO_RETURN),
         'EFFORT_TO_COST': safe_json(Constants.EFFORT_TO_COST),
         'return_share': int(self.group.agent_return_share * 100)
     }
Example #3
0
    def vars_for_template(self):

        var = self.group.variation()
        j = range(0, len(Constants.choice_catch))
        r = range(0, len(Constants.other_choice_catch))
        tab_payoff = self.group.set_payoffTable()
        choice = "0:%d" % (Constants.elementPayoff_Tab)

        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        data = {'Payoff': tab_payoff, 'round.number': self.subsession.round_number, 'biomass': self.group.b_round,
                'choicevar': choice,'variation':var, 'j': j,'r':r,
                'Bmsy': Constants.Bmsy,
                'Blim': Constants.Blim,
                'Blim_min': self.group.Blim_min,
                'Blim_max': self.group.Blim_max,
                'years': Constants.xp_years,
                'colorBlim': colorBlim,
                'colorBlim_range': colorBlim_range,
                'colorBlim_range_label': colorBlim_range_label,
                'colorBlim_label': colorBlim_label
                }

        data['seriesBiomass'] = list()
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()

        biomass = [p.b_round for p in self.group.in_all_rounds()]

        data['seriesBiomass'].append({'name': 'Biomass','data': biomass})

        data['seriesBlim_min'].append({'name': 'Blim_min',
                                       'data': self.group.Blim_min})
        data['seriesBlim_max'].append({'name': 'Blim_max',
                                       'data': self.group.Blim_max})

        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBmsy'] = safe_json(data['seriesBmsy'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return data
Example #4
0
    def vars_for_template(self):

        var = self.group.variation()
        j = range(0, len(Constants.choice_catch))
        r = range(0, len(Constants.other_choice_catch))
        tab_payoff = self.group.set_payoffTable()
        choice = "0:%d" % (Constants.elementPayoff_Tab)

        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        data = {'Payoff': tab_payoff, 'round.number': self.subsession.round_number, 'biomass': self.group.biomass,
                'choicevar': choice,'variation':var, 'j': j,'r':r,
                'Biomass': self.group.biomass,
                'Bmsy': Constants.Bmsy,
                'Blim': Constants.Blim,
                'Blim_min': self.group.Blim_min,
                'Blim_max': self.group.Blim_max,
                'years': Constants.xp_years,
                'colorBlim': colorBlim,
                'colorBlim_range': colorBlim_range,
                'colorBlim_range_label': colorBlim_range_label,
                'colorBlim_label': colorBlim_label
                }

        data['seriesBiomass'] = list()
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()

        data['seriesBiomass'].append({'name': 'Biomass',
                                      'data': self.group.biomass})

        data['seriesBlim_min'].append({'name': 'Blim_min',
                                       'data': self.group.Blim_min})
        data['seriesBlim_max'].append({'name': 'Blim_max',
                                       'data': self.group.Blim_max})

        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBmsy'] = safe_json(data['seriesBmsy'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return data
Example #5
0
    def vars_for_template(self):
        # Filling the data for graph

        ## Catch, profit total and by player for each round
        catch_round = []
        totalCatch_round = []
        totalIndCatch = []
        profit_round = []
        totalProfit_round =  []
        totalIndProfit = []
        oCatch = []
        oProfit = []
        oID = []
        oData =[]

        # own cacth & profit per player
        for p in self.player.in_all_rounds():
            catch_round.append(p.catch_choice)
            profit_round.append(p.profit)
            totalIndCatch = sum(catch_round)
            totalIndProfit = sum(profit_round)

        # others cacth & profit per player
        for p in self.player.get_others_in_group():
                oCatch.append(p.catch_choice)
                oProfit.append(p.profit)
                oID.append(p.id_in_group)

        others_data = {'Player':oID, 'catch':oCatch, 'profit':oProfit}
        others_data = collections.OrderedDict(sorted(others_data .items(), key=lambda t: t[0]))

        for element, value in others_data.items():
            oData.append(value)

        # total harvest & total profit
        for p in self.group.in_all_rounds():
            totalCatch_round.append(p.total_catch)
            totalProfit_round.append(p.total_profit)

        # gather data to make series
        data = {'Player': self.player.id_in_group, 'Catch': catch_round,'Profit': profit_round,
                'TotalIndCatch':totalIndCatch,'TotalIndProfit':totalIndProfit,
                'Total_catch':  totalCatch_round, 'Total_profit':  totalProfit_round}

        # create series to plot
        seriesCatch=[]
        seriesCatch.append({'name': 'Own Catch', 'data': catch_round})
        seriesCatch.append({'name':'Total Catch', 'data': totalCatch_round})
        Catchseries = safe_json(seriesCatch)

        seriesProfit = []
        seriesProfit.append({'name': 'Own Profit', 'data': profit_round})
        seriesProfit.append({'name': 'Total Profit', 'data': totalProfit_round})
        Profitseries = safe_json(seriesProfit)

        return {'data': data, 'Catchseries': Catchseries, 'Profitseries': Profitseries,'others_data':others_data,
                'nation': oData[0], 'catch': oData[1], 'profit': oData[2], 'testunrange':self.group.b_unrange,
                'TotalIndProfit': totalIndProfit}
Example #6
0
 def vars_for_template(self):
     for player in self.player.in_all_rounds():
         if player.subsession.final:
             break
     data = {'old_player': player}
     #
     # Filling the data for graph
     #
     # transaction price for each round (None if no transaction happened)
     transaction_price = []
     for round in self.player.in_all_rounds():
         if round.group.seller():
             transaction_price.append(round.group.seller().price)
         else:
             transaction_price.append(None)
     data['series'] = list()
     data['series'].append({
         'name': 'Transaction Price',
         'data': transaction_price
     })
     # payoffs for both buyer and sellers in each round
     for player in self.group.get_players():
         payoffs = []
         for round in player.in_all_rounds():
             payoffs.append(round.payoff)
         data['series'].append({
             'name':
             'Earnings for %s' % player.role().capitalize(),
             'data':
             payoffs
         })
     data['series'] = safe_json(data['series'])
     return data
Example #7
0
    def vars_for_template(self):
        # create chart lists
        transaction_price_list = []
        dividend_per_share_list = []
        shares_traded_list = []

        for p in self.player.in_all_rounds():
            transaction_price_list.append(int(p.group.transaction_price or 0))
            dividend_per_share_list.append(int(p.group.dividend_per_share))
            shares_traded_list.append(p.group.shares_traded)

        return {
            'transaction_price_list': safe_json(transaction_price_list),
            'dividend_per_share_list': safe_json(dividend_per_share_list),
            'shares_traded_list': safe_json(shares_traded_list),
        }
Example #8
0
 def vars_for_template(self):
     for player in self.player.in_all_rounds():
         if player.subsession.final:
             break
     data = {'old_player': player,
             'payoff': player.payoff + Constants.participation_fee,
             'participation_fee': Constants.participation_fee}
     # 
     # Filling the data for graph
     #
     # transaction price for each round (None if no transaction happened)
     transaction_price = []
     for round in self.player.in_all_rounds():
         if round.group.seller():
             transaction_price.append(round.group.seller().price)
         else:
             transaction_price.append(None)
     data['series'] = list()
     data['series'].append({'name': 'Transaction Price',
                            'data': transaction_price})
     # payoffs for both buyer and sellers in each round
     for player in self.group.get_players():
         payoffs = []
         for round in player.in_all_rounds():
             payoffs.append(round.payoff)
         data['series'].append({'name': 'Earnings for %s' % player.role().capitalize(),
                                'data': payoffs})
     data['series'] = safe_json(data['series'])
     return data
Example #9
0
 def vars_for_template(self):
     otree_vars = {
         'num_rows': Constants.num_rows,
         'num_cols': Constants.num_cols,
         'box_width': Constants.box_width,
         'box_height': Constants.box_height,
         'num_bombs': self.player.risk,
     }
     return {'otree_vars': safe_json(otree_vars)}
Example #10
0
    def vars_for_template(self):

        # create chart lists
        transaction_price_list = []
        dividend_per_share_list = []
        shares_traded_list = []

        for p in self.player.in_all_rounds():
            transaction_price_list.append(int(p.group.transaction_price or 0))
            dividend_per_share_list.append(int(p.group.dividend_per_share))
            shares_traded_list.append(p.group.shares_traded)

        return {

            'transaction_price_list': safe_json(transaction_price_list),
            'dividend_per_share_list': safe_json(dividend_per_share_list),
            'shares_traded_list': safe_json(shares_traded_list),
        }
Example #11
0
    def variables_for_template(self):

        # create chart lists
        transaction_price_list = []
        dividend_per_share_list = []
        shares_traded_list = []

        for p in self.player.in_all_rounds():
            transaction_price_list.append(int(p.group.transaction_price or 0))
            dividend_per_share_list.append(int(p.group.dividend_per_share))
            shares_traded_list.append(p.group.shares_traded)

        return {
            'cash': self.player.cash,
            'shares': self.player.shares,
            'fixed_pay': self.player.participant.session.fixed_pay,
            'total_payoff': self.player.payoff + self.player.participant.session.fixed_pay,
            'transaction_price_list': safe_json(transaction_price_list),
            'dividend_per_share_list': safe_json(dividend_per_share_list),
            'shares_traded_list': safe_json(shares_traded_list),
        }
Example #12
0
    def vars_for_template(self):
        must_hit = 0
        if self.player.id_in_group == self.session.vars['must_hit'][
                self.round_number - 1]:
            must_hit = 1

        otree_vars = {
            'num_rows': Constants.num_rows,
            'num_cols': Constants.num_cols,
            'box_width': Constants.box_width,
            'box_height': Constants.box_height,
            'num_bombs': self.player.risk,
            'must_hit': must_hit
        }
        return {'otree_vars': safe_json(otree_vars)}
Example #13
0
 def vars_for_admin_report(self):
     allplayers = self.get_players()
     alldata = []
     descriptions = Constants.descriptions
     for i in range(1, 5):
         tempdict = {}
         tempdict['name'] = 'ns6_{}'.format(i)
         tempdict['description'] = descriptions[i-1]
         tempdict['data'] = [getattr(p, tempdict['name'])
                             for p in allplayers]
         try:
             tempdict['average'] = round(sum(tempdict['data']) /
                                         len(tempdict['data']), 1)
         except:
             tempdict['average'] = 'no data yet'
         tempdict['data'] = safe_json(tempdict['data'])
         alldata.append(tempdict)
     return{'data': alldata}
Example #14
0
    def vars_for_template(self):
        pre_rounds = self.player.in_previous_rounds()
        if len(pre_rounds) > 0:
            self.player.risk = pre_rounds[-1].risk
            self.player.adapt = pre_rounds[-1].adapt

        otree_vars = {
            'num_rows': Constants.num_rows,
            'num_cols': Constants.num_cols,
            'box_width': Constants.box_width,
            'box_height': Constants.box_height,
            'num_bombs': str(self.player.risk)
        }

        return {
            'otree_vars': safe_json(otree_vars),
            'year_no': self.round_number
        }
Example #15
0
    def vars_for_template(self):

        allplayers = self.subsession.get_players()
        alldata = []
        descriptions = Constants.descriptions
        for i in range(1, 5):
            tempdict = {}
            tempdict['name'] = 'ns6_{}'.format(i)
            tempdict['description'] = descriptions[i - 1]
            tempdict['data'] = [
                getattr(p, tempdict['name']) for p in allplayers
            ]
            tempdict['average'] = round(
                sum(tempdict['data']) / len(tempdict['data']), 1)
            tempdict['you'] = int(getattr(self.player, tempdict['name']))
            tempdict['data'] = safe_json(tempdict['data'])
            alldata.append(tempdict)
        return {'data': alldata}
Example #16
0
    def vars_for_template(self):
        reset = self.participant.vars.get('reset', False)
        if reset == True:
            del self.participant.vars['reset']

        input = not Constants.devils_game if not Constants.dynamic else False

        otree_vars = {
            'reset': reset,
            'input': input,
            'random': Constants.random,
            'dynamic': Constants.dynamic,
            'num_rows': Constants.num_rows,
            'num_cols': Constants.num_cols,
            'feedback': Constants.feedback,
            'undoable': Constants.undoable,
            'box_width': Constants.box_width,
            'box_height': Constants.box_height,
            'time_interval': Constants.time_interval,
        }

        return {'otree_vars': safe_json(otree_vars)}
Example #17
0
 def vars_for_template(self):
     return {
         'EFFORT_TO_RETURN': safe_json(Constants.EFFORT_TO_RETURN),
         'EFFORT_TO_COST': safe_json(Constants.EFFORT_TO_COST),
     }
Example #18
0
    def vars_for_admin_report(self):
        group =  self.get_groups()[0]
        ## color setting
        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        catch    = [p.total_catch for p in group.in_all_rounds()]
        profit   = [p.total_profit for p in group.in_all_rounds()]
        biomass  = [p.b_round for p in group.in_all_rounds()]
        blim_min = [p.Blim_min for p in group.in_all_rounds()]
        blimmin  =  blim_min[0]
        blim_max = [p.Blim_max for p in group.in_all_rounds()]
        blimmax  =  blim_max[0]

        data = {'Total_catch': catch, 'Total_profit': profit,
                'Biomass': biomass,
                'Bmsy': Constants.Bmsy,
                'Blim': Constants.Blim,
                'years': Constants.xp_years,
                'colorBlim': colorBlim,
                'colorBlim_range': colorBlim_range,
                'colorBlim_range_label': colorBlim_range_label,
                'colorBlim_label': colorBlim_label
                }

        seriesCatch=[]
        seriesCatch.append({'name': 'Total Catch', 'data': catch})
        Catchseries = safe_json(seriesCatch)
        seriesProfit = []
        seriesProfit.append({'name': 'Total Profit', 'data': profit})
        Profitseries = safe_json(seriesProfit)
        seriesBiomass = []
        seriesBiomass.append({'name': 'Biomass', 'data': biomass})
        Biomassseries = safe_json(seriesBiomass)
        seriesBlim_min = []
        seriesBlim_min.append({'name': 'Blim_min', 'data': blim_min})
        seriesBlim_min = safe_json(seriesBlim_min)
        seriesBlim_max = []
        seriesBlim_max.append({'name': 'Blim_max', 'data': blim_max})
        seriesBlim_max = safe_json(seriesBlim_max)

        ##Biomass series
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        data['seriesBmsy'] = safe_json(data['Bmsy'])
        data['seriesBlim'] = safe_json(data['Blim'])

        return {'data': data, 'Catchseries': Catchseries, 'Profitseries': Profitseries,
                'seriesBiomass': Biomassseries,
                'seriesBlim_min': seriesBlim_min , 'seriesBlim_max': seriesBlim_max,
                'seriesBmsy': data['seriesBmsy'],
                'seriesBlim': data['seriesBlim'],
                'Bmsy': Constants.Bmsy,
                'Blim': Constants.Blim,
                'Blim_min':blimmin, 'Blim_max':blimmax,
                'years': Constants.xp_years,
                'colorBlim': colorBlim,
                'colorBlim_range': colorBlim_range,
                'colorBlim_range_label': colorBlim_range_label,
                'colorBlim_label': colorBlim_label
                }
Example #19
0
    def vars_for_template(self):

        ## create area range series for projection uncertainty on biomass plot
        ## projection uncertainty
        proj = self.group.projection()
        proj_un = self.group.projUncertainty()

        j = -1
        UNarea = []
        seq = list(range(len(proj) + 1))

        # simplify nested list
        for i in range(1, 2):
            unArea = sum(proj_un, [])

        for row in unArea[0]:
            j = j + 1
            UNarea.append([[seq[j]] + row])

        UNarea = sum(UNarea, [])

        ## color setting
        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        ## Filling the data for graph
        ## Biomass estimation + projection under statu quo (same harvest level)

        data = {
            'Biomass': self.group.b_round,
            'Bmsy': Constants.Bmsy,
            'Blim': Constants.Blim,
            'Projection': proj,
            'UnRange': UNarea,
            'Bmax': self.group.bmax_round,
            'Bmin': self.group.bmin_round,
            'Blim_min': self.group.Blim_min,
            'Blim_max': self.group.Blim_max,
            'years': Constants.xp_years,
            'colorBlim': colorBlim,
            'colorBlim_range': colorBlim_range,
            'colorBlim_range_label': colorBlim_range_label,
            'colorBlim_label': colorBlim_label
        }

        data['seriesBiomass'] = list()
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        data['seriesProjection'] = list()
        data['seriesUnRange'] = list()
        data['seriesBrange'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()

        data['seriesProjection'].append({'name': 'Projection', 'data': proj})
        data['seriesBiomass'].append({
            'name': 'Biomass',
            'data': self.group.b_round
        })
        # data['seriesBmsy'].append({'name': 'Bmsy',
        #                          'data': self.group.target})
        # data['seriesBlim'].append({'name': 'Bmsy',
        #                          'data': self.group.lim})
        data['seriesUnRange'].append({'name': 'UnRange', 'data': UNarea})
        data['seriesBlim_min'].append({
            'name': 'Blim_min',
            'data': self.group.Blim_min
        })
        data['seriesBlim_max'].append({
            'name': 'Blim_max',
            'data': self.group.Blim_max
        })

        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBmsy'] = safe_json(data['seriesBmsy'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesProjection'] = safe_json(data['seriesProjection'])
        data['seriesUnRange'] = safe_json(data['seriesUnRange'])
        data['seriesBrange'] = safe_json(data['seriesBrange'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return data
Example #20
0
    def vars_for_template(self):
        # Filling the data for graph

        ## Catch, profit total and by player for each round
        catch_round = []
        totalCatch_round = []
        totalIndCatch = []
        profit_round = []
        totalProfit_round = []
        totalIndProfit = []
        oCatch = []
        oProfit = []
        oID = []
        oData = []

        # own cacth & profit per player
        for p in self.player.in_all_rounds():
            catch_round.append(p.catch_choice)
            profit_round.append(p.profit)
            totalIndCatch = sum(catch_round)
            totalIndProfit = sum(profit_round)

        # others cacth & profit per player
        for p in self.player.get_others_in_group():
            oCatch.append(p.catch_choice)
            oProfit.append(p.profit)
            oID.append(p.id_in_group)

        others_data = {"Player": oID, "catch": oCatch, "profit": oProfit}
        others_data = collections.OrderedDict(sorted(others_data.items(), key=lambda t: t[0]))

        for element, value in others_data.items():
            oData.append(value)

        # total harvest & total profit
        for p in self.group.in_all_rounds():
            totalCatch_round.append(p.total_catch)
            totalProfit_round.append(p.total_profit)

        # gather data to make series
        data = {
            "Player": self.player.id_in_group,
            "Catch": catch_round,
            "Profit": profit_round,
            "TotalIndCatch": totalIndCatch,
            "TotalIndProfit": totalIndProfit,
            "Total_catch": totalCatch_round,
            "Total_profit": totalProfit_round,
        }

        # create series to plot
        seriesCatch = []
        seriesCatch.append({"name": "Own Catch", "data": catch_round})
        seriesCatch.append({"name": "Total Catch", "data": totalCatch_round})
        Catchseries = safe_json(seriesCatch)

        seriesProfit = []
        seriesProfit.append({"name": "Own Profit", "data": profit_round})
        seriesProfit.append({"name": "Total Profit", "data": totalProfit_round})
        Profitseries = safe_json(seriesProfit)

        return {
            "data": data,
            "Catchseries": Catchseries,
            "Profitseries": Profitseries,
            "others_data": others_data,
            "nation": oData[0],
            "catch": oData[1],
            "profit": oData[2],
            "TotalIndProfit": totalIndProfit,
        }
Example #21
0
 def vars_for_template(self):
     return {'fixed_pay': self.group.agent_fixed_pay,
             'EFFORT_TO_RETURN': safe_json(Constants.EFFORT_TO_RETURN),
             'EFFORT_TO_COST': safe_json(Constants.EFFORT_TO_COST),
             'return_share': int(self.group.agent_return_share * 100)}
Example #22
0
    def vars_for_template(self):
        reset = self.session.vars.get('reset',False)
        if reset == True:
           del self.session.vars['reset']

        input = not Constants.devils_game if not Constants.dynamic else False

        return {
            'reset':         safe_json(reset),
            'input':         safe_json(input),
            'random':        safe_json(Constants.random),
            'dynamic':       safe_json(Constants.dynamic),
            'num_rows':      safe_json(Constants.num_rows),
            'num_cols':      safe_json(Constants.num_cols),
            'feedback':      safe_json(Constants.feedback),
            'undoable':      safe_json(Constants.undoable),
            'box_width':     safe_json(Constants.box_width),
            'box_height':    safe_json(Constants.box_height),
            'time_interval': safe_json(Constants.time_interval),
        }
Example #23
0
 def vars_for_template(self):
     return {
         'EFFORT_TO_RETURN': safe_json(Constants.EFFORT_TO_RETURN),
         'EFFORT_TO_COST': safe_json(Constants.EFFORT_TO_COST),
     }
Example #24
0
    def vars_for_template(self):
        # Filling the data for graph

        ## create area range series for projection uncertainty on biomass plot
        ## projection uncertainty
        proj = self.group.projection()
        proj_un = self.group.projUncertainty()

        j = -1
        UNarea = []
        seq = list(range(len(proj) + 1))

        # simplify nested list
        for i in range(1, 2):
            unArea = sum(proj_un, [])

        for row in unArea[0]:
            j = j + 1
            UNarea.append([[seq[j]] + row])

        UNarea = sum(UNarea, [])

        ## color setting
        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        ## Catch, profit total and by player for each round
        catch_round = []
        totalCatch_round = []
        totalIndCatch = []
        profit_round = []
        totalProfit_round = []
        totalIndProfit = []
        oCatch = []
        oProfit = []
        oID = []
        oData = []
        predProfit_round = []
        IndHarvestEuros = []
        IndpredEuros = []

        # own cacth & profit per player
        for p in self.player.in_all_rounds():
            catch_round.append(p.catch_choice)
            profit_round.append(p.profit)
            totalIndCatch = sum(catch_round)
            totalIndProfit = round(sum(profit_round), 1)
            IndHarvestEuros = round(
                sum(profit_round) * Constants.convertionCurrency, 1)
            predProfit_round.append(p.predProfit)
            IndpredEuros = round(sum(predProfit_round), 1)

        #IndpredEuros = self.participant.payoff - round(IndHarvestEuros,1)

        # others cacth & profit per player
        for p in self.player.get_others_in_group():
            oCatch.append(p.catch_choice)
            oProfit.append(p.profit)
            oID.append(p.id_in_group)

        others_data = {'Player': oID, 'catch': oCatch, 'profit': oProfit}
        others_data = collections.OrderedDict(
            sorted(others_data.items(), key=lambda t: t[0]))

        for element, value in others_data.items():
            oData.append(value)

        # total harvest & total profit
        for p in self.group.in_all_rounds():
            totalCatch_round.append(p.total_catch)
            totalProfit_round.append(p.total_profit)

        # gather data to make series
        data = {
            'Player': self.player.id_in_group,
            'Catch': catch_round,
            'Profit': profit_round,
            'TotalIndCatch': totalIndCatch,
            'TotalIndProfit': totalIndProfit,
            'Total_catch': totalCatch_round,
            'Total_profit': totalProfit_round,
            'Harvestpayoff': IndHarvestEuros,
            'Predpayoff': IndpredEuros,
            'Biomass': self.group.b_round,
            'Bmsy': Constants.Bmsy,
            'Blim': Constants.Blim,
            'Projection': proj,
            'UnRange': UNarea,
            'Bmax': self.group.bmax_round,
            'Bmin': self.group.bmin_round,
            'Blim_min': self.group.Blim_min,
            'Blim_max': self.group.Blim_max,
            'years': Constants.xp_years,
            'colorBlim': colorBlim,
            'colorBlim_range': colorBlim_range,
            'colorBlim_range_label': colorBlim_range_label,
            'colorBlim_label': colorBlim_label
        }

        # create series to plot
        data['seriesBiomass'] = list()
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        data['seriesProjection'] = list()
        data['seriesUnRange'] = list()
        data['seriesBrange'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()

        seriesCatch = []
        seriesCatch.append({'name': 'Ma capture', 'data': catch_round})
        seriesCatch.append({
            'name': 'Capture totale',
            'data': totalCatch_round
        })
        Catchseries = safe_json(seriesCatch)

        seriesProfit = []
        seriesProfit.append({'name': 'Mon profit', 'data': profit_round})
        seriesProfit.append({
            'name': 'Profit total',
            'data': totalProfit_round
        })
        Profitseries = safe_json(seriesProfit)

        data['seriesProjection'].append({'name': 'Projection', 'data': proj})

        data['seriesBiomass'].append({
            'name': 'Biomass',
            'data': self.group.b_round
        })
        data['seriesUnRange'].append({'name': 'UnRange', 'data': UNarea})
        data['seriesBlim_min'].append({
            'name': 'Blim_min',
            'data': self.group.Blim_min
        })
        data['seriesBlim_max'].append({
            'name': 'Blim_max',
            'data': self.group.Blim_max
        })

        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBmsy'] = safe_json(data['seriesBmsy'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesProjection'] = safe_json(data['seriesProjection'])
        data['seriesUnRange'] = safe_json(data['seriesUnRange'])
        data['seriesBrange'] = safe_json(data['seriesBrange'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return {
            'data': data,
            'Catchseries': Catchseries,
            'Profitseries': Profitseries,
            'others_data': others_data,
            'nation': oData[0],
            'catch': oData[1],
            'profit': oData[2],
            'TotalIndProfit': totalIndProfit,
            'seriesBiomass': data['seriesBiomass'],
            'Harvestpayoff': IndHarvestEuros,
            'Predpayoff': IndpredEuros,
            'seriesBmsy': data['seriesBmsy'],
            'seriesBlim': data['seriesBlim'],
            'seriesProjection': data['seriesProjection'],
            'seriesUnRange': data['seriesUnRange'],
            'seriesBlim_min': data['seriesBlim_min'],
            'seriesBlim_max': data['seriesBlim_max'],
            'Biomass': self.group.b_round,
            'Bmsy': Constants.Bmsy,
            'Blim': Constants.Blim,
            'Projection': proj,
            'UnRange': UNarea,
            'Bmax': self.group.bmax_round,
            'Bmin': self.group.bmin_round,
            'Blim_min': self.group.Blim_min,
            'Blim_max': self.group.Blim_max,
            'years': Constants.xp_years,
            'colorBlim': colorBlim,
            'colorBlim_range': colorBlim_range,
            'colorBlim_range_label': colorBlim_range_label,
            'colorBlim_label': colorBlim_label
        }
Example #25
0
 def vars_for_template(self):
     return {'income': safe_json(self.player.available_income)}
Example #26
0
    def vars_for_admin_report(self):

        group = self.get_groups()[0]
        ## color setting
        if self.session.config['T'] == 1:
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['T'] == 2:
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['T'] == 3:
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        # total harvest & total profit
        totalProfit_round = []
        totalCatch_round = []
        for p in group.in_all_rounds():
            totalCatch_round.append(p.total_catch)
            totalProfit_round.append(p.total_profit)

        data = {
            'Total_catch': totalCatch_round,
            'Total_profit': totalProfit_round,
            'Biomass': self.group.b_round,
            'Bmsy': Constants.Bmsy,
            'Blim': Constants.Blim,
            'years': Constants.xp_years,
            'colorBlim': colorBlim,
            'colorBlim_range': colorBlim_range,
            'colorBlim_range_label': colorBlim_range_label,
            'colorBlim_label': colorBlim_label
        }
        seriesCatch = []
        seriesCatch.append({'name': 'Total Catch', 'data': totalCatch_round})
        Catchseries = safe_json(seriesCatch)
        seriesProfit = []
        seriesProfit.append({
            'name': 'Total Profit',
            'data': totalProfit_round
        })
        Profitseries = safe_json(seriesProfit)

        ##Biomass series
        data['seriesBiomass'] = list()
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        biomass = [p.b_round for p in group.in_all_rounds()]

        data['seriesBiomass'].append({'name': 'Biomass', 'data': biomass})
        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBmsy'] = safe_json(data['seriesBmsy'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return {
            'data': data,
            'Catchseries': Catchseries,
            'Profitseries': Profitseries,
            'payoff': self.participant.payoff,
            'seriesBiomass': data['seriesBiomass'],
            'seriesBmsy': data['seriesBmsy'],
            'seriesBlim': data['seriesBlim'],
            'Biomass': self.group.b_round,
            'Bmsy': Constants.Bmsy,
            'Blim': Constants.Blim,
            'years': Constants.xp_years,
            'colorBlim': colorBlim,
            'colorBlim_range': colorBlim_range,
            'colorBlim_range_label': colorBlim_range_label,
            'colorBlim_label': colorBlim_label
        }
Example #27
0
    def vars_for_template(self):
        reset = self.session.vars.get('reset',False)
        if reset == True:
           del self.session.vars['reset']

        input = not Constants.devils_game if not Constants.dynamic else False

        return {
            'reset':         safe_json(reset),
            'input':         safe_json(input),
            'random':        safe_json(Constants.random),
            'dynamic':       safe_json(Constants.dynamic),
            'num_rows':      safe_json(Constants.num_rows),
            'num_cols':      safe_json(Constants.num_cols),
            'feedback':      safe_json(Constants.feedback),
            'undoable':      safe_json(Constants.undoable),
            'box_width':     safe_json(Constants.box_width),
            'box_height':    safe_json(Constants.box_height),
            'time_interval': safe_json(Constants.time_interval),
        }
Example #28
0
    def vars_for_template(self):

        ##create area range series for uncertainty on biomass plot

        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label='rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label='rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim ="red"
            colorBlim_label='gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label='rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim ="rgba(68, 170, 213, 0)"
            colorBlim_label='rgba(68, 170, 213, 0)'
            colorBlim_range= 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        ## projection uncertainty
        j = -1
        UNarea=[]
        seq = list(range(len(self.group.b_proj)+1))

        # simplify nested list
        #dim_list = self.group.number_of_lists(self.group.b_unrange)

        # ! ici solution provisoire
        for i in range (1, 4):
            unArea = sum(self.group.b_unrange,[])

        for row in unArea[self.subsession.round_number - 1]:
            j=j+1
            UNarea.append([[seq[j]] + row])
        UNarea = sum(UNarea,[])

        ## Filling the data for graph
        ## Biomass estimation + projection under statu quo (same harvest level)

        data = {'Biomass': self.group.biomass,
                'Bmsy': Constants.Bmsy,
                'Blim':Constants.Blim,
                'Projection': self.group.b_proj,
                'UnRange': UNarea,
                'Blim_min':self.group.Blim_min,
                'Blim_max': self.group.Blim_max,
                'years' : Constants.xp_years,
                'colorBlim':colorBlim,
                'colorBlim_range':colorBlim_range,
                'colorBlim_range_label':colorBlim_range_label,
                'colorBlim_label':colorBlim_label}

        data['seriesBiomass'] = list()
        data['seriesBmsy'] = list()
        data['seriesBlim'] = list()
        data['seriesProjection'] = list()
        data['seriesUnRange'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()

        data['seriesProjection'].append({'name': 'Projection',
                                         'data': self.group.b_proj})
        data['seriesBiomass'].append({'name': 'Biomass',
                                      'data': self.group.biomass})
        #data['seriesBmsy'].append({'name': 'Bmsy',
         #                          'data': self.group.target})
        #data['seriesBlim'].append({'name': 'Bmsy',
         #                          'data': self.group.lim})
        data['seriesUnRange'].append({'name': 'UnRange',
                                      'data': UNarea})
        data['seriesBlim_min'].append({'name': 'Blim_min',
                                      'data': self.group.Blim_min})
        data['seriesBlim_max'].append({'name': 'Blim_max',
                                       'data': self.group.Blim_max})

        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBmsy'] = safe_json(data['seriesBmsy'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesProjection'] = safe_json(data['seriesProjection'])
        data['seriesUnRange'] = safe_json(data['seriesUnRange'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return data
Example #29
0
    def vars_for_template(self):

        biomassRange = []
        for i in self.group.in_all_rounds():
            biomassRange.append([i.bmin_round, i.bmax_round])

        # set biomass variation rate for the next year
        var = self.group.variation()
        j = range(0, len(Constants.choice_catch))
        r = range(0, len(Constants.other_choice_catch) * 2)

        year = self.group.year()
        name = self.player.in_round(1).name

        tab_payoff = self.group.set_payoffTable()

        choice = "0:%d" % (Constants.elementPayoff_Tab)

        if self.session.config['treatment'] == 'T1':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T2':
            colorBlim = "red"
            colorBlim_label = 'gray'
            colorBlim_range = 'rgba(68, 170, 213, 0)'
            colorBlim_range_label = 'rgba(68, 170, 213, 0)'
        elif self.session.config['treatment'] == 'T3':
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = 'rgba(68, 170, 213, 0)'
            colorBlim_range = 'rgba(213, 70, 150, 0.2)'
            colorBlim_range_label = 'gray'

        data = {
            'Payoff': tab_payoff,
            'round.number': self.subsession.round_number,
            'choicevar': choice,
            'variation': var,
            'j': j,
            'r': r,
            'Biomass': self.group.b_round,
            'Bmsy': Constants.Bmsy,
            'Blim': Constants.Blim,
            'Brange': biomassRange,
            'Bmax': self.group.bmax_round,
            'Bmin': self.group.bmin_round,
            'Blim_min': self.group.Blim_min,
            'Blim_max': self.group.Blim_max,
            'years': Constants.xp_years,
            'colorBlim': colorBlim,
            'colorBlim_range': colorBlim_range,
            'colorBlim_range_label': colorBlim_range_label,
            'colorBlim_label': colorBlim_label,
            'MyName': name,
            'MyID': self.player.id_in_group,
            'Year': year,
            'Round': self.subsession.round_number
        }

        data['seriesBiomass'] = list()
        data['seriesBlim'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()
        data['seriesBrange'] = list()
        data['seriesBlim_min'] = list()
        data['seriesBlim_max'] = list()

        data['seriesBiomass'].append({
            'name': 'Biomass',
            'data': self.group.b_round
        })
        data['seriesBrange'].append({
            'name': 'BiomassRange',
            'data': biomassRange
        })
        data['seriesBlim_min'].append({
            'name': 'Blim_min',
            'data': self.group.Blim_min
        })
        data['seriesBlim_max'].append({
            'name': 'Blim_max',
            'data': self.group.Blim_max
        })
        data['seriesBiomass'] = safe_json(data['seriesBiomass'])
        data['seriesBlim'] = safe_json(data['seriesBlim'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])
        data['seriesBrange'] = safe_json(data['seriesBrange'])
        data['seriesBlim_min'] = safe_json(data['seriesBlim_min'])
        data['seriesBlim_max'] = safe_json(data['seriesBlim_max'])

        return data
Example #30
0
    def vars_for_template(self):

        # set biomass variation rate for the next year
        var = self.group.variation()
        j = range(0, len(Constants.choice_catch))
        r = range(0, len(Constants.other_choice_catch) * 2)

        year = self.group.year()
        name = self.player.in_round(1).name

        tab_payoff = self.group.set_payoffTable()

        choice = "0:%d" % (Constants.elementPayoff_Tab)

        if self.session.config["treatment"] == "T1":
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = "rgba(68, 170, 213, 0)"
            colorBlim_range = "rgba(68, 170, 213, 0)"
            colorBlim_range_label = "rgba(68, 170, 213, 0)"
        elif self.session.config["treatment"] == "T2":
            colorBlim = "red"
            colorBlim_label = "gray"
            colorBlim_range = "rgba(68, 170, 213, 0)"
            colorBlim_range_label = "rgba(68, 170, 213, 0)"
        elif self.session.config["treatment"] == "T3":
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = "rgba(68, 170, 213, 0)"
            colorBlim_range = "rgba(213, 70, 150, 0.2)"
            colorBlim_range_label = "gray"

        data = {
            "Payoff": tab_payoff,
            "round.number": self.subsession.round_number,
            "biomass": self.group.biomass,
            "Bmin": self.group.Bmin,
            "Bmax": self.group.Bmax,
            "choicevar": choice,
            "variation": var,
            "j": j,
            "r": r,
            "Biomass": self.group.biomass,
            "Bmsy": Constants.Bmsy,
            "Blim": Constants.Blim,
            "Brange": self.group.Bun,
            "Bmax": self.group.bmax_round,
            "Bmin": self.group.bmin_round,
            "Blim_min": self.group.Blim_min,
            "Blim_max": self.group.Blim_max,
            "years": Constants.xp_years,
            "colorBlim": colorBlim,
            "colorBlim_range": colorBlim_range,
            "colorBlim_range_label": colorBlim_range_label,
            "colorBlim_label": colorBlim_label,
            "MyName": name,
            "MyID": self.player.id_in_group,
            "Year": year,
            "Round": self.subsession.round_number,
        }

        data["seriesBiomass"] = list()
        data["seriesBmsy"] = list()
        data["seriesBlim"] = list()
        data["seriesBlim_min"] = list()
        data["seriesBlim_max"] = list()
        data["seriesBrange"] = list()
        data["seriesBlim_min"] = list()
        data["seriesBlim_max"] = list()

        data["seriesBiomass"].append({"name": "Biomass", "data": self.group.biomass})
        data["seriesBrange"].append({"name": "Brange", "data": self.group.Bun})
        data["seriesBlim_min"].append({"name": "Blim_min", "data": self.group.Blim_min})
        data["seriesBlim_max"].append({"name": "Blim_max", "data": self.group.Blim_max})

        data["seriesBiomass"] = safe_json(data["seriesBiomass"])
        data["seriesBlim"] = safe_json(data["seriesBlim"])
        data["seriesBlim_min"] = safe_json(data["seriesBlim_min"])
        data["seriesBlim_max"] = safe_json(data["seriesBlim_max"])
        data["seriesBrange"] = safe_json(data["seriesBrange"])
        data["seriesBlim_min"] = safe_json(data["seriesBlim_min"])
        data["seriesBlim_max"] = safe_json(data["seriesBlim_max"])

        return data
Example #31
0
    def vars_for_template(self):

        ##create area range series for uncertainty on biomass plot

        if self.session.config["treatment"] == "T1":
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = "rgba(68, 170, 213, 0)"
            colorBlim_range = "rgba(68, 170, 213, 0)"
            colorBlim_range_label = "rgba(68, 170, 213, 0)"
        elif self.session.config["treatment"] == "T2":
            colorBlim = "red"
            colorBlim_label = "gray"
            colorBlim_range = "rgba(68, 170, 213, 0)"
            colorBlim_range_label = "rgba(68, 170, 213, 0)"
        elif self.session.config["treatment"] == "T3":
            colorBlim = "rgba(68, 170, 213, 0)"
            colorBlim_label = "rgba(68, 170, 213, 0)"
            colorBlim_range = "rgba(213, 70, 150, 0.2)"
            colorBlim_range_label = "gray"

        ## projection uncertainty
        j = -1
        UNarea = []
        seq = list(range(len(self.group.b_proj) + 1))

        # simplify nested list
        # dim_list = self.group.number_of_lists(self.group.b_unrange)

        # ! ici solution provisoire
        for i in range(1, 4):
            unArea = sum(self.group.b_unrange, [])

        for row in unArea[self.subsession.round_number - 1]:
            j = j + 1
            UNarea.append([[seq[j]] + row])

        UNarea = sum(UNarea, [])

        ## Filling the data for graph
        ## Biomass estimation + projection under statu quo (same harvest level)

        data = {
            "Biomass": self.group.biomass,
            "Bmsy": Constants.Bmsy,
            "Blim": Constants.Blim,
            "Projection": self.group.b_proj,
            "UnRange": UNarea,
            "Brange": self.group.Bun,
            "Bmax": self.group.bmax_round,
            "Bmin": self.group.bmin_round,
            "Blim_min": self.group.Blim_min,
            "Blim_max": self.group.Blim_max,
            "years": Constants.xp_years,
            "colorBlim": colorBlim,
            "colorBlim_range": colorBlim_range,
            "colorBlim_range_label": colorBlim_range_label,
            "colorBlim_label": colorBlim_label,
        }

        data["seriesBiomass"] = list()
        data["seriesBmsy"] = list()
        data["seriesBlim"] = list()
        data["seriesProjection"] = list()
        data["seriesUnRange"] = list()
        data["seriesBrange"] = list()
        data["seriesBlim_min"] = list()
        data["seriesBlim_max"] = list()

        data["seriesProjection"].append({"name": "Projection", "data": self.group.b_proj})
        data["seriesBiomass"].append({"name": "Biomass", "data": self.group.biomass})
        # data['seriesBmsy'].append({'name': 'Bmsy',
        #                          'data': self.group.target})
        # data['seriesBlim'].append({'name': 'Bmsy',
        #                          'data': self.group.lim})
        data["seriesUnRange"].append({"name": "UnRange", "data": UNarea})
        data["seriesBrange"].append({"name": "Brange", "data": self.group.Bun})
        data["seriesBlim_min"].append({"name": "Blim_min", "data": self.group.Blim_min})
        data["seriesBlim_max"].append({"name": "Blim_max", "data": self.group.Blim_max})

        data["seriesBiomass"] = safe_json(data["seriesBiomass"])
        data["seriesBmsy"] = safe_json(data["seriesBmsy"])
        data["seriesBlim"] = safe_json(data["seriesBlim"])
        data["seriesProjection"] = safe_json(data["seriesProjection"])
        data["seriesUnRange"] = safe_json(data["seriesUnRange"])
        data["seriesBrange"] = safe_json(data["seriesBrange"])
        data["seriesBlim_min"] = safe_json(data["seriesBlim_min"])
        data["seriesBlim_max"] = safe_json(data["seriesBlim_max"])

        return data
Example #32
0
def preparing_charts(me=None, final=False, isSubsession=False):
    num_rounds = models.Constants.num_rounds
    series = []
    if isSubsession:
        mysubsession = me
    else:
        mysubsession = me.subsession
    empty_rounds = range(mysubsession.round_number + 1, num_rounds + 1)
    making_add = list(zip(list(empty_rounds), [''] * len(empty_rounds)))

    if final:
        all_contribs = [[r.round_number, (a.contribution or 0)]
                        for r in mysubsession.in_all_rounds()
                        for a in r.get_players()]
        all_contribs += making_add
        popsize = len(mysubsession.get_players())
        all_contribs_average = [[
            r.round_number,
            round(
                sum([(p.contribution or 0)
                     for p in r.get_players()]) / popsize)
        ] for r in mysubsession.in_all_rounds()]

        series.append({
            'name': 'All participants',
            'type': 'scatter',
            'data': all_contribs,
            'marker': {
                'fillColor': '#FFFFFF',
                'lineWidth': 1,
                'lineColor': 'blue',
                'symbol': 'circle',
                'radius': 7,
            }
        })
        series.append({
            'name': 'Overall average',
            'type': 'line',
            'color': 'rgba(0, 0, 0, 0.2)',
            'lineWidth': 15,
            'data': all_contribs_average,
            'marker': {
                'enabled': False,
                'fillColor': '#FFFFFF',
                'lineWidth': 1,
                'lineColor': 'blue',
                'radius': 1,
                'symbol': 'circle',
            }
        })
    if me and not isSubsession:

        mygroupaverage = [[
            p.round_number,
            round(p.group.average_contribution),
        ] for p in me.in_all_rounds()]
        mygroupcontribs = [[r.round_number, (a.contribution or 0)]
                           for r in me.group.in_all_rounds()
                           for a in r.get_players()]
        personcontribs = [[
            p.round_number,
            p.contribution,
        ] for p in me.in_all_rounds()]
        mygroupcontribs += making_add
        personcontribs += making_add
        series.append({
            'name': 'Your group average',
            'type': 'line',
            'data': mygroupaverage
        })

        series.append({
            'name': 'Your group members',
            'type': 'scatter',
            'data': mygroupcontribs,
            'marker': {
                'fillColor': '#FFFFFF',
                'lineWidth': 1,
                'lineColor': 'red',
                'radius': 7,
                'symbol': 'circle'
            },
        })

        series.append({
            'name': 'Your contributions',
            'type': 'line',
            'data': personcontribs,
            'marker': {
                'radius': 5,
            }
        })

    highcharts_series = safe_json(series)
    return highcharts_series