<commit_before>class MapDisplayController < ApplicationController
  def map

    # Select Leaflet image based on browser
    browser = Browser.new(request.user_agent)
    @extension = ".png"

    if (browser.chrome? or browser.firefox? or browser.safari?) and !browser.platform.ios? and !browser.platform.android?
      @extension = ".svg"
    end

    # Read URL params
    @shelfmark = params[:shelfmark]
    identifier = params[:identifier]
    @library = params[:library]
    @floor = params[:floor]
    @title = params[:title]
    @author = params[:author]
    @element_name = params[:element_name]
    if session[:ui_view].nil? then
      session[:ui_view] = params[:view]
    end

    unless @floor
      @floor = 1
    end

    unless @library
      @library = "main"
    end

    unless identifier
      identifier = "lc_hub"
    end

    # If URL is passing paramenters
    if @shelfmark and @library and @floor
        @is_searching = true
        
        unless browser.platform.ios? or browser.platform.android? or browser.platform.windows_phone?
          @qr = RQRCode::QRCode.new(request.original_url)
        end

        #If Main Library Floor is passed through, else floor needs to be calculated
        if @library == "main"
          # Matches all the shelves in the EAS Collection
          if identifier == "eas_main"
            @elements = Element.where("identifier = :identifier AND library = :library AND floor = :floor", {identifier: identifier, library: @library, floor: @floor})

            # Matches all the file in special collections (C.A.S., Watt, Smith, Serjeant)
          elsif @shelfmark.match(/^(Smith Coll.|Watt Coll.|Serj. Coll.|C.A.S.)/)
            identifier = "cwss_main"
            @elements = Element.where("identifier = :identifier AND library = :library AND floor = :floor", {identifier: identifier, library: @library, floor: @floor})

            # Matches all other shelves (HUB, Library of Congress, Dewey Decimal...)
          else
            shelfmarkNumber = shelfmarkToOrder(@shelfmark, identifier)
            @elements = Element.where("range_end >= :shelfmark AND range_start <= :shelfmark AND library = :library AND floor = :floor AND identifier = :identifier", {shelfmark: shelfmarkNumber, library: @library, floor: @floor, identifier: identifier})
          end
        else
          shelfmarkNumber = shelfmarkToOrder(@shelfmark, identifier)
          @elements = Element.where("range_end >= :shelfmark AND range_start <= :shelfmark AND library = :library AND identifier = :identifier", {shelfmark: shelfmarkNumber, library: @library, identifier: identifier})
          @floor = @elements[0].floor
        end
    end<commit_msg>Nicer error screen when no shelfmark passed through #40<commit_after>class MapDisplayController < ApplicationController
  def map

    # Select Leaflet image based on browser
    browser = Browser.new(request.user_agent)
    @extension = ".png"

    if (browser.chrome? or browser.firefox? or browser.safari?) and !browser.platform.ios? and !browser.platform.android?
      @extension = ".svg"
    end

    # Read URL params
    @shelfmark = params[:shelfmark]
    identifier = params[:identifier]
    @library = params[:library]
    @floor = params[:floor]
    @title = params[:title]
    @author = params[:author]
    @element_name = params[:element_name]
    if session[:ui_view].nil? then
      session[:ui_view] = params[:view]
    end

    unless @floor
      @floor = 1
    end

    unless @library
      @library = "main"
    end

    unless identifier
      identifier = "lc_hub"
    end

    # If URL is passing paramenters
    if @shelfmark and @library and @floor
        @is_searching = true
        
        unless browser.platform.ios? or browser.platform.android? or browser.platform.windows_phone?
          @qr = RQRCode::QRCode.new(request.original_url)
        end

        #If Main Library Floor is passed through, else floor needs to be calculated
        if @library == "main"
          # Matches all the shelves in the EAS Collection
          if identifier == "eas_main"
            @elements = Element.where("identifier = :identifier AND library = :library AND floor = :floor", {identifier: identifier, library: @library, floor: @floor})

            # Matches all the file in special collections (C.A.S., Watt, Smith, Serjeant)
          elsif @shelfmark.match(/^(Smith Coll.|Watt Coll.|Serj. Coll.|C.A.S.)/)
            identifier = "cwss_main"
            @elements = Element.where("identifier = :identifier AND library = :library AND floor = :floor", {identifier: identifier, library: @library, floor: @floor})

            # Matches all other shelves (HUB, Library of Congress, Dewey Decimal...)
          else
            shelfmarkNumber = shelfmarkToOrder(@shelfmark, identifier)
            @elements = Element.where("range_end >= :shelfmark AND range_start <= :shelfmark AND library = :library AND floor = :floor AND identifier = :identifier", {shelfmark: shelfmarkNumber, library: @library, floor: @floor, identifier: identifier})
          end
        else
          shelfmarkNumber = shelfmarkToOrder(@shelfmark, identifier)
          @elements = Element.where("range_end >= :shelfmark AND range_start <= :shelfmark AND library = :library AND identifier = :identifier", {shelfmark: shelfmarkNumber, library: @library, identifier: identifier})
          if @elements.any?
            @floor = @elements[0].floor
          end
        end
    end
{'fraction_non_alphanumeric': 0.10551296093464768, 'fraction_numerical': 0.001095290251916758, 'mean_word_length': 2.861169837914024, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '4029566', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1484, 'n_words': 464}