Commit 56b3d479 authored by Alessandro Frigeri's avatar Alessandro Frigeri
Browse files

updated example

parent 2392d4d5
Loading
Loading
Loading
Loading
+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"]
@@ -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)
      

+1 KiB (11.8 KiB)

File changed.

No diff preview for this file type.

+36 −12
Original line number Diff line number Diff line
@@ -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:
@@ -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)

@@ -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):