-
Notifications
You must be signed in to change notification settings - Fork 68
initial addition to include filters for export_labels #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
958198d
initial addition to include filters for export_labels
jtsodapop 4e1a4a5
nit update
jtsodapop 46dd3c9
nit update
jtsodapop 4801391
additional update to yml for an updated mypy
jtsodapop 16f455b
update to docstring
jtsodapop b6108ff
update to docstring
jtsodapop 632166e
update to docstring
jtsodapop 95c3e8a
update to docstring
jtsodapop acb6cd8
update type ignore
jtsodapop 27b15ee
update to ignore attr defined
jtsodapop 835907c
update to ignore attr defined
jtsodapop 8240417
update to test to remove the assert
jtsodapop c8887be
Merge branch 'develop' into al-1351
jtsodapop 1abe4ba
update for yapf
jtsodapop 6634f82
update for yapf
jtsodapop 6a7431d
nit update to invitelimit
jtsodapop e612234
updates to simplify code
jtsodapop 1274529
removal of extra import
jtsodapop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,7 +194,9 @@ def export_queued_data_rows(self, | |
self.uid) | ||
time.sleep(sleep_time) | ||
|
||
def video_label_generator(self, timeout_seconds=600) -> LabelGenerator: | ||
def video_label_generator(self, | ||
timeout_seconds=600, | ||
**kwargs) -> LabelGenerator: | ||
""" | ||
Download video annotations | ||
|
||
|
@@ -203,7 +205,8 @@ def video_label_generator(self, timeout_seconds=600) -> LabelGenerator: | |
""" | ||
_check_converter_import() | ||
json_data = self.export_labels(download=True, | ||
timeout_seconds=timeout_seconds) | ||
timeout_seconds=timeout_seconds, | ||
**kwargs) | ||
# assert that the instance this would fail is only if timeout runs out | ||
assert isinstance( | ||
json_data, | ||
|
@@ -222,7 +225,7 @@ def video_label_generator(self, timeout_seconds=600) -> LabelGenerator: | |
"Or use project.label_generator() for text and imagery data.") | ||
return LBV1Converter.deserialize_video(json_data, self.client) | ||
|
||
def label_generator(self, timeout_seconds=600) -> LabelGenerator: | ||
def label_generator(self, timeout_seconds=600, **kwargs) -> LabelGenerator: | ||
""" | ||
Download text and image annotations | ||
|
||
|
@@ -231,7 +234,8 @@ def label_generator(self, timeout_seconds=600) -> LabelGenerator: | |
""" | ||
_check_converter_import() | ||
json_data = self.export_labels(download=True, | ||
timeout_seconds=timeout_seconds) | ||
timeout_seconds=timeout_seconds, | ||
**kwargs) | ||
# assert that the instance this would fail is only if timeout runs out | ||
assert isinstance( | ||
json_data, | ||
|
@@ -250,26 +254,69 @@ def label_generator(self, timeout_seconds=600) -> LabelGenerator: | |
"Or use project.video_label_generator() for video data.") | ||
return LBV1Converter.deserialize(json_data) | ||
|
||
def export_labels( | ||
self, | ||
download=False, | ||
timeout_seconds=600) -> Optional[Union[str, List[Dict[Any, Any]]]]: | ||
def export_labels(self, | ||
download=False, | ||
timeout_seconds=600, | ||
**kwargs) -> Optional[Union[str, List[Dict[Any, Any]]]]: | ||
""" Calls the server-side Label exporting that generates a JSON | ||
payload, and returns the URL to that payload. | ||
|
||
Will only generate a new URL at a max frequency of 30 min. | ||
|
||
Args: | ||
download (bool): Returns the url if False | ||
timeout_seconds (float): Max waiting time, in seconds. | ||
start (str): Earliest date for labels, formatted "YYYY-MM-DD" | ||
end (str): Latest date for labels, formatted "YYYY-MM-DD" | ||
Returns: | ||
URL of the data file with this Project's labels. If the server didn't | ||
generate during the `timeout_seconds` period, None is returned. | ||
""" | ||
|
||
def _string_from_dict(dictionary: dict, value_with_quotes=False) -> str: | ||
"""Returns a concatenated string of the dictionary's keys and values | ||
|
||
The string will be formatted as {key}: 'value' for each key. Value will be inclusive of | ||
quotations while key will not. This can be toggled with `value_with_quotes`""" | ||
|
||
quote = "\"" if value_with_quotes else "" | ||
return ",".join([ | ||
f"""{c}: {quote}{dictionary.get(c)}{quote}""" | ||
for c in dictionary | ||
if dictionary.get(c) | ||
]) | ||
Comment on lines
+282
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you test this? |
||
|
||
def _validate_datetime(string_date: str) -> bool: | ||
"""helper function validate that datetime is as follows: YYYY-MM-DD for the export""" | ||
if string_date: | ||
try: | ||
datetime.strptime(string_date, "%Y-%m-%d") | ||
except ValueError: | ||
raise ValueError(f"""Incorrect format for: {string_date}. | ||
Format must be \"YYYY-MM-DD\"""") | ||
return True | ||
|
||
sleep_time = 2 | ||
id_param = "projectId" | ||
filter_param = "" | ||
filter_param_dict = {} | ||
|
||
if "start" in kwargs or "end" in kwargs: | ||
created_at_dict = { | ||
"start": kwargs.get("start", ""), | ||
"end": kwargs.get("end", "") | ||
} | ||
[_validate_datetime(date) for date in created_at_dict.values()] | ||
filter_param_dict["labelCreatedAt"] = "{%s}" % _string_from_dict( | ||
created_at_dict, value_with_quotes=True) | ||
|
||
if filter_param_dict: | ||
filter_param = """, filters: {%s }""" % (_string_from_dict( | ||
filter_param_dict, value_with_quotes=False)) | ||
|
||
query_str = """mutation GetLabelExportUrlPyApi($%s: ID!) | ||
{exportLabels(data:{projectId: $%s }) {downloadUrl createdAt shouldPoll} } | ||
""" % (id_param, id_param) | ||
{exportLabels(data:{projectId: $%s%s}) {downloadUrl createdAt shouldPoll} } | ||
""" % (id_param, id_param, filter_param) | ||
|
||
while True: | ||
res = self.client.execute(query_str, {id_param: self.uid}) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.