Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding project.maintenance #396

Merged
merged 7 commits into from Aug 31, 2021
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
62 changes: 59 additions & 3 deletions pyiron_base/project/generic.py
Expand Up @@ -13,11 +13,12 @@
import numpy as np
import pkgutil
from git import Repo, InvalidGitRepositoryError

from warnings import warn
from pyiron_base.project.path import ProjectPath
from pyiron_base.database.filetable import FileTable
from pyiron_base.settings.generic import Settings
from pyiron_base.settings.publications import list_publications
from pyiron_base.database.performance import get_database_statistics
from pyiron_base.database.jobtable import (
get_db_columns,
get_job_ids,
Expand Down Expand Up @@ -130,6 +131,14 @@ def __init__(self, path="", user=None, sql_query=None, default_working_directory
self.db = FileTable(project=path)
self.job_type = JobTypeChoice()

self._maintenance = None

@property
def maintenance(self):
if self._maintenance is None:
self._maintenance = Maintenance()
return self._maintenance

@property
def parent_group(self):
"""
Expand Down Expand Up @@ -1462,7 +1471,6 @@ def _update_jobs_in_old_database_format(self, job_name):
for entry in db_entry_in_old_format:
self.db.item_update({"project": self.project_path}, entry["id"])


def pack(self, destination_path, csv_file_name='export.csv', compress=True):
"""
by this funtion, the job table is exported to a csv file
Expand All @@ -1480,7 +1488,6 @@ def pack(self, destination_path, csv_file_name='export.csv', compress=True):
df = export_archive.export_database(self, directory_to_transfer, destination_path)
df.to_csv(csv_file_name)


def unpack(self, origin_path, csv_file_name='export.csv', compress=True):
"""
by this function, job table is imported from a given csv file,
Expand All @@ -1498,6 +1505,55 @@ def unpack(self, origin_path, csv_file_name='export.csv', compress=True):
)


class Maintenance:
"""
The purpose of maintenance class is to provide
some measures of perfomance for pyiron, whether local to the project
or global (describing the status of pyiron on the running machine)
"""
def __init__(self):
"""
initialize the local and global attributes to None
"""
self._global = None
self._local = None

@property
def global_status(self):
if self._global is None:
self._global = GlobalMaintenance()
return self._global
max-hassani marked this conversation as resolved.
Show resolved Hide resolved


class GlobalMaintenance:
def __init__(self):
"""
initialize the flag self._check_postgres, to control whether pyiron is
set to communicate with a postgres database.
"""
s = Settings()
connection_string = s._configuration['sql_connection_string']
if "postgresql" not in connection_string:
warn(
"""
The detabase statistics is only available for a Postgresql database
"""
)
self._check_postgres = False
else:
self._check_postgres = True

def get_database_statistics(self):
if self._check_postgres:
return get_database_statistics()
else:
raise RuntimeError(
"""
The detabase statistics is only available for a Postgresql database
"""
)


class Creator:
def __init__(self, project):
self._job_factory = JobFactory(project=project)
Expand Down