コード例 #1
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)
コード例 #2
0
    def test_signup_and_login(self):
        username = self._random_str()
        password = self._random_str()

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

        self.assertTrue(bool(api._token))
        self.assertGreater(api._expiration, 0)

        with self.assertRaises(HTTPError):
            api.create_user()
コード例 #3
0
    def test_runs(self):
        username = self._random_str()
        password = self._random_str()
        project_name = self._random_str()
        model_name = self._random_str()

        api = TrackerMLAPI(username, password, base_url=self.BASE_URL)
        api.create_user()
        project_id = api.post_project(project_name)["id"]
        model_id = api.post_model(model_name, project_id)

        self.assertEqual(len(api.get_runs(project_id, model_id)), 0)

        params = {"p1": 1}
        api.post_run(project_id, model_id, params)
        runs = api.get_runs(project_id, model_id)
        self.assertEqual(len(runs), 1)
        self.assertEqual(runs[0]["parameters"], params)
コード例 #4
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)
コード例 #5
0
    def test_models(self):
        username = self._random_str()
        password = self._random_str()
        project_name = self._random_str()
        model_name = self._random_str()

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

        project_id = api.post_project(project_name)["id"]
        self.assertEqual(len(api.get_models(project_id)), 0)

        model_id = api.post_model(model_name, project_id)
        models = api.get_models(project_id)

        self.assertEqual(len(models), 1)
        self.assertEqual(model_name, models[0]["type"])
        self.assertEqual(model_id, models[0]["model_id"])
        self.assertEqual(project_id, models[0]["project_id"])

        with self.assertRaises(HTTPError):
            api.post_model(model_name, project_id)
コード例 #6
0
ファイル: tools.py プロジェクト: trackerml/trackerml-sdk
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)
コード例 #7
0
 def login(self, username: str, password: str):
     self.__api = TrackerMLAPI(username, password)
     self.__api.ensure_token()