示例#1
0
        public async Task<IEnumerable<WeeklySalesDataPoint>> GetWeeklySalesDataPointsAsync(IEnumerable<Order> orders, int numberOfWeeks = defaultNumberOfWeeks, OrderStatusOption statusOption = OrderStatusOption.Both)
        {
            var now = DateTime.UtcNow;

            var today = DateTime.SpecifyKind(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), DateTimeKind.Utc);

            int delta = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - today.DayOfWeek;

            if(delta > 0)
                delta -= 7;
            
            var firstDayOfCurrentWeek = today.AddDays(delta);

            var weekStart = firstDayOfCurrentWeek;

            var weekEnd = weekStart.AddDays(7);

            var enumerableOrders = orders as IList<Order> ?? orders.ToList();

            var weeklySalesDataPoints = new List<WeeklySalesDataPoint>();

            double weekTotal = 0;

            for (int i = 0; i < numberOfWeeks; i++)
            {
                weekStart = weekStart.AddDays(-7);
                weekEnd = weekEnd.AddDays(-7);
                weekTotal = GetOrderTotalForPeriod(enumerableOrders, weekStart, weekEnd);
                weeklySalesDataPoints.Add(new WeeklySalesDataPoint() { DateStart = weekStart, DateEnd = weekEnd, Amount = weekTotal });
            }

            return weeklySalesDataPoints;
        }
示例#2
0
        public async Task<IEnumerable<IGrouping<string, CategorySalesDataPoint>>> GetCategorySalesDataPointsAsync(IEnumerable<Order> orders, int numberOfWeeks = defaultNumberOfWeeks, OrderStatusOption statusOption = OrderStatusOption.Both)
        {
            var now = DateTime.UtcNow;

            var today = DateTime.SpecifyKind(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), DateTimeKind.Utc);

            int delta = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - today.DayOfWeek;

            if(delta > 0)
                delta -= 7;

            var firstDayOfCurrentWeek = today.AddDays(delta);

            var dateEnd = firstDayOfCurrentWeek;

            var dateStart = dateEnd.AddDays(numberOfWeeks * -7);

            var enumerableOrders = orders as IList<Order> ?? orders.ToList();

            var categorySalesDataPoints = new List<CategorySalesDataPoint>();

            IEnumerable<Order> dateRangedOrders;

            switch (statusOption)
            {
                case OrderStatusOption.Open:
                    dateRangedOrders = enumerableOrders.Where(
                        order => 
                        order.IsOpen &&
                        order.OrderDate >= dateStart &&
                        order.OrderDate < dateEnd);
                    break;
                case OrderStatusOption.Closed:
                    dateRangedOrders = enumerableOrders.Where(
                        order => 
                        !order.IsOpen &&
                        order.OrderDate >= dateStart &&
                        order.OrderDate < dateEnd);
                    break;
                default:
                    dateRangedOrders = enumerableOrders.Where(
                        order => 
                        order.OrderDate >= dateStart &&
                        order.OrderDate < dateEnd);
                    break;
            }

            foreach (var r in dateRangedOrders)
            {
                categorySalesDataPoints.Add(new CategorySalesDataPoint() { CategoryName = (await _DataClient.GetTopLevelCategory((await _DataClient.GetProductByNameAsync(r.Item)).CategoryId)).Name, Amount = r.Price });
            }

            var groupedCategorySalesDataPoints = categorySalesDataPoints.GroupBy(x => x.CategoryName);

            return groupedCategorySalesDataPoints;
        }
示例#3
0
        public async Task <IEnumerable <IGrouping <string, CategorySalesDataPoint> > > GetCategorySalesDataPointsAsync(IEnumerable <Order> orders, int numberOfWeeks = defaultNumberOfWeeks, OrderStatusOption statusOption = OrderStatusOption.Both)
        {
            var now = DateTime.UtcNow;

            var today = DateTime.SpecifyKind(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), DateTimeKind.Utc);

            int delta = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - today.DayOfWeek;

            if (delta > 0)
            {
                delta -= 7;
            }

            var firstDayOfCurrentWeek = today.AddDays(delta);

            var dateEnd = firstDayOfCurrentWeek;

            var dateStart = dateEnd.AddDays(numberOfWeeks * -7);

            var enumerableOrders = orders as IList <Order> ?? orders.ToList();

            var categorySalesDataPoints = new List <CategorySalesDataPoint>();

            IEnumerable <Order> dateRangedOrders;

            switch (statusOption)
            {
            case OrderStatusOption.Open:
                dateRangedOrders = enumerableOrders.Where(
                    order =>
                    order.IsOpen &&
                    order.OrderDate >= dateStart &&
                    order.OrderDate < dateEnd);
                break;

            case OrderStatusOption.Closed:
                dateRangedOrders = enumerableOrders.Where(
                    order =>
                    !order.IsOpen &&
                    order.OrderDate >= dateStart &&
                    order.OrderDate < dateEnd);
                break;

            default:
                dateRangedOrders = enumerableOrders.Where(
                    order =>
                    order.OrderDate >= dateStart &&
                    order.OrderDate < dateEnd);
                break;
            }

            foreach (var r in dateRangedOrders)
            {
                categorySalesDataPoints.Add(new CategorySalesDataPoint()
                {
                    CategoryName = (await _DataClient.GetTopLevelCategory((await _DataClient.GetProductByNameAsync(r.Item)).CategoryId)).Name, Amount = r.Price
                });
            }

            var groupedCategorySalesDataPoints = categorySalesDataPoints.GroupBy(x => x.CategoryName);

            return(groupedCategorySalesDataPoints);
        }
示例#4
0
        public async Task <IEnumerable <WeeklySalesDataPoint> > GetWeeklySalesDataPointsAsync(IEnumerable <Order> orders, int numberOfWeeks = defaultNumberOfWeeks, OrderStatusOption statusOption = OrderStatusOption.Both)
        {
            var now = DateTime.UtcNow;

            var today = DateTime.SpecifyKind(new DateTime(now.Year, now.Month, now.Day, 0, 0, 0), DateTimeKind.Utc);

            int delta = CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek - today.DayOfWeek;

            if (delta > 0)
            {
                delta -= 7;
            }

            var firstDayOfCurrentWeek = today.AddDays(delta);

            var weekStart = firstDayOfCurrentWeek;

            var weekEnd = weekStart.AddDays(7);

            var enumerableOrders = orders as IList <Order> ?? orders.ToList();

            var weeklySalesDataPoints = new List <WeeklySalesDataPoint>();

            double weekTotal = 0;

            for (int i = 0; i < numberOfWeeks; i++)
            {
                weekStart = weekStart.AddDays(-7);
                weekEnd   = weekEnd.AddDays(-7);
                weekTotal = GetOrderTotalForPeriod(enumerableOrders, weekStart, weekEnd);
                weeklySalesDataPoints.Add(new WeeklySalesDataPoint()
                {
                    DateStart = weekStart, DateEnd = weekEnd, Amount = weekTotal
                });
            }

            return(weeklySalesDataPoints);
        }
示例#5
0
        static double GetOrderTotalForPeriod(IEnumerable <Order> orders, DateTime dateStart, DateTime dateEnd, OrderStatusOption statusOption = OrderStatusOption.Both)
        {
            double total = 0;

            IEnumerable <Order> results;

            switch (statusOption)
            {
            case OrderStatusOption.Open:
                results = orders.Where(
                    order =>
                    order.IsOpen &&
                    order.OrderDate >= dateStart &&
                    order.OrderDate < dateEnd);
                break;

            case OrderStatusOption.Closed:
                results = orders.Where(
                    order =>
                    !order.IsOpen &&
                    order.OrderDate >= dateStart &&
                    order.OrderDate < dateEnd);
                break;

            default:
                results = orders.Where(
                    order =>
                    order.OrderDate >= dateStart &&
                    order.OrderDate < dateEnd);
                break;
            }

            foreach (var order in results)
            {
                total += order.Price;
            }

            return(total);
        }
示例#6
0
        static double GetOrderTotalForPeriod(IEnumerable<Order> orders, DateTime dateStart, DateTime dateEnd, OrderStatusOption statusOption = OrderStatusOption.Both)
        {
            double total = 0;

            IEnumerable<Order> results;

            switch (statusOption)
            {
                case OrderStatusOption.Open:
                    results = orders.Where(
                        order => 
                        order.IsOpen &&
                        order.OrderDate >= dateStart &&
                        order.OrderDate < dateEnd);
                    break;
                case OrderStatusOption.Closed:
                    results = orders.Where(
                        order => 
                        !order.IsOpen &&
                        order.OrderDate >= dateStart &&
                        order.OrderDate < dateEnd);
                    break;
                default:
                    results = orders.Where(
                        order => 
                        order.OrderDate >= dateStart &&
                        order.OrderDate < dateEnd);
                    break;
            }

            foreach (var order in results)
            {
                total += order.Price;
            }

            return total;
        }