예제 #1
0
    def __init__(self, name, team, index):
        sys.path.append(path)
        from output_formatter import OutputFormatter
        from input_formatter import InputFormatter
        import torch

        BaseAgent.__init__(self, name, team, index)
        self.actor_model = None
        self.single_model = None
        self.torch = torch
        self.output_formatter = OutputFormatter()
        self.input_formatter = InputFormatter(self.index, self.index, self.team)
예제 #2
0
    def __init__(self, name, team, index):
        sys.path.append(path)
        from output_formatter import OutputFormatter
        from input_formatter import InputFormatter
        from cool_atba import Atba
        import torch

        BaseAgent.__init__(self, name, team, index)
        self.atba = Atba()
        self.torch = torch
        self.output_formatter = OutputFormatter()
        self.input_formatter = InputFormatter(self.index, self.index,
                                              self.team)
예제 #3
0
class TorchLearner(BaseAgent):
    def __init__(self, name, team, index):
        sys.path.append(path)
        from output_formatter import OutputFormatter
        from input_formatter import InputFormatter
        import torch

        BaseAgent.__init__(self, name, team, index)
        self.actor_model = None
        self.single_model = None
        self.torch = torch
        self.output_formatter = OutputFormatter()
        self.input_formatter = InputFormatter(self.index, self.index,
                                              self.team)

    def initialize_agent(self):
        from torch_model import SingleAction, SymmetricModel
        self.actor_model = SymmetricModel()
        self.actor_model.load_state_dict(
            self.torch.load('levi/cool_atba.actor'))
        self.single_model = SingleAction(self.actor_model)

    def get_output(self, game_tick_packet):
        spatial, car_stats = self.input_formatter.get_input(game_tick_packet)

        with self.torch.no_grad():
            action = self.single_model.get_action(spatial, car_stats)

        in_the_air = game_tick_packet.game_cars[self.index].jumped
        player_input = self.output_formatter.get_output(action, in_the_air)

        return player_input
예제 #4
0
class TorchLearner(BaseAgent):
    def __init__(self, name, team, index):
        sys.path.append(path)
        from output_formatter import OutputFormatter
        from input_formatter import InputFormatter
        from cool_atba import Atba
        import torch

        BaseAgent.__init__(self, name, team, index)
        self.atba = Atba()
        self.torch = torch
        self.output_formatter = OutputFormatter()
        self.input_formatter = InputFormatter(self.index, self.index,
                                              self.team)

    def get_output(self, game_tick_packet):
        spatial, car_stats = self.input_formatter.get_input(game_tick_packet)

        atba_action = self.atba.get_action(spatial, car_stats)

        in_the_air = game_tick_packet.game_cars[self.index].jumped
        player_input = self.output_formatter.get_output(
            atba_action, in_the_air)

        return player_input
예제 #5
0
 def add_content(self, cache, project, url):
     """
     Add OutputFormatter containing cache filtered through
     user's filters.
     """
     self._content = OutputFormatter(cache, project, url, self._css, self._filters)
예제 #6
0
class Recipient:
    """
    Contains email address and output formatter object targeting
    given email recipient.
    """

    def __init__(self, email, filters, css):
        self._email = email
        self._css = css
        self._content = None
        self._filters = filters

    def add_content(self, cache, project, url):
        """
        Add OutputFormatter containing cache filtered through
        user's filters.
        """
        self._content = OutputFormatter(cache, project, url, self._css, self._filters)

    def send_email(self, project, smtp_config, gpg_recipient, dry_run):
        """
        - EITHER: send an html email to Recipient using given smtp configuration
                  and gpg_recipient (to get encrypted authentication info)
        - OR: if dry_run is set to true, dump the json into stdout.
        """

        def _subject():
            timenow = datetime.now()
            return f"{project} Gerrit digest {timenow.strftime('%A %d %B %Y')}"

        def _decrypt_auth(gpg_recipient):
            gpg = gnupg.GPG(gnupghome=os.path.join(os.environ["HOME"], ".gnupg"))
            with open(gpg_recipient + ".gpg", "rb") as fgpg:
                decrypted_data = gpg.decrypt_file(fgpg)
                if not decrypted_data.ok:
                    raise Exception(
                        f"failed to send mail: {decrypted_data.stderr}"  # pylint: disable=no-member
                    )
            return str(decrypted_data).strip()

        message = self._content.format_html()
        if dry_run:
            logging.info(self._email)
            logging.info(self._content.format_json())
            logging.info(message)
            return

        msg = EmailMessage()
        msg["Subject"] = _subject()
        msg["From"] = smtp_config.from_address
        msg["To"] = self._email
        msg.set_content(
            "For the list of today's changes in AOSP Gerrit, please turn on HTML."
        )
        msg.add_alternative(message, subtype="html")
        smtp = smtplib.SMTP(smtp_config.url)
        if smtp_config.authentication:
            smtp.ehlo()
            pwd = _decrypt_auth(gpg_recipient)
            smtp.login(smtp_config.uname, pwd)
        smtp.send_message(msg)