Example #1
0
        public static void SaveStatSummary(StatSummaryVM ss, string userId)
        {
            ApplicationDbContext _context = new ApplicationDbContext();

            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();
        }
Example #2
0
        public static StatSummaryVM GetSummaryVM(Dictionary <string, List <string> > dictFile, SelectTypeVM vm)
        {
            ApplicationDbContext _context = new ApplicationDbContext();

            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 = Methods.ConcatAlph(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);
                        //_context.SaveChanges();
                    }

                    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);
                        //_context.SaveChanges();
                    }


                    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);
                        //_context.ChiStats.Add(chiStats);
                        //_context.SaveChanges();
                    }

                    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);
                        }

                        //anovaStats.SaveStat();
                        _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);
        }