Skip to content

feat: add child files to dataset iterator. #59

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions sdk/diffgram/core/diffgram_dataset_iterator.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,24 @@ def gen_tag_instances(self, instance_list):
result.append(elm)
return result

def get_file_instances(self, diffgram_file):
sample = {'diffgram_file': diffgram_file}
def get_file_instances(self, diffgram_file) -> dict:
if not diffgram_file:
return
sample = {'diffgram_file': diffgram_file, 'type': diffgram_file.type}
if diffgram_file.type not in ['image', 'frame', 'compound']:
logging.warning('File type "{}" is not supported yet'.format(diffgram_file.type))
return sample
if diffgram_file.type in ['image', 'frame']:
sample['image'] = self.get_image_data(diffgram_file)
elif diffgram_file.type is not None and diffgram_file.type.startswith('compound'):
from diffgram.file.compound_file import CompoundFile
compound_file: CompoundFile = diffgram_file
sample['children'] = []
child_files = compound_file.fetch_child_files(with_instances = True)
print('chsad', child_files)
for child in child_files:
result = self.get_file_instances(child)
sample['children'].append(result)
instance_list = diffgram_file.instance_list
instance_types_in_file = set([x['type'] for x in instance_list])
# Process the instances of each file
Expand Down
2 changes: 1 addition & 1 deletion sdk/diffgram/core/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def all_file_ids(self, query = None):
page_num = page_num,
file_view_mode = 'ids_only',
query = query,
with_children_files = True)
with_children_files = False)

if diffgram_ids is False:
raise Exception('Error Fetching Files: Please check you are providing a valid query.')
Expand Down
7 changes: 4 additions & 3 deletions sdk/diffgram/file/compound_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,21 @@ def __init__(self, project: Project, name: str, directory_id: int, instance_list
def from_dict(project: Project, dir_id: int, dict_data: dict):
result = CompoundFile(project = project, name = dict_data.get('original_filename'), directory_id = dir_id)
result.__refresh_compound_file_from_data_dict(data = dict_data)
child_files = result.__fetch_child_files()
child_files = result.fetch_child_files()
result.child_files = child_files
return result

def __fetch_child_files(self) -> List[CompoundChildFile]:
def fetch_child_files(self, with_instances: bool = False) -> List[CompoundChildFile]:
client = self.project
endpoint = f"/api/v1/project/{self.project.project_string_id}/file/{self.id}/child-files"

response = client.session.get(client.host + endpoint)
response = client.session.get(client.host + endpoint, params = {'with_instances': with_instances})

client.handle_errors(response)

data = response.json()
child_files_data = data['child_files']
print('child_files_data', child_files_data)
result = []
for elm in child_files_data:
child_file = CompoundChildFile(root_file = self, child_file_type = elm.get('type'))
Expand Down
17 changes: 7 additions & 10 deletions sdk/diffgram/file/file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ..regular.regular import refresh_from_dict


class File():
"""
file literal object
Expand Down Expand Up @@ -36,7 +37,7 @@ def new(

"""

file = File(client=client)
file = File(client = client)
refresh_from_dict(file, file_json)
return file

Expand Down Expand Up @@ -65,9 +66,9 @@ def update(
if overwrite:
packet['mode'] = "update_with_existing"

self.client.file.from_packet(packet=packet)
self.client.file.from_packet(packet = packet)

def copy(self, destination_dir, copy_instances=False):
def copy(self, destination_dir, copy_instances = False):
payload = {
'mode': 'TRANSFER',
'file_list': [
Expand All @@ -88,17 +89,13 @@ def copy(self, destination_dir, copy_instances=False):

response = self.client.session.post(
self.client.host + endpoint,
json=payload)
json = payload)

self.client.handle_errors(response)

data = response.json()
new_file_data = data['log']['info']['new_file'][0]

return File.new(
client=self.client,
file_json=new_file_data)




client = self.client,
file_json = new_file_data)