class Tasklist
A class for tracking and managing the status of study tasks through a Neo4j graph database, monitoring progress through a predefined sequence of workflow steps.
/tf/active/vicechatdev/resources/taskmanager.py
33 - 90
moderate
Purpose
The Tasklist class provides a comprehensive interface for managing study workflow status in a Neo4j database. It tracks a study's progress through 13 predefined tasks (from Quote to Final Report), queries the database to determine current status, and provides methods to retrieve numerical progress indicators. The class maintains both overall study status and detailed status information for each task, making it suitable for workflow management and progress tracking in laboratory or research study contexts.
Source Code
class Tasklist():
"""
Class for gathering and tracking the list of studies
Attributes
----------
graph : Py2neo.Graph
Database graph
tasks : list
An internal task lists, which defines all the mandatory tasks to go through, in linear order.
study : str
A string containing the unique ID of a study
status : str
The current status of the study, by default set to Finished
numerated_status : int
The current status in number format, i.e. step 3 out of 10
max_tasks : int
The total number of tasks in our current task list
status_dict : dictionary
A dictionary mapping each task to its current status
details_status : dictionary
A dictionary mapping teach task to a list of all its current statusses,
for example: Grossing:['Pending','Pending','Finished','Finished']
Parameters
----------
study : str
A string containing the unique ID of a study
"""
tasks = ["Quote", "Study Plan", "Delivery", "Sample Registration", "Grossing", "Embedding", "Sectioning", "Staining", "Scanning", "Digital QA","Assessment","Draft Report","Final Report"]
def __init__(self, study):
# self.graph = Graph("bolt://neodev:7687",auth=('neo4j','innoser'),name='neo4j')
self.graph = Graph(config.DB_ADDR, auth=config.DB_AUTH, name=config.DB_NAME)
self.study = study
self.status = 'Finished'
self.numerated_status = int()
self.max_tasks = len(self.tasks)+1
self.status_dict = {i:"Pending" for i in self.tasks}
self.detailed_status = {i:[] for i in self.tasks}
self._get_status()
def _get_status(self):
for task in self.tasks:
result = self.graph.run(f"MATCH (:Study {{UID:'{self.study}'}})-[*]->(t:Task {{T:'{task}'}}) RETURN COLLECT(t.T)").evaluate()
if len(result) > 0:
self.status = task
else:
self.status_dict[task] = 'Completed'
continue
break
def numerate_status(self):
try:
self.numerated_status = self.tasks.index(self.status)+1
except Exception as e:
self.numerated_status = 10
return self.numerated_status, self.max_tasks
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
- | - |
Parameter Details
study: A unique identifier string for the study being tracked. This UID is used to query the Neo4j database to retrieve task status information and must match the UID stored in the database's Study nodes.
Return Value
Instantiation returns a Tasklist object with initialized status tracking. The numerate_status() method returns a tuple of (numerated_status: int, max_tasks: int) representing the current task number and total number of tasks respectively.
Class Interface
Methods
__init__(self, study: str)
Purpose: Initializes a Tasklist instance, establishes database connection, and retrieves current study status
Parameters:
study: Unique identifier string for the study to track
Returns: None (constructor)
_get_status(self) -> None
Purpose: Private method that queries the Neo4j database to determine the current status of the study by checking which tasks are completed
Returns: None (updates instance attributes status and status_dict)
numerate_status(self) -> tuple[int, int]
Purpose: Converts the current status string to a numerical representation indicating progress through the task list
Returns: Tuple containing (numerated_status: int, max_tasks: int) - the current task number and total number of tasks
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
tasks |
list[str] | Class variable containing the ordered list of 13 task names that define the study workflow from Quote to Final Report | class |
graph |
py2neo.Graph | Instance of py2neo Graph object representing the connection to the Neo4j database | instance |
study |
str | The unique identifier (UID) of the study being tracked | instance |
status |
str | The current status/task name of the study, defaults to 'Finished' and updated by _get_status() | instance |
numerated_status |
int | The numerical representation of the current status (e.g., 3 for the third task) | instance |
max_tasks |
int | The total number of tasks in the workflow (length of tasks list + 1) | instance |
status_dict |
dict[str, str] | Dictionary mapping each task name to its current status ('Pending' or 'Completed') | instance |
detailed_status |
dict[str, list] | Dictionary mapping each task name to a list of detailed status entries (initialized as empty lists, not populated in current implementation) | instance |
Dependencies
py2neodatetimeiopanelparamjsonconfig
Required Imports
from neo4j_driver import *
import datetime as dt
import io
import panel as pn
import param
import json
import config
Usage Example
# Ensure config.py has DB_ADDR, DB_AUTH, and DB_NAME configured
# Example: config.DB_ADDR = 'bolt://localhost:7687'
# config.DB_AUTH = ('neo4j', 'password')
# config.DB_NAME = 'neo4j'
from tasklist import Tasklist
# Instantiate with a study UID
tasklist = Tasklist(study='STUDY-12345')
# Check current status
print(f"Current status: {tasklist.status}")
# Get numerical progress
current_step, total_steps = tasklist.numerate_status()
print(f"Progress: {current_step}/{total_steps}")
# Check status dictionary
for task, status in tasklist.status_dict.items():
print(f"{task}: {status}")
# Access detailed status information
print(f"Detailed status: {tasklist.detailed_status}")
Best Practices
- Ensure Neo4j database is properly configured and accessible before instantiating the class
- The study UID passed to __init__ must exist in the database as a Study node
- The class automatically queries the database upon instantiation via _get_status(), so instantiation may take time depending on database performance
- The tasks class variable defines the workflow order and should not be modified unless the database schema is updated accordingly
- The _get_status() method is private and called automatically during initialization; manual calls are not necessary
- The status_dict attribute is initialized with all tasks as 'Pending' and updated to 'Completed' based on database queries
- The numerate_status() method returns a default value of 10 if an exception occurs, which may not reflect actual progress
- Database connection is established per instance; consider connection pooling for multiple instances
- The detailed_status dictionary is initialized but never populated in the current implementation
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class Total_tasks 77.1% similar
-
class Study_overview 58.8% similar
-
function get_task_status 48.3% similar
-
function api_task_status 48.0% similar
-
function api_chat_status 47.8% similar