Skip to content

Commit 673d8fa

Browse files
authored
Merge pull request #889 from Labelbox/ms/last-activity
last activity filter
2 parents 9850566 + 1e5866c commit 673d8fa

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22

33
# Version 3.37.0 (2023-xx-xx)
4+
## Added
5+
* New `last_activity_start` param to `project.export_labels()` for filtering which labels are exported. See docstring for more on how this works.
6+
47
## Changed
58
* Rename `Classification.instructions` to `Classification.name`
69

labelbox/schema/project.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ def export_labels(self,
301301
timeout_seconds (float): Max waiting time, in seconds.
302302
start (str): Earliest date for labels, formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
303303
end (str): Latest date for labels, formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
304+
last_activity_start (str): Will include all labels that have had any updates to
305+
data rows, issues, comments, metadata, or reviews since this timestamp.
306+
formatted "YYYY-MM-DD" or "YYYY-MM-DD hh:mm:ss"
307+
304308
Returns:
305309
URL of the data file with this Project's labels. If the server didn't
306310
generate during the `timeout_seconds` period, None is returned.
@@ -346,6 +350,12 @@ def _validate_datetime(string_date: str) -> bool:
346350
filter_param_dict["labelCreatedAt"] = "{%s}" % _string_from_dict(
347351
created_at_dict, value_with_quotes=True)
348352

353+
if "last_activity_start" in kwargs:
354+
last_activity_start = kwargs['last_activity_start']
355+
_validate_datetime(last_activity_start)
356+
filter_param_dict["lastActivityAt"] = "{%s}" % _string_from_dict(
357+
{"start": last_activity_start}, value_with_quotes=True)
358+
349359
if filter_param_dict:
350360
filter_param = """, filters: {%s }""" % (_string_from_dict(
351361
filter_param_dict, value_with_quotes=False))
@@ -355,6 +365,7 @@ def _validate_datetime(string_date: str) -> bool:
355365
""" % (id_param, id_param, filter_param)
356366

357367
start_time = time.time()
368+
358369
while True:
359370
res = self.client.execute(query_str, {id_param: self.uid})
360371
res = res["exportLabels"]

tests/integration/test_export.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import uuid
2+
import datetime
23

34
from labelbox.data.annotation_types.annotation import ObjectAnnotation
45
from labelbox.schema.annotation_import import LabelImport
@@ -98,3 +99,47 @@ def test_export_filtered_dates(client,
9899
start="2020-01-01",
99100
end="2020-01-02")
100101
assert len(empty_export) == 0
102+
103+
104+
def test_export_filtered_activity(client,
105+
configured_project_with_complex_ontology):
106+
project, data_row = configured_project_with_complex_ontology
107+
ontology = project.ontology().normalized
108+
109+
tool = ontology["tools"][0]
110+
111+
data = [{
112+
"uuid": str(uuid.uuid4()),
113+
"schemaId": tool['featureSchemaId'],
114+
"dataRow": {
115+
"id": data_row.uid
116+
},
117+
"bbox": {
118+
"top": 20,
119+
"left": 20,
120+
"height": 50,
121+
"width": 50
122+
}
123+
}]
124+
125+
task = LabelImport.create_from_objects(client, project.uid,
126+
f'label-import-{uuid.uuid4()}', data)
127+
task.wait_until_done()
128+
129+
regular_export = project.export_labels(download=True)
130+
assert len(regular_export) == 1
131+
132+
filtered_export = project.export_labels(download=True,
133+
last_activity_start="2020-01-01")
134+
assert len(filtered_export) == 1
135+
136+
filtered_export_with_time = project.export_labels(
137+
download=True, last_activity_start="2020-01-01 00:00:01")
138+
assert len(filtered_export_with_time) == 1
139+
140+
empty_export = project.export_labels(
141+
download=True,
142+
last_activity_start=(datetime.datetime.now() +
143+
datetime.timedelta(days=1)).strftime("%Y-%m-%d"),
144+
)
145+
assert len(empty_export) == 0

0 commit comments

Comments
 (0)