<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using Cas2016.Api.Models;
using Cas2016.Api.Repositories;

namespace Cas2016.Api.Controllers
{
    [RoutePrefix("sessions")]
    public class SessionsController : ApiController
    {
        private readonly ISessionRepository _sessionsRepository;

        public SessionsController(ISessionRepository sessionRepository)
        {
            _sessionsRepository = sessionRepository;
        }

        [Route("", Name = "Sessions")]
        public IHttpActionResult Get()
        {
            var sessions = _sessionsRepository.GetAll();

            var sessionsWithSelfLinks = sessions.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        [Route("{sessionId:int}", Name = "Session")]
        public IHttpActionResult Get(int sessionId)
        {
            var session = _sessionsRepository.Get(sessionId);

            var sessionWithSelfLink = AddSelfLinkTo(session);

            sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
            sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
            sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);

            return Ok(sessionWithSelfLink);
        }

        [Route("{sessionDate:datetime}")]
        public IHttpActionResult Get(DateTime sessionDate)
        {
            var sessions = _sessionsRepository.GetAll().Where(s => s.StartTime.Date == sessionDate.Date);

            var sessionsWithSelfLinks = sessions.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        [Route("tags/{name}", Name = "Tag")]
        public IHttpActionResult Get(string name)
        {
            var allSessions = _sessionsRepository.GetAll();

            var sessionsWithTag = allSessions.Where(s => s.Tags.Any(t => t.Name == name));

            var sessionsWithSelfLinks = sessionsWithTag.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        private SessionModel AddSelfLinkTo(SessionModel session)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Session", new {sessionId = session.Id});
            session.Links = new List<LinkModel> {selfLink};

            return session;
        }

        private MinimalSpeakerModel AddSelfLinkTo(MinimalSpeakerModel speaker)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Speaker", new { speakerId = speaker.Id });
            speaker.Links = new List<LinkModel> { selfLink };

            return speaker;
        }

        private TagModel AddSelfLinkTo(TagModel tag)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Tag", new { name = tag.Name });
            tag.Links = new List<LinkModel> { selfLink };

            return tag;
        }

        private RoomModel AddSelfLinkTo(RoomModel room)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Room", new { roomId = room.Id });
            room.Links = new List<LinkModel> { selfLink };

            return room;
        }
    }
}<commit_msg>Add filter by hour<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using Cas2016.Api.Models;
using Cas2016.Api.Repositories;

namespace Cas2016.Api.Controllers
{
    [RoutePrefix("sessions")]
    public class SessionsController : ApiController
    {
        private readonly ISessionRepository _sessionsRepository;

        public SessionsController(ISessionRepository sessionRepository)
        {
            _sessionsRepository = sessionRepository;
        }

        [Route("", Name = "Sessions")]
        public IHttpActionResult Get()
        {
            var sessions = _sessionsRepository.GetAll();

            var sessionsWithSelfLinks = sessions.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        [Route("{sessionId:int}", Name = "Session")]
        public IHttpActionResult Get(int sessionId)
        {
            var session = _sessionsRepository.Get(sessionId);

            var sessionWithSelfLink = AddSelfLinkTo(session);

            sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
            sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
            sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);

            return Ok(sessionWithSelfLink);
        }

        [Route("{sessionDate:datetime}")]
        public IHttpActionResult Get(DateTime sessionDate)
        {
            var sessions = _sessionsRepository.GetAll().Where(s => s.StartTime.Date == sessionDate.Date);

            var sessionsWithSelfLinks = sessions.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        [Route("{sessionDate:datetime}/{hour:int}")]
        public IHttpActionResult Get(DateTime sessionDate, int hour)
        {
            var sessions = _sessionsRepository.GetAll().Where(s => s.StartTime.Date == sessionDate.Date && s.StartTime.Hour <= hour && s.EndTime.Hour >= hour);

            var sessionsWithSelfLinks = sessions.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        [Route("tags/{name}", Name = "Tag")]
        public IHttpActionResult Get(string name)
        {
            var allSessions = _sessionsRepository.GetAll();

            var sessionsWithTag = allSessions.Where(s => s.Tags.Any(t => t.Name == name));

            var sessionsWithSelfLinks = sessionsWithTag.Select(AddSelfLinkTo);

            foreach (var sessionWithSelfLink in sessionsWithSelfLinks)
            {
                sessionWithSelfLink.Speakers = sessionWithSelfLink.Speakers.Select(AddSelfLinkTo);
                sessionWithSelfLink.Tags = sessionWithSelfLink.Tags.Select(AddSelfLinkTo);
                sessionWithSelfLink.Room = AddSelfLinkTo(sessionWithSelfLink.Room);
            }

            return Ok(sessionsWithSelfLinks);
        }

        private SessionModel AddSelfLinkTo(SessionModel session)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Session", new {sessionId = session.Id});
            session.Links = new List<LinkModel> {selfLink};

            return session;
        }

        private MinimalSpeakerModel AddSelfLinkTo(MinimalSpeakerModel speaker)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Speaker", new { speakerId = speaker.Id });
            speaker.Links = new List<LinkModel> { selfLink };

            return speaker;
        }

        private TagModel AddSelfLinkTo(TagModel tag)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Tag", new { name = tag.Name });
            tag.Links = new List<LinkModel> { selfLink };

            return tag;
        }

        private RoomModel AddSelfLinkTo(RoomModel room)
        {
            var selfLink = ModelFactory.CreateLink(Url, "self", "Room", new { roomId = room.Id });
            room.Links = new List<LinkModel> { selfLink };

            return room;
        }
    }
}
{'fraction_non_alphanumeric': 0.08897136797454931, 'fraction_numerical': 0.002545068928950159, 'mean_word_length': 2.444485025566107, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 19, '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': '6097919', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2404, 'n_words': 443}