Beispiel #1
0
def initPredictor():
    global predictor, predictor_thread, chasemapper_config, pred_settings
    try:
        from cusfpredict.predict import Predictor
        from cusfpredict.utils import gfs_model_age, available_gfs

        # Check if we have any GFS data
        _model_age = gfs_model_age(pred_settings['gfs_path'])
        if _model_age == "Unknown":
            logging.error("No GFS data in directory.")
            chasemapper_config['pred_model'] = "No GFS Data."
            flask_emit_event('predictor_model_update',
                             {'model': "No GFS data."})
            chasemapper_config['pred_enabled'] = False
        else:
            # Check model contains data to at least 4 hours into the future.
            (_model_start,
             _model_end) = available_gfs(pred_settings['gfs_path'])
            _model_now = datetime.utcnow() + timedelta(0, 60 * 60 * 4)
            if (_model_now < _model_start) or (_model_now > _model_end):
                # No suitable GFS data!
                logging.error("GFS Data in directory does not cover now!")
                chasemapper_config['pred_model'] = "Old GFS Data."
                flask_emit_event('predictor_model_update',
                                 {'model': "Old GFS data."})
                chasemapper_config['pred_enabled'] = False

            else:
                chasemapper_config['pred_model'] = _model_age
                flask_emit_event('predictor_model_update',
                                 {'model': _model_age})
                predictor = Predictor(bin_path=pred_settings['pred_binary'],
                                      gfs_path=pred_settings['gfs_path'])

                # Start up the predictor thread if it is not running.
                if predictor_thread == None:
                    predictor_thread = Thread(target=predictorThread)
                    predictor_thread.start()

                # Set the predictor to enabled, and update the clients.
                chasemapper_config['pred_enabled'] = True

        flask_emit_event('server_settings_update', chasemapper_config)

    except Exception as e:
        traceback.print_exc()
        logging.error("Loading predictor failed: " + str(e))
        flask_emit_event('predictor_model_update',
                         {'model': "Failed - Check Log."})
        chasemapper_config['pred_model'] = "Failed - Check Log."
        print("Loading Predictor failed.")
        predictor = None
Beispiel #2
0
        return "Already Downloading."

    _download_thread = Thread(
        target=predictor_download_model,
        kwargs={
            "command": command,
            "callback": callback
        },
    )
    _download_thread.start()

    return "Started downloader."


if __name__ == "__main__":
    import sys
    from .config import parse_config_file
    from cusfpredict.utils import gfs_model_age, available_gfs

    _cfg_file = sys.argv[1]

    _cfg = parse_config_file(_cfg_file)

    if _cfg["pred_model_download"] == "none":
        print("Model download not enabled.")
        sys.exit(1)

    predictor_download_model(_cfg["pred_model_download"])

    print(available_gfs(_cfg["pred_gfs_directory"]))
Beispiel #3
0
def initPredictor():
    global predictor, predictor_thread, chasemapper_config, pred_settings

    if chasemapper_config["offline_predictions"]:
        # Attempt to initialize an Offline Predictor instance
        try:
            from cusfpredict.predict import Predictor
            from cusfpredict.utils import gfs_model_age, available_gfs

            # Check if we have any GFS data
            _model_age = gfs_model_age(pred_settings["gfs_path"])
            if _model_age == "Unknown":
                logging.error("No GFS data in directory.")
                chasemapper_config["pred_model"] = "No GFS Data."
                flask_emit_event("predictor_model_update",
                                 {"model": "No GFS data."})
                chasemapper_config["offline_predictions"] = False
            else:
                # Check model contains data to at least 4 hours into the future.
                (_model_start,
                 _model_end) = available_gfs(pred_settings["gfs_path"])
                _model_now = datetime.utcnow() + timedelta(0, 60 * 60 * 4)
                if (_model_now < _model_start) or (_model_now > _model_end):
                    # No suitable GFS data!
                    logging.error("GFS Data in directory does not cover now!")
                    chasemapper_config["pred_model"] = "Old GFS Data."
                    flask_emit_event("predictor_model_update",
                                     {"model": "Old GFS data."})
                    chasemapper_config["offline_predictions"] = False

                else:
                    chasemapper_config[
                        "pred_model"] = _model_age + " (Offline)"
                    flask_emit_event("predictor_model_update",
                                     {"model": _model_age + " (Offline)"})
                    predictor = Predictor(
                        bin_path=pred_settings["pred_binary"],
                        gfs_path=pred_settings["gfs_path"],
                    )

                    # Start up the predictor thread if it is not running.
                    if predictor_thread == None:
                        predictor_thread = Thread(target=predictorThread)
                        predictor_thread.start()

                    # Set the predictor to enabled, and update the clients.
                    chasemapper_config["offline_predictions"] = True

        except Exception as e:
            traceback.print_exc()
            logging.error("Loading predictor failed: " + str(e))
            flask_emit_event("predictor_model_update",
                             {"model": "Failed - Check Log."})
            chasemapper_config["pred_model"] = "Failed - Check Log."
            print("Loading Predictor failed.")
            predictor = None

    else:
        # No initialization required for the online predictor
        predictor = "Tawhiri"
        flask_emit_event("predictor_model_update", {"model": "Tawhiri"})

        # Start up the predictor thread if it is not running.
        if predictor_thread == None:
            predictor_thread = Thread(target=predictorThread)
            predictor_thread.start()

    flask_emit_event("server_settings_update", chasemapper_config)
Beispiel #4
0
    if model_download_running:
        return "Already Downloading."

    _download_thread = Thread(target=predictor_download_model,
                              kwargs={
                                  'command': command,
                                  'callback': callback
                              })
    _download_thread.start()

    return "Started downloader."


if __name__ == "__main__":
    import sys
    from .config import parse_config_file
    from cusfpredict.utils import gfs_model_age, available_gfs

    _cfg_file = sys.argv[1]

    _cfg = parse_config_file(_cfg_file)

    if _cfg['pred_model_download'] == "none":
        print("Model download not enabled.")
        sys.exit(1)

    predictor_download_model(_cfg['pred_model_download'])

    print(available_gfs(_cfg['pred_gfs_directory']))