def calls_by_body_hash(session, body_hash): query = (session.query(*Call.basic_columns + (Function.data,)) .join(Function) .filter_by(body_hash=body_hash) .order_by(Call.start_time.desc())[:200]) calls = [Call.basic_dict(withattrs(Call(), **row._asdict())) for row in query] function_data_set = {row.data for row in query} ranges = set() loop_ranges = set() for function_data in function_data_set: function_data = json.loads(function_data) def add(key, ranges_set): for node in function_data[key]: ranges_set.add((node['start'], node['end'])) add('node_ranges', ranges) # All functions are expected to have the same set # of loop nodes current_loop_ranges = set() add('loop_ranges', current_loop_ranges) assert loop_ranges in (set(), current_loop_ranges) loop_ranges = current_loop_ranges ranges = [dict(start=start, end=end) for start, end in ranges] loop_ranges = [dict(start=start, end=end) for start, end in loop_ranges] return DecentJSONEncoder().encode(dict( calls=calls, ranges=ranges, loop_ranges=loop_ranges))
def api_call_view(call_id): call = Session().query(Call).filter_by(id=call_id).one() func = call.function return DecentJSONEncoder().encode( dict(call=dict(data=call.parsed_data, **Call.basic_dict(call)), function=dict(data=func.parsed_data, **Function.basic_dict(func))))
def body_hashes_present(): hashes = request.json query = (Session().query(Function.body_hash, sqlalchemy.func.count( Call.id)).outerjoin(Call).filter( Function.body_hash.in_(hashes)).group_by(Function.body_hash)) return DecentJSONEncoder().encode( [dict(hash=h, count=count) for h, count in query])
self.parts = [] self.stdout = SysStream(self, "white") self.stderr = SysStream(self, "red") def pop(self): parts = self.parts.copy() self.parts.clear() return parts def string(self): return "".join(part["text"] for part in self.parts) output_buffer = OutputBuffer() json_encoder = DecentJSONEncoder() def make_result( passed=False, messages=(), awaiting_input=False, output=None, output_parts=None, birdseye_objects=None, error=None, ): if output is None: output = output_buffer.string() if output_parts is None: