Skip to content

Commit

Permalink
Merge pull request #46 from ttngu207/main
Browse files Browse the repository at this point in the history
  • Loading branch information
yambottle authored Nov 8, 2024
2 parents 4f37a78 + 75a486c commit f342e8b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 54 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.5.0] - 2024-11-08

### Added

- Started CHANGELOG
- Install with `pyproject.toml`


[0.0.0]: https://github.com/datajoint-company/datajoint-utilities/releases/tag/0.5.0
47 changes: 36 additions & 11 deletions datajoint_utilities/dj_worker/worker_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,33 @@ class Process(dj.Part):
"""

@classmethod
def get_workers_progress(cls):
def get_workers_progress(cls, worker_name=None, process_name=None):
"""
Return the operation progress for all registered workers (jobs status for each AutoPopulate process)
:return: pandas DataFrame of workers jobs status
Args:
worker_name (str): name of the worker (optionally restrict by worker_name)
process_name (str): name of the process (optionally restrict by process_name)
Returns:
pandas DataFrame of workers jobs status
"""
restriction = {}
if worker_name:
restriction["worker_name"] = worker_name
if process_name:
restriction["process"] = process_name

workflow_status = (
(cls.Process & "key_source_sql is not NULL")
.proj(
"process",
"key_source_sql",
table_name="full_table_name",
total="NULL",
incomplete="NULL",
(
(cls.Process & "key_source_sql is not NULL").proj(
"process",
"key_source_sql",
table_name="full_table_name",
total="NULL",
incomplete="NULL",
)
& restriction
)
.fetch(format="frame")
.reset_index()
Expand Down Expand Up @@ -96,7 +110,7 @@ def get_workers_progress(cls):
(
workflow_status.loc[r_idx, "total"],
workflow_status.loc[r_idx, "incomplete"],
) = cls._get_key_source_count(r.key_source_sql, r.table_name)
) = cls.get_key_source_count(r.key_source_sql, r.table_name)

# merge key_source and jobs status
workflow_status.set_index("table_name", inplace=True)
Expand Down Expand Up @@ -124,7 +138,10 @@ def get_workers_progress(cls):
return workflow_status

@classmethod
def _get_key_source_count(cls, key_source_sql, target_full_table_name):
def get_incomplete_key_source_sql(cls, key_source_sql, target_full_table_name):
"""
From `key_source_sql`, build a SQL statement to find incomplete key_source entries in the target table
"""
def _rename_attributes(table, props):
return (
table.proj(
Expand Down Expand Up @@ -169,6 +186,14 @@ def _remove_enclosed_parentheses(input_string):
key_source_sql
+ f"{AND_or_WHERE}(({ks_attrs_sql}) not in (SELECT {ks_attrs_sql} FROM {target.full_table_name}))"
)
return incomplete_sql

@classmethod
def get_key_source_count(cls, key_source_sql, target_full_table_name):
"""
From `key_source_sql`, count the total and incomplete key_source entries in the target table
"""
incomplete_sql = cls.get_incomplete_key_source_sql(key_source_sql, target_full_table_name)
try:
total = len(dj.conn().query(key_source_sql).fetchall())
incomplete = len(dj.conn().query(incomplete_sql).fetchall())
Expand Down
2 changes: 1 addition & 1 deletion datajoint_utilities/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package metadata."""

__version__ = "0.4.0"
__version__ = "0.5.0"
61 changes: 61 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[build-system]
requires = ["setuptools>=62.0", "wheel>=0.37"]
build-backend = "setuptools.build_meta"

[project]
name = "datajoint-utilities"
version = "0.5.0"
description = "A general purpose repository containing all generic tools/utilities surrounding the DataJoint ecosystem"
requires-python = ">=3.9, <3.12"
license = { file = "LICENSE" }
authors = [{ name = "DataJoint", email = "[email protected]" }]
keywords = ["datajoint", "workflow"]
classifiers = [
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
]
dependencies = [
"datajoint>=0.14.3",
"termcolor",
"slack-sdk",
"python-dotenv",
"boto3",
"requests",
]

[project.scripts]
tmplcfg = "datajoint_utilities.cmdline.tmplcfg:cli"

[project.urls]
Source = "https://github.com/datajoint-company/datajoint-utilities"
DataJoint = "https://datajoint.com/docs"

[tool.setuptools]
package-data = { "*" = ["*.pyi", "py.typed"] }

[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-rA"
testpaths = ["tests"]

[tool.black]
line-length = 88
target-version = ["py310"]
color = false
exclude = '''
/(
\.git
| \.venv
| _build
| example_data
| build
| dist
| env
| venv
)/
'''

[tool.isort]
profile = "black"
6 changes: 0 additions & 6 deletions requirements.txt

This file was deleted.

36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

0 comments on commit f342e8b

Please sign in to comment.