def get_result(self, id, filter_parameters=None): print("Received result request for id=%s, filter_parameters=%s" % (id, filter_parameters)) task = self.task_collection.find_by_id(id) if not task.is_complete: return None result = read_from_file(task.output_file) if filter_parameters is None: return result filter_id, filter_mod = filter_parameters return [(key, value) for key, value in result if hash_function(key) % filter_mod == filter_id]
def run(self): while True: # poll db task = self.task_collection.find_one({"is_complete": 0}) if task is None: # if there are no remaining tasks, then sleep time.sleep(5) continue input_arguments = read_from_file(task.input_file) if task.kind == 'map': result = sorted(self.run_map_task(task.name, input_arguments), key=operator.itemgetter(0)) else: result = self.run_reduce_task(task.name, input_arguments) save_to_file(task.output_file, result) self.task_collection.update_by_id(task.id, {"is_complete": 1})
def read_json(fname): text = misc.read_from_file(fname) if len(text) > 0: return json.loads(text) return None
def battery_status_original(): m = re.search('(\w+)', misc.read_from_file(status_file)) if m: return m.group(1)
def battery_capacity(): m = re.search('(\d+)', misc.read_from_file(capacity_file)) if m: return _limit(int(m.group(1)), 0, 100)