當你辛苦寫好一支程式碼時,有時還要構思該如何寫RERADME讓每個協作者能夠快速理解,但文字終究是沒有圖片來的好理解,但流程圖也必須花費時間思考及呈製作,今天就用一點時間教大家如何用一分鐘快速為自己的專案或程式製作精美的流程圖
範例為一支Flask 程式碼描述了一個簡單的 Web 應用程序,它允許用戶上傳 CSV 文件、選擇統計測試,並查看測試結果,程式碼僅節錄一段
#....前段略
@app.route('/T', methods=['GET', 'POST'])
def test():
if request.method == 'POST':
# 執行你想在提交表單時進行的操作
pass
# 取得資料庫中的表格清單
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
tables = cursor.fetchall()
# 获取列信息
selected_table = request.form.get('table_select') # 获取前端选择的表格名
cursor.execute(f"PRAGMA table_info({selected_table})")
columns = [column[1] for column in cursor.fetchall()]
conn.close()
# 将列信息传递给模板
return render_template('T-statistical_test.html', tables=tables, columns=columns)
@app.route('/get_columns', methods=['POST'])
def get_columns():
try:
selected_table = request.form.get('table')
# 檢查使用者是否登入
if 'username' not in session:
return jsonify({'error': 'User not logged in'})
# 檢查表格是否屬於當前使用者
if session['username'] not in selected_table:
return jsonify({'error': 'Access denied'})
# 连接到 SQLite 数据库
conn = sqlite3.connect(db_file)
cursor = conn.cursor()
# 使用 PRAGMA table_info 獲取表格的列信息
cursor.execute(f"PRAGMA table_info({selected_table})")
columns = [column[1] for column in cursor.fetchall()]
# 關閉数据库连接
conn.close()
return jsonify({'columns': columns})
except Exception as e:
return jsonify({'error': str(e)})
@app.route('/perform_test', methods=['POST'])
def perform_test():
if request.method == 'POST':
table_name = request.form['table_select']
# 檢查表格是否屬於當前使用者
if session['username'] not in table_name:
return "Access denied"
control_variable1 = request.form['control_variable1']
control_variable2 = request.form['control_variable2']
analysis_type = request.form['analysis_type']
print(f"Performing {analysis_type} analysis for {control_variable1} and {control_variable2}")
result_str = perform_statistical_test(table_name, control_variable1, control_variable2, analysis_type)
print(f"Result: {result_str}")
return render_template('T-output.html', result=result_str)
return redirect(url_for('test'))
if __name__ == '__main__':
app.run(debug=True)
我們先將全部程式碼丟進chatgpt,讓他用文字幫你描述整支程式碼的運作流程,就會得到類似以下結果
Learn More →
在chatgpt得到統整後,接者來到excalidraw,點開更多工具
>文字轉圖表
Learn More →
按下genrate ,就會透過AI自動幫你產生流程圖
- (圖片都會是英文,若要中文要加上Draw a flowchart that aligns with the project management process.Please use Traditional Chinese ),只是有機率會出錯,建議還是讓他自動生成英文
- 透過文字生成在免費版上限1000字,每天限制生成十次
Learn More →
Learn More →
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up