<commit_before>require 'miletus'

require 'atom'
require 'date'

class RecordController < ApplicationController

  def index
    concepts = Miletus::Merge::Concept.order(:sort_key).all
    @concepts, @types = [], Set.new
    concepts.each do |c|
      next if c.type.nil?
      @types << c.type
      @concepts << c
    end
  end

  def view
    k = [:id, :uuid].detect {|sym| params.key?(sym) }
    @concept = Miletus::Merge::Concept.send('find_by_%s!' % k, params[k])
    # Redirect if a better path exists
    if k == :id and @concept.uuid
      redirect_to :action => 'view', :uuid => @concept.uuid, :status => 301
    end
    @doc = Miletus::Merge::RifcsDoc.create(@concept.to_rif)
  end

  def view_format
    case params[:format]
    when 'html'
      redirect_to :action => 'view', :uuid => params[:uuid], :status => 301
    when 'rifcs.xml'
      concept = Miletus::Merge::Concept.find_by_uuid(params[:uuid]) || not_found
      if stale?(:last_modified => concept.updated_at, :public => true)
        xml = concept.to_rif || not_found
        render :text => xml, :content_type => 'text/xml'
      end
    else
      not_found
    end
  end

  def graph
    # No data required
  end

  def atom
    if params[:date]
      begin
        date = Date.iso8601(params[:date])
      rescue ArgumentError
        return render :text => '', :status => :bad_request
      end
      expires_in(30.days, :public => true) if date < Date.today
      render :content_type => 'application/atom+xml',
        :text => Miletus::Output::Atom::feed(date, url_options).to_xml
    else
      redirect_to :action => 'atom',
        :date => DateTime.now.utc.strftime('%Y-%m-%d'),
        :status => 303
    end
  end

  def gexf
    target = params.key?(:id) ?
      Miletus::Merge::Concept.find_by_id!(params[:id]) : Miletus::Merge::Concept
    if stale?(:last_modified => target.updated_at, :public => true)
      render :text => target.to_gexf, :content_type => 'text/xml'<commit_msg>Adding fairly rudimentary 304 Not Modified support for Atom.<commit_after>require 'miletus'

require 'atom'
require 'date'

class RecordController < ApplicationController

  def index
    concepts = Miletus::Merge::Concept.order(:sort_key).all
    @concepts, @types = [], Set.new
    concepts.each do |c|
      next if c.type.nil?
      @types << c.type
      @concepts << c
    end
  end

  def view
    k = [:id, :uuid].detect {|sym| params.key?(sym) }
    @concept = Miletus::Merge::Concept.send('find_by_%s!' % k, params[k])
    # Redirect if a better path exists
    if k == :id and @concept.uuid
      redirect_to :action => 'view', :uuid => @concept.uuid, :status => 301
    end
    @doc = Miletus::Merge::RifcsDoc.create(@concept.to_rif)
  end

  def view_format
    case params[:format]
    when 'html'
      redirect_to :action => 'view', :uuid => params[:uuid], :status => 301
    when 'rifcs.xml'
      concept = Miletus::Merge::Concept.find_by_uuid(params[:uuid]) || not_found
      if stale?(:last_modified => concept.updated_at, :public => true)
        xml = concept.to_rif || not_found
        render :text => xml, :content_type => 'text/xml'
      end
    else
      not_found
    end
  end

  def graph
    # No data required
  end

  def atom
    if params[:date]
      begin
        date = Date.iso8601(params[:date])
      rescue ArgumentError
        return render :text => '', :status => :bad_request
      end
      expires_in(30.days, :public => true) if date < Date.today
      if stale?(:last_modified => Miletus::Merge::Concept.updated_at,
                :public => true)
        render :content_type => 'application/atom+xml',
          :text => Miletus::Output::Atom::feed(date, url_options).to_xml
      end
    else
      redirect_to :action => 'atom',
        :date => DateTime.now.utc.strftime('%Y-%m-%d'),
        :status => 303
    end
  end

  def gexf
    target = params.key?(:id) ?
      Miletus::Merge::Concept.find_by_id!(params[:id]) : Miletus::Merge::Concept
    if stale?(:last_modified => target.updated_at, :public => true)
      render :text => target.to_gexf, :content_type => 'text/xml'
{'fraction_non_alphanumeric': 0.14396887159533073, 'fraction_numerical': 0.008025291828793774, 'mean_word_length': 2.8619718309859157, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, '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': '5432653', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1362, 'n_words': 325}