public ActionResult GetReport(int id) { string userId = User.Identity.GetUserId(); bool reportSaved; if (userId != null) { reportSaved = Methods.CheckIfReportSaved(userId, id); if (reportSaved) { ViewBag.Saved = "true"; } else { ViewBag.Saved = "false"; } } else { ViewBag.Saved = "true"; } StatSummaryVM ss = Methods.GetSummaryById(id); return(View("Report", ss)); }
public void SaveStatSummary(StatSummaryVM ss, string userId) { if (userId != null) { ApplicationUser user = _context.Users.Include(u => u.StatSummaries).SingleOrDefault(u => u.Id == userId); ss.Author = user.UserName; user.StatSummaries.Add(ss); } _context.StatSummaryVMs.Add(ss); _context.SaveChanges(); }
public IHttpActionResult SaveToReports(int id) { string userId = User.Identity.GetUserId(); ApplicationUser user = _context.Users.Include(u => u.StatSummaries).SingleOrDefault(u => u.Id == userId); StatSummaryVM statSummary = _context.StatSummaryVMs.SingleOrDefault(ss => ss.Id == id); if (!_summaryService.CheckIfReportSaved(userId, statSummary.Id)) { statSummary.ApplicationUsers.Add(user); user.StatSummaries.Add(statSummary); _context.SaveChanges(); } return(Ok()); }
public ActionResult ProcessCSV(SelectTypeVM vm) { _configurationService.MakeDropDownAndFirstFive(vm); if (vm.ColumnTypes.Values.Where(x => x != "").Count() < 2) { ModelState.AddModelError(string.Empty, "*You must select at least two variables"); TempData["ViewData"] = ViewData; TempData["ModelState"] = ModelState; ViewData = (ViewDataDictionary)TempData["ViewData"]; return(View("SelectTypes", vm)); } Dictionary <string, List <string> > invalidColumns = _parsingService.CheckForInvalidColumns(vm.ColumnTypes, vm.FirstFiveRows); if (invalidColumns.Count > 0) { ViewBag.Error = "<p class='viewbag-error'>*Invalid data found* <br/>Did you mark a categorical variabal as numeral? </p>"; TempData["ViewData"] = ViewData; TempData["ModelState"] = ModelState; ViewData = (ViewDataDictionary)TempData["ViewData"]; return(View("SelectTypes", vm)); } Dictionary <string, List <string> > dictFile = _parsingService.CsvToDictionary(vm.Path); StatSummaryVM summaryVM = _summaryService.GetSummaryVM(dictFile, vm); summaryVM.CreatedOn = DateTime.Now; string userId = User.Identity.GetUserId(); _summaryService.SaveStatSummary(summaryVM, userId); ViewBag.Saved = "true"; return(View("Report", summaryVM)); }
public StatSummaryVM GetSummaryVM(Dictionary <string, List <string> > dictFile, SelectTypeVM vm) { List <string> checkedColumns = new List <string>(); List <ChiStats> chiStatsList = new List <ChiStats>(); List <AnovaStats> anovaStatsList = new List <AnovaStats>(); List <PearsonCorr> pearsonCorrelations = new List <PearsonCorr>(); List <DateAndCategory> dateAndCategories = new List <DateAndCategory>(); List <DateAndNumeral> dateAndNumerals = new List <DateAndNumeral>(); StatSummaryVM statsSummary = new StatSummaryVM(); foreach (KeyValuePair <string, List <string> > entry in dictFile) { foreach (KeyValuePair <string, List <string> > entryCompare in dictFile) { var checkedKey = CompareAndConcat(entry.Key, entryCompare.Key); if (entry.Key == entryCompare.Key || checkedColumns.Contains(checkedKey) || (entry.Value.Count != entryCompare.Value.Count) || (vm.ColumnTypes[entry.Key] == EXCLUDE || vm.ColumnTypes[entryCompare.Key] == EXCLUDE)) { continue; } if ((vm.ColumnTypes[entry.Key] == DATE_TIME || vm.ColumnTypes[entryCompare.Key] == DATE_TIME) && (vm.ColumnTypes[entry.Key] == CATEGORICAL || vm.ColumnTypes[entryCompare.Key] == CATEGORICAL)) { DateAndCategory dateCat = new DateAndCategory(); if (vm.ColumnTypes[entry.Key] == DATE_TIME) { dateCat.GetLinePlotData(entry.Value, entryCompare.Value); } else { dateCat.GetLinePlotData(entryCompare.Value, entry.Value); } dateCat.Variable1 = entry.Key; dateCat.Variable2 = entryCompare.Key; dateAndCategories.Add(dateCat); } if ((vm.ColumnTypes[entry.Key] == DATE_TIME || vm.ColumnTypes[entryCompare.Key] == DATE_TIME) && (vm.ColumnTypes[entry.Key] == NUMERAL || vm.ColumnTypes[entryCompare.Key] == NUMERAL)) { DateAndNumeral dateNum = new DateAndNumeral(); if (vm.ColumnTypes[entry.Key] == DATE_TIME) { dateNum.MakeDataBlob(entry.Value, entryCompare.Value); dateNum.DateName = entry.Key; dateNum.NumeralName = entryCompare.Key; } else { dateNum.MakeDataBlob(entryCompare.Value, entry.Value); dateNum.DateName = entryCompare.Key; dateNum.NumeralName = entry.Key; } dateAndNumerals.Add(dateNum); } if (vm.ColumnTypes[entry.Key] == CATEGORICAL && vm.ColumnTypes[entryCompare.Key] == CATEGORICAL) { ChiStats chiStats = new ChiStats(); chiStats.GetChiStat(entry.Value, entryCompare.Value); chiStats.Variable1 = entryCompare.Key.Replace("\"", ""); chiStats.Variable2 = entry.Key.Replace("\"", ""); chiStatsList.Add(chiStats); } if ((vm.ColumnTypes[entry.Key] == CATEGORICAL || vm.ColumnTypes[entryCompare.Key] == CATEGORICAL) && (vm.ColumnTypes[entry.Key] == NUMERAL || vm.ColumnTypes[entryCompare.Key] == NUMERAL)) { AnovaStats anovaStats = new AnovaStats(); if (vm.ColumnTypes[entry.Key] == NUMERAL) { anovaStats.GetAnovaStats(entryCompare.Value, entry.Value); anovaStats.CategoricalVariable = entryCompare.Key; anovaStats.NumericalVariable = entry.Key; anovaStatsList.Add(anovaStats); } else { anovaStats.GetAnovaStats(entry.Value, entryCompare.Value); anovaStats.CategoricalVariable = entry.Key; anovaStats.NumericalVariable = entryCompare.Key; anovaStatsList.Add(anovaStats); } _context.AnovaStats.Add(anovaStats); _context.SaveChanges(); } if (vm.ColumnTypes[entry.Key] == NUMERAL && vm.ColumnTypes[entryCompare.Key] == NUMERAL) { PearsonCorr pearsonCorr = new PearsonCorr(); pearsonCorr.Variable1 = entry.Key; pearsonCorr.Variable2 = entryCompare.Key; pearsonCorr.ComputeCoeff(entry.Value, entryCompare.Value); pearsonCorrelations.Add(pearsonCorr); _context.SaveChanges(); } checkedColumns.Add(checkedKey); } } statsSummary.Name = vm.Name != null ? vm.Name : "Untitled"; statsSummary.Description = vm.Description != null ? vm.Description : "no description available"; statsSummary.AnovaStats = anovaStatsList; statsSummary.ChiStats = chiStatsList; statsSummary.PearsonCorrs = pearsonCorrelations; statsSummary.DateAndCatories = dateAndCategories; statsSummary.DateAndNumerals = dateAndNumerals; statsSummary.Path = vm.Path; statsSummary.FileName = vm.FileName; return(statsSummary); }