From a5726126c8230b01f9e7c6310d6ebd0a5fa92bc6 Mon Sep 17 00:00:00 2001 From: Antoine Sauray Date: Sat, 30 Mar 2019 17:29:17 +0100 Subject: [PATCH] describe project --- .gitignore | 124 +++++++++++++++++++++++++++++++ library/foundaml.py | 28 +++++++ library/project.py | 29 ++++++++ library/project_configuration.py | 6 ++ library/requirements.txt | 5 ++ samples/index.py | 5 ++ 6 files changed, 197 insertions(+) create mode 100644 .gitignore create mode 100644 library/foundaml.py create mode 100644 library/project.py create mode 100644 library/project_configuration.py create mode 100644 library/requirements.txt create mode 100644 samples/index.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dedd352 --- /dev/null +++ b/.gitignore @@ -0,0 +1,124 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don’t work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + diff --git a/library/foundaml.py b/library/foundaml.py new file mode 100644 index 0000000..1b90e57 --- /dev/null +++ b/library/foundaml.py @@ -0,0 +1,28 @@ +import json +import requests +from project_configuration import ProjectConfiguration +from project import Project + +class FoundaMl: + def __init__(self, host, port, protocol='http'): + self.host = host + self.port = port + self.protocol = protocol + + def getProject(self, projectId): + url = f'{self.protocol}://{self.host}:{self.port}/projects/{projectId}' + response = requests.get(url) + if response.status_code == 200: + responseData = json.loads(response.content ) + projectId = responseData['id'] + projectName = responseData['name'] + projectProblem = responseData['problem'] + projectAlgorithms = responseData['algorithms'] + projectPolicy = responseData['policy'] + projectFeaturesConfiguration = responseData['configuration']['features'] + projectLabelsConfiguration = responseData['configuration']['labels'] + projectConfiguration = ProjectConfiguration(projectFeaturesConfiguration, projectLabelsConfiguration) + project = Project(projectId, projectName, projectProblem, projectAlgorithms, projectPolicy, projectConfiguration) + return project + else: + return None diff --git a/library/project.py b/library/project.py new file mode 100644 index 0000000..ad4bc49 --- /dev/null +++ b/library/project.py @@ -0,0 +1,29 @@ + +class Project: + def __init__(self, projectId, name, problem, algorithms, policy, configuration): + self.projectId = projectId + self.name = name + self.problem = problem + self.algorithms = algorithms + self.policy = policy + self.configuration = configuration + + def describe(self): + print(f"Name: {self.name}") + print(f"Problem: {self.problem} \n") + print("Features:") + for feature in self.configuration.features: + featureName = feature['name'] + featureDescription = feature['description'] + featureType = feature['type'] + print(f"{featureName}|{featureType}|{featureDescription}") + + print("") + labels = self.configuration.labels + labelType = labels['type'] + if labelType == 'oneOf': + print("Labels:") + for labelName in labels['oneOf']: + print(labelName) + else: + print("Label: Dynamic") diff --git a/library/project_configuration.py b/library/project_configuration.py new file mode 100644 index 0000000..0fc4d5f --- /dev/null +++ b/library/project_configuration.py @@ -0,0 +1,6 @@ + +class ProjectConfiguration: + + def __init__(self, features, labels): + self.features = features + self.labels = labels diff --git a/library/requirements.txt b/library/requirements.txt new file mode 100644 index 0000000..e7f4362 --- /dev/null +++ b/library/requirements.txt @@ -0,0 +1,5 @@ +certifi==2019.3.9 +chardet==3.0.4 +idna==2.8 +requests==2.21.0 +urllib3==1.24.1 diff --git a/samples/index.py b/samples/index.py new file mode 100644 index 0000000..e702880 --- /dev/null +++ b/samples/index.py @@ -0,0 +1,5 @@ +from foundaml import FoundaMl + +instance = FoundaMl('127.0.0.1', 8080) +project = instance.getProject('kaggle-titanic') +project.describe()