<commit_before>﻿namespace Showcase.Server.Api.Controllers
{
    using System;
    using System.Linq;
    using System.Web.Http;

    using Showcase.Server.Api.Infrastructure.Extensions;
    using Showcase.Services.Data.Contracts;
    using Showcase.Server.DataTransferModels.Statistics;
    using System.Collections.Generic;

    [RoutePrefix("api/Statistics")]
    public class StatisticsController : ApiController
    {
        private IStatisticsService statisticsService;

        public StatisticsController(IStatisticsService statisticsService)
        {
            this.statisticsService = statisticsService;
        }

        public IHttpActionResult Get()
        {
            // TODO: cache statistics
            return this.Data(this.statisticsService.Current());
        }

        [HttpGet]
        [Route("ProjectsLastSixMonths")]
        public IHttpActionResult ProjectsLastSixMonths()
        {
            var total = 0;
            var result = new LineChartResponseModel
            {
                Labels = new List<string>(),
                Values = new List<int>()
            };

            this.statisticsService
                .ProjectsLastSixMonths()
                .ToList()
                .ForEach(r =>
                {
                    total += r.Count;
                    result.Values.Add(total);
                    result.Labels.Add(this.IntegerToMonthName(r.Date.Month));
                });
            
            return this.Data(result);
        }

        [HttpGet]
        [Route("ProjectsCountByTag")]
        public IHttpActionResult ProjectsCountByTag()
        {
            var result = this.statisticsService
                .ProjectsCountByTag()
                .ToList();

            return this.Data(result);
        }

        private string IntegerToMonthName(int monthIndex)
        {
            switch (monthIndex)
            {
                case 1: return "January";
                case 2: return "February";
                case 3: return "March";
                case 4: return "April";
                case 5: return "May";
                case 6: return "June";
                case 7: return "July";<commit_msg>Added get top projects action to Statistics Controller<commit_after>﻿namespace Showcase.Server.Api.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Http;

    using AutoMapper.QueryableExtensions;

    using Showcase.Server.Api.Infrastructure.Extensions;
    using Showcase.Services.Data.Contracts;
    using Showcase.Server.DataTransferModels.Project;
    using Showcase.Server.DataTransferModels.Statistics;

    [RoutePrefix("api/Statistics")]
    public class StatisticsController : ApiController
    {
        private IStatisticsService statisticsService;

        public StatisticsController(IStatisticsService statisticsService)
        {
            this.statisticsService = statisticsService;
        }

        public IHttpActionResult Get()
        {
            // TODO: cache statistics
            return this.Data(this.statisticsService.Current());
        }

        [HttpGet]
        [Route("ProjectsLastSixMonths")]
        public IHttpActionResult ProjectsLastSixMonths()
        {
            var total = 0;
            var result = new LineChartResponseModel
            {
                Labels = new List<string>(),
                Values = new List<int>()
            };

            this.statisticsService
                .ProjectsLastSixMonths()
                .ToList()
                .ForEach(r =>
                {
                    total += r.Count;
                    result.Values.Add(total);
                    result.Labels.Add(this.IntegerToMonthName(r.Date.Month));
                });
            
            return this.Data(result);
        }

        [HttpGet]
        [Route("ProjectsCountByTag")]
        public IHttpActionResult ProjectsCountByTag()
        {
            var result = this.statisticsService
                .ProjectsCountByTag()
                .ToList();

            return this.Data(result);
        }

        [HttpGet]
        [Route("MostLiked")]
        public IHttpActionResult MostLikedProjects()
        {
            var model = this.statisticsService
                .MostLikedProjects()
                .Project()
                .To<ProjectResponseModel>()
                .ToList();

            return this.Data(model);
        }

        private string IntegerToMonthName(int monthIndex)
        {
            switch (monthIndex)
            {
                case 1: return "January";
                case 2: return "February";
                case 3: return "March";
                case 4: return "April";
                case 5: return "May";
                case 6: return "June";
                case 7: return "July";
{'fraction_non_alphanumeric': 0.08526813231970413, 'fraction_numerical': 0.0032874460653379905, 'mean_word_length': 1.5540398740818469, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6000926', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1147, 'n_words': 246}