def set_tg(self):
        """ Try to grab the treatment group number for the student.
        If there is no treatment group number available, request it
        from the server.
        """
        # Checks to see the student currently has a treatment group number.
        if not os.path.isfile(self.current_working_dir + LOCAL_TG_FILE):
            cur_email = self.assignment.get_student_email()
            log.info("Current email is %s", cur_email)
            if not cur_email:
                self.tg_id = -1
                return EMPTY_MISUCOUNT_TGID_PRNTEDMSG

            tg_url = ("{}{}/{}{}"
                      .format(TGSERVER, cur_email, self.assignment_name,
                              TG_SERVER_ENDING))
            try:
                log.info("Accessing treatment server at %s", tg_url)
                data = requests.get(tg_url, timeout=1).json()
            except IOError:
                data = {"tg": -1}
                log.warning("Failed to communicate to server", exc_info=True)

            if data.get("tg") is None:
                log.warning("Server returned back a bad treatment group ID.")
                data = {"tg": -1}

            with open(self.current_working_dir + LOCAL_TG_FILE, "w") as fd:
                fd.write(str(data["tg"]))

        tg_file = open(self.current_working_dir + LOCAL_TG_FILE, 'r')
        self.tg_id = int(tg_file.read())
def set_tg ( self ) : if not os . path . isfile ( self . current_working_dir + LOCAL_TG_FILE ) : cur_email = self . assignment . get_student_email ( ) log . info ( "Current email is %s" , cur_email ) if not cur_email : self . tg_id = - 1 return EMPTY_MISUCOUNT_TGID_PRNTEDMSG tg_url = ( "{}{}/{}{}" . format ( TGSERVER , cur_email , self . assignment_name , TG_SERVER_ENDING ) ) try : log . info ( "Accessing treatment server at %s" , tg_url ) data = requests . get ( tg_url , timeout = 1 ) . json ( ) except IOError : data = { "tg" : - 1 } log . warning ( "Failed to communicate to server" , exc_info = True ) if data . get ( "tg" ) is None : log . warning ( "Server returned back a bad treatment group ID." ) data = { "tg" : - 1 } with open ( self . current_working_dir + LOCAL_TG_FILE , "w" ) as fd : fd . write ( str ( data [ "tg" ] ) ) tg_file = open ( self . current_working_dir + LOCAL_TG_FILE , 'r' ) self . tg_id = int ( tg_file . read ( ) )
Try to grab the treatment group number for the student.
        If there is no treatment group number available, request it
        from the server.