Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //var sampler = new GsrPpgSampler("COM3", 115200, SamplingRate.SR500Hz, SamplingRate.SR500Hz);
            //sampler.GsrDataArrived += (s, e) =>
            //{
            //    Console.WriteLine($"[GSR] Timestamp = {e.Timestamp}, Data = {e.Data}");
            //};

            //sampler.PpgDataArrived += (s, e) =>
            //{
            //    Console.WriteLine($"[Ppg] Timestamp = {e.Timestamp}, Data = {e.Data}");
            //};

            //sampler.StartReading();
            //Console.ReadKey();
            //sampler.StopReading();

            var data = GsrPpgUtil.ReadGsrPpgData("190430.json");

            //var filteredData = GsrPpgUtil.PPGfiltering(data["PPG"].Select(e => e.Value).ToArray());
            var filteredData = GsrPpgUtil.GSRfiltering(data["GSR"]);

            //var filteredData = GsrPpgUtil.GetPPGdata(data["PPG"], TimeSpan.FromMilliseconds(100));

            foreach (var item in filteredData)
            {
                Console.WriteLine(item.Value);
            }
        }
Ejemplo n.º 2
0
        static int RunExtractAndReturnExitCode(ExtractOptions opts)
        {
            // read data from input file
            var museDataCollection = MuseUtil.ReadMuseData(opts.InputFile);
            var gsrPpgCollection   = GsrPpgUtil.ReadGsrPpgData(opts.InputFile);

            // slice data by specified time span
            var museDataFragments = museDataCollection.SelectByTime(opts.TimeOff, opts.Duration);
            var gsrPpgFragments   = gsrPpgCollection.SelectByTime(opts.TimeOff, opts.Duration);

            // post-process gsr/ppg data
            var processedGsr = GsrPpgUtil.GSRfiltering(gsrPpgFragments["GSR"]);
            var processedPpg = GsrPpgUtil.GetPPGdata(gsrPpgFragments["PPG"], TimeSpan.FromMilliseconds(100));

            using (var fs = new FileStream(opts.OutputFile, FileMode.Create, FileAccess.Write))
                using (var package = new ExcelPackage(fs))
                {
                    // process Muse data
                    foreach (var d in museDataFragments)
                    {
                        var sheet = package.Workbook.Worksheets.Add(d.Key.ToString());

                        switch (d.Value[0])
                        {
                        case Channel _:
                            var channels = d.Value.ChangeType <Channel>();
                            var query    = from c in channels
                                           select new { Timestamp = new TimeSpan(c.Timestamp).ToString("g"), c.TP9, c.AF7, c.AF8, c.TP10 };
                            sheet.Cells[1, 1].LoadFromCollection(query, PrintHeaders: true);
                            sheet.Cells[sheet.Dimension.Address].AutoFitColumns();
                            var table = sheet.Tables.Add(sheet.Dimension, d.Key.ToString());
                            // Set table properties (order matters!)
                            table.ShowRowStripes  = false;
                            table.TableStyle      = TableStyles.Medium9;
                            table.ShowFirstColumn = true;
                            break;

                        default:
                            throw new NotImplementedException();
                        }
                    }

                    // process Raw GSR/PPG data
                    foreach (var d in gsrPpgFragments)
                    {
                        var sheet = package.Workbook.Worksheets.Add(d.Key);

                        var query = from p in d.Value
                                    select new { Timestamp = new TimeSpan(p.Timestamp).ToString("g"), p.Value };
                        sheet.Cells[1, 1].LoadFromCollection(query, PrintHeaders: true);
                        sheet.Cells[sheet.Dimension.Address].AutoFitColumns();
                        var table = sheet.Tables.Add(sheet.Dimension, d.Key);
                        // Set table properties (order matters!)
                        table.ShowRowStripes  = false;
                        table.TableStyle      = TableStyles.Medium14;
                        table.ShowFirstColumn = true;
                    }

                    // process post-processed GSR/PPG data
                    var processedGsrSheet = package.Workbook.Worksheets.Add("Processed GSR");
                    var processedGsrQuery = from p in processedGsr
                                            select new { Timestamp = new TimeSpan(p.Timestamp).ToString("g"), p.Value };
                    processedGsrSheet.Cells[1, 1].LoadFromCollection(processedGsrQuery, PrintHeaders: true);
                    processedGsrSheet.Cells[processedGsrSheet.Dimension.Address].AutoFitColumns();
                    var processedGsrTable = processedGsrSheet.Tables.Add(processedGsrSheet.Dimension, "ProcessedGSR");
                    // Set table properties (order matters!)
                    processedGsrTable.ShowRowStripes  = false;
                    processedGsrTable.TableStyle      = TableStyles.Medium13;
                    processedGsrTable.ShowFirstColumn = true;

                    var bpmSheet = package.Workbook.Worksheets.Add("BPM");
                    var bpmQuery = from p in processedPpg
                                   select new { Timestamp = new TimeSpan(p.Timestamp).ToString("g"), p.Value };
                    bpmSheet.Cells[1, 1].LoadFromCollection(bpmQuery, PrintHeaders: true);
                    bpmSheet.Cells[bpmSheet.Dimension.Address].AutoFitColumns();
                    var bpmTable = bpmSheet.Tables.Add(bpmSheet.Dimension, "BPM");
                    // Set table properties (order matters!)
                    bpmTable.ShowRowStripes  = false;
                    bpmTable.TableStyle      = TableStyles.Medium13;
                    bpmTable.ShowFirstColumn = true;

                    package.Save();
                }

            return(0);
        }