Loading examples/Apollo11_soils.py +49 −2 Original line number Diff line number Diff line 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.mission = ["Apollo 11"] Loading @@ -6,10 +50,13 @@ f.analyte = ["Na2O","CaO"] f.specimenType = ["SOIL"] results = f.get_results() for r in results: for dr in r.dataResults: print(dr.variable,dr.value,dr.unit) print(dr) #print(dr.laboratory,dr.variable,dr.value,dr.unit) moondb/__pycache__/core.cpython-37.pyc +1 KiB (11.8 KiB) File changed.No diff preview for this file type. View original file View changed file moondb/core.py +36 −12 Original line number Diff line number Diff line Loading @@ -128,8 +128,8 @@ def _get_resp(path): r = resp.json() #print(r) # To be checked with Peng if 'result' and 'count' in r: return r['count'],r['result'] #if 'result' and 'count' in r: # return r['count'],r['result'] if 'results' and 'count' in r: return r['count'],r['results'] else: Loading Loading @@ -169,35 +169,37 @@ def get_specimens(sc=None,mn=None,ln=None,sty=None,ste=None): ste: list list of sampling techniques ''' #print(mn) sp_list = [] if sc: for s in sc: spec = _get_resp('/specimen/'+s) sp_list.append(spec) count,spec = _get_resp('/specimen/'+s) sp_list.extend(spec) if mn: for n in mn: spec = _get_resp('/specimenlist/mission/'+n) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+n) sp_list.extend(spec) if ln: for n in ln: spec = _get_resp('/specimenlist/mission/'+n) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+n) sp_list.extend(spec) if sty: for st in sty: spec = _get_resp('/specimenlist/mission/'+st) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+st) sp_list.extend(spec) if ste: for st in ste: spec = _get_resp('/specimenlist/mission/'+st) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+st) sp_list.extend(spec) sp_obj_list = [] for s in sp_list: # dict unpack # print(s) s_o = Specimen(**s) sp_obj_list.append(s_o) Loading Loading @@ -272,6 +274,28 @@ def get_samplingtechnique(): 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: def __init__(self): Loading Loading
examples/Apollo11_soils.py +49 −2 Original line number Diff line number Diff line 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.mission = ["Apollo 11"] Loading @@ -6,10 +50,13 @@ f.analyte = ["Na2O","CaO"] f.specimenType = ["SOIL"] results = f.get_results() for r in results: for dr in r.dataResults: print(dr.variable,dr.value,dr.unit) print(dr) #print(dr.laboratory,dr.variable,dr.value,dr.unit)
moondb/__pycache__/core.cpython-37.pyc +1 KiB (11.8 KiB) File changed.No diff preview for this file type. View original file View changed file
moondb/core.py +36 −12 Original line number Diff line number Diff line Loading @@ -128,8 +128,8 @@ def _get_resp(path): r = resp.json() #print(r) # To be checked with Peng if 'result' and 'count' in r: return r['count'],r['result'] #if 'result' and 'count' in r: # return r['count'],r['result'] if 'results' and 'count' in r: return r['count'],r['results'] else: Loading Loading @@ -169,35 +169,37 @@ def get_specimens(sc=None,mn=None,ln=None,sty=None,ste=None): ste: list list of sampling techniques ''' #print(mn) sp_list = [] if sc: for s in sc: spec = _get_resp('/specimen/'+s) sp_list.append(spec) count,spec = _get_resp('/specimen/'+s) sp_list.extend(spec) if mn: for n in mn: spec = _get_resp('/specimenlist/mission/'+n) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+n) sp_list.extend(spec) if ln: for n in ln: spec = _get_resp('/specimenlist/mission/'+n) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+n) sp_list.extend(spec) if sty: for st in sty: spec = _get_resp('/specimenlist/mission/'+st) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+st) sp_list.extend(spec) if ste: for st in ste: spec = _get_resp('/specimenlist/mission/'+st) sp_list.append(spec) count,spec = _get_resp('/specimenlist/mission/'+st) sp_list.extend(spec) sp_obj_list = [] for s in sp_list: # dict unpack # print(s) s_o = Specimen(**s) sp_obj_list.append(s_o) Loading Loading @@ -272,6 +274,28 @@ def get_samplingtechnique(): 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: def __init__(self): Loading