Create root package and database subpackage
This commit is contained in:
parent
d707c4a3a7
commit
131d687d42
1
.gitignore
vendored
1
.gitignore
vendored
@ -2,3 +2,4 @@ Enrichment/
|
|||||||
__pycache__/
|
__pycache__/
|
||||||
Logs/
|
Logs/
|
||||||
[Dd]ata/
|
[Dd]ata/
|
||||||
|
*.egg-info/
|
||||||
|
|||||||
10
minigrida/__init__.py
Normal file
10
minigrida/__init__.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# file __init__.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 22 mai 2020
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
12
minigrida/database/__init__.py
Normal file
12
minigrida/database/__init__.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# file __init__.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 22 mai 2020
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .design import *
|
||||||
|
from .helpers import *
|
||||||
46
minigrida/database/design.py
Normal file
46
minigrida/database/design.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# file design.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 22 mai 2020
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from datetime import date
|
||||||
|
from pony import orm
|
||||||
|
|
||||||
|
db = orm.Database()
|
||||||
|
|
||||||
|
class Experiment(db.Entity):
|
||||||
|
sessions = orm.Set('Session')
|
||||||
|
urgency = orm.Required(int, default=1)
|
||||||
|
status = orm.Required(str, default='pending')
|
||||||
|
|
||||||
|
protocol = orm.Required(str)
|
||||||
|
expe = orm.Required(orm.Json)
|
||||||
|
expe_hash = orm.Required(str, 32, unique=True)
|
||||||
|
|
||||||
|
start_date = orm.Optional(date)
|
||||||
|
end_date = orm.Optional(date)
|
||||||
|
worker = orm.Optional(str)
|
||||||
|
ressources = orm.Optional(orm.Json)
|
||||||
|
|
||||||
|
report = orm.Optional(orm.Json)
|
||||||
|
oa = orm.Optional(float)
|
||||||
|
aa = orm.Optional(float)
|
||||||
|
k = orm.Optional(float)
|
||||||
|
|
||||||
|
class Session(db.Entity):
|
||||||
|
project = orm.Required('Project')
|
||||||
|
date = orm.Required(date)
|
||||||
|
name = orm.PrimaryKey(str)
|
||||||
|
desc = orm.Optional(str)
|
||||||
|
urgency = orm.Required(int, default=1)
|
||||||
|
experiments = orm.Set('Experiment')
|
||||||
|
|
||||||
|
class Project(db.Entity):
|
||||||
|
name = orm.PrimaryKey(str)
|
||||||
|
sessions = orm.Set('Session')
|
||||||
|
|
||||||
62
minigrida/database/helpers.py
Normal file
62
minigrida/database/helpers.py
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# file helpers.py
|
||||||
|
# author Florent Guiotte <florent.guiotte@irisa.fr>
|
||||||
|
# version 0.0
|
||||||
|
# date 22 mai 2020
|
||||||
|
"""Abstract
|
||||||
|
|
||||||
|
doc.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pony import orm
|
||||||
|
from datetime import datetime, date
|
||||||
|
import json
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
from .design import *
|
||||||
|
|
||||||
|
def compute_expe_hash(experiment):
|
||||||
|
return hashlib.md5(json.dumps(experiment, sort_keys=True).encode('utf-8')).hexdigest()
|
||||||
|
|
||||||
|
@orm.db_session
|
||||||
|
def create_experiment(session_name, protocol, expe, urgency=1):
|
||||||
|
session = Session.select(lambda x: x.name == session_name)
|
||||||
|
if not session.exists():
|
||||||
|
raise ValueError('Session "{}" does not exist'.format(session_name))
|
||||||
|
|
||||||
|
expe_hash = compute_expe_hash(expe)
|
||||||
|
q = Experiment.select(lambda x: x.expe_hash == expe_hash)
|
||||||
|
|
||||||
|
if q.exists():
|
||||||
|
e = q.first()
|
||||||
|
e.sessions.add(session)
|
||||||
|
else:
|
||||||
|
Experiment(sessions=session, protocol=protocol, expe=experiment, expe_hash=expe_hash)
|
||||||
|
|
||||||
|
@orm.db_session
|
||||||
|
def create_project(name):
|
||||||
|
if not Project.select(lambda x: x.name == name).exists():
|
||||||
|
Project(name=name)
|
||||||
|
else:
|
||||||
|
print('Project "{}" already exists.'.format(name))
|
||||||
|
|
||||||
|
@orm.db_session
|
||||||
|
def create_session(name, desc, project_name, urgency=1):
|
||||||
|
project = Project[project_name]
|
||||||
|
|
||||||
|
if not Session.select(lambda x: x.name == name).exists():
|
||||||
|
Session(project=project, date=datetime.now(),
|
||||||
|
name=name, desc=desc, urgency=1)
|
||||||
|
else:
|
||||||
|
print('Session "{}" already exists.'.format(name))
|
||||||
|
|
||||||
|
def bind_testing():
|
||||||
|
db.bind('sqlite', ':memory:')
|
||||||
|
db.generate_mapping(create_tables=True)
|
||||||
|
|
||||||
|
def bind(credentials_file):
|
||||||
|
with open(credentials_file) as f:
|
||||||
|
credentials = json.load(f)
|
||||||
|
db.bind(**credentials)
|
||||||
|
db.generate_mapping(create_tables=True)
|
||||||
|
|
||||||
4
setup.py
4
setup.py
@ -11,10 +11,10 @@
|
|||||||
from distutils.core import setup
|
from distutils.core import setup
|
||||||
|
|
||||||
setup(name='minigrida',
|
setup(name='minigrida',
|
||||||
version='1.11',
|
version='2.0',
|
||||||
description='Simple and decentralized computing grid',
|
description='Simple and decentralized computing grid',
|
||||||
author='Florent Guiotte',
|
author='Florent Guiotte',
|
||||||
author_email='florent.guiotte@uhb.fr',
|
author_email='florent.guiotte@uhb.fr',
|
||||||
url='https://git.guiotte.fr/Florent/minigrida',
|
url='https://git.guiotte.fr/Florent/minigrida',
|
||||||
packages=['cvgenerators', 'descriptors', 'protocols'],
|
packages=['minigrida'],#'cvgenerators', 'descriptors', 'protocols', 'database'],
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user