#!/usr/bin/env python3
import json
import os

from malware_ml.model import load_model, apply_model_to_json
from malware_ml.prepare_data import DEFAULT_TARGET

DEFAULT_PATH_TO_MODEL = 'models/xgb_classifer'
DEFAULT_DB_PATH = 'storage/log.db'


def change_location():
    script_location = os.path.dirname(os.path.abspath(__file__))
    os.chdir(script_location)


def main():
    change_location()
    print('Send json string to get prediction.')
    print('Send \'stop\' string to finish.')
    model = load_model(DEFAULT_PATH_TO_MODEL)

    while True:
        input_string = input()
        if input_string == 'stop':
            break
        data = json.loads(input_string)
        ##target = data.get(DEFAULT_TARGET)
        prediction = apply_model_to_json(model, data)
        print(prediction)

if __name__ == '__main__':
    main()
