creates chain functions to expand the dataset from the entrypoint
This commit is contained in:
115
src/main.py
115
src/main.py
@@ -60,60 +60,87 @@ def call_layers_from_list(elabid_list):
|
|||||||
)
|
)
|
||||||
return list_of_layers # list of Layer-class objects
|
return list_of_layers # list of Layer-class objects
|
||||||
|
|
||||||
def call_batch_from_entrypoint(sample_object):
|
def chain_entrypoint_to_batch(sample_object):
|
||||||
'''
|
'''
|
||||||
Takes an Entrypoint-class object, looks at its .batch_elabid attribute and returns a Material-class object containing data on the substrate batch associated to the starting sample.
|
Takes an Entrypoint-class object, looks at its .batch_elabid attribute and returns a Material-class object containing data on the substrate batch associated to the starting sample.
|
||||||
|
|
||||||
|
Dependency: call_material_from_elabid.
|
||||||
'''
|
'''
|
||||||
material_elabid = sample_object.batch_elabid
|
material_elabid = sample_object.batch_elabid
|
||||||
material_object = call_material_from_elabid(material_elabid)
|
material_object = call_material_from_elabid(material_elabid)
|
||||||
return material_object
|
return material_object
|
||||||
|
|
||||||
sample_object = call_entrypoint_from_elabid(elabid)
|
def chain_entrypoint_to_layers(sample_object):
|
||||||
from_entrypoint_to_material(sample_object)
|
'''
|
||||||
|
Takes an Entrypoint-class object, looks at its .linked_experiments_elabid attribute (list) and returns a list of Layer-class objects containing data on the deposition layers associated to the starting sample - using the function call_layers_from_list.
|
||||||
|
|
||||||
|
The list is sorted by progressive layer number (layer_number attribute).
|
||||||
|
|
||||||
|
Dependency: call_layers_from_list.
|
||||||
|
'''
|
||||||
|
linked_experiments_elabid = sample_object.linked_experiments_elabid # list of elabid
|
||||||
|
layer_object_list = call_layers_from_list(linked_experiments_elabid)
|
||||||
|
layer_object_list.sort(key=lambda x: x.layer_number)
|
||||||
|
return layer_object_list
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#sample_object = call_entrypoint_from_elabid(elabid)
|
||||||
|
#from_entrypoint_to_material(sample_object)
|
||||||
|
|
||||||
|
|
||||||
if __name__=="__main__":
|
if __name__=="__main__":
|
||||||
print(f"=======================\n===== DEBUG MODE! =====\n=======================\n")
|
print(f"=======================\n===== DEBUG MODE! =====\n=======================\n")
|
||||||
ELABFTW_API_URL = "https://elabftw.fisica.unina.it/api/v2"
|
ELABFTW_API_URL = "https://elabftw.fisica.unina.it/api/v2"
|
||||||
apikey = getpass("Paste API key here: ")
|
apikey = getpass("Paste API key here: ")
|
||||||
# TEST. In production the entryType will probably just be "items" since the entrypoint is an item (sample).
|
elabid = input("Enter elabid of your starting sample [default= 1111]: ") or 1111
|
||||||
entryType = None
|
data = APIHandler(apikey).get_entry_from_elabid(elabid)
|
||||||
while entryType not in ["items", "experiments"]:
|
sample = Entrypoint(data)
|
||||||
eT = input("Enter a valid entry type [items, experiments]: ")
|
layers = chain_entrypoint_to_layers(sample)
|
||||||
# This allows for a shortcut: instead of prompting the type before and the elabid after I can just prompt both at the same time - e.g. e51 is exp. 51, i1108 is item 1108...
|
print(f"Sample name:\n{sample.name}\n")
|
||||||
if eT[0] in ["e", "i"] and eT[-1].isnumeric():
|
print(f"Layers data:")
|
||||||
try:
|
for layer in layers:
|
||||||
elabid = int(eT[1:])
|
ld = layer.__dict__
|
||||||
eT = eT[0]
|
ld.pop("extra")
|
||||||
except Exception:
|
print(ld)
|
||||||
print("Usage: i|item|items|i[ELABID] for items, e|experiment|experiments|e[ELABID] for experiments.")
|
|
||||||
continue
|
# entryType = None
|
||||||
match eT:
|
# while entryType not in ["items", "experiments"]:
|
||||||
case "items" | "i" | "item":
|
# eT = input("Enter a valid entry type [items, experiments]: ")
|
||||||
entryType = "items"
|
# # This allows for a shortcut: instead of prompting the type before and the elabid after I can just prompt both at the same time - e.g. e51 is exp. 51, i1108 is item 1108...
|
||||||
case "experiments" | "e" | "exp" | "experiment":
|
# if eT[0] in ["e", "i"] and eT[-1].isnumeric():
|
||||||
entryType = "experiments"
|
# try:
|
||||||
case _:
|
# elabid = int(eT[1:])
|
||||||
continue
|
# eT = eT[0]
|
||||||
# This will probably be reworked in production
|
# except Exception:
|
||||||
try:
|
# print("Usage: i|item|items|i[ELABID] for items, e|experiment|experiments|e[ELABID] for experiments.")
|
||||||
elabid = elabid
|
# continue
|
||||||
except NameError:
|
# match eT:
|
||||||
elabid = input("Input elabid here [default = 1111]: ") or 1111
|
# case "items" | "i" | "item":
|
||||||
data = APIHandler(apikey).get_entry_from_elabid(elabid, entryType)
|
# entryType = "items"
|
||||||
if entryType == "experiments":
|
# case "experiments" | "e" | "exp" | "experiment":
|
||||||
layer = Layer(data)
|
# entryType = "experiments"
|
||||||
result = layer.__dict__
|
# case _:
|
||||||
result.pop("extra")
|
# continue
|
||||||
print(result)
|
# # This will probably be reworked in production
|
||||||
elif entryType == "items":
|
# try:
|
||||||
if data.get("category_title") == "Sample":
|
# elabid = elabid
|
||||||
item = Entrypoint(data)
|
# except NameError:
|
||||||
elif data.get("category_title") in ["PLD Target", "Substrate"]:
|
# elabid = input("Input elabid here [default = 1111]: ") or 1111
|
||||||
item = Material(data)
|
# data = APIHandler(apikey).get_entry_from_elabid(elabid, entryType)
|
||||||
print(item.get_compound_formula(apikey))
|
# if entryType == "experiments":
|
||||||
else:
|
# layer = Layer(data)
|
||||||
raise Exception("The selected item or experiment is not in one of the following categories: [Sample, PLD Target, Substrate, PLD Deposition].")
|
# result = layer.__dict__
|
||||||
result = item.__dict__
|
# result.pop("extra")
|
||||||
result.pop("extra")
|
# print(result)
|
||||||
print(result)
|
# elif entryType == "items":
|
||||||
|
# if data.get("category_title") == "Sample":
|
||||||
|
# item = Entrypoint(data)
|
||||||
|
# elif data.get("category_title") in ["PLD Target", "Substrate"]:
|
||||||
|
# item = Material(data)
|
||||||
|
# print(item.get_compound_formula(apikey))
|
||||||
|
# else:
|
||||||
|
# raise Exception("The selected item or experiment is not in one of the following categories: [Sample, PLD Target, Substrate, PLD Deposition].")
|
||||||
|
# result = item.__dict__
|
||||||
|
# result.pop("extra")
|
||||||
|
# print(result)
|
||||||
Reference in New Issue
Block a user