123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WpfTest1.Toolkits
- {
- public class CSVWriter
- {
- public static void generateWaveToCSV(List<double> leftRed, List<double> leftInfrared, List<double> rightRed, List<double> rightInfrared, SQLite.Patient pa, SQLite.Record re)
- {
- FileStream fs = new FileStream(Constants.exportWavePath + "\\" + re.recordTime.ToString("yyyyMMddHHmmss") + "_" + pa.p_name + ".csv", FileMode.Create);
- StreamWriter sw = new StreamWriter(fs);
- //开始写入
- sw.Write("leftRed,leftInfrared,rightRed,rightInfrared\n");
- int counter = new int[] { leftRed.Count, rightRed.Count, leftInfrared.Count, rightInfrared.Count }.Max();
- for(int i = 0; i < counter; ++i)
- {
- string[] thisLine = new string[] { "","","",""};
- if((re.hand == "b" || re.hand=="l"))
- {
- if(i < leftRed.Count)
- {
- thisLine[0] = leftRed[i].ToString();
- }
- if(i < leftInfrared.Count)
- {
- thisLine[1] = leftInfrared[i].ToString();
- }
- }
- if ((re.hand == "b" || re.hand == "r" ))
- {
- if (i < rightRed.Count)
- {
- thisLine[2] = rightRed[i].ToString();
- }
- if (i < rightInfrared.Count)
- {
- thisLine[3] = rightInfrared[i].ToString();
- }
- }
- sw.Write(thisLine[0]+","+ thisLine[1] + "," + thisLine[2] + "," + thisLine[3] + "\n");
- }
- //清空缓冲区
- sw.Flush();
- //关闭流
- sw.Close();
- fs.Close();
- }
- }
- }
|