Skip to content
Snippets Groups Projects
Commit 56b3d479 authored by Alessandro Frigeri's avatar Alessandro Frigeri
Browse files

updated example

parent 2392d4d5
No related branches found
No related tags found
No related merge requests found
import moondb import moondb,sys
#s0 = moondb.get_specimens(mn=['Apollo 11',])
s = moondb.SpecimenFilter()
s.missionName = ["Apollo 11"]
res = s.get_results()
apollo11_weight = 0
for r in res:
if r.weight is not None:
apollo11_weight += float(r.weight.split(' ')[0])
print(apollo11_weight)
s1 = moondb.SpecimenFilter()
s1.missionName = ["Apollo 17"]
res = s1.get_results()
apollo17_weight = 0
for r in res:
if r.weight is not None:
apollo17_weight += float(r.weight.split(' ')[0])
print(apollo17_weight)
moon_missions = moondb.get_missions()
weight_cum = 0
for m in moon_missions:
s = moondb.SpecimenFilter()
s.missionName = [ m.name ]
res = s.get_results()
weight = 0
for r in res:
if r.weight is not None:
weight += float(r.weight.split(' ')[0])
weight_cum += weight
print("MoonDB holds {:.3f} kg of specimens from {}".format(weight/1000.0,m.name))
print("MoonDB contains a total of {:.3f} kg of specimen from the Moon!".format(weight_cum/1000.0))
sys.exit(0)
f = moondb.AnalysisFilter() f = moondb.AnalysisFilter()
f.mission = ["Apollo 11"] f.mission = ["Apollo 11"]
...@@ -6,10 +50,13 @@ f.analyte = ["Na2O","CaO"] ...@@ -6,10 +50,13 @@ f.analyte = ["Na2O","CaO"]
f.specimenType = ["SOIL"] f.specimenType = ["SOIL"]
results = f.get_results() results = f.get_results()
for r in results: for r in results:
for dr in r.dataResults: for dr in r.dataResults:
print(dr.variable,dr.value,dr.unit) print(dr)
#print(dr.laboratory,dr.variable,dr.value,dr.unit)
No preview for this file type
...@@ -128,8 +128,8 @@ def _get_resp(path): ...@@ -128,8 +128,8 @@ def _get_resp(path):
r = resp.json() r = resp.json()
#print(r) #print(r)
# To be checked with Peng # To be checked with Peng
if 'result' and 'count' in r: #if 'result' and 'count' in r:
return r['count'],r['result'] # return r['count'],r['result']
if 'results' and 'count' in r: if 'results' and 'count' in r:
return r['count'],r['results'] return r['count'],r['results']
else: else:
...@@ -169,35 +169,37 @@ def get_specimens(sc=None,mn=None,ln=None,sty=None,ste=None): ...@@ -169,35 +169,37 @@ def get_specimens(sc=None,mn=None,ln=None,sty=None,ste=None):
ste: list ste: list
list of sampling techniques list of sampling techniques
''' '''
#print(mn)
sp_list = [] sp_list = []
if sc: if sc:
for s in sc: for s in sc:
spec = _get_resp('/specimen/'+s) count,spec = _get_resp('/specimen/'+s)
sp_list.append(spec) sp_list.extend(spec)
if mn: if mn:
for n in mn: for n in mn:
spec = _get_resp('/specimenlist/mission/'+n) count,spec = _get_resp('/specimenlist/mission/'+n)
sp_list.append(spec) sp_list.extend(spec)
if ln: if ln:
for n in ln: for n in ln:
spec = _get_resp('/specimenlist/mission/'+n) count,spec = _get_resp('/specimenlist/mission/'+n)
sp_list.append(spec) sp_list.extend(spec)
if sty: if sty:
for st in sty: for st in sty:
spec = _get_resp('/specimenlist/mission/'+st) count,spec = _get_resp('/specimenlist/mission/'+st)
sp_list.append(spec) sp_list.extend(spec)
if ste: if ste:
for st in ste: for st in ste:
spec = _get_resp('/specimenlist/mission/'+st) count,spec = _get_resp('/specimenlist/mission/'+st)
sp_list.append(spec) sp_list.extend(spec)
sp_obj_list = [] sp_obj_list = []
for s in sp_list: for s in sp_list:
# dict unpack # dict unpack
# print(s)
s_o = Specimen(**s) s_o = Specimen(**s)
sp_obj_list.append(s_o) sp_obj_list.append(s_o)
...@@ -272,6 +274,28 @@ def get_samplingtechnique(): ...@@ -272,6 +274,28 @@ def get_samplingtechnique():
pass pass
class dataFilter:
def __init__(self):
pass
def _toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__,sort_keys=True,separators=(",", ":"))
@dataclass
class SpecimenFilter:
specimenCode: list = None
missionName: list = None
landmarkName: list = None
specimenType: list = None
samplingTechnique: list = None
def get_results(self):
#res_list = get_specimens(mn=["Apollo 11"])
res_list = get_specimens(sc=self.specimenCode,
mn=self.missionName,
ln=self.landmarkName,
sty=self.specimenType,
ste=self.samplingTechnique)
return res_list
class AnalysisFilter: class AnalysisFilter:
def __init__(self): def __init__(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment