Exemplo n.º 1
0
    def test_projects(self):
        username = self._random_str()
        password = self._random_str()
        project_name = self._random_str()

        api = TrackerMLAPI(username, password, base_url=self.BASE_URL)
        api.create_user()

        self.assertEqual(len(api.get_projects()), 0)
        project = api.post_project(project_name)
        self.assertEqual(project["name"], project_name)

        projects = api.get_projects()
        self.assertEqual(len(projects), 1)
        self.assertEqual(project["name"], projects[0]["name"])
        self.assertEqual(project["id"], projects[0]["id"])
        self.assertEqual(project["creator_id"], projects[0]["creator_id"])

        with self.assertRaises(HTTPError):
            api.post_project(project_name)
Exemplo n.º 2
0
def init_dir(username: str,
             password: str,
             project_name: str,
             project_id: int,
             api_key: str,
             rolling: bool,
             max_roll: int,
             ctx=None):
    if os.path.exists(".tracker/"):
        click.secho("Error: tracker was already initialized", fg="red")
        return

    os.makedirs(".tracker/")
    os.makedirs(".tracker/logs/")
    os.makedirs(".tracker/trials/")

    current_time = str(datetime.datetime.now())
    meta = {
        "created": current_time,
        "updated": current_time,
        "files": {},
        "current_trial": 0,
        "models": {}
    }
    config = {
        "project_name": project_name,
        "project_id": project_id,
        "api_key": api_key,
        "rolling": rolling,
        "max_roll": max_roll
    }

    try:
        if username and password:
            api = TrackerMLAPI(username, password)

            if project_name and not project_id:
                config["project_id"] = api.post_project(project_name)["id"]
            elif project_id and not project_name:
                for p in api.get_projects():
                    if p["id"] == project_id:
                        config["project_name"] = p["name"]
                if not config["project_name"]:
                    click.secho("Warning: no project with id {} found".format(
                        project_id),
                                fg="yellow")
    except:
        click.secho("Warning: problem connecting to tracker.ml API",
                    fg="yellow")
    finally:
        fo.set_meta(meta, ctx)
        fo.set_config(config, ctx)
Exemplo n.º 3
0
def init_dir(username: str,
             password: str,
             project_name: str,
             project_id: int,
             api_key: str,
             rolling: bool,
             max_roll: int,
             ctx=None):
    if os.path.exists(".tracker/"):
        click.secho("Error: tracker was already initialized", fg="red")
        return

    os.makedirs(".tracker/")
    os.makedirs(".tracker/logs/")
    os.makedirs(".tracker/trials/")

    current_time = str(datetime.datetime.now())
    meta = {
        "created": current_time,
        "updated": current_time,
        "files": {},
        "current_trial": 0,
        "models": {}
    }
    config = {
        "project_name": project_name,
        "project_id": project_id,
        "api_key": api_key,
        "rolling": rolling,
        "max_roll": max_roll
    }

    # # Kaggle setup
    # kaggle_dir = ""
    # if "KAGGLE_CONFIG_DIR" in os.environ:
    #     kaggle_dir = os.environ["KAGGLE_CONFIG_DIR"]
    # elif "win" in sys.platform():
    #     kaggle_dir = "C:\\Users\\{}\\.kaggle".format(os.getlogin())
    # else:
    #     kaggle_dir = "~/.kaggle"

    try:
        if username and password:
            api = TrackerMLAPI(username, password, api_key=api_key)

            if project_name and not project_id:
                config["project_id"] = api.post_project(project_name)["id"]
            elif project_id and not project_name:
                for p in api.get_projects():
                    if p["id"] == project_id:
                        config["project_name"] = p["name"]
                if not config["project_name"]:
                    click.secho("Warning: no project with id {} found".format(
                        project_id),
                                fg="yellow")
    except Exception as e:
        print(e)
        click.secho("Warning: problem connecting to tracker.ml API",
                    fg="yellow")
    finally:
        fo.set_meta(meta, ctx)
        fo.set_config(config, ctx)