def _find_profitable_paths(self, max_transaction_length):
        logging.info("Checking for profitable conversions...")
        t_start = time.time()
        for c in self.graph.keys():
            # For currency @c, find all paths within the constructed path that are
            # at most @max_transaction_length long
            paths = graph.find_paths(self.graph, c, c, self.user_config,
                                     max_transaction_length)
            profitable_conversions = []

            for p in paths:
                conversion = graph.build_conversion(p, self.user_config)
                if conversion is not None and conversion["winnings"] > 0:
                    profitable_conversions.append(conversion)

            if self.logging:
                n_profitable = len(profitable_conversions)
                if n_profitable > 0:
                    logging.info("Checking {} -> {} Conversions".format(
                        c, n_profitable))

            profitable_conversions = sorted(profitable_conversions,
                                            key=lambda k: k["winnings"],
                                            reverse=True)

            self.results[c] = profitable_conversions

        t_end = time.time()
        if self.logging:
            logging.info("Spent {}s finding paths".format(
                round(t_end - t_start, 2)))
    def test_build_graph(self):
        # Hand-crafted offers to produce a profitable path
        offers_with_vendor = [
            Offer(league="Heist",
                  have="Orb of Regret",
                  want="Chaos Orb",
                  stock=8,
                  conversion_rate=8,
                  contact_ign="some_guy"),
            Offer(league="Heist",
                  have="Orb of Alchemy",
                  want="Orb of Regret",
                  stock=8,
                  conversion_rate=1,
                  contact_ign=VENDOR_OFFER_IGN),
            Offer(league="Heist",
                  have="Chaos Orb",
                  want="Orb of Alchemy",
                  stock=100,
                  conversion_rate=.25,
                  contact_ign="some_guy"),
        ]

        graph = build_graph(offers_with_vendor)
        paths = find_paths(graph, "Chaos Orb", "Chaos Orb", user_config)

        self.assertTrue(len(paths) > 0)
예제 #3
0
 def test_find_paths(self):
     paths_small_same_currency = find_paths(expected_graph_small, "Chaos",
                                            "Chaos", user_config)
     self.assertListEqual(expected_profitable_paths_small_same_currency(),
                          paths_small_same_currency)