コード例 #1
0
        private void WriteCategoriesByYear(XLWorkbook workbook)
        {
            var ws = workbook.AddWorksheet("Categorization (by year)");

            var all_posts  = profile.AggregatedPosts().OrderBy(p => p.Date);
            var first_date = all_posts.First().Date;
            var last_date  = all_posts.Last().Date;

            // Find posts per category
            var all_categories    = Category.Flatten(profile.RootCategory);
            var posts_by_category = all_categories.ToDictionary(category => category, category => category.AggregatePosts().Distinct().ToList());

            ws.Row(1).Cell(1).SetValue("Year");
            for (int i = 0; i < all_categories.Count; i++)
            {
                ws.Row(1).Cell(i + 2).SetValue(all_categories[i].Name);
            }

            for (int i = first_date.Year; i <= last_date.Year; i++)
            {
                var row = i - first_date.Year + 2;
                ws.Row(row).Cell(1).SetValue(i);

                for (int j = 0; j < all_categories.Count; j++)
                {
                    var total = posts_by_category[all_categories[j]].Where(p => p.Date.Year == i).Sum(p => p.Value);
                    ws.Row(row).Cell(j + 2).SetValue(total);
                }
            }
        }
コード例 #2
0
        public long Categorize()
        {
            ResetCategories();

            var sw = Stopwatch.StartNew();

            foreach (var post in profile.AggregatedPosts())
            {
                foreach (var category in Category.Flatten(profile.RootCategory).Where(c => c.Filters.Count > 0))
                {
                    if (category.IsMatch(post))
                    {
                        category.Posts.Add(post);
                        post.Categories.Add(category);
                    }
                }
            }
            sw.Stop();
            return(sw.ElapsedMilliseconds);
        }
コード例 #3
0
        private void WriteCategoriesByMonth(XLWorkbook workbook)
        {
            var ws = workbook.AddWorksheet("Categorization (by month)");

            var all_posts  = profile.AggregatedPosts().OrderBy(p => p.Date);
            var first_date = all_posts.First().Date;
            var last_date  = all_posts.Last().Date;

            var all_categories    = Category.Flatten(profile.RootCategory);
            var posts_by_category = all_categories.ToDictionary(category => category, category => category.AggregatePosts().Distinct().ToList());

            ws.Row(1).Cell(1).SetValue("Date");
            for (int i = 0; i < all_categories.Count; i++)
            {
                ws.Row(1).Cell(i + 2).SetValue(all_categories[i].Name);
            }

            var current_date = new DateTime(first_date.Year, first_date.Month, 1);

            last_date = new DateTime(last_date.Year, last_date.Month, 1).AddMonths(1);
            var current_row = 2;

            while (current_date != last_date)
            {
                ws.Row(current_row).Cell(1).SetValue(current_date.ToShortDateString());

                for (int j = 0; j < all_categories.Count; j++)
                {
                    var total = posts_by_category[all_categories[j]].Where(p => p.Date.Year == current_date.Year && p.Date.Month == current_date.Month).Sum(p => p.Value);
                    ws.Row(current_row).Cell(j + 2).SetValue(total);
                }

                current_row++;
                current_date = current_date.AddMonths(1);
            }
        }