1import nomad.api.exceptions 2 3from nomad.api.base import Requester 4 5 6class Evaluation(Requester): 7 8 """ 9 The evaluation endpoint is used to query a specific evaluations. 10 By default, the agent's local region is used; another region can 11 be specified using the ?region= query parameter. 12 13 https://www.nomadproject.io/docs/http/eval.html 14 """ 15 ENDPOINT = "evaluation" 16 17 def __init__(self, **kwargs): 18 super(Evaluation, self).__init__(**kwargs) 19 20 def __str__(self): 21 return "{0}".format(self.__dict__) 22 23 def __repr__(self): 24 return "{0}".format(self.__dict__) 25 26 def __getattr__(self, item): 27 msg = "{0} does not exist".format(item) 28 raise AttributeError(msg) 29 30 def __contains__(self, item): 31 32 try: 33 e = self.get_evaluation(item) 34 return True 35 except nomad.api.exceptions.URLNotFoundNomadException: 36 return False 37 38 def __getitem__(self, item): 39 40 try: 41 e = self.get_evaluation(item) 42 43 if e["ID"] == item: 44 return e 45 except nomad.api.exceptions.URLNotFoundNomadException: 46 raise KeyError 47 48 def get_evaluation(self, id): 49 """ Query a specific evaluation. 50 51 https://www.nomadproject.io/docs/http/eval.html 52 53 arguments: 54 - id 55 returns: dict 56 raises: 57 - nomad.api.exceptions.BaseNomadException 58 - nomad.api.exceptions.URLNotFoundNomadException 59 """ 60 return self.request(id, method="get").json() 61 62 def get_allocations(self, id): 63 """ Query the allocations created or modified by an evaluation. 64 65 https://www.nomadproject.io/docs/http/eval.html 66 67 arguments: 68 - id 69 returns: list 70 raises: 71 - nomad.api.exceptions.BaseNomadException 72 - nomad.api.exceptions.URLNotFoundNomadException 73 """ 74 return self.request(id, "allocations", method="get").json() 75