Skip to content

Commit

Permalink
Merge branch 'feature/resovle-grads-in-comp' into feature/run-recipes…
Browse files Browse the repository at this point in the history
…-from-firebase
  • Loading branch information
rugeli authored Jul 13, 2023
2 parents a928c1d + 39435a1 commit d8b9a5a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 42 deletions.
41 changes: 2 additions & 39 deletions cellpack/autopack/DBRecipeHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,6 @@ def is_nested_list(item):
and isinstance(item[0], (list, tuple))
)

@staticmethod
def is_db_dict(item):
if isinstance(item, dict) and len(item) > 0:
for key, value in item.items():
if key.isdigit() and isinstance(value, list):
return True
return False

@staticmethod
def prep_data_for_db(data):
"""
Expand Down Expand Up @@ -440,6 +432,8 @@ def upload_objects(self, objects):
_, doc_id = object_doc.should_write(self.db)
if doc_id:
print(f"objects/{object_doc.name} is already in firestore")
obj_path = self.db.create_path("objects", doc_id)
self.objects_to_path_map[obj_name] = obj_path
else:
_, obj_path = self.upload_data("objects", object_doc.as_dict())
self.objects_to_path_map[obj_name] = obj_path
Expand Down Expand Up @@ -541,34 +535,3 @@ def upload_recipe(self, recipe_meta_data, recipe_data):
recipe_to_save = self.upload_collections(recipe_meta_data, recipe_data)
key = self.get_recipe_id(recipe_to_save)
self.upload_data("recipes", recipe_to_save, key)

def prep_db_doc_for_download(self, db_doc):
"""
convert data from db and resolve references.
"""
prep_data = {}
if isinstance(db_doc, dict):
for key, value in db_doc.items():
if self.is_db_dict(value):
unpack_dict = [value[str(i)] for i in range(len(value))]
prep_data[key] = unpack_dict
elif key == "composition":
compositions = db_doc["composition"]
for comp_name, reference in compositions.items():
ref_link = reference["inherit"]
comp_doc = CompositionDoc(
comp_name,
object_key=None,
count=None,
regions={},
molarity=None,
)
composition_data, _ = comp_doc.get_reference_data(
ref_link, self.db
)
comp_doc.resolve_db_regions(composition_data, self.db)
compositions[comp_name] = composition_data
prep_data[key] = compositions
else:
prep_data[key] = value
return prep_data
3 changes: 1 addition & 2 deletions cellpack/autopack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ def read_text_file(filename, destination="", cache="collisionTrees", force=None)


def load_file(filename, destination="", cache="geometries", force=None):
# what is the param destination for? should we use it to store db names?
if is_remote_path(filename):
database_name, file_path = convert_db_shortname_to_url(filename)
# command example: `pack -r firebase:recipes/peroxisomes_surface_gradient_v-linear -c examples/packing-configs/peroxisome_packing_config.json`
Expand All @@ -405,7 +404,7 @@ def load_file(filename, destination="", cache="geometries", force=None):
local_file_path = get_local_file_location(
filename, destination=destination, cache=cache, force=force
)
return json.load(open(local_file_path, "r")), None
return json.load(open(local_file_path, "r"))


def fixPath(adict): # , k, v):
Expand Down
2 changes: 1 addition & 1 deletion cellpack/autopack/loaders/migrate_v1_to_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def split_ingredient_data(object_key, ingredient_data):

def get_and_store_v2_object(ingredient_key, ingredient_data, region_list, objects_dict):
if "include" in ingredient_data:
ingredient_data, _ = load_file(ingredient_data["include"], cache="recipes")
ingredient_data = load_file(ingredient_data["include"], cache="recipes")
check_required_attributes(ingredient_data)
converted_ingredient = migrate_ingredient(ingredient_data)
object_info, composition_info = split_ingredient_data(
Expand Down

0 comments on commit d8b9a5a

Please sign in to comment.