Esempio n. 1
0
 def get(self, id=None, height=0, range=None, fields=None):
     database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     LOGGER.warn(
         "WorkerAPI_stats get id:{} height:{} range:{} fields:{}".format(
             id, height, range, fields))
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = Blocks.get_latest().height
     stats = []
     if id is None:
         for stat in Worker_stats.get_by_height(height, range):
             #print("YYY: {}".format(stats))
             stats.append(stat.to_json(fields))
         return stats
     else:
         if range is None:
             res = Worker_stats.get_by_height_and_id(id, height)
             if res is None:
                 return "[]".to_json()
             return res.to_json(fields)
         else:
             for stat in Worker_stats.get_by_height_and_id(
                     id, height, range):
                 stats.append(stat.to_json(fields))
             return stats
Esempio n. 2
0
 def get(self, id=None, height=0, range=None, fields=None):
     database = lib.get_db()
     fields = lib.fields_to_list(fields)
     if height == 0:
         height = grin.get_current_height()
     stats = []
     if id == None:
         for stat in Worker_stats.get_by_height(height, range):
             stats.append(stat.to_json(fields))
         return stats
     else:
         if range == None:
             res = Worker_stats.get_by_height_and_id(id, height)
             if res is None:
                 return res
             return res.to_json(fields)
         else:
             for stat in Worker_stats.get_by_height_and_id(
                     id, height, range):
                 stats.append(stat.to_json(fields))
             return stats
Esempio n. 3
0
 def get(self, id, height=0, range=None, fields=None):
     global database
     #database = lib.get_db()
     LOGGER = lib.get_logger(PROCESS)
     # AUTH FILTER
     if id != g.user.id:
         response = jsonify(
             {'message': 'Not authorized to access data for other users'})
         response.status_code = 403
         return response
     debug and LOGGER.warn(
         "WorkerAPI_stats get id:{} height:{} range:{} fields:{}".format(
             id, height, range, fields))
     # Enforce range limit
     if range is not None:
         range = min(range, worker_stats_range_limit)
     fields = lib.fields_to_list(fields)
     res = None
     if range is None:
         # Getting a single record
         if height == 0:
             # Get the most recent stats for this user
             res = Worker_stats.get_latest_by_id(id)
         else:
             res = Worker_stats.get_by_height_and_id(id, height)
         if res is None:
             return None
         return res.to_json(fields)
     else:
         # Getting a range of records
         if height == 0:
             height = Blocks.get_latest().height
         res = Worker_stats.get_by_height_and_id(id, height, range)
         if res is None:
             return None
         stats = []
         for stat in res:
             stats.append(stat.to_json(fields))
         return stats