|
| 1 | +from flask import Flask, jsonify |
| 2 | +from flask_cors import CORS |
| 3 | +app = Flask(__name__) |
| 4 | +CORS(app) |
| 5 | + |
| 6 | + |
| 7 | +@app.route('/api/graph/fields') |
| 8 | +def fetch_graph_fields(): |
| 9 | + nodes_fields = [{"field_name": "id", "type": "string"}, |
| 10 | + {"field_name": "title", "type": "string", |
| 11 | + }, |
| 12 | + {"field_name": "subTitle", "type": "string"}, |
| 13 | + {"field_name": "mainStat", "type": "string"}, |
| 14 | + {"field_name": "secondaryStat", "type": "number"}, |
| 15 | + {"field_name": "arc__failed", |
| 16 | + "type": "number", "color": "red"}, |
| 17 | + {"field_name": "arc__passed", |
| 18 | + "type": "number", "color": "green"}, |
| 19 | + {"field_name": "detail__role", |
| 20 | + "type": "string", "displayName": "Role"}] |
| 21 | + edges_fields = [ |
| 22 | + {"field_name": "id", "type": "string"}, |
| 23 | + {"field_name": "source", "type": "string"}, |
| 24 | + {"field_name": "target", "type": "string"}, |
| 25 | + {"field_name": "mainStat", "type": "number"}, |
| 26 | + ] |
| 27 | + result = {"nodes_fields": nodes_fields, |
| 28 | + "edges_fields": edges_fields} |
| 29 | + return jsonify(result) |
| 30 | + |
| 31 | + |
| 32 | +@app.route('/api/graph/data') |
| 33 | +def fetch_graph_data(): |
| 34 | + |
| 35 | + nodes = [{"id": "1", "title": "Service1", "subTitle": "instance:#2", "detail__role": "load", |
| 36 | + "arc__failed": 0.7, "arc__passed": 0.3, "mainStat": "qaz"}, |
| 37 | + {"id": "2", "title": "Service2", "subTitle": "instance:#2", "detail__role": "transform", |
| 38 | + "arc__failed": 0.5, "arc__passed": 0.5, "mainStat": "qaz"}, |
| 39 | + {"id": "3", "title": "Service3", "subTitle": "instance:#3", "detail__role": "extract", |
| 40 | + "arc__failed": 0.3, "arc__passed": 0.7, "mainStat": "qaz"}, |
| 41 | + {"id": "4", "title": "Service3", "subTitle": "instance:#1", "detail__role": "transform", |
| 42 | + "arc__failed": 0.5, "arc__passed": 0.5, "mainStat": "qaz"}, |
| 43 | + {"id": "5", "title": "Service4", "subTitle": "instance:#5", "detail__role": "transform", |
| 44 | + "arc__failed": 0.5, "arc__passed": 0.5, "mainStat": "qaz"}] |
| 45 | + edges = [{"id": "1", "source": "1", "target": "2", "mainStat": 53}, |
| 46 | + {"id": "2", "source": "2", "target": "3", "mainStat": 53}, |
| 47 | + {"id": "2", "source": "1", "target": "4", "mainStat": 5}, |
| 48 | + {"id": "3", "source": "3", "target": "5", "mainStat": 70}, |
| 49 | + {"id": "4", "source": "2", "target": "5", "mainStat": 100}] |
| 50 | + result = {"nodes": nodes, "edges": edges} |
| 51 | + return jsonify(result) |
| 52 | + |
| 53 | + |
| 54 | +@app.route('/api/health') |
| 55 | +def check_health(): |
| 56 | + return "API is working well!" |
| 57 | + |
| 58 | + |
| 59 | +app.run(host='0.0.0.0', port=5000) |
0 commit comments