Skip to content

Commit 967f11c

Browse files
authored
Merge pull request #64 from SmartBioTech/documentation
Documentation
2 parents 4eee7e0 + e11ae05 commit 967f11c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1378
-199
lines changed

.readthedocs.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# .readthedocs.yml
2+
# Read the Docs configuration file
3+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4+
5+
# Required
6+
version: 2
7+
8+
# Build documentation in the docs/ directory with Sphinx
9+
sphinx:
10+
builder: html
11+
configuration: docs/source/conf.py
12+
13+
python:
14+
version: "3.8"
15+
install:
16+
- requirements: docs/requirements.txt

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[![Python Package](https://github.com/SmartBioTech/DeviceControl/actions/workflows/python-flask.yml/badge.svg)](https://github.com/SmartBioTech/DeviceControl/actions/workflows/python-flask.yml)
22
[![Docker](https://github.com/SmartBioTech/DeviceControl/actions/workflows/docker.yml/badge.svg)](https://github.com/SmartBioTech/DeviceControl/actions/workflows/docker.yml)
3+
[![docs](https://readthedocs.org/projects/devicecontrol/badge/?version=latest)](https://devicecontrol.readthedocs.io/en/latest/)
34

45
# DeviceControl
56

67
`DeviceControl` is a tool to provide unified interface to control and measure data in specific cultivation device.
7-
We recommend reading [wiki](https://github.com/SmartBioTech/DeviceControl/wiki) to get started with the tool.
8+
We recommend reading [wiki](https://github.com/SmartBioTech/DeviceControl/wiki) to get started with the tool
9+
and [documentation](http://devicecontrol.readthedocs.io/) to get more details about the implementation.
810

911
## Installation
1012

app/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def create_app(config_name):
3131

3232
if config_name != 'testing':
3333
scheduler.init_app(app)
34-
scheduler.add_job(func=app_manager.restore_session, id='load_session',
34+
scheduler.add_job(func=app_manager._restore_session, id='load_session',
3535
run_date=datetime.now() + timedelta(seconds=30))
3636
scheduler.start()
3737

@@ -47,4 +47,4 @@ def setup_app_manager(app):
4747
db.create_all()
4848

4949
app_manager.init_app()
50-
app_manager.dataManager.store_permanent()
50+
app_manager.dataManager._store_permanent()

app/core/app_manager.py

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,14 @@ def validate_attributes(required, attributes, class_name):
1515

1616

1717
class AppManager:
18+
"""
19+
Defines entry points to the application.
20+
"""
21+
1822
def init_app(self):
23+
"""
24+
Initializes the application.
25+
"""
1926
from app.src.task_manager import TaskManager
2027
from app.src.data_manager import DataManager
2128
from app.src.device_manager import DeviceManager
@@ -26,6 +33,13 @@ def init_app(self):
2633

2734
@log_initialise('device')
2835
def register_device(self, config: dict) -> Response:
36+
"""
37+
Register a new device (see
38+
`details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#device-initiation>`__).
39+
40+
:param config: A dictionary with pre-defined keys
41+
:return: Response object
42+
"""
2943
try:
3044
validate_attributes(['device_id', 'device_class', 'device_type', 'address'], config, 'Connector')
3145
device = self.deviceManager.new_device(config)
@@ -38,6 +52,12 @@ def register_device(self, config: dict) -> Response:
3852

3953
@log_terminate
4054
def end_device(self, device_id: str) -> Response:
55+
"""
56+
Terminates an existing device.
57+
58+
:param device_id: ID of an existing device
59+
:return: Response object
60+
"""
4161
try:
4262
self.deviceManager.remove_device(device_id)
4363
self.dataManager.event_device_end(device_id)
@@ -51,7 +71,14 @@ def end_device(self, device_id: str) -> Response:
5171
Log.error(exc)
5272
return Response(False, None, exc)
5373

54-
def command(self, config) -> Response:
74+
def command(self, config: dict) -> Response:
75+
"""
76+
Run a specific command (see
77+
`details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#command>`__).
78+
79+
:param config: A dictionary with pre-defined keys
80+
:return: Response object
81+
"""
5582
try:
5683
validate_attributes(['device_id', 'command_id'], config, 'Command')
5784

@@ -61,7 +88,7 @@ def command(self, config) -> Response:
6188
source = config.get('source', 'external')
6289
await_result = config.get('await', False)
6390

64-
cmd = self.create_command(device_id, command_id, args, source)
91+
cmd = self._create_command(device_id, command_id, args, source)
6592
if await_result:
6693
self.deviceManager.get_device(device_id).post_command(cmd)
6794
cmd.await_cmd()
@@ -74,7 +101,14 @@ def command(self, config) -> Response:
74101
return Response(False, None, e)
75102

76103
@log_initialise('task')
77-
def register_task(self, config) -> Response:
104+
def register_task(self, config: dict) -> Response:
105+
"""
106+
Register a new task (see
107+
`details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#task-initiation>`__).
108+
109+
:param config: A dictionary with pre-defined keys
110+
:return: Response object
111+
"""
78112
try:
79113
validate_attributes(['task_id', 'task_class', 'task_type'], config, 'Task')
80114
task = self.taskManager.create_task(config)
@@ -87,6 +121,12 @@ def register_task(self, config) -> Response:
87121

88122
@log_terminate
89123
def end_task(self, task_id) -> Response:
124+
"""
125+
Terminate an existing task.
126+
127+
:param task_id: ID of an existing task
128+
:return: Response object
129+
"""
90130
try:
91131
device_id = self.taskManager.remove_task(task_id)
92132
self.dataManager.event_task_end(device_id, task_id)
@@ -97,12 +137,25 @@ def end_task(self, task_id) -> Response:
97137
return Response(False, None, exc)
98138

99139
def ping(self) -> Response:
140+
"""
141+
Get status information about the running devices and tasks (see
142+
`details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#ping>`__).
143+
144+
:return: Response object
145+
"""
100146
return Response(True, {
101147
'devices': self.deviceManager.ping(),
102148
'tasks': self.taskManager.ping()
103149
}, None)
104150

105-
def get_data(self, config) -> Response:
151+
def get_data(self, config: dict) -> Response:
152+
"""
153+
Retrieves data in supported format (see
154+
`details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#get-data>`__).
155+
156+
:param config: A dictionary with pre-defined keys
157+
:return: Response object
158+
"""
106159
try:
107160
validate_attributes(['device_id', 'type'], config, 'GetData')
108161

@@ -120,6 +173,12 @@ def get_data(self, config) -> Response:
120173
return Response(False, None, e)
121174

122175
def get_latest_data(self, config) -> Response:
176+
"""
177+
Retrieves the last data entry for specified Device ID and Data Type.
178+
179+
:param config: A dictionary which specifies the "device_id": string and "type": string
180+
:return: Response object
181+
"""
123182
try:
124183
validate_attributes(['device_id', 'type'], config, 'GetData')
125184
device_id = config.get('device_id')
@@ -130,18 +189,24 @@ def get_latest_data(self, config) -> Response:
130189
Log.error(e)
131190
return Response(False, None, e)
132191

133-
@staticmethod
134-
def create_command(device_id, command_id, args, source):
135-
from ..command import Command
136-
return Command(device_id, command_id, eval(args), source)
137-
138192
@log_terminate_all
139193
def end(self) -> Response:
194+
"""
195+
Ends the application (see
196+
`details <https://github.com/SmartBioTech/DeviceControl/wiki/End-Points#end>`__).
197+
198+
:return: Response object
199+
"""
140200
self.taskManager.end()
141201
self.deviceManager.end()
142202
return Response(True, None, None)
143203

144-
def restore_session(self):
204+
@staticmethod
205+
def _create_command(device_id, command_id, args, source):
206+
from ..command import Command
207+
return Command(device_id, command_id, eval(args), source)
208+
209+
def _restore_session(self):
145210
# first start devices
146211
tasks = []
147212
for log in self.dataManager.load_log():

0 commit comments

Comments
 (0)