Skip to content

Commit 69b2d94

Browse files
author
labkey-ians
committed
Merge remote-tracking branch 'origin/experiment' into experiment
# Conflicts: # labkey/query.py
2 parents de90d15 + 266cfac commit 69b2d94

File tree

5 files changed

+56
-50
lines changed

5 files changed

+56
-50
lines changed

labkey/experiment.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
# print("Load an Assay batch from the server")
3333
# assay_id = # provide one from your server
3434
# batch_id = # provide one from your server
35-
# run_group = load_batch(assay_id, batch_id, server_context)
35+
# run_group = load_batch(server_context, assay_id, batch_id)
3636
#
3737
# if run_group is not None:
3838
# print("Batch Id: " + str(run_group.id))
@@ -44,23 +44,24 @@
4444
# run_group.properties[batch_property_name] = batch_property_value
4545
#
4646
# print("Save the batch")
47-
# save_batch(assay_id, run_group, server_context)
47+
# save_batch(server_context, assay_id, run_group)
4848

4949
# --------
5050
# /EXAMPLE
5151

5252
# TODO Incorporate logging
5353

54-
def load_batch(assay_id, batch_id, server_context):
54+
def load_batch(server_context, assay_id, batch_id):
5555
"""
5656
Loads a batch from the server.
57+
:param server_context: A LabKey server context. See utils.create_server_context.
5758
:param assay_id: The protocol id of the assay from which to load a batch.
5859
:param batch_id:
59-
:param server_context: A LabKey server context. See utils.create_server_context.
6060
:return:
6161
"""
62-
load_batch_url = build_url('assay', 'getAssayBatch.api', server_context)
62+
load_batch_url = build_url(server_context, 'assay', 'getAssayBatch.api')
6363
session = server_context['session']
64+
loaded_batch = None
6465

6566
payload = {
6667
'assayId': assay_id,
@@ -76,39 +77,38 @@ def load_batch(assay_id, batch_id, server_context):
7677
response = session.post(load_batch_url, data=json.dumps(payload), headers=headers)
7778
json_body = handle_response(response)
7879
if json_body is not None:
79-
return Batch.from_data(json_body['batch'])
80+
loaded_batch = Batch.from_data(json_body['batch'])
8081
except SSLError as e:
8182
raise Exception("Failed to match server SSL configuration. Failed to load batch.")
8283

83-
return None
84+
return loaded_batch
8485

8586

86-
def save_batch(assay_id, batch, server_context):
87+
def save_batch(server_context, assay_id, batch):
8788
"""
8889
Saves a modified batch.
90+
:param server_context: A LabKey server context. See utils.create_server_context.
8991
:param assay_id: The assay protocol id.
9092
:param batch: The Batch to save.
91-
:param server_context: A LabKey server context. See utils.create_server_context.
9293
:return:
9394
"""
94-
result = save_batches(assay_id,[batch],server_context)
95+
result = save_batches(server_context, assay_id, [batch])
9596

9697
if result is not None:
9798
return result[0]
98-
else:
99-
return None
99+
return None
100100

101101

102-
def save_batches(assay_id, batches, server_context):
102+
def save_batches(server_context, assay_id, batches):
103103
"""
104104
Saves a modified batches.
105-
:param assay_id: The assay protocol id.
106-
:param batch: The Batch(es) to save.
107105
:param server_context: A LabKey server context. See utils.create_server_context.
106+
:param assay_id: The assay protocol id.
107+
:param batches: The Batch(es) to save.
108108
:return:
109109
"""
110110

111-
save_batch_url = build_url('assay', 'saveAssayBatch.api', server_context)
111+
save_batch_url = build_url(server_context, 'assay', 'saveAssayBatch.api')
112112
session = server_context['session']
113113

114114
json_batches = []
@@ -145,7 +145,7 @@ def save_batches(assay_id, batches, server_context):
145145

146146
class ExpObject(object):
147147
def __init__(self, **kwargs):
148-
self.lsid = kwargs.pop('lsid', None)
148+
self.lsid = kwargs.pop('lsid', None) # Life Science identifier
149149
self.name = kwargs.pop('name', None)
150150
self.id = kwargs.pop('id', 0)
151151
self.row_id = self.id

labkey/query.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ class Pagination(Enum):
5858
all = 3
5959
none = 4
6060

61-
62-
def delete_rows(schema_name, query_name, rows, server_context, container_path=None):
63-
url = build_url('query', 'deleteRows.api', server_context, container_path=container_path)
61+
def delete_rows(server_context, schema_name, query_name, rows, container_path=None):
62+
url = build_url(server_context, 'query', 'deleteRows.api', container_path=container_path)
6463

6564
payload = {
6665
'schemaName': schema_name,
@@ -72,9 +71,9 @@ def delete_rows(schema_name, query_name, rows, server_context, container_path=No
7271
return delete_rows_response
7372

7473

75-
def execute_sql(schema_name, sql, server_context, container_path=None,
74+
def execute_sql(server_context, schema_name, sql, container_path=None,
7675
max_rows=None, sort=None, offset=None, container_filter=None):
77-
url = build_url('query', 'executeSql.api', server_context, container_path=container_path)
76+
url = build_url(server_context, 'query', 'executeSql.api', container_path=container_path)
7877

7978
payload = {
8079
'schemaName': schema_name,
@@ -97,8 +96,8 @@ def execute_sql(schema_name, sql, server_context, container_path=None,
9796
return execute_sql_response
9897

9998

100-
def insert_rows(schema_name, query_name, rows, server_context, container_path=None):
101-
url = build_url('query', 'insertRows.api', server_context, container_path=container_path)
99+
def insert_rows(server_context, schema_name, query_name, rows, container_path=None):
100+
url = build_url(server_context, 'query', 'insertRows.api', container_path=container_path)
102101

103102
payload = {
104103
'schemaName': schema_name,
@@ -111,8 +110,7 @@ def insert_rows(schema_name, query_name, rows, server_context, container_path=No
111110

112111

113112
# TODO: Support all the properties
114-
def select_rows(schema_name, query_name, server_context,
115-
view_name=None,
113+
def select_rows(server_context, schema_name, query_name, view_name=None,
116114
filter_array=None,
117115
container_path=None,
118116
columns=None,
@@ -130,10 +128,11 @@ def select_rows(schema_name, query_name, server_context,
130128
required_version=None
131129
):
132130
# TODO: Support data_region_name
133-
url = build_url('query', 'getQuery.api', server_context, container_path=container_path)
131+
url = build_url(server_context, 'query', 'getQuery.api', container_path=container_path)
132+
134133
payload = {
135134
'schemaName': schema_name,
136-
'query.queryName': query_name,
135+
'query.queryName': query_name
137136
}
138137

139138
# TODO: Roll these checks up
@@ -185,8 +184,8 @@ def select_rows(schema_name, query_name, server_context,
185184
return select_rows_response
186185

187186

188-
def update_rows(schema_name, query_name, rows, server_context, container_path=None):
189-
url = build_url('query', 'updateRows.api', server_context, container_path=container_path)
187+
def update_rows(server_context, schema_name, query_name, rows, container_path=None):
188+
url = build_url(server_context, 'query', 'updateRows.api', container_path=container_path)
190189

191190
payload = {
192191
'schemaName': schema_name,
@@ -205,5 +204,3 @@ def _make_request(server_context, url, payload):
205204
return handle_response(raw_response)
206205
except SSLError as e:
207206
raise Exception('Failed to match server SSL configuration. Ensure the server_context is configured correctly.')
208-
209-

labkey/utils.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,16 @@ def init_poolmanager(self, connections, maxsize, block=False):
3333

3434

3535
def create_server_context(domain, container_path, context_path=None, use_ssl=True):
36-
# TODO: Document
36+
"""
37+
Create a LabKey server context. This context is used to encapsulate properties
38+
about the LabKey server that is being requested against. This includes, but is not limited to,
39+
the domain, container_path, and if the server is using SSL.
40+
:param domain:
41+
:param container_path:
42+
:param context_path:
43+
:param use_ssl:
44+
:return:
45+
"""
3746
server_context = dict(domain=domain, container_path=container_path, context_path=context_path)
3847

3948
if use_ssl:
@@ -55,13 +64,13 @@ def create_server_context(domain, container_path, context_path=None, use_ssl=Tru
5564
return server_context
5665

5766

58-
def build_url(controller, action, server_context, container_path=None):
67+
def build_url(server_context, controller, action, container_path=None):
5968
"""
6069
Builds a URL from a controller and an action. Users the server context to determine domain,
6170
context path, container, etc.
71+
:param server_context: A LabKey server context. See utils.create_server_context.
6272
:param controller: The controller to use in building the URL
6373
:param action: The action to use in building the URL
64-
:param server_context:
6574
:param container_path:
6675
:return:
6776
"""

samples/load_batch_example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
print("Load an Assay batch from the server")
1111
assay_id = 1168 # provide one from your server
1212
batch_id = 95 # provide one from your server
13-
run_group = load_batch(assay_id, batch_id, server_context)
13+
run_group = load_batch(server_context, assay_id, batch_id)
1414

1515
if run_group is not None:
1616
print("Batch Id: " + str(run_group.id))

samples/save_batch_example.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
dataRows = [
1414
{
1515
# ColumnName : Value
16-
"SampleId": "Monkey 1"
17-
, "TimePoint": "2008/11/02 11:22:33"
18-
, "DoubleData": 4.5
19-
, "HiddenData": "another data point"
16+
"SampleId": "Monkey 1",
17+
"TimePoint": "2008/11/02 11:22:33",
18+
"DoubleData": 4.5,
19+
"HiddenData": "another data point"
2020
}, {
21-
"SampleId": "Monkey 2"
22-
, "TimePoint": "2008/11/02 14:00:01"
23-
, "DoubleData": 3.1
24-
, "HiddenData": "fozzy bear"
21+
"SampleId": "Monkey 2",
22+
"TimePoint": "2008/11/02 14:00:01",
23+
"DoubleData": 3.1,
24+
"HiddenData": "fozzy bear"
2525
}, {
26-
"SampleId": "Monkey 3"
27-
, "TimePoint": "2008/11/02 14:00:01"
28-
, "DoubleData": 1.5
29-
, "HiddenData": "jimbo"
26+
"SampleId": "Monkey 3",
27+
"TimePoint": "2008/11/02 14:00:01",
28+
"DoubleData": 1.5,
29+
"HiddenData": "jimbo"
3030
}
3131
]
3232

@@ -43,7 +43,7 @@
4343
batch.properties['PropertyName'] = 'Property Value'
4444

4545
# Execute save api
46-
RESULT = save_batch(assay_id, batch, server_context)
47-
# RESULT = save_batches(assay_id, [batch1, batch2], server_context)
46+
RESULT = save_batch(server_context, assay_id, batch)
47+
# RESULT = save_batches(server_context, assay_id, [batch1, batch2])
4848
print(RESULT.id)
4949

0 commit comments

Comments
 (0)