예제 #1
0
    def start_demo(self):

        data_store2 = DataStore()
        data_store2.data_dict = {}
        valid_password = "******"
        sd = 0.05
        stdev_learn_array = []
        passed = True

        # Reset Key events
        self.key_events = []

        # Create HookManager
        hook = HookManager()
        # Define our callback to fire when a key is pressed down
        hook.KeyDown = self.key_log
        # Hook the keyboard
        hook.HookKeyboard()
        # Start the HookManager
        hook.start()

        user_input = input("Enter your password: "******"""We are commenting this out because this was just for testing"""
        """print(data_store2.data_dict)"""
        hook.cancel()

        for key in data_store2.data_dict:
            if key in self.data_store.data_dict:
                if data_store2.data_dict[key] > self.data_store.data_dict[
                        key] + sd or data_store2.data_dict[
                            key] < self.data_store.data_dict[key] - sd:
                    passed = False
            else:
                passed = False

        print(passed is True)
        if passed is True and user_input == valid_password:
            print("Passed")
        else:
            print("failed")
    def message(self, pubnub, message):
        now = date.today()
        filename = '%s_bitflyer.json' % now
        output_path = os.path.join('./log/stream', filename)

        measurement = 'bitflyer_executions_history_%s' % now.strftime(
            '%Y_%m_%d')
        influx_db = DataStore(measurement)

        f = open(output_path, 'a')
        messages_list = message.message
        for line in messages_list:
            f.write("%s\n" % json.dumps(line))
            WriteStreamData(influx_db).execute(line)
            print('%s %s' % (line['price'], line['exec_date']))
def main():
  state = State.no_order
  bitflyer_order = BitflyerOrder()
  while True:
    try:
      time.sleep(8)
      measurement = 'bitflyer_executions_history_%s' % date.today().strftime('%Y_%m_%d')
      influx_db = DataStore(measurement)
      check_order_condition = CheckOrderCondition(influx_db)

      filename = '%s_execute_result.log' % date.today()
      output_path = os.path.join('./log/orders', filename)

      print('state=%s' % state.name)

      # 買い注文の判定
      if state == State.no_order and check_order_condition.is_buy():
        result = bitflyer_order.buy()
        state = State.ordered
        buy_price = result.get('price')
        write_execute_log(output_path, 'buy', result)
        continue

      # 売り注文の判定
      if state == State.ordered and check_order_condition.is_sell(buy_price):
        result = bitflyer_order.sell()
        state = State.no_order
        buy_price = None
        write_execute_log(output_path, 'sell', result)
        time.sleep(300)

    except Exception:
      with open("./log/error.log", 'a') as f:
        now = datetime.now(pytz.timezone('Asia/Tokyo'))
        f.write(now.strftime('%Y-%m-%d %H:%M:%S'))
        traceback.print_exc(file=f)
        print(now.strftime('%Y-%m-%d %H:%M:%S'))
        traceback.print_exc()
예제 #4
0
# Get Neo4J Connetion and clean Database
link_eol('TestComponent', '01-01-2016', '01-01-2016')
query = "MATCH (n) DETACH DELETE n"
try:
    graph.cypher.execute(query)
except:
    e = sys.exc_info()[1]
    ec = sys.exc_info()[0]
    log_msg = "Neo4J not running? Error Class: %s, Message: %s"
    my_log.critical(log_msg, ec, e)
    sys.exit(1)
calendar = GregorianCalendar(graph)
# Get constraints on Neo4J database
# set_neo4j_constraints(graph)
# Get DataStore object
ds = DataStore(config)
# Initialize ci_type translation
ci_type = ds.get_ci_type_translation()
# Then get all Component rows
rows = ds.get_components()
node_obj = {}
loc_obj = {}
node_info = my_env.LoopInfo("Nodes", 100)
for row in rows:
    del row["ID"]
    node_label, row = get_component_type(row, ci_type)
    if node_label == 'SW.Prod.Install.':
        component = handle_sw_product(row)
    else:
        # Not a SW Product, so default component handling
        on_location, row = get_location(row)
예제 #5
0
class MainProgram:

    data_store = DataStore()
    previous_event = KeyEvent()
    key_events = []

    def key_log(self, event):
        current_event = KeyEvent()
        if event.Ascii == 13:
            pass
        else:
            current_event.key = event.Key
            current_event.timestamp = time.time()
            self.key_events.append(current_event)

    def start_learning(self):
        # Dump the previous learned data, if applicable.
        self.data_store.data_dict = {}
        tempPass = "******"
        # Create HookManager
        hook = HookManager()
        # Define our callback to fire when a key is pressed down
        hook.KeyDown = self.key_log
        # Hook the keyboard
        hook.HookKeyboard()
        hook.start()
        i = 1
        while i < 11:
            # Start the listener
            self.key_events = []
            print("Trial: {0} \t Enter password [again].".format(i))
            # Catch variable for user input while learning. Solves issue with main menu.
            tempPass2 = input()
            """Problem Child below"""
            if tempPass2 == tempPass:
                for j in range(1, self.key_events.__len__()):
                    data = self.key_events[j].log(
                        self.key_events[j - 1].key,
                        self.key_events[j - 1].timestamp)
                    self.data_store.save(data, i)
                i = i + 1
            else:
                print("Password did not match, please redo trial: \n")
        """Commenting out testing
        print(self.data_store.data_dict)"""
        hook.cancel()

    def start_demo(self):

        data_store2 = DataStore()
        data_store2.data_dict = {}
        valid_password = "******"
        sd = 0.05
        stdev_learn_array = []
        passed = True

        # Reset Key events
        self.key_events = []

        # Create HookManager
        hook = HookManager()
        # Define our callback to fire when a key is pressed down
        hook.KeyDown = self.key_log
        # Hook the keyboard
        hook.HookKeyboard()
        # Start the HookManager
        hook.start()

        user_input = input("Enter your password: "******"""We are commenting this out because this was just for testing"""
        """print(data_store2.data_dict)"""
        hook.cancel()

        for key in data_store2.data_dict:
            if key in self.data_store.data_dict:
                if data_store2.data_dict[key] > self.data_store.data_dict[
                        key] + sd or data_store2.data_dict[
                            key] < self.data_store.data_dict[key] - sd:
                    passed = False
            else:
                passed = False

        print(passed is True)
        if passed is True and user_input == valid_password:
            print("Passed")
        else:
            print("failed")

    def main(self):

        while True:
            selection = input("""Please select one of the following options:
             \n1. Learn
             \n2. Demo
             \n3. Exit
             """)

            if selection is '1':
                print("You selected the Learn option \n")
                self.start_learning()
            elif selection is '2':
                print("You selected the Demo option \n")
                self.start_demo()
            elif selection is '3':
                quit()
            else:
                print("You did not select a valid option please try again:\n")
예제 #6
0
    for user in ul:
        rowdict = {}
        for col in cols:
            if col in user:
                if col in ["created"]:
                    rowdict[col] = dateutil.parser.parse(user[col]).strftime("%d/%m/%Y %H:%M:%S")
                elif user[col]:
                    rowdict[col] = user[col]
        dbConn.insert_row('user_data', rowdict)
    return


if __name__ == "__main__":
    # Get ini-file first.
    projectname = 'openvl'
    modulename = my_env.get_modulename(__file__)
    config = my_env.get_inifile(projectname, __file__)
    # Now configure logfile
    my_env.init_loghandler(config, modulename)
    logging.info('Start Application')
    logdir = config['Main']['logdir']
    dbConn = DataStore(config)
    # Reset Table
    dbConn.remove_table_user_data()
    dbConn.create_table_user_data()
    columns = dbConn.get_columns('user_data')
    ckan_conn = get_ckan_conn()
    ul = user_list()
    handle_ul(ul, columns)
    logging.info('End Application')
예제 #7
0
        rowdict["tracking_summary_recent"] = res["tracking_summary"]["recent"]
    ds.insert_row('dataset', rowdict)
    return


if __name__ == "__main__":
    # Get ini-file first.
    projectname = 'opennl'
    modulename = my_env.get_modulename(__file__)
    config = my_env.get_inifile(projectname, __file__)
    # Now configure logfile
    my_env.init_loghandler(config, modulename)
    logging.info('Start Application')
    logdir = config['Main']['logdir']
    dataset_dir = config['Main']['ds_dir']
    dbConn = DataStore(config)
    # Reset Table
    dbConn.remove_tables()
    dbConn.create_tables()
    columns = dbConn.get_columns('dataset')
    print("Cols: {cols}".format(cols=columns))
    filelist = [
        file for file in os.listdir(dataset_dir)
        if os.path.splitext(file)[1] == ".json"
    ]
    for idx, file in enumerate(filelist):
        handle_ds(os.path.join(dataset_dir, file), dbConn, columns)
        if idx % 100 == 0:
            logging.info("{idx} files processed.".format(idx=idx))
    logging.info('End Application')
예제 #8
0
    # Special handling for tracking_summary
    if res["tracking_summary"]:
        rowdict["tracking_summary_total"] = res["tracking_summary"]["total"]
        rowdict["tracking_summary_recent"] = res["tracking_summary"]["recent"]
    ds.insert_row('dataset', rowdict)
    return


if __name__ == "__main__":
    # Get ini-file first.
    projectname = 'opennl'
    modulename = my_env.get_modulename(__file__)
    config = my_env.get_inifile(projectname, __file__)
    # Now configure logfile
    my_env.init_loghandler(config, modulename)
    logging.info('Start Application')
    logdir = config['Main']['logdir']
    dataset_dir = config['Main']['ds_dir']
    dbConn = DataStore(config)
    # Reset Table
    dbConn.remove_tables()
    dbConn.create_tables()
    columns = dbConn.get_columns('dataset')
    print("Cols: {cols}".format(cols=columns))
    filelist = [file for file in os.listdir(dataset_dir) if os.path.splitext(file)[1] == ".json"]
    for idx, file in enumerate(filelist):
        handle_ds(os.path.join(dataset_dir, file), dbConn, columns)
        if idx % 100 == 0:
            logging.info("{idx} files processed.".format(idx=idx))
    logging.info('End Application')
예제 #9
0
"""
This script will rebuild the database from scratch. It should run only once during production
and many times during development.
"""

import logging
from lib.datastore import DataStore
from lib import my_env

if __name__ == "__main__":
    # Initialize Environment
    projectname = "openvl"
    modulename = my_env.get_modulename(__file__)
    config = my_env.get_inifile(projectname, __file__)
    my_env.init_loghandler(config, modulename)
    ds = DataStore(config)
    logging.info('Start Application')
    ds.remove_tables()
    ds.create_tables()
    logging.info('End Application')
예제 #10
0
        rowdict = {}
        for col in cols:
            if col in user:
                if col in ["created"]:
                    rowdict[col] = dateutil.parser.parse(
                        user[col]).strftime("%d/%m/%Y %H:%M:%S")
                elif user[col]:
                    rowdict[col] = user[col]
        dbConn.insert_row('user_data', rowdict)
    return


if __name__ == "__main__":
    # Get ini-file first.
    projectname = 'openvl'
    modulename = my_env.get_modulename(__file__)
    config = my_env.get_inifile(projectname, __file__)
    # Now configure logfile
    my_env.init_loghandler(config, modulename)
    logging.info('Start Application')
    logdir = config['Main']['logdir']
    dbConn = DataStore(config)
    # Reset Table
    dbConn.remove_table_user_data()
    dbConn.create_table_user_data()
    columns = dbConn.get_columns('user_data')
    ckan_conn = get_ckan_conn()
    ul = user_list()
    handle_ul(ul, columns)
    logging.info('End Application')