def refresh_events(db: DbStore):
    config = util.config()["gen_events"]
    if not config["enable"]:
        logging.info("Skipping events as gen_events disbled")
        return

    logging.info("Refreshing events")

    last_event = db.latest_event()

    if last_event is not None:
        after = last_event["timestamp"]
        states = player_store.store().player_states_after_time_asc(after)
        logging.info("Processing events after {}({})".format(after, unix_to_iso(after)))
        initial_state = last_event
    else:
        logging.info("Processing all events (no existing events)")
        states = player_store.store().player_get_states_asc_timestamp()
        initial_state = {"state": {}}

    logging.info("Initial state for event gen: {}".format(initial_state.__str__()))
    logging.info("Num states to process = {}".format(len(states)))
    new_events = gen_events(initial_state, states)
    logging.info("Generated {} new events".format(len(new_events)))

    if len(new_events) > 0:
        for event in new_events:
            db.add_event(event)

    add_prev_track_id(db)

    logging.info("Deleting old states...")
    player_store.store().delete_states()
    logging.info("Done with gen_events")
def move_events():
    db = DbStore()
    total = util.get_spotify_db().events.find().count()
    for i, event in enumerate(util.get_spotify_db().events.find()):
        if i % 100 == 0:
            print("Moving events {}%".format(util.percent(i, total)))

        db.add_event(event)
    db.commit()