<commit_before>﻿using System;
using System.Globalization;
using System.Linq;
using Gmtl.HandyLib;
using Nancy;
using NetDevPL.Features.Facebook;

namespace NetDevPLWeb.Features.Facebook
{
    public class FacebookModule : NancyModule
    {
        readonly Repository _facebookDataRepository = new Repository();

        public FacebookModule()
        {
            Get["/facebook"] = parameters =>
            {
                var posts = _facebookDataRepository.PostsGetList(PostFilter.Empty);

                return View["facebookPosts", new FacebookPostsViewModel(posts)];
            };

            Get["/facebook-karma"] = parameters =>
            {
                var karma = new NetDevPL.Features.Reporting.FacebookStats().UserKarma();

                return String.Join("<br/>", karma.Take(100).Select(k => k.Name + " " + k.KarmaPoints));
            };

            Get["/facebook/top-last-month"] = parameters =>
            {
                var lastMonth = DateTime.Now.AddMonths(-1);
                var firstDay = new DateTime(lastMonth.Year, lastMonth.Month, 1);

                var filter = new PostFilter
                {
                    StartDate = firstDay,
                    EndDate = firstDay.AddMonths(1).AddMilliseconds(-1),
                    SortingExpression = post => post.Likes,
                    SortingDirection = SortDirection.Descending
                };
                var posts = _facebookDataRepository.PostsGetList(filter);

                return View["facebookPosts", new FacebookPostsViewModel(posts)];
            };
        }
    }

    public class FacebookPostsViewModel
    {
        public FacebookPostsViewModel(HLListPage<FacebookPost> posts)
        {
            Posts = posts;
        }
        
        public HLListPage<FacebookPost> Posts { get; set; }
    }
}
<commit_msg>Added current year top posts<commit_after>﻿using System;
using System.Globalization;
using System.Linq;
using Gmtl.HandyLib;
using Nancy;
using NetDevPL.Features.Facebook;

namespace NetDevPLWeb.Features.Facebook
{
    public class FacebookModule : NancyModule
    {
        readonly Repository _facebookDataRepository = new Repository();

        public FacebookModule()
        {
            Get["/facebook"] = parameters =>
            {
                var posts = _facebookDataRepository.PostsGetList(PostFilter.Empty);

                return View["facebookPosts", new FacebookPostsViewModel(posts)];
            };

            Get["/facebook-karma"] = parameters =>
            {
                var karma = new NetDevPL.Features.Reporting.FacebookStats().UserKarma();

                return String.Join("<br/>", karma.Take(100).Select(k => k.Name + " " + k.KarmaPoints));
            };

            Get["/facebook/top-last-month"] = parameters =>
            {
                var lastMonth = DateTime.Now.AddMonths(-1);
                var firstDay = new DateTime(lastMonth.Year, lastMonth.Month, 1);
                var lastDay = firstDay.AddMonths(1).AddMilliseconds(-1);

                return GetPostsForPeriod(firstDay, lastDay);
            };

            Get["/facebook/top-current-year"] = parameters =>
            {
                var firstDay = new DateTime(DateTime.Now.Year, 1, 1);
                var lastDay = firstDay.AddYears(1).AddMilliseconds(-1);
                
                return GetPostsForPeriod(firstDay, lastDay);
            };
        }

        private dynamic GetPostsForPeriod(DateTime startDate, DateTime endDate)
        {
            var filter = new PostFilter
            {
                StartDate = startDate,
                EndDate = endDate,
                SortingExpression = post => post.Likes,
                SortingDirection = SortDirection.Descending
            };
            var posts = _facebookDataRepository.PostsGetList(filter);

            return View["facebookPosts", new FacebookPostsViewModel(posts)];
        }
    }

    public class FacebookPostsViewModel
    {
        public FacebookPostsViewModel(HLListPage<FacebookPost> posts)
        {
            Posts = posts;
        }

        public HLListPage<FacebookPost> Posts { get; set; }
    }
}

{'fraction_non_alphanumeric': 0.09763101220387653, 'fraction_numerical': 0.004307250538406317, 'mean_word_length': 1.8435374149659864, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '828689', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1028, 'n_words': 208}