diff --git a/__pycache__/dax_parser.cpython-313.pyc b/__pycache__/dax_parser.cpython-313.pyc index 9910f5d..d5ffba0 100644 Binary files a/__pycache__/dax_parser.cpython-313.pyc and b/__pycache__/dax_parser.cpython-313.pyc differ diff --git a/__pycache__/model_connector.cpython-313.pyc b/__pycache__/model_connector.cpython-313.pyc index 0fed43c..db4bc91 100644 Binary files a/__pycache__/model_connector.cpython-313.pyc and b/__pycache__/model_connector.cpython-313.pyc differ diff --git a/app.py b/app.py index 9e2e48e..c493458 100644 --- a/app.py +++ b/app.py @@ -1,6 +1,7 @@ from flask import Flask, render_template, jsonify, request import json import os +import requests from model_connector import ModelConnector from dax_parser import DaxParser @@ -56,6 +57,41 @@ def get_call_graph(): except Exception as e: return jsonify({'success': False, 'message': str(e)}) +@app.route('/format_dax', methods=['POST']) +def format_dax(): + """Proxy for DAX formatter service.""" + try: + dax_code = request.json.get('daxCode') + if not dax_code: + return jsonify({'success': False, 'message': 'No DAX code provided'}) + + # 调用新的DAX格式化API + payload = { + 'dax': dax_code, + 'callerApp': 'https://www.daxformatter.com/', + 'callerVersion': '0.5.3', + 'listSeparator': ',', + 'decimalSeparator': '.', + 'maxLineLength': 0 + } + + response = requests.post('https://daxformatter.azurewebsites.net/api/DaxTokenFormat/', + json=payload) + + if response.status_code != 200: + return jsonify({'success': False, 'message': 'DAX formatting service error'}) + + # 解析返回的JSON + formatted_data = response.json() + + # 检查是否有错误 + if formatted_data.get('errors') and len(formatted_data['errors']) > 0: + return jsonify({'success': False, 'message': 'DAX formatting error: ' + str(formatted_data['errors'])}) + + return jsonify({'success': True, 'formattedTokens': formatted_data['formatted']}) + except Exception as e: + return jsonify({'success': False, 'message': str(e)}) + if __name__ == '__main__': app.run(debug=True) diff --git a/model_connector.py b/model_connector.py index 07393f5..1f8639e 100644 --- a/model_connector.py +++ b/model_connector.py @@ -1,5 +1,5 @@ from sys import path -path.append('C:\\Users\\ChenwuServise\\OneDrive - AZCollaboration\\Desktop\\GIT\\PBI-Measure-CallGraph\\MSNET') +path.append('C:\\Users\\Chenw\\Documents\\Trae\\PBI-Measure-CallGraph\\MSNET') import pyadomd import pandas as pd diff --git a/requirements.txt b/requirements.txt index c7a3cf0..33c6d25 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Flask==2.3.3 pyodbc==4.0.39 pandas==2.2.3 +requests==2.31.0 +beautifulsoup4==4.12.2 diff --git a/static/css/dax-highlight.css b/static/css/dax-highlight.css new file mode 100644 index 0000000..ec6015d --- /dev/null +++ b/static/css/dax-highlight.css @@ -0,0 +1,41 @@ +/* DAX语法高亮样式 */ +#measure-expression { + font-family: 'Consolas', 'Monaco', 'Courier New', monospace; + background-color: #f8f8f8; + padding: 10px; + border-radius: 4px; + overflow: auto; + line-height: 1.5; + white-space: pre-wrap; +} + +/* 关键字 */ +.dax-keyword { + color: #0000ff; + font-weight: bold; +} + +/* 函数 */ +.dax-function { + color: #795e26; +} + +/* 括号 */ +.dax-parenthesis { + color: #000000; +} + +/* 数字 */ +.dax-number { + color: #098658; +} + +/* 字符串 */ +.dax-string { + color: #a31515; +} + +/* 普通文本 */ +.dax-normal { + color: #000000; +} \ No newline at end of file diff --git a/templates/index.html b/templates/index.html index 2c5d5cd..e8cfe67 100644 --- a/templates/index.html +++ b/templates/index.html @@ -5,6 +5,8 @@ Power BI Measure Call Graph + +