<commit_before># gems
require 'sinatra/base'
require 'pry'
require 'date'
require 'haml'

module Resa
  class App < Sinatra::Base
    set :static, true
    set :public,  File.dirname(__FILE__) + '/../../public'
    set :views, File.dirname(__FILE__) + '/../../views'

    helpers do
      def find_room(id)
        @room = Room.where(:name => id).first
    rescue Mongoid::Errors::DocumentNotFound, BSON::InvalidObjectId
        halt 404, '404 - Page not found'
      end
    end

    before do
      content_type 'application/json', :charset => 'utf-8'
    end

    # Return rooms available now
    get '/' do
      content_type 'text/html', :charset => 'utf-8'
      haml :index, :format => :html5
    end

    # Return list of rooms
    get '/rooms' do
      Room.list.to_json
    end

    # Return room's availability for the current day
    get '/rooms/:id' do
      find_room(params[:id])
      @room.to_json
    end

    # Return reservations of the day
    get '/rooms/:id/reservations' do
      find_room(params[:id])
      reservations = @room.reservations_for_a_day

      reservations.to_json
    end

    # Return reservations for a month.
    get '/rooms/:id/reservations/:year/:month' do
      find_room(params[:id])
      reservations = @room.reservations_for_a_month(params[:year], params[:month])

      reservations.to_json
    end


    # Return reservations for a day.
    get '/rooms/:id/reservations/:year/:month/:day' do
      find_room(params[:id])
      reservations = @room.reservations_for_a_day("#{params[:year]}-#{params[:month]}-#{params[:day]}")

      reservations.to_json<commit_msg>add events route<commit_after># gems
require 'sinatra/base'
require 'pry'
require 'date'
require 'haml'

module Resa
  class App < Sinatra::Base
    set :static, true
    set :public,  File.dirname(__FILE__) + '/../../public'
    set :views, File.dirname(__FILE__) + '/../../views'

    helpers do
      def find_room(id)
        @room = Room.where(:name => id).first
    rescue Mongoid::Errors::DocumentNotFound, BSON::InvalidObjectId
        halt 404, '404 - Page not found'
      end
    end

    before do
      content_type 'application/json', :charset => 'utf-8'
    end

    # Return rooms available now
    get '/' do
      content_type 'text/html', :charset => 'utf-8'
      haml :index, :format => :html5
    end

    # Return list of rooms
    get '/rooms' do
      Room.list.to_json
    end

    # Return room's availability for the current day
    get '/rooms/:id' do
      find_room(params[:id])
      @room.to_json
    end

    # Return room's availability for the current day
    get '/rooms/:id/events' do
      find_room(params[:id])
      @room.events.to_json
    end

    # Return reservations of the day
    get '/rooms/:id/reservations' do
      find_room(params[:id])
      reservations = @room.reservations_for_a_day

      reservations.to_json
    end

    # Return reservations for a month.
    get '/rooms/:id/reservations/:year/:month' do
      find_room(params[:id])
      reservations = @room.reservations_for_a_month(params[:year], params[:month])

      reservations.to_json
    end


    # Return reservations for a day.
    get '/rooms/:id/reservations/:year/:month/:day' do
      find_room(params[:id])
      reservations = @room.reservations_for_a_day("#{params[:year]}-#{params[:month]}-#{params[:day]}")

      reservations.to_json
{'fraction_non_alphanumeric': 0.1305375073833432, 'fraction_numerical': 0.005316007088009451, 'mean_word_length': 2.7016393442622952, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2830082', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1098, 'n_words': 268}