Skip to content

Commit e9fd9c3

Browse files
author
Kevin Kim
committed
Add result field to Task and get_result()
1 parent 94d2d91 commit e9fd9c3

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

labelbox/orm/db_object.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def _to_many(self, where=None, order_by=None):
150150
query_string, params = query.relationship(
151151
self.source if self.filter_on_id else type(self.source), rel, where,
152152
order_by)
153+
print(f"!! QUery string {query_string}")
153154
return PaginatedCollection(
154155
self.source.client, query_string, params,
155156
[utils.camel_case(self.source.type_name()), rel.graphql_name],

labelbox/schema/dataset.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,11 @@ def export_data_rows(self, timeout_seconds=120) -> Generator:
430430
response = requests.get(download_url)
431431
response.raise_for_status()
432432
reader = ndjson.reader(StringIO(response.text))
433+
for r in reader:
434+
print(f"Reader: {r}")
433435
# TODO: Update result to parse metadataFields when resolver returns
434-
return (Entity.DataRow(self.client, {
435-
**result, 'metadataFields': []
436-
}) for result in reader)
436+
return (
437+
Entity.DataRow(self.client, result) for result in reader)
437438
elif res["status"] == "FAILED":
438439
raise LabelboxError("Data row export failed.")
439440

labelbox/schema/task.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import logging
2+
import requests
23
import time
4+
import validators
5+
from validators import ValidationFailure
36
from typing import TYPE_CHECKING, Optional
47

58
from labelbox.exceptions import ResourceNotFoundError
@@ -31,6 +34,7 @@ class Task(DbObject):
3134
name = Field.String("name")
3235
status = Field.String("status")
3336
completion_percentage = Field.Float("completion_percentage")
37+
result = Field.String("result")
3438
_user: Optional["User"] = None
3539

3640
# Relationships
@@ -65,3 +69,15 @@ def wait_till_done(self, timeout_seconds=300) -> None:
6569
timeout_seconds -= check_frequency
6670
time.sleep(sleep_time_seconds)
6771
self.refresh()
72+
73+
def get_result(self) -> str:
74+
""" Downloads the result file from Task
75+
"""
76+
if self.result:
77+
result_url = validators.url(self.result)
78+
if isinstance(result_url, ValidationFailure):
79+
raise TypeError(f"{result_url} is not a valid url")
80+
response = requests.get(self.result)
81+
response.raise_for_status()
82+
return response.text
83+
return ""

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ typeguard
1313
imagesize
1414
pyproj
1515
pygeotile
16-
typing-extensions
16+
typing-extensions
17+
validators

0 commit comments

Comments
 (0)