public ActionResult Actigraphy(ResearchAccelerometerViewModel model) { if (!ModelState.IsValid) { ViewBag.Users = _service.GetUserNames().OrderBy(s => s); return(View("Index")); } ModelState.Clear(); if (model._From > model._To) { ModelState.AddModelError("_From", @"The first date must be less than second"); ModelState.AddModelError("To", @"The first date must be less than second"); ViewBag.Users = _service.GetUserNames().OrderBy(s => s); return(View()); } string fileName, report; string exportedUserId = _service.GetUserId(model._UserName); var activities = BulkCommands.GetActivities(exportedUserId, model._From, model._To); List <ActivityPerMinute> activityPerMinute = null; switch (model._ActivityOptions) { case AcceptableActivityOptions.Export: model._ExportOptions = AcceptableExportOptions.Text; fileName = "Report"; report = ReportHelper.GetAccelerometerData(activities); break; case AcceptableActivityOptions.StandardDeviation: model._ExportOptions = AcceptableExportOptions.Text; fileName = "StdDev"; double devX = StandardDeviation.CalculateStdDev(activities.Select(m => (double)m.X).ToList()); double devY = StandardDeviation.CalculateStdDev(activities.Select(m => (double)m.Y).ToList()); double devZ = StandardDeviation.CalculateStdDev(activities.Select(m => (double)m.Z).ToList()); report = ReportHelper.ExportStdDev(devX, devY, devZ); break; case AcceptableActivityOptions.EnergyExpenditure: case AcceptableActivityOptions.ZeroCrossing: activityPerMinute = CalculateActivity.BeginAnalyzation(model._ActivityOptions, activities); report = ReportHelper.ExportProcessedData(activityPerMinute); fileName = string.Concat("Processed-", model._ActivityOptions); break; default: throw new ArgumentOutOfRangeException(); } activities.Clear(); GC.Collect(); switch (model._ExportOptions) { case AcceptableExportOptions.Chart: var chart = ReportHelper.CreateChart(activityPerMinute); // ReSharper disable once PossibleNullReferenceException activityPerMinute.Clear(); GC.Collect(); return(File(chart.GetBytes(), "jpeg", string.Concat(fileName, "-accelerometer - ", model._UserName, " - ", DateTime.Now, ".jpeg"))); case AcceptableExportOptions.Text: return(File(Encoding.UTF8.GetBytes(report), "text/plain", string.Concat(fileName, "-accelerometer - ", model._UserName, " - ", DateTime.Now, ".txt"))); default: throw new ArgumentOutOfRangeException(); } }
public static void BeginAnalyzation() { var openFileDialog = new OpenFileDialog(); openFileDialog.ShowDialog(); string fileName = openFileDialog.FileName; Console.WriteLine(string.Concat("* Opened file: ", fileName)); List <RowType> rows; List <LocationViewModel> locations; if (fileName.Contains(".csv") || fileName.Contains(".txt")) { rows = TextFileHandler.GetData(fileName); locations = new List <LocationViewModel>(0); } else { locations = DatabaseHandler.GetLocations(fileName); rows = DatabaseHandler.GetData(fileName, out string userName); Console.WriteLine(string.Concat("* Analyzed user: "******"* Preprocessed acc. rows: ", rows.Count)); Console.WriteLine(string.Concat("* Preprocessed loc. rows: ", locations.Count)); rows = rows.OrderBy(m => m.DateTime).ToList(); //rows = rows.Where((elem, idx) => idx % 2 == 0).ToList(); Console.WriteLine( "* Select a process option: Export | EnergyExpenditure | ZeroCrossing | StandardDeviation | | ActivityIndex | TAT | Int | ..."); AcceptableActivityOptions option; while (!Enum.TryParse(Console.ReadLine(), true, out option)) { Console.WriteLine( "* Select a process option from these: Export | EnergyExpenditure | ZeroCrossing | StandardDeviation | ActivityIndex | TAT | Int | ..."); } if (option != AcceptableActivityOptions.Export || option != AcceptableActivityOptions.Sync) { RemoveGravity(rows); } switch (option) { case AcceptableActivityOptions.Export: Export.ExportText.ExportRows(rows); break; case AcceptableActivityOptions.Sync: Sync.SyncLocations.Syncronize(locations.OrderBy(m => m.SaveTime).ToList()); break; case AcceptableActivityOptions.StandardDeviation: double devX = StandardDeviation.CalculateStdDev(rows.Select(m => (double)m.X).ToList()); double devY = StandardDeviation.CalculateStdDev(rows.Select(m => (double)m.Y).ToList()); double devZ = StandardDeviation.CalculateStdDev(rows.Select(m => (double)m.Z).ToList()); Export.ExportText.ExportStdDev(devX, devY, devZ); break; case AcceptableActivityOptions.Dist: var distFileDialog = new OpenFileDialog(); distFileDialog.ShowDialog(); string distFileName = distFileDialog.FileName; Console.WriteLine(string.Concat("* Opened file: ", distFileName)); List <ActivityPerMinute> distances; distances = DistFileHandler.GetData(distFileName); distances = distances.Where(m => m.DateTime >= beginDate && m.DateTime < endDate).ToList(); var activities = CalculateActivity.BeginAnalyzation(AcceptableActivityOptions.TAT, rows); CalculateActivity.CorrelationBetweenDistanceAndActivity(distances, activities); //PostProcessTasks(distances); break; default: PostProcessTasks(CalculateActivity.BeginAnalyzation(option, rows)); break; } // ReSharper disable once RedundantAssignment rows = null; GC.Collect(); }