我對燒瓶完全陌生(實際上我今天早上才開始),到目前為止我只設法實作了一個基本的上傳功能(取自燒瓶檔案)。檔案上傳有效,但我似乎無法弄清楚如何將檔案傳遞給另一種方法(挖掘)。當我這樣做時,我總是收到錯誤訊息:AttributeError: '_io.BytesIO' object has no attribute 'lower'。接受任何形式的幫助對我來說都意味著整個世界!謝謝大家。
def mining(xes):
log = xes_importer.apply(xes)
tracefilter_log_pos = attributes_filter.apply_events(log, ["complete"], parameters={attributes_filter.Parameters.ATTRIBUTE_KEY: "lifecycle:transition", attributes_filter.Parameters.POSITIVE: True})
variants = pm4py.get_variants_as_tuples(tracefilter_log_pos)
Alpha(variants.keys())
Heuristic(variants.keys(), 1, 0.5)
UPLOAD_FOLDER = '/Users/jenny/processmining_lab/uploads'
ALLOWED_EXTENSIONS = set(['xes'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/', methods=['GET', 'POST'])
def upload_file():
if request.method == 'POST':
# check if the post request has the file part
if 'file' not in request.files:
flash('No file part')
return redirect(request.url)
file = request.files['file']
# If the user does not select a file, the browser submits an
# empty file without a filename.
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
return mining(file)
return '''
<!doctype html>
<title>Upload new File</title>
<h1>Upload new File</h1>
<form method=post enctype=multipart/form-data>
<input type=file name=file>
<input type=submit value=Upload>
</form>
'''
這是回溯
uj5u.com熱心網友回復:
這取決于您的mining功能是什么樣的。
file是一個werkzeug.FileStorage物件,它有自己的各種方法。
所以(沒有看到)你的mining函式應該是這樣的:
def mining(file_obj):
lower_fname = file_obj.filename.lower()
data = file_obj.read()
# Do something
在AttributeError你提到喜歡你的聲音正在嘗試運行lower的一些東西,不回傳一個字串的方法。
附帶說明:由于您從未發布完整的回溯,因此很難知道此例外在您的代碼中的何處未發生。
編輯
我的挖掘功能實際上位于我插入的代碼的頂部。我現在也包含了回溯。
看起來您正在使用PM4Py,本檔案指出:
from pm4py.objects.log.importer.xes import importer as xes_importer log = xes_importer.apply('<path_to_xes_file.xes>')
因此,您需要實際將檔案路徑傳遞給挖掘函式。
我建議更改您的主要代碼以執行以下操作:
if file and allowed_file(file.filename):
sfilename = secure_filename(file.filename)
output_path = os.path.join(app.config['UPLOAD_FOLDER'], sfilename)
# Now save to this `output_path` and pass that same var to your mining function
file.save(output_path)
return mining(output_path)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/334873.html
