Пример #1
0
        public ActionResult Filter(string category, string startMonth, string startYear, string endMonth, string endYear)
        {
            //ParseExact method is used to parse both month strings and convert them to an integer

            //gets the number of days in month of the selected ending date
            //used to select the last day of the month
            int daysInMonth = DateTime.DaysInMonth(int.Parse(endYear), DateTime.ParseExact(endMonth, "MMMM", CultureInfo.CurrentCulture).Month);

            //creates the start-date DateTime object
            DateTime startDate = new DateTime(int.Parse(startYear), DateTime.ParseExact(startMonth, "MMMM", CultureInfo.CurrentCulture).Month, 1);

            //creates the end-date DateTime object
            //time of day is set to 11:59 PM, with 59 seconds and 999 milliseconds
            DateTime endDate = new DateTime(int.Parse(endYear), DateTime.ParseExact(endMonth, "MMMM", CultureInfo.CurrentCulture).Month, daysInMonth, 23, 59, 59, 999);

            if (startDate > endDate)
            {
                return(RedirectToAction("Index", new { validDates = false }));
            }

            TrendsViewModel model = this.CreateModel(startDate, endDate, category);

            if (!String.IsNullOrEmpty(category))
            {
                model.Category = category;
            }
            return(View("Index", model));
        }
Пример #2
0
        private static TrendsViewModel GetTrendsSeriesVariantData(int id, DateTime startDate, DateTime endDate)
        {
            var model = new TrendsViewModel();

            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        UserDTO user = FormsAuthenticationWrapper.User;

                        model.TrendSeries = new List <TrendSeries>();

                        var getRequest = new GetTrendsDataVariantRequest()
                        {
                            VariantID = id, StartDate = startDate, EndDate = endDate, User = user
                        };
                        var getResponse = _certonaService.GetTrendsDataVariant(getRequest);
                        if (getResponse.Success && getResponse.TrendsData != null && getResponse.TrendsData.Count > 0)
                        {
                            foreach (var dto in getResponse.TrendsData)
                            {
                                var seriesDataPoint = new TrendSeries()
                                {
                                    Category = dto.Category, Group = dto.Group, Data = dto.Data
                                };
                                model.TrendSeries.Add(seriesDataPoint);
                            }
                        }
                        else
                        {
                            var seriesDataPoint = new TrendSeries()
                            {
                                Category = "No Data", Group = "No Data"
                            };
                            model.TrendSeries.Add(seriesDataPoint);
                        }
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception ex)
            {
                _certonaService.Abort();
                throw;
            }

            return(model);
        }
Пример #3
0
        private TrendsViewModel CreateModel(DateTime startDate, DateTime endDate, string category)
        {
            TrendsViewModel model = new TrendsViewModel();

            model.StartDate = startDate;
            model.EndDate   = endDate;
            //model.BudgetTotals = this.GetBudgetGoalTotals(startDate, endDate);
            model.Categories = this.GetCategories();

            if (!String.IsNullOrEmpty(category))
            {
                DateTime newStartDate = startDate;
                if (startDate.AddMonths(12) < endDate)
                {
                    startDate           = endDate.AddMonths(-12);
                    newStartDate        = new DateTime(startDate.Year, startDate.Month, 1, 0, 0, 0, 0);
                    model.StartDate     = newStartDate;
                    model.TooManyMonths = true;
                }
                Dictionary <string, decimal> initialTransactions = this.GetTransactionsByCategory(newStartDate, endDate, category);
                Dictionary <string, decimal> updatedTransactions = this.NewDictionary(newStartDate, endDate);
                updatedTransactions      = this.UpdateDictionary(initialTransactions, updatedTransactions);
                model.TransactionAmounts = updatedTransactions;

                Dictionary <string, decimal> initialBudgetGoals = this.GetBudgetGoalsByCategory(startDate, endDate, category);
                Dictionary <string, decimal> updatedBudgetGoals = this.NewDictionary(startDate, endDate);
                updatedBudgetGoals = this.UpdateDictionary(initialBudgetGoals, updatedBudgetGoals);
                model.BudgetTotals = updatedBudgetGoals;

                model.ChartLabels = updatedTransactions.Keys.ToList();
            }
            else
            {
                Dictionary <string, decimal> initialTransactions = this.GetTransactionTotals(startDate, endDate);
                Dictionary <string, decimal> updatedTransactions = this.InitializeDictionary(model.Categories);
                updatedTransactions      = this.UpdateDictionary(initialTransactions, updatedTransactions);
                model.TransactionAmounts = updatedTransactions;

                Dictionary <string, decimal> initialBudgetGoals = this.GetBudgetGoalTotals(startDate, endDate);
                Dictionary <string, decimal> updatedBudgetGoals = this.InitializeDictionary(model.Categories);
                updatedBudgetGoals = this.UpdateDictionary(initialBudgetGoals, updatedBudgetGoals);
                model.BudgetTotals = updatedBudgetGoals;

                model.ChartLabels = model.Categories.Where(x => x.CategoryID != 1).Select(x => x.CategoryType).ToList();
                //model.ChartLabels = updatedTransactions.Keys.ToList();
            }

            model.TotalSpent         = model.TransactionAmounts.Sum(x => x.Value);
            model.MostSpent          = model.TransactionAmounts.Max(x => x.Value);
            model.MostSpentCategory  = model.TransactionAmounts.OrderByDescending(x => x.Value).First().Key;
            model.LeastSpent         = model.TransactionAmounts.Min(x => x.Value);
            model.LeastSpentCategory = model.TransactionAmounts.OrderBy(x => x.Value).First().Key;
            model.AverageSpending    = model.TransactionAmounts.Average(x => x.Value);
            model.Colors             = this.GenerateColors(model, model.TransactionAmounts.Count());
            model.ValidDates         = true;
            return(model);
        }
Пример #4
0
        private List <string> GenerateColors(TrendsViewModel model, int size)
        {
            List <string> colors = new List <string>();

            for (int i = 0; i < size; i++)
            {
                colors.Add(model.ColorsList[i]);
            }
            return(colors);
        }
Пример #5
0
        private static TrendsViewModel CreateTrendsViewModel(string id, string title, string chartName, NodeType nodeType)
        {
            var model = new TrendsViewModel()
            {
                Title       = title,
                ChartName   = chartName,
                NodeType    = nodeType,
                StartDate   = ReportingStartDate,
                EndDate     = ReportingEndDate,
                ID          = id,
                TrendSeries = new List <TrendSeries>()
            };

            model.ReportingLastUpdated = ReportingDateLastUpdated();
            return(model);
        }
Пример #6
0
        // GET: Trends
        public ActionResult Index(bool?validDates)
        {
            ActionResult result = checkUser();

            if (result != null)
            {
                return(result);
            }

            DateTime endDate  = System.DateTime.Now;
            DateTime tempDate = endDate.AddMonths(-3); //default is spending from last three months

            //initialize startDate to be midnight on the first of the month
            DateTime startDate = new DateTime(tempDate.Year, tempDate.Month, 1, 0, 0, 0, 0);

            TrendsViewModel model = this.CreateModel(startDate, endDate, null);

            //set model's ValidDates to true if the validDates parameter is null
            model.ValidDates = validDates == null ? true : false;

            return(View(model));
        }
        public async Task <ActionResult> TrendTopicsAsync()
        {
            var auth = new MvcAuthorizer
            {
                CredentialStore = new SessionStateCredentialStore()
            };
            var ctx = new TwitterContext(auth);

            var trends = await(from trend in ctx.Trends
                               where trend.Type == TrendType.Place && trend.WoeID == 23424768
                               select trend).ToListAsync();

            List <TrendsViewModel> trendsViewModels = new List <TrendsViewModel>();

            foreach (var item in trends)
            {
                var tempModel = new TrendsViewModel
                {
                    AsOf      = item.AsOf,
                    CreatedAt = item.CreatedAt,
                    Events    = item.Events,
                    Exclude   = item.Exclude,
                    //Latitude = item.Latitude,
                    //Longitude = item.Longitude,
                    Name = item.Name,
                    //Query = item.Query,
                    //PromotedContent = item.PromotedContent,
                    //Locations = item.Locations,
                    //SearchUrl = item.SearchUrl,
                    TweetVolume = item.TweetVolume,
                    //Type = item.Type,
                    //WoeID = item.WoeID
                };
                trendsViewModels.Add(tempModel);
            }

            return(View(trendsViewModels));
        }
Пример #8
0
        public static TrendsViewModel RefreshTrends(int startYear, int startMonth, int startDay, int endYear, int endMonth, int endDay, string ID, NodeType nodeType)
        {
            // only update the series data
            var startDate = new DateTime(startYear, startMonth, startDay);
            var endDate   = new DateTime(endYear, endMonth, endDay);

            ReportingStartDate = startDate;
            ReportingEndDate   = endDate;

            TrendsViewModel model = null;

            switch (nodeType)
            {
            case NodeType.Application:
                model = GetTrendsSeriesApplicationData(ID, startDate, endDate);
                break;

            case NodeType.Package:
                model = GetTrendsSeriesPackageData(int.Parse(ID), startDate, endDate);
                break;

            case NodeType.Scheme:
                model = GetTrendsSeriesSchemeData(int.Parse(ID), startDate, endDate);
                break;

            case NodeType.Experience:
                model = GetTrendsSeriesExperienceData(int.Parse(ID), startDate, endDate);
                break;

            case NodeType.Variant:
                model = GetTrendsSeriesVariantData(int.Parse(ID), startDate, endDate);
                break;

            default:
                throw new ApplicationException(String.Format("RefreshTrends(): Unsupported Node Type {0}", nodeType.ToString()));
            }

            #region Dummy Data
            //string group = "Dynamic Page";
            //var series = new TrendSeries();
            //series.Data = 100.273; series.Group = group; series.Category = "Jan 2012";
            //model.TrendSeries.Add(series);
            //series = new TrendSeries();
            //series.Data = 99.325; series.Group = group; series.Category = "Feb 2012";
            //model.TrendSeries.Add(series);
            //series = new TrendSeries();
            ////series.Data = 77.390; series.Group = group; series.Category = "March 2012";
            //series.Data = null; series.Group = group; series.Category = "March 2012";
            //model.TrendSeries.Add(series);
            //series = new TrendSeries();
            //series.Data = 88.458; series.Group = group; series.Category = "Apr 2012";
            //model.TrendSeries.Add(series);
            //series = new TrendSeries();
            //series.Data = 99.344; series.Group = group; series.Category = "May 2012";
            //model.TrendSeries.Add(series);
            //series = new TrendSeries();
            //series.Data = 92.225; series.Group = group; series.Category = "Jun 2012";
            //model.TrendSeries.Add(series);
            //series = new TrendSeries();
            //series.Data = 85.256; series.Group = group; series.Category = "Jul 2012";
            //model.TrendSeries.Add(series);
            #endregion

            return(model);
        }
Пример #9
0
        private static TrendsViewModel GetTrendsSeriesApplicationData(string id, DateTime startDate, DateTime endDate)
        {
            var model = new TrendsViewModel();

            try
            {
                using (_certonaService = new CertonaServiceClient())
                {
                    try
                    {
                        UserDTO user = FormsAuthenticationWrapper.User;

                        model.TrendSeries = new List <TrendSeries>();

                        var getRequest = new GetTrendsDataApplicationRequest()
                        {
                            ApplicationID = id, StartDate = startDate, EndDate = endDate, User = user
                        };
                        var getResponse = _certonaService.GetTrendsDataApplication(getRequest);
                        if (getResponse.Success && getResponse.TrendsData != null && getResponse.TrendsData.Count > 0)
                        {
                            foreach (var dto in getResponse.TrendsData)
                            {
                                var seriesDataPoint = new TrendSeries()
                                {
                                    Category = dto.Category, Group = dto.Group, Data = dto.Data
                                };
                                model.TrendSeries.Add(seriesDataPoint);
                            }
                        }
                        else
                        {
                            var seriesDataPoint = new TrendSeries()
                            {
                                Category = "No Data", Group = "No Data"
                            };
                            model.TrendSeries.Add(seriesDataPoint);
                        }

                        #region Dummy Data

                        //var series = new TrendSeries();
                        //series.Data = 2.8654690555282922; series.Group = "Shopping Cart Page"; series.Category = "Mar 2013";
                        //series.Data = 3.889; series.Group = "Shopping Cart Page"; series.Category = "Mar 2013";
                        //trendSeriesList.Add(series);
                        //series = new TrendSeries();
                        //series.Data = 3.936; series.Group = "Shopping Cart Page"; series.Category = "Apr 2013";
                        //trendSeriesList.Add(series);
                        //series = new TrendSeries();
                        //series.Data = 4.165; series.Group = "Shopping Cart Page"; series.Category = "March 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = 4.165; series.Group = "Shopping Cart Page"; series.Category = "Apr 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = 5.021; series.Group = "Shopping Cart Page"; series.Category = "May 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = 4.596; series.Group = "Shopping Cart Page"; series.Category = "Jun 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = 5.575; series.Group = "Shopping Cart Page"; series.Category = "Jul 2012";
                        //model.TrendSeries.Add(series);

                        //series = new TrendSeries();
                        //series.Data = .273; series.Group = "Home Page"; series.Category = "Jan 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = .325; series.Group = "Home Page"; series.Category = "Feb 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = .390; series.Group = "Home Page"; series.Category = "March 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = .458; series.Group = "Home Page"; series.Category = "Apr 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = .344; series.Group = "Home Page"; series.Category = "May 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = .225; series.Group = "Home Page"; series.Category = "Jun 2012";
                        //model.TrendSeries.Add(series);
                        //series = new TrendSeries();
                        //series.Data = .256; series.Group = "Home Page"; series.Category = "Jul 2012";
                        //model.TrendSeries.Add(series);

                        #endregion
                    }
                    catch (TimeoutException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                    catch (CommunicationException exception)
                    {
                        _certonaService.Abort();
                        throw;
                    }
                }
            }
            catch (Exception)
            {
                _certonaService.Abort();
                throw;
            }

            return(model);
        }