private CohortAnalysisResultModel Analyse(List <CohortAnalysisModel> preparedData, string groupId)
        {
            var analyser = new CohortAnalyser();

            var absoluteData          = analyser.BuildAbsoluteValues(preparedData);
            var relativeData          = analyser.BuildRelativeValues(absoluteData);
            var relativeDataWithShift = analyser.BuildRelativeValuesWithShift(absoluteData);
            var mediumDataWithShift   = analyser.BuildMediumValuesWithShift(absoluteData);
            var mediumData            = analyser.MediumValuesWithShift(absoluteData).ToList();

            var result = new CohortAnalysisResultModel
            {
                AbsoluteValues          = absoluteData,
                RelativeValues          = relativeData,
                RelativeValuesWithShift = relativeDataWithShift,
                MediumValuesWithShift   = mediumDataWithShift,
                MediumValues            = mediumData,
                TableLength             = preparedData.Count,
                GroupId = groupId
            };

            result.TotalHorizontal = CountTotalHorizontal(result.AbsoluteValues);
            result.TotalVertical   = CountTotalVertical(result.AbsoluteValues);

            return(result);
        }
        public CohortAnalysisResultModel Analyze(List <CohortAnalysisModel> models, int step, DateTime dateOfTheBeginning, DateTime dateOfTheEnd, string groupId)
        {
            var result = new CohortAnalysisResultModel();

            var preparedData = PrepareDataForCohortAnalyse(models, step, dateOfTheBeginning, dateOfTheEnd).OrderBy(d => d.PostDate).ToList();

            result = Analyse(preparedData, groupId);

            if (step == 1)
            {
                for (var dt = dateOfTheBeginning; dt < dateOfTheEnd; dt = dt.AddDays(1))
                {
                    result.Dates.Add(dt.ToShortDateString());
                }
            }

            if (step == 2)
            {
                var allDays      = GetTotalDays(dateOfTheBeginning, dateOfTheEnd);
                var st           = 7;
                var countOfSteps = Math.Ceiling(allDays / st);
                for (var i = 0; i < countOfSteps; i++)
                {
                    var startDate = dateOfTheBeginning.AddDays(i * st);
                    var endDate   = dateOfTheBeginning.AddDays((i + 1) * st);
                    if (endDate > dateOfTheEnd)
                    {
                        endDate = dateOfTheEnd;
                    }

                    result.Dates.Add(string.Format("{0} - {1}", startDate.ToShortDateString(), endDate.ToShortDateString()));
                }
            }

            if (step == 3)
            {
                var allDays      = GetTotalDays(dateOfTheBeginning, dateOfTheEnd);
                var st           = 30;
                var countOfSteps = Math.Ceiling(allDays / st);
                for (var i = 0; i < countOfSteps; i++)
                {
                    var startDate = dateOfTheBeginning.AddDays(i * st);
                    var endDate   = dateOfTheBeginning.AddDays((i + 1) * st);
                    if (endDate > dateOfTheEnd)
                    {
                        endDate = dateOfTheEnd;
                    }

                    result.Dates.Add(string.Format("{0} - {1}", startDate.ToShortDateString(), endDate.ToShortDateString()));
                }
            }

            return(result);
        }
Exemple #3
0
        public void SaveAnalyzeOfSalesWithList(CohortAnalysisResultModel result, string userId, string name, string groupId)
        {
            using (var ms = new MemoryStream())
            {
                var binaryFormatter = new BinaryFormatter();
                binaryFormatter.Serialize(ms, result);
                byte[] rr = ms.GetBuffer();

                var cntx = new BaseDb();
                cntx.VkCohortSalesAnalyseWithListResults.Add(new VkCohortSalesAnalyseWithListResults
                {
                    UserId         = userId,
                    Name           = name,
                    CollectionDate = DateTime.Now,
                    GroupId        = groupId,
                    Result         = rr
                });
                cntx.SaveChanges();
            }
        }
        public ActionResult ResultWithList(int id)
        {
            var resultDb = _dbContext.VkCohortSalesAnalyseWithListResults.FirstOrDefault(rest => rest.Id == id);
            var result   = new CohortAnalysisResultModel();

            try
            {
                var formatter = new BinaryFormatter();
                using (var ms = new MemoryStream(resultDb.Result))
                {
                    result = (CohortAnalysisResultModel)formatter.Deserialize(ms);
                }
            }
            catch (Exception ex)
            {
                Logger.Error(string.Format("Error: {0}", ex));
            }

            return(View(result));
        }
Exemple #5
0
        public ActionResult Index()
        {
            var userId = User.Identity.GetUserId();
            var cntx   = new BaseDb();
            var result = cntx.VkCohortAnalyseResults.FirstOrDefault(x => x.UserId == userId);

            var set = new CohortAnalysisResultModel();

            try
            {
                var formatter = new BinaryFormatter();
                using (var ms = new MemoryStream(result.Result))
                {
                    set = (CohortAnalysisResultModel)formatter.Deserialize(ms);
                }
            }
            catch (Exception ex)
            {
                // removed error handling logic!
            }

            return(View());
        }