Exemplo n.º 1
0
class Batcher:
    def __init__(self, batch_size=1024):
        self.batch_size = batch_size
        self.oracle = Oracle()

    def set_batch_size(self, batch_size: int):
        self.batch_size = batch_size

    # make predictions one batch at a time, then aggregate the results and return
    def batch_predict(self, input_data):
        output = list()
        while input_data:
            batch = self.next_batch(input_data)
            output.append(self.oracle.query(batch))
        output = np.concatenate(output)
        print('{} results predicted'.format(len(output)))
        return tf.convert_to_tensor(output, dtype=tf.float32)

    # pop off a batch from the beginning and return
    # if no more data, return None
    def next_batch(self, input_data) -> list:
        batch = list()
        for i in range(self.batch_size):
            if input_data:
                batch.append(input_data.pop(0))
            else:
                break
        return batch
Exemplo n.º 2
0
    def execute(self):
        # display controller parameters
        self.output_params()

        # initialize driver
        initializer = DriverInitializer(debug=self.debug)
        driver = initializer.get_driver()

        # login and refine research
        login_agent = LoginAgent(driver,
                                 job_title=self.job_title,
                                 job_location=self.job_location)
        login_agent.login()
        refine_agent = RefineAgent(driver,
                                   distance=self.distance,
                                   experience=self.experience,
                                   order_by_date=self.order_by_date)
        refine_agent.refine()

        # create PageLooper object
        looper = PageLooper(driver,
                            limit=self.limit,
                            duration=self.duration,
                            date_limit=self.date_limit)
        result = looper.loop()

        # close driver and all windows
        if not self.debug:
            driver.quit()

        # get data from PageLooper object
        input_data, summaries, links = looper.get_all()

        if self.mode == 'browse':
            # use oracle to process input_data
            oracle = Oracle()
            output = oracle.query(input_data)

            # stop timer and record time elapsed in minutes
            runtime_duration = round((time.time() - self.timer) / 60)

            # use reporter to process output
            reporter = Reporter()
            reporter.report(output, summaries, links, runtime_duration,
                            self.confidence_threshold)

        else:
            # save input_data
            with open(self.feature_path, 'w') as output:
                for entry in input_data:
                    output.write(entry)
                    output.write('<<END>>\n\n')

        # return driver
        return driver
Exemplo n.º 3
0
"""
A class for aeternity oracle clients and servers.
Author: John Newby

Copyright (c) 2018 aeternity developers

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
"""

from oracle import Oracle
import sys

oracle = Oracle()

oracle_pubkey, query_fee, query_ttl, response_ttl, fee, query = sys.argv[1:7]
query_id = oracle.query(oracle_pubkey, query_fee, query_ttl, response_ttl, fee,
                        query)
oracle.subscribe_query(query_id)
Exemplo n.º 4
0
Copyright (c) 2018 aeternity developers

Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all
copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.

"""

import json
from oracle import Oracle
import sys

oracle = Oracle()

oracle_pubkey = sys.argv[1]

query = json.dumps({"action": "recv"})
query_id = oracle.query(oracle_pubkey, 0, 5, 5, 3, query)
oracle.subscribe_query(query_id)