Beispiel #1
0
def _set_configuration(args):
    """
    This method using for set configurations of program and logger
    :param args: arguments from user console input
    :return: exit code
    """
    conf_type_obj = args.pop(ParserArgs.CONFIG_TYPE.name)
    if conf_type_obj == ParserArgs.SETTINGS.name:
        storage_path = args.pop(ParserArgs.STORAGE_PATH.dest)
        try:
            Configuration.edit_settings(storage_path)
        except Exception as e:
            sys.stderr.write(str(e))
            return ERROR_CODE
        print('Program settings edited...')

    elif conf_type_obj == ParserArgs.LOGGER.name:
        level = args.pop(ParserArgs.LOGGER_LEVEL.dest)
        enabled = args.pop(ParserArgs.ENABLED_LOGGER.dest)
        log_file_path = args.pop(ParserArgs.LOG_FILE_PATH.dest)

        Configuration.edit_logger_configs(Files.LOG_CONFIG, level, enabled,
                                          log_file_path)
        print('Logger configs edited...')
    return 0
Beispiel #2
0
def start_ai():
    global running
    keyboard = Controller()
    running = True
    keys = File.read_keys(Configuration.get_selected_game())
    labels = File.read_labels(Configuration.get_selected_game())
    model = create_model()
    dir = os.path.dirname(
        File.get_checkpoint_file(Configuration.get_selected_game()))
    latest = tf.train.latest_checkpoint(dir)
    model.load_weights(latest)

    class_amount = len(File.read_labels(Configuration.get_selected_game()))
    yolo_model = File.get_yolo_cfg_file_fullpath(class_amount)
    label_path = File.get_yolo_label_textfile_fullpath(
        Configuration.get_selected_game())

    options = {
        'model': yolo_model,
        'load': latest_checkpoint(),
        'threshold': 0.2,
        'gpu': 0.8,
        'labels': label_path
    }
    tfnet = TFNet(options)

    while running:
        img = ImageGrab.grab()
        img_np = np.array(img)
        frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2RGB)
        results = tfnet.return_predict(frame)
        reset_label_dict(labels)
        shorten_list(results)
        tensor = []
        for label in label_data_dict:
            tensor.append(int(label_data_dict[label][0]))
            tensor.append(int(label_data_dict[label][1]))
            tensor.append(int(label_data_dict[label][2]))
            tensor.append(int(label_data_dict[label][3]))
        #print(tensor)
        single_row = np.expand_dims(tensor, axis=0)
        retval = model.predict(single_row)[0]
        for index, val in enumerate(retval):
            mapped_key = get_key_code(keys[index])
            print(val)
            if (val < 0.5):
                keyboard.release(mapped_key)
                print('released: ' + str(mapped_key))
            if (val > 0.5):
                keyboard.press(mapped_key)
                print('pressed: ' + str(mapped_key))
        print(keys)
        print(retval)

    return
Beispiel #3
0
def _reset_configuration(conf_type_obj):
    if (conf_type_obj == ParserArgs.LOGGER.name
            and os.path.exists(Files.LOG_CONFIG)):

        os.remove(Files.LOG_CONFIG)
        print('Logger configs reset...')

    if (conf_type_obj == ParserArgs.SETTINGS.name
            and os.path.exists(Files.SETTINGS)):
        Files.set_default()
        Configuration.reset_settings()
        os.remove(Files.SETTINGS)
        print('Program settings reset...')
    return 0
Beispiel #4
0
    def __init__(self, config: Configuration):

        self.WIDGET_SPACING = 8
        # self.configuration = config
        config.widgets['settings-window-box'] = self
        print(config.widgets)
        self.setup_ui()
Beispiel #5
0
    def register_participant(self, routing_identifier: str) -> None:
        if not self.__client.is_connected:
            self._error("NATS.IO CLIENT NOT CONNECTED")
            return None
        try:
            node: str = Configuration.get_instance().node()
            request: ParticipantJoined = ParticipantJoined(
                identifier=routing_identifier, node=node)
            response = self.__client.request(
                subject="{}/{}".format(ADDRESS_SERVICE, "/register"),
                payload=request.SerializeToString())
            result: Result = Result()
            result.ParseFromString(response.data)
            if result.status == Result.Status.SUCCESS:
                self._info("REGISTERED TO NODE: {} TO NODE: {} \n {}".format(
                    routing_identifier, node, result.message))
            elif result.status == Result.Status.SUCCESS:
                self._error(
                    "FAILED TO REGISTER :{} TO NODE: {} TO NONE: {} \n {}".
                    format(routing_identifier, node, result.message))

        except ErrConnectionClosed as e:
            self._error("Connection closed prematurely. {}", e)
            return None

        except ErrTimeout as e:
            self._error("Timeout occurred when publishing msg :{}".format(e))
            return None
Beispiel #6
0
 async def test_subscription(self):
     payload = ParticipantPassOver()
     payload.sender_identifier = "XXXXXX"
     payload.target_identifier = "YYYYYY"
     payload.originating_node = "saber-fox"
     payload.payload = "guniowevw".encode()
     await self.__client.publish(
         subject="v1/node/{}/participants/pass-over".format(
             Configuration.get_instance().node()),
         payload=payload.SerializeToString())
Beispiel #7
0
def migrate() -> None:
    configuration: Configuration = Configuration.get_instance()

    click.echo("DATABASE URL: {}\n".format(configuration.database_uri()))
    click.echo("MIGRATIONS FOLDER: {}\n".format(MIGRATIONS_FOLDER))

    handler = SQLMigrationHandler(
        database_url=configuration.database_uri(),
        migration_folder=MIGRATIONS_FOLDER
    )
    handler.migrate()
Beispiel #8
0
def run_build_cli(dry_run: bool, branch: str, commit_id: str):
    from app.build import Build
    from app.configuration import Configuration
    from app.runner import Runner

    conf = Configuration.from_file('config.yml', branch, commit_id)
    conf.dry_run = dry_run

    build = Build.from_configuration(conf)
    runner = Runner.from_build(build)
    runner.run()
Beispiel #9
0
def lstm_prediction(indicator_file_name, data_input):
    modelh5_path = Configuration.get_file_model_file(indicator_file_name)
    # initialize the Recurrent Neural Network
    # Solving pattern with sequence of data
    regressor = keras.models.load_model(modelh5_path)
    predicted_price = regressor.predict(data_input)
    result = {
        'summary': str(regressor.summary()),
        'predicted_price': predicted_price
    }
    return result
 def setUp(self) -> None:
     configuration: Configuration = Configuration.get_instance(testing=True)
     self.migration_handler = SQLMigrationHandler(
         database_url=configuration.database_uri(),
         migration_folder=MIGRATIONS_FOLDER)
     self.migration_handler.migrate()
     self.__debug = True
     engine = create_engine(configuration.database_uri(), echo=self.__debug)
     session_factory = sessionmaker(bind=engine)
     self.session = scoped_session(session_factory)
     BaseModel.set_session(session=self.session)
     BaseModel.prepare(engine, reflect=True)
Beispiel #11
0
 def get():
     """RNN Learning [get] method
     Returns:
         Response: The response
     """
     indicator_files = []
     indicator_files = Configuration.get_files()
     message = json.dumps({
         "api_version": "1.0.0",
         "indicator_files": indicator_files
     })
     response = Response(
         message,
         status=200,  # Status OK
         mimetype='application/json')
     return response
Beispiel #12
0
def run_build(res):
    branch = res['ref'].rsplit('/', maxsplit=1)[1]

    tag = None
    if res['ref'].startswith('refs/heads/'):
        branch = res['ref'][len('refs/heads/'):]
    elif res['ref'].startswith('refs/tags/') and 'base_ref' in res:
        branch = res['base_ref'][len('refs/heads/'):]
        tag = res['ref'][len('refs/tags/'):]
    else:
        return

    commit_id = res['head_commit']['id']

    conf = Configuration.from_file('config.yml', branch, commit_id)
    if conf is None:
        return

    build = Build.from_configuration(conf)
    runner = Runner.from_build(build)
    runner.run()
Beispiel #13
0
def run() -> int:
    """
    Start program
    :return: int - exit code
    """
    # check settings
    Configuration.apply_settings()
    set_logger_enabled(Configuration.is_logger_enabled())

    # check for files and create it if they missed
    check_program_data_files(Files.FOLDER, Files.FILES)

    # set logging configuration
    if os.path.exists(Files.LOG_CONFIG):
        set_logger_config_file(Files.LOG_CONFIG)
    else:
        set_logger_config_file(Files.DEFAULT_LOG_CONFIG_FILE)

    # create loggers and
    cli_logger = get_logger()
    cli_logger.info('Start program.')

    # load data from storage and create entities controllers
    users_wrapper_storage = UserWrapperStorage(Files.AUTH_FILE, Files.ONLINE)

    queue_storage = JsonQueueStorage(Files.QUEUES_FILE)
    queue_controller = QueueController(queue_storage)

    task_storage = JsonTaskStorage(Files.TASKS_FILE)
    task_controller = TaskController(task_storage)

    user_storage = JsonUserStorage(Files.USERS_FILE)
    user_controller = UserController(user_storage)

    plan_storage = JsonPlanStorage(Files.PLANS_FILE)
    plan_controller = PlanController(plan_storage)

    # init library interface
    library = Interface(users_wrapper_storage.online_user, queue_controller,
                        user_controller, task_controller, plan_controller)

    # update reminders deadlines queue and other
    library.update_all()
    _show_new_messages(library)

    parser = get_parsers()
    args = vars(parser.parse_args())
    cli_logger.debug('Console args: {}'.format(args))

    # check that target is defined
    target = args.pop(ParserArgs.TARGET.name)
    if target is None:
        parser.error('target is required', need_to_exit=False)
        return ERROR_CODE

    if target == ParserArgs.UPDATE.name:
        return 0

    # check that action is defined
    action = args.pop(ParserArgs.ACTION)
    if action is None:
        FormattedParser.active_sub_parser.error('action is required',
                                                need_to_exit=False)
        return ERROR_CODE

    # check that target is config and do action with it
    if target == ParserArgs.CONFIG.name:
        if action == ParserArgs.SET:
            return _set_configuration(args)

        if action == ParserArgs.RESET:
            conf_type_obj = args.pop(ParserArgs.CONFIG_TYPE.name)
            return _reset_configuration(conf_type_obj)

    # check that target is user and do action with it
    if target == ParserArgs.USER.name:
        if action == ParserArgs.ADD:
            return _add_user(nick=args.pop(ParserArgs.NICKNAME.name),
                             password=args.pop(ParserArgs.PASSWORD.name),
                             users_storage=users_wrapper_storage,
                             library=library)

        if action == ParserArgs.LOGIN.name:
            return _login(nick=args.pop(ParserArgs.NICKNAME.name),
                          password=args.pop(ParserArgs.PASSWORD.name),
                          users_storage=users_wrapper_storage,
                          library=library)

        if action == ParserArgs.LOGOUT.name:
            return _logout(users_wrapper_storage)

        if action == ParserArgs.SHOW:
            long = args.pop(ParserArgs.LONG.dest)
            sortby = args.pop(ParserArgs.SORT_BY.dest)
            return _show_user_tasks(library, long, sortby)

    # check that target is queue and do action with it
    if target == ParserArgs.QUEUE.name:
        if action == ParserArgs.ADD:
            return _add_queue(name=args.pop(
                ParserArgs.QUEUE_NAME.name).strip(' '),
                              library=library)

        if action == ParserArgs.DELETE:
            return _del_queue(key=args.pop(
                ParserArgs.QUEUE_NAME.name).strip(' '),
                              recursive=args.pop(ParserArgs.RECURSIVE.dest),
                              library=library)

        if action == ParserArgs.SET:
            key = args.pop(ParserArgs.KEY.name)
            new_name = args.pop(ParserArgs.NEW_NAME.dest)
            if new_name is None:
                parser.active_sub_parser.help()
                return 0

            return _edit_queue(key=key, new_name=new_name, library=library)

        if action == ParserArgs.SHOW:
            return _show_queue_tasks(
                key=args.pop(ParserArgs.KEY.name),
                opened=args.pop(ParserArgs.OPEN_TASKS.dest),
                archive=args.pop(ParserArgs.SOLVED_TASKS.dest),
                failed=args.pop(ParserArgs.FAILED_TASKS.dest),
                long=args.pop(ParserArgs.LONG.dest),
                library=library,
                sortby=args.pop(ParserArgs.SORT_BY.dest))

        if action == ParserArgs.FIND:
            name = args.pop(ParserArgs.QUEUE_NAME.name)
            return _find_queues(name, library)

    # check that target is task and do action with it
    if target == ParserArgs.TASK.name:
        if action == ParserArgs.ADD:
            return _add_task(args, library)

        if action == ParserArgs.SET:
            return _edit_task(args, library)

        if action == ParserArgs.DELETE:
            return _del_task(args, library)

        if action == ParserArgs.SHOW:
            return _show_task(args.pop(ParserArgs.KEY.name), library,
                              args.pop(ParserArgs.LONG.dest))

        if action == ParserArgs.FIND:
            return _find_task(args, library)

        if action == ParserArgs.ACTIVATE:
            key = args.pop(ParserArgs.KEY.name)
            return _activate_task(key, library)

    # check that target is plan and do action with it
    if target == ParserArgs.PLAN.name:
        if action == ParserArgs.ADD:
            name = args.pop(ParserArgs.PLAN_NAME.name)
            period = args.pop(ParserArgs.PLAN_PERIOD.name)
            activation_time = args.pop(ParserArgs.PLAN_ACTIVATION_TIME.name)
            reminder = args.pop(ParserArgs.TASK_REMINDER.dest)
            return _add_plan(name, activation_time, period, reminder, library)

        if action == ParserArgs.SET:
            key = args.pop(ParserArgs.KEY.name)
            new_name = args.pop(ParserArgs.PLAN_NAME_OPTIONAL.dest)
            period = args.pop(ParserArgs.PLAN_PERIOD_OPTIONAL.dest)
            activation_time = args.pop(
                ParserArgs.PLAN_ACTIVATION_TIME_OPTIONAL.dest)

            reminder = args.pop(ParserArgs.TASK_REMINDER.dest)
            return _edit_plan(key, new_name, period, activation_time, reminder,
                              library)

        if action == ParserArgs.SHOW:
            return _show_plans(library)

        if action == ParserArgs.DELETE:
            key = args.pop(ParserArgs.KEY.name)
            return _delete_plan(key, library)

    if target == ParserArgs.NOTIFICATIONS.name:
        if action == ParserArgs.SHOW:
            notifications = library.online_user.notifications
            print('Notifications for user "{}":'.format(
                library.online_user.nick))
            if _show_messages(notifications):
                print('Notifications not found!')
            library.clear_new_messages()

        if action == ParserArgs.DELETE:
            _del_notifications(library,
                               _all=args.pop(ParserArgs.ALL.dest),
                               old=args.pop(ParserArgs.OLD.dest))
Beispiel #14
0
from flask import Flask

from app.configuration import Configuration

from flask_bootstrap import Bootstrap
from flask_login import LoginManager

configuration = Configuration().load()

app = Flask(__name__)
app.config.update(configuration)

bootstrap = Bootstrap(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

from app import views, login_manager
class ParticipantService(LoggerMixin):
    def __init__(self, configuration: Configuration, command_bus: CommandBus,
                 participant_repository: ParticipantRepository,
                 message_repository: MessageRepository) -> None:
        self.__configuration = configuration
        self.__online_participants: Dict[Participant] = {}
        self.__contact_pairing: Dict[str] = {}
        self.__route_pairing: Dict[str] = {}
        self.__command_bus: CommandBus = command_bus
        self.__participant_repository: ParticipantRepository = participant_repository
        self.__message_repository: MessageRepository = message_repository

    def fetch(self, identifier) -> Participant:
        if identifier != self.__online_participants:
            self.__fetch_details(identifier=identifier)
        return self.__online_participants[identifier]

    @EventListener(subject="v1/node/{}/participants/pass-over".format(
        Configuration.get_instance().node()),
                   event_type=ParticipantPassOver)
    def on_external_participant_event(self,
                                      event: ParticipantPassOver) -> None:
        self._info("SENDER            : {0}".format(event.sender_identifier))
        self._info("TARGET            : {0}".format(event.target_identifier))
        self._info("ORIGINATING NODE  : {0}".format(event.originating_node))
        self._info("MARKER            : {0}".format(event.marker))

        if event.target_identifier in self.__route_pairing:
            target_identifier = self.__route_pairing[event.target_identifier]
            self.__command_bus.handle(
                MessageDispatchCommand(
                    participant_identifier=target_identifier,
                    payload=event.payload,
                    response_type=ResponseType.RECEIVE_DIRECT_MESSAGE))
            self.__save_direct_message(
                sender_identifier=event.sender_identifier,
                target_identifier=target_identifier,
                message=event.payload,
                marker=event.marker)

    def resolve_contacts(self, content: bytearray) -> bytearray:
        contact_batch_request = BatchContactMatchRequest()
        contact_batch_request.ParseFromString(content)
        resolved_contact_batch = self.__resolve_contacts(
            contact_batch_request=contact_batch_request)
        return resolved_contact_batch.SerializeToString()

    def __resolve_contacts(
        self, contact_batch_request: BatchContactMatchRequest
    ) -> BatchContactMatchResponse:
        response = BatchContactMatchResponse()
        for contact_request in contact_batch_request.requests:
            if contact_request.type is ContactRequest.ContactType.EMAIL and \
                    contact_request.value in self.__contact_pairing:
                participant: Participant = self.__online_participants[
                    self.__contact_pairing[contact_request.value]]
                response.contacts.append(
                    Contact(profile_picture_url=participant.photo_url,
                            nickname=participant.nickname,
                            identifier=participant.routing_identity))

        return response

    def __fetch_details(self, identifier: str) -> None:
        url: str = "{0}/{1}/{2}".format(
            self.__configuration.account_service_url(),
            "/api/v1/account-service/users/details",
        )
        response: requests.Response = requests.get(url=url)
        if response.status_code is not 200:
            self._error("FAILED TO FETCH USER: {}".format(response.text))
        else:
            content_map: Dict = response.json()
            if not self.is_identity_known(
                    participant_identifier=content_map['identifier']):
                self.create_routing_identity(
                    participant_identifier=content_map['identifier'])
            routing_identifier = self.fetch_routing_identity(
                participant_identifier=content_map['identifier'])
            self.__online_participants[identifier] = Participant(
                routing_identity=routing_identifier,
                content_map=response.json())
            self.__route_pairing[routing_identifier] = content_map['identity']
            self.__contact_pairing[response.json()["email"]] = identifier
            self._info("ADDED PARTICIPANT ENTRY FOR: {}".format(identifier))
            get_client().register_participant(
                routing_identifier=routing_identifier)

    def is_identity_known(self, participant_identifier: str) -> bool:
        return self.__participant_repository.has_identity(
            participant_identifier=participant_identifier)

    def fetch_routing_identity(self, participant_identifier: str) -> str:
        identity: Identity = self.__participant_repository.fetch_identity(
            participant_identifier=participant_identifier)
        return identity.routing_identity

    def create_routing_identity(self, participant_identifier: str) -> None:
        routing_identifier = str(uuid.uuid4())
        self.__participant_repository.create_identity(
            participant_identifier=participant_identifier,
            routing_identifier=routing_identifier)

    def relay_direct_message(self, sender_identifier: str,
                             payload: bytearray) -> None:
        direct_message = DirectMessage()
        direct_message.ParseFromString(payload)
        marker = str(uuid.uuid4())
        if direct_message.target_identifier in self.__route_pairing:
            target_identifier = self.__route_pairing[
                direct_message.target_identifier]
            self.__command_bus.handle(
                MessageDispatchCommand(
                    participant_identifier=target_identifier,
                    payload=payload,
                    response_type=ResponseType.RECEIVE_DIRECT_MESSAGE))
            self.__save_direct_message(sender_identifier=sender_identifier,
                                       target_identifier=target_identifier,
                                       message=payload,
                                       marker=marker)
            self.__report_delivery_success(
                sender_identifier=sender_identifier,
                target_identifier=direct_message.target_identifier,
                marker=marker)
        else:
            node: str = self.__resolve_last_known_node(
                target_identifier=direct_message.target_identifier)
            if node is None:
                self.__report_delivery_failure(
                    sender_identifier=sender_identifier,
                    target_identifier=direct_message.target_identifier,
                    delivery_failed_at=direct_message.sent_at)
            else:
                self.__send_direct_message_to_node(
                    node=node,
                    sender_identifier=sender_identifier,
                    target_identifier=direct_message.target_identifier,
                    marker=marker,
                    payload=payload)

    def save_device_information(self, participant_identifier: str,
                                device_information: DeviceDetails) -> None:
        self.__participant_repository.add_device(
            participant_identifier=participant_identifier,
            device=device_information)

    def __save_direct_message(self, sender_identifier: str,
                              target_identifier: str, message: bytearray,
                              marker: str) -> None:
        current_time = datetime.utcnow()
        self.__message_repository.save(sender=sender_identifier,
                                       target=target_identifier,
                                       payload=message,
                                       marker=marker,
                                       received_at=current_time)

    def __report_delivery_success(self, sender_identifier: str,
                                  target_identifier: str, marker: str) -> None:
        utc_now = datetime.utcnow()
        current_time = Timestamp()
        current_time.FromDatetime(utc_now)
        self.__send_delivery_status(sender_identifier=sender_identifier,
                                    target_identifier=target_identifier,
                                    message="Successfully delivered message",
                                    marker=marker,
                                    status=Delivery.State.FAILED,
                                    sent_at=current_time)

    def __report_message_read(self, sender_identifier: str,
                              target_identifier: str, marker: str) -> None:
        utc_now = datetime.utcnow()
        current_time = Timestamp()
        current_time.FromDatetime(utc_now)
        self.__send_delivery_status(sender_identifier=sender_identifier,
                                    target_identifier=target_identifier,
                                    message="Successfully delivered message",
                                    marker=marker,
                                    status=Delivery.State.READ,
                                    sent_at=current_time)

    def __report_delivery_failure(self, sender_identifier: str,
                                  target_identifier: str,
                                  sender_timestamp: Timestamp) -> None:
        self.__send_delivery_status(sender_identifier=sender_identifier,
                                    target_identifier=target_identifier,
                                    message="Failed to deliver the message :(",
                                    marker="",
                                    status=Delivery.State.FAILED,
                                    sent_at=sender_timestamp)

    def __send_delivery_status(self, sender_identifier: str,
                               target_identifier: str, message: str,
                               marker: str, status: Delivery.State,
                               sender_timestamp: Timestamp) -> None:
        delivery_note: Delivery = Delivery(message=message,
                                           state=status,
                                           marker=marker,
                                           target_identifier=target_identifier,
                                           sent_at=sender_timestamp)
        self.__command_bus.handle(
            MessageDispatchCommand(
                participant_identifier=self.__route_pairing[sender_identifier],
                payload=delivery_note.SerializeToString(),
                response_type=ResponseType.DELIVERY_STATE,
                sent_at=sender_timestamp))

    @staticmethod
    def __resolve_last_known_node(target_identifier: str) -> Optional[str]:
        client: ParticipantClient = get_client()
        return client.fetch_last_known_node(
            target_identifier=target_identifier)

    @staticmethod
    def __send_direct_message_to_node(node: str, sender_identifier: str,
                                      target_identifier: str,
                                      payload: bytearray) -> None:
        client: ParticipantClient = get_client()
        passover: ParticipantPassOver = ParticipantPassOver(
            originating_node=node,
            sender_identifier=sender_identifier,
            target_identifier=target_identifier,
            payload=payload)
        client.passover_direct_message_to(passover=passover)
Beispiel #16
0
def run() -> falcon.App:
    application = ServerApplication(configuration=Configuration.get_instance())
    return application.run()
Beispiel #17
0
"""Main Entrypoint"""
from flask_restful import Api
from flask import Flask
from flask_cors import CORS
from app.configuration import Configuration
from app.views.predict import Predict
from app.views.task_status import TaskStatus
from app.views.recurrent_neural_network import RecurrentNeuralNetwork

if __name__ == '__main__':
    configuration = Configuration()
    application = Flask(__name__, static_url_path='/static')
    # allow CORS for all domains on all routes
    cors = CORS(application, resources={r"/api/v1/*": {"origins": "*"}})
    api = Api(application)
    # route initialization
    rnn_routes = [
        '/',
        '/api/v1/rnn/',
    ]
    api.add_resource(RecurrentNeuralNetwork,
                     *rnn_routes,
                     resource_class_kwargs={'configuration': configuration})
    api.add_resource(TaskStatus,
                     '/api/v1/taskstatus/',
                     resource_class_kwargs={'configuration': configuration})
    api.add_resource(Predict,
                     '/api/v1/predict/',
                     resource_class_kwargs={'configuration': configuration})
    configuration.mi_logger.info('Machine Learning Service Starting')
    # application initialization
Beispiel #18
0
    def __init__(self):

        self.__configuration = NATSConfiguration(
            content_map=Configuration.get_instance().nats_configuration())
        self.__client: Client = Client()
Beispiel #19
0
        'Key.f19': Key.f19,
        'Key.f20': Key.f20,
        'Key.f2': Key.f2,
        'Key.f3': Key.f3,
        'Key.f4': Key.f4,
        'Key.f5': Key.f5,
        'Key.f6': Key.f6,
        'Key.f7': Key.f7,
        'Key.f8': Key.f8,
        'Key.f9': Key.f9,
        'Key.home': Key.home,
        'Key.insert': Key.insert,
        'Key.left': Key.left,
        'Key.menu': Key.menu,
        'Key.num_lock': Key.num_lock,
        'Key.page_down': Key.page_down,
        'Key.page_up': Key.page_up,
        'Key.pause': Key.pause,
        'Key.print_screen': Key.print_screen,
        'Key.right': Key.right,
        'Key.scroll_lock': Key.scroll_lock,
        'Key.shift': Key.shift,
        'Key.shift_l': Key.shift_l,
        'Key.shift_r': Key.shift_r
    }.get(key, key)


if __name__ == "__main__":
    Configuration.set_selected_game('pong')
    start_ai()
Beispiel #20
0
def get_client() -> ParticipantClient:
    configuration: Configuration = Configuration.get_instance()
    if configuration.is_in_test_mode():
        return FakeParticipantClient.instance()
    return NATSParticipantClient.instance()
 def configuration():
     return Configuration.get_instance(testing=True)
Beispiel #22
0
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.


# Press the green button in the gutter to run the script.
from app.application import Application
from app.configuration import Configuration

if __name__ == '__main__':
    application: Application = Application(configuration=Configuration.get_instance())
    application.run()


Beispiel #23
0
def initialise_model_lstm(indicator_file_name, timesteps, test_set_input,
                          test_set_output, train_set_input, train_set_output,
                          epochs):
    """[summary]

    Args:
        indicator_file_name ([type]): [description]
        timesteps ([type]): [description]
        test_set_input ([type]): [description]
        test_set_output ([type]): [description]
        train_set_input ([type]): [description]
        train_set_output ([type]): [description]
        epochs ([type]): [description]

    Returns:
        [type]: [description]
    """
    keras_model_directory = Configuration.get_directory(indicator_file_name)
    modelh5_path = Configuration.get_file_model_file(indicator_file_name)
    # define the RNN input shape
    lstm_input_shape = (timesteps, 1)
    # initialize the Recurrent Neural Network
    # Solving pattern with sequence of data
    regressor = keras.models.Sequential()
    training.update_state(state="PROGRESS", meta={'progress': 70})
    neurons = 50
    batch_size = 32

    # Long Short Term Memory model -
    # supervised Deep Neural Network that is very good at doing time-series prediction.
    # adding the first LSTM Layer and some Dropout regularisation
    #
    # Dropout: Makes sure that network can never rely on any given activation
    # to be present because at any moment they could become squashed i.e. value = 0
    # forced to learn a redunant representation for everything
    #
    # return sequences: We want output after every layer in which will be
    # passed to the next layer
    regressor.add(
        keras.layers.LSTM(units=neurons,
                          return_sequences=True,
                          input_shape=lstm_input_shape))
    regressor.add(keras.layers.Dropout(0.2))

    # adding a second LSTM Layer and some Dropout regularisation
    regressor.add(keras.layers.LSTM(units=neurons, return_sequences=True))
    regressor.add(keras.layers.Dropout(0.2))

    # adding a third LSTM Layer and some Dropout regularisation
    regressor.add(keras.layers.LSTM(units=neurons, return_sequences=True))
    regressor.add(keras.layers.Dropout(0.2))

    # adding a fourth LSTM Layer and some Dropout regularisation
    regressor.add(keras.layers.LSTM(units=neurons))
    regressor.add(keras.layers.Dropout(0.2))

    # adding the output layer
    # Dense format output layer
    regressor.add(keras.layers.Dense(units=1))  # prediction

    # compile network
    # find the global minimal point
    regressor.compile(optimizer='adam', loss='mean_absolute_error')
    regressor.summary()
    accuracy = regressor.evaluate(test_set_input, test_set_output)
    print('Restored model, accuracy: {:5.2f}%'.format(100 * accuracy))

    # fitting the RNN to the training set
    # giving input in batch sizes of 5
    # loss should decrease on each an every epochs
    history = regressor.fit(train_set_input,
                            train_set_output,
                            batch_size=batch_size,
                            epochs=epochs,
                            steps_per_epoch=5,
                            validation_data=(test_set_input, test_set_output),
                            verbose=0,
                            callbacks=[KerasFitCallback(training, epochs)])

    # save the model for javascript format readable
    tfjs.converters.save_keras_model(regressor, keras_model_directory)
    # save the model for python format readable
    regressor.save(modelh5_path)
    predicted_price = regressor.predict(test_set_input)
    result = {
        'summary': str(regressor.summary()),
        'history': str(history),
        'predicted_price': predicted_price
    }
    return result