Beispiel #1
0
    def creating_session(self):
        ## DEBUG
        for p in self.get_players():
            set_default_pvars(p)

        num_per_page = 5

        for locale in ["usa", "rsa"]:
            dat = pd.read_csv("configs/time_input_" + locale + ".csv")
            self.session.vars[locale + "_time_dat"] = dat

        # Colors picked with a good pallete
        # They overwrite, so just put the one you want here
        time_hex_colors = ["#F8766D", "#00BA38", "#619CFF"]

        for p in self.get_players():
            locale = p.participant.vars["locale"]
            dat = self.session.vars[locale + "_time_dat"]
            block_names = get_block_names(dat)

            # Show a maximum of 20 groups if more than 20 are set
            num_rounds = min(len(block_names), 20)

            p.participant.vars["time_hex_colors"] = time_hex_colors
            p.participant.vars["time_num_rounds"] = num_rounds
            p.participant.vars["time_block_names"] = block_names
            p.participant.vars["time_num_per_page"] = num_per_page
Beispiel #2
0
 def creating_session(self):
     treatment = self.session.config["treatment"]
     wave = self.session.config["wave"]
     lookup_data = pd.read_csv("configs/w" + str(wave) + "t" +
                               str(treatment) + "_lookup.csv")
     self.session.vars["lookup_data"] = lookup_data
     for p in self.get_players():
         set_default_pvars(p)
Beispiel #3
0
def set_beliefs_data(page_obj):
    for p in page_obj.subsession.get_players():
        set_default_pvars(p)
        locale = p.participant.vars["locale"]
        nrounds = page_obj.session.vars["beliefs_" + locale +
                                        "_dat"]["gid"].unique()
        nrounds = len(nrounds)
        p.participant.vars["beliefs_num_rounds"] = nrounds
Beispiel #4
0
    def creating_session(self):
        # DEBUG
        for p in self.get_players():
            set_default_pvars(p)

        for locale in ["usa", "rsa"]:
            dat = pd.read_csv("configs/ca_input_" + locale + ".csv")
            self.session.vars[locale + "_ca_dat"] = dat

        for p in self.get_players():

            locale = p.participant.vars["locale"]
            dat = self.session.vars[locale + "_ca_dat"]

            p.participant.vars["ca_num_ops"] = getAvals(dat.iloc[0, :])
            p.participant.vars["ca_num_rounds"] = len(dat["pair_id"])
            p.participant.vars["ca_hex_colors"] = ["#F8766D", "#00BFC4"]
Beispiel #5
0
 def creating_subsession(self):
     for p in self.get_players():
         set_default_pvars(p)
Beispiel #6
0
    def vars_for_template(self):

        # Where are we
        locale = self.participant.vars["locale"]

        start_time = self.participant.vars["start_time"]
        if locale == "rsa":
            rsa_tz = tz.gettz("Africa/Johannesburg")
            start_time = start_time.astimezone(rsa_tz)
        elif locale == "usa":
            usa_tz = tz.gettz("America/New_York")
            start_time = start_time.astimezone(usa_tz)

        ## DEBUG
        set_default_pvars(self)
        if self.participant.label == None:
            self.participant.label = "test_subject"

        if "utc_finish_time" not in self.participant.vars:
            # What time is it right now in utc
            self.participant.vars["utc_finish_time"] = datetime.now(tz=timezone.utc)

            risk_results    = self.participant.vars["risk_results"]
            time_results    = self.participant.vars["time_results"]
            ca_results      = self.participant.vars["ca_results"]
            beliefs_results = self.participant.vars["beliefs_results"]


            risk_when = risk_results["final_payment"]["when"][0]
            time_when = time_results["final_payment"]["when"][0]
            ca0_when  = ca_results["final_payment"]["when"][0]
            ca1_when  = ca_results["final_payment"]["when"][1]

            risk_when = start_time + timedelta(days = risk_when)
            time_when = start_time + timedelta(days = time_when)
            ca0_when  = start_time + timedelta(days = ca0_when)
            ca1_when  = start_time + timedelta(days = ca1_when)

            risk_when = risk_when.strftime("%d %B %Y")
            time_when = time_when.strftime("%d %B %Y")
            ca0_when  = ca0_when.strftime("%d %B %Y")
            ca1_when  = ca1_when.strftime("%d %B %Y")

            risk_results["final_payment"]["when"][0] = risk_when
            time_results["final_payment"]["when"][0] = time_when
            ca_results["final_payment"]["when"][0]   = ca0_when
            ca_results["final_payment"]["when"][1]   = ca1_when
            ca_results["final_payment"]["is_date"]   = True

            self.participant.vars["risk_results"]    = risk_results
            self.participant.vars["time_results"]    = time_results
            self.participant.vars["ca_results"]      = ca_results
            self.participant.vars["beliefs_results"] = beliefs_results

        risk_results    = self.participant.vars["risk_results"]
        time_results    = self.participant.vars["time_results"]
        ca_results      = self.participant.vars["ca_results"]
        beliefs_results = self.participant.vars["beliefs_results"]

        beliefs_final_payment = self.participant.vars["beliefs_final_payment"]
        risk_final_payment    = self.participant.vars["risk_final_payment"]
        time_final_payment    = self.participant.vars["time_final_payment"]
        ca_final_payment      = self.participant.vars["ca_final_payment"]
        endowment             = self.participant.vars["endowment"]

        # Subjects have finished on time if their finish_time precedes the end time
        end_time       = self.participant.vars["end_time"]
        finish_time    = self.participant.vars["utc_finish_time"]
        print("subject finish time: " + str(finish_time))
        print("session end time: " + str(end_time))
        finish_on_time = finish_time < end_time
        setattr(self.player, "finish_time", str(finish_time))

        # Start time just to find

        full_final_pay = {
                "plabel"         : self.participant.label,
                "locale"         : locale,
                "wave"           : self.participant.vars["wave"],
                "start_time"     : start_time.strftime("%Y-%m-%d %H:%M"),
                "end_time"       : self.participant.vars["end_time"].strftime("%Y-%m-%d %H:%M"),
                "finish_time"    : self.participant.vars["utc_finish_time"].strftime("%Y-%m-%d %H:%M"),
                "finish_on_time" : finish_on_time,
                "endowment"      : endowment,
                "beliefs"        : beliefs_final_payment,
                "risk"           : risk_final_payment,
                "time"           : time_final_payment,
                "ca"             : ca_final_payment,
                "payment_method" : self.participant.vars["payment_method"],
                }

        self.player.final_pay = json.dumps(full_final_pay)
        # Save the final_pay for the subject to a CSV
        final_pay_to_csv(full_final_pay)

        final_dat = {
            "session_date"     : start_time.strftime("%d %B %Y"),
            "endowment" : endowment,
            "risk_dat": risk_results,
            "time_dat": time_results,
            "ca_dat": ca_results,
            "beliefs_dat": beliefs_results,
            "finish_on_time": finish_on_time
            }
        return final_dat