トピックス一覧
詳細は個別のリンクを
クリックしてください
パルスオキシメータから抽出したデータをpythonでExcel化
購入したパルスオキシメータ
今回使用したソフトウェア:DB Browser
データベースの構造が分かります
抽出したデータ文字列
# bodimetrics SpO2計のデータからSoP2値とHR値とを抽出してExcel化するスクリプト # # 2019年5月1日 初版 import xlsxwriter # 処理するファイルを指定する NameOfFile = "hogehoge.txt" # ワークシート名 NameOfWorksheet = "2019.5.1" workbook = xlsxwriter.Workbook("vibe" + NameOfWorksheet + ".xlsx") worksheet = workbook.add_worksheet(NameOfWorksheet) # Excelのセル座標変数を初期化 row = 0 col = 0 # 各列の項目を記述 worksheet.write(row, col, "time(s)") worksheet.write(row, col + 1, "time(h)") worksheet.write(row, col + 2, "SpO2") worksheet.write(row, col + 3, "HR") row += 1 # ファイルを読み込んでExcel化 with open(NameOfFile, mode = "r", encoding = "utf-8") as f: for line in f: length = len(line) k = 0 for i in range(80, length-80 , 10): worksheet.write(row, col, k) worksheet.write(row, col + 1, "=$A$" + str(row + 1) + "/3600") worksheet.write(row, col + 2, int(line[i:i+2],16)) worksheet.write(row, col + 3, int(line[i+2:i+4],16)) row += 1 k += 2 # SpO2のトレンドグラフを描画 chart_SpO2 = workbook.add_chart({"type":"scatter"}) chart_SpO2.set_x_axis({"name":"time /h", "name_font":{"size":14, "bold":True}, "min":0, "max":10, "major_unit":1}) chart_SpO2.set_y_axis({"name":"SpO2(%)", "name_font":{"size":14, "bold":True}, "min":80, "max":100, "major_unit":10}) chart_SpO2.add_series({"categories":"='"+NameOfWorksheet+"'!$B$2:$B$"+str(row), "values":"='"+NameOfWorksheet+"'!$C$2:$C$"+str(row), "name":"SpO2(%)", "line":{"width":1.25, "color":"#0000ff"}, "marker":{"type":"none"}}) chart_SpO2.set_size({"width":800, "height":400}) chart_SpO2.set_title({"name":"SpO2 trend (" + NameOfWorksheet + ")"}) chart_SpO2.set_plotarea({"border":{"color":"#000000", "width":1.25, "dash_type":"solid"}}) worksheet.insert_chart("G7", chart_SpO2) # 心拍数のトレンドグラフを描画 chart_HR = workbook.add_chart({"type":"scatter"}) chart_HR.set_x_axis({"name":"time /h", "name_font":{"size":14, "Bold":True}, "min":0, "max":10, "major_unit":1}) chart_HR.set_y_axis({"name":"Heart Rate /bpm", "name_font":{"size":14, "Bold":True}, "min":40, "max":80, "major_unit":10}) chart_HR.add_series({"categories":"='" + NameOfWorksheet + "'!$B$2:$B$" + str(row), "values":"='"+NameOfWorksheet+"'!$D$2:$D$"+str(row), "name":"Heart Rate /bpm", "line":{"width":1.25, "color":"#ff0000"}, "marker":{"type":"none"}}) chart_HR.set_size({"width":800, "height":400}) chart_HR.set_title({"name":"Heart Rate Trend (" + NameOfWorksheet + ")"}) chart_HR.set_plotarea({"border":{"color":"#000000", "width":1.25, "dash_type":"solid"}}) worksheet.insert_chart("J7", chart_HR) workbook.close()