def update_logs_db(slack, channel_name, num_msg): """Update logs and category database from daily_logs channel""" channel_id = get_channel_id(slack, channel_name) if channel_id: channel_msgs = get_channel_msg(slack, channel_id, num_msg) year = datetime.date.today().year db_path = os.path.join(os.getcwd(), Config.DB_DIR, Config.LOGS_DB) logs_db_path = os.path.join(db_path, str(year) + '.pkl') category_db_path = os.path.join(db_path, str(year) + '_category.pkl') if os.path.exists(logs_db_path) and os.path.getsize(logs_db_path) > 0: with open(logs_db_path, 'rb') as f, open(category_db_path, 'rb') as g: logs_db = pickle.load(f) category_db = pickle.load(g) change_msg_to_db(channel_msgs, logs_db, category_db, year_db=True) else: logs_db = nested_dict() category_db = nested_dict() change_msg_to_db(channel_msgs, logs_db, category_db, year_db=True) with open(logs_db_path, 'wb') as f, open(category_db_path, 'wb') as g: pickle.dump(logs_db, f, protocol=pickle.HIGHEST_PROTOCOL) pickle.dump(category_db, g, protocol=pickle.HIGHEST_PROTOCOL) else: pass
def init_log_db(): """Initilize logs and category database from exported data""" logs_db = nested_dict() category_db = nested_dict() # Load data exported_db_path = os.path.join(os.getcwd(), app.config['EXPORTED_DB_DIR']) logs_files = get_logs_files(exported_db_path) for logs_dir in logs_files.keys(): for log_file in logs_files[logs_dir]: with open(os.path.join(exported_db_path, logs_dir, log_file), 'rb') as f: logs_msgs = json.load(f) change_msg_to_db(logs_msgs, logs_db, category_db) # Save data db_path = os.path.join(os.getcwd(), app.config['DB_DIR'], app.config['LOGS_DB']) for year in logs_db.keys(): with open(os.path.join(db_path, year + '.pkl'), 'wb') as f: pickle.dump(logs_db[year], f, protocol=pickle.HIGHEST_PROTOCOL) with open(os.path.join(db_path, year + '_category.pkl'), 'wb') as g: pickle.dump(category_db[year], g, protocol=pickle.HIGHEST_PROTOCOL)
def initialize_gammas(self, rand=False): L = self.corpus.get_L() self.gammas = utils.nested_dict() for E, F in self.corpus.corpus: l = len(E) m = len(F) initial_prob = 1 / (l + 1) for i in range(l + 1): for j in range(m + 1): if self.use_jump: self.gammas[self.jump( i, j, l, m)] = 1. / L if not rand else random.uniform( 0, 0.05) else: self.gammas[i][j][l][ m] = initial_prob if not rand else random.uniform( 0, 0.05) print('Gammas initialized')
def index(): """Show daily logs and categorize task""" now = datetime.datetime.now() year = now.strftime("%Y") month = now.strftime("%m") logs_db, category_db = read_db(year) user = '******' my_logs = logs_db[user][month] type_logs = dict() # TODO dict() vs {}? for date in sorted(my_logs.keys()): tasks = my_logs[date] type_logs[date] = [] for task_type in app.config['TASK_TYPE']: if task_type not in tasks.keys(): tasks[task_type] = [] type_logs[date].append(tasks[task_type]) my_cate = category_db[user][month] category_count = nested_dict() for cate in my_cate.values(): intersected_types = set(app.config['TASK_TYPE']) & set(cate.keys()) for task_type in intersected_types: for task_cate in cate[task_type].keys(): if task_cate in category_count[task_type]: category_count[task_type][task_cate] += cate[task_type][task_cate] else: category_count[task_type][task_cate] = cate[task_type][task_cate] done_cate, todo_cate, pause_cate = dict(), dict(), dict() # TODO dict() vs {}? done_cate = category_count[app.config['TASK_TYPE'][0]] todo_cate = category_count[app.config['TASK_TYPE'][1]] pause_cate = category_count[app.config['TASK_TYPE'][2]] return render_template('index.html', types=app.config['TASK_TYPE'], type_logs=type_logs, month=month, done_cate=done_cate, todo_cate=todo_cate, pause_cate=pause_cate, category_count=category_count)
def start_game(self, position): super(SmartPlayer, self).start_game(position) self.memory = nested_dict() self.memory["action_count"] = 0 self.memory["discards_left"] = 0
def start_game(self, position): self.position = position self.info = nested_dict() self.other_players = filter(lambda player: player != self, self.game.players)