diff --git a/EcomAnalysis/Form1.Designer.cs b/EcomAnalysis/Form1.Designer.cs index 4d311dc..73c1371 100644 --- a/EcomAnalysis/Form1.Designer.cs +++ b/EcomAnalysis/Form1.Designer.cs @@ -53,6 +53,10 @@ this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.BtnSaveSceneTable = new System.Windows.Forms.Button(); + this.saveFileDialogCsv = new System.Windows.Forms.SaveFileDialog(); + this.label12 = new System.Windows.Forms.Label(); + this.TxtVisit = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // label1 @@ -218,7 +222,7 @@ // // TxtDateTime // - this.TxtDateTime.BackColor = System.Drawing.SystemColors.Control; + this.TxtDateTime.BackColor = System.Drawing.SystemColors.Info; this.TxtDateTime.BorderStyle = System.Windows.Forms.BorderStyle.None; this.TxtDateTime.Font = new System.Drawing.Font("MS UI Gothic", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); this.TxtDateTime.Location = new System.Drawing.Point(373, 40); @@ -303,13 +307,13 @@ // // TxtSubject // - this.TxtSubject.BackColor = System.Drawing.SystemColors.Control; + this.TxtSubject.BackColor = System.Drawing.SystemColors.Info; this.TxtSubject.BorderStyle = System.Windows.Forms.BorderStyle.None; this.TxtSubject.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); this.TxtSubject.Location = new System.Drawing.Point(373, 77); this.TxtSubject.Name = "TxtSubject"; this.TxtSubject.ReadOnly = true; - this.TxtSubject.Size = new System.Drawing.Size(255, 27); + this.TxtSubject.Size = new System.Drawing.Size(152, 27); this.TxtSubject.TabIndex = 20; // // label11 @@ -340,11 +344,52 @@ this.columnHeader8.TextAlign = System.Windows.Forms.HorizontalAlignment.Right; this.columnHeader8.Width = 100; // + // BtnSaveSceneTable + // + this.BtnSaveSceneTable.Location = new System.Drawing.Point(191, 359); + this.BtnSaveSceneTable.Name = "BtnSaveSceneTable"; + this.BtnSaveSceneTable.Size = new System.Drawing.Size(82, 24); + this.BtnSaveSceneTable.TabIndex = 21; + this.BtnSaveSceneTable.Text = "CSV保存"; + this.BtnSaveSceneTable.UseVisualStyleBackColor = true; + this.BtnSaveSceneTable.Click += new System.EventHandler(this.BtnSaveSceneTable_Click); + // + // saveFileDialogCsv + // + this.saveFileDialogCsv.DefaultExt = "csv"; + this.saveFileDialogCsv.Filter = "CSVファイル|*.csv"; + this.saveFileDialogCsv.Title = "CSVファイルに保存"; + // + // label12 + // + this.label12.AutoSize = true; + this.label12.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); + this.label12.Location = new System.Drawing.Point(531, 77); + this.label12.Name = "label12"; + this.label12.Size = new System.Drawing.Size(62, 27); + this.label12.TabIndex = 22; + this.label12.Text = "Visit"; + // + // TxtVisit + // + this.TxtVisit.BackColor = System.Drawing.SystemColors.Info; + this.TxtVisit.BorderStyle = System.Windows.Forms.BorderStyle.None; + this.TxtVisit.Font = new System.Drawing.Font("MS UI Gothic", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(128))); + this.TxtVisit.Location = new System.Drawing.Point(599, 77); + this.TxtVisit.Name = "TxtVisit"; + this.TxtVisit.ReadOnly = true; + this.TxtVisit.Size = new System.Drawing.Size(29, 27); + this.TxtVisit.TabIndex = 23; + this.TxtVisit.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(652, 597); + this.Controls.Add(this.TxtVisit); + this.Controls.Add(this.label12); + this.Controls.Add(this.BtnSaveSceneTable); this.Controls.Add(this.TxtSubject); this.Controls.Add(this.label11); this.Controls.Add(this.label10); @@ -406,6 +451,10 @@ private System.Windows.Forms.ColumnHeader columnHeader6; private System.Windows.Forms.ColumnHeader columnHeader7; private System.Windows.Forms.ColumnHeader columnHeader8; + private System.Windows.Forms.Button BtnSaveSceneTable; + private System.Windows.Forms.SaveFileDialog saveFileDialogCsv; + private System.Windows.Forms.Label label12; + private System.Windows.Forms.TextBox TxtVisit; } } diff --git a/EcomAnalysis/Form1.cs b/EcomAnalysis/Form1.cs index 6f9ebda..852d112 100644 --- a/EcomAnalysis/Form1.cs +++ b/EcomAnalysis/Form1.cs @@ -17,6 +17,8 @@ "stimNo", "sceneNo", "stimTime", "contact time", "Feedback", "RR", "gazeVx", "gazeVy", "pupilR", "pupilL" }; private Dictionary _SceneNoAssign = new Dictionary(); private List _Data = new List(); + private List _SceneTable = new List(); + private SceneMean _ScMean = new SceneMean(); /// /// コンストラクタ @@ -77,7 +79,6 @@ var sceneBegin = _Data.Where(s => s.SceneNo > 0).Min(s => s.SceneNo); var sceneEnd = _Data.Where(s => s.SceneNo > 0).Max(s => s.SceneNo); - var allData = new List(); for (int sc = sceneBegin; sc <= sceneEnd; sc++) { var scDat = new SceneData(); scDat.SceneNo = sc; @@ -100,22 +101,28 @@ $"{scDat.Beat:0.00} bpm", $"{scDat.Blink} 回", $"{scDat.Pupil.R:0.00} mm", $"{scDat.Pupil.L:0.00} mm"}; listView1.Items.Add(new ListViewItem(items)); - allData.Add(scDat); + _SceneTable.Add(scDat); } - var validBeat = allData.Where(s => s.Beat > 0); - var meanBeat = validBeat.Count() > 0 ? validBeat.Select(s => s.Beat).Average() : 0; - var validLatency = allData.Where(s => s.FBCount > 0); - var meanLatency = validLatency.Count() > 0 ? validLatency.Select(s => s.Latency).Average() : 0; + _ScMean.FBCount = _SceneTable.Select(s => s.FBCount).Average(); + _ScMean.ECTime = _SceneTable.Select(s => s.ECTime).Average(); + var validLatency = _SceneTable.Where(s => s.FBCount > 0); + _ScMean.Latency = validLatency.Count() > 0 ? validLatency.Select(s => s.Latency).Average() : 0; + var validBeat = _SceneTable.Where(s => s.Beat > 0); + _ScMean.Beat = validBeat.Count() > 0 ? validBeat.Select(s => s.Beat).Average() : 0; + _ScMean.Blink = _SceneTable.Select(s => s.Blink).Average(); + _ScMean.Pupil.R = _SceneTable.Select(s => s.Pupil.R).Average(); + _ScMean.Pupil.L = _SceneTable.Select(s => s.Pupil.L).Average(); + listView1.Items.Add(new ListViewItem(new string[] { "平均", - $"{allData.Select(s=>s.FBCount).Average():0.00} 回", - $"{allData.Select(s=>s.ECTime).Average():0.00} 秒", - $"{meanLatency:0.00} 秒", - $"{meanBeat:0.00} bpm", - $"{allData.Select(s=>s.Blink).Average():0.00} 回", - $"{allData.Select(s=>s.Pupil.R).Average():0.00} ms", - $"{allData.Select(s=>s.Pupil.L).Average():0.00} ms"})); + $"{_ScMean.FBCount:0.00} 回", + $"{_ScMean.ECTime:0.00} 秒", + $"{_ScMean.Latency:0.00} 秒", + $"{_ScMean.Beat:0.00} bpm", + $"{_ScMean.Blink:0.00} 回", + $"{_ScMean.Pupil.R:0.00} ms", + $"{_ScMean.Pupil.L:0.00} ms"})); } // 表示 @@ -205,8 +212,32 @@ filename.Substring(6, 2), filename.Substring(9, 2), filename.Substring(11, 2)); var strs = filename.Split('_'); - TxtSubject.Text = $"{strs[2]} Visit {strs[3]}"; + TxtSubject.Text = $"{strs[2]}"; + TxtVisit.Text = $"{strs[3]}"; } } + + /// + /// CSV保存ボタン + /// + /// + /// + private void BtnSaveSceneTable_Click(object sender, EventArgs e) { + if (_SceneTable.Count < 1) return; + + saveFileDialogCsv.FileName = $"シーン解析_{TxtSubject.Text}_{TxtVisit.Text}.csv"; + if (saveFileDialogCsv.ShowDialog() == DialogResult.Cancel) return; + + var enc = Encoding.GetEncoding("Shift_JIS"); + var sr = new StreamWriter(saveFileDialogCsv.FileName, false, enc); + sr.WriteLine("シーン,FB回数,EC時間(s),潜時(s),心拍数,瞬目回数,瞳孔径:右(mm),瞳孔径:左(mm)"); + foreach (var sc in _SceneTable) { + sr.WriteLine($"{sc.SceneNo},{sc.FBCount},{sc.ECTime:0.00},{sc.Latency:0.00},{sc.Beat:0.00}," + + $"{sc.Blink},{sc.Pupil.R:0.00},{sc.Pupil.L:0.00}"); + } + sr.WriteLine($"平均,{_ScMean.FBCount},{_ScMean.ECTime:0.00},{_ScMean.Latency:0.00},{_ScMean.Beat:0.00}," + + $"{_ScMean.Blink},{_ScMean.Pupil.R:0.00},{_ScMean.Pupil.L:0.00}"); + sr.Close(); + } } } diff --git a/EcomAnalysis/Form1.resx b/EcomAnalysis/Form1.resx index 1af7de1..1ac257b 100644 --- a/EcomAnalysis/Form1.resx +++ b/EcomAnalysis/Form1.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/EcomAnalysis/LogData.cs b/EcomAnalysis/LogData.cs index ad4ed9c..2987421 100644 --- a/EcomAnalysis/LogData.cs +++ b/EcomAnalysis/LogData.cs @@ -41,4 +41,13 @@ public double Beat; public LR Pupil; } + + class SceneMean { + public double FBCount; + public double ECTime; + public double Latency; + public double Beat; + public double Blink; + public LR Pupil; + } }