<commit_before>

module ApplicationHelpers
  API_BASE_URI = 'http://trendcrawl.herokuapp.com'
  API_VER = '/api/v1/'

  def current_page?(path = ' ')
    path_info = request.path_info
    path_info += ' ' if path_info == '/'
    request_path = path_info.split '/'
    request_path[1] == path
  end

  def api_url(res)
    URI.join(API_BASE_URI, API_VER, res).to_s
  end

  def error_send(url, msg)
    flash[:error] = msg
    redirect url
    halt 303        # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  end

  # Show the according links in each keyword area
  def right_nav(tag)
    @tags = tag
    options = { headers: { 'Content-Type' => 'application/json' }, query: { :tags => @tags } }
    @open_url = HTTParty.get(api_url('article/filter'), options)
    @list = {}

    @n = link_num(5) - 1

    for i in 0..@n
      viewid = @open_url[i]['link'][-5..-1] # Extract view id from article link
      article_url = '/article?viewid=' + viewid
      @list[@open_url[i]['title']] = article_url
    end
    @list
  end

  # Decide the amount of links to show.
  def link_num(num)
    unless (@open_url.length) < num
      @link_num = num
    else
      @link_num = @open_url.length
    end
  end

  def add_keyword(keyword)
    options = { headers: { 'Content-Type' => 'application/json' }, query: { :tags => keyword } }
    @open_url = HTTParty.get(api_url('article/filter'), options)

    if session[:hot_keywords].include? keyword
      flash[:notice] = 'Keyword already exists.'
    else
      unless @open_url.length == 0
        session[:hot_keywords] << keyword 
      else
        flash[:notice] = 'No matched articles. We cannot add this keyword.'
      end
    end

    redirect '/'
  end

  def del_keyword(keyword)
    session[:hot_keywords].delete(keyword)
    redirect '/'
  end
end
<commit_msg>add method to count number of article<commit_after>

module ApplicationHelpers
  API_BASE_URI = 'http://trendcrawl.herokuapp.com'
  API_VER = '/api/v1/'

  def current_page?(path = ' ')
    path_info = request.path_info
    path_info += ' ' if path_info == '/'
    request_path = path_info.split '/'
    request_path[1] == path
  end

  def api_url(res)
    URI.join(API_BASE_URI, API_VER, res).to_s
  end

  def error_send(url, msg)
    flash[:error] = msg
    redirect url
    halt 303        # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  end

  # Show the according links in each keyword area
  def right_nav(tag)
    @tags = tag
    options = { headers: { 'Content-Type' => 'application/json' }, query: { :tags => @tags } }
    @open_url = HTTParty.get(api_url('article/filter'), options)
    @list = {}

    @n = link_num(5) - 1

    for i in 0..@n
      viewid = @open_url[i]['link'][-5..-1] # Extract view id from article link
      article_url = '/article?viewid=' + viewid
      @list[@open_url[i]['title']] = article_url
    end
    @list
  end

  # Decide the amount of links to show.
  def link_num(num)
    unless (@open_url.length) < num
      @link_num = num
    else
      @link_num = @open_url.length
    end
  end

  def add_keyword(keyword)
    options = { headers: { 'Content-Type' => 'application/json' }, query: { :tags => keyword } }
    @open_url = HTTParty.get(api_url('article/filter'), options)

    if session[:hot_keywords].include? keyword
      flash[:notice] = 'Keyword already exists.'
    else
      unless @open_url.length == 0
        session[:hot_keywords] << keyword
      else
        flash[:notice] = 'No matched articles. We cannot add this keyword.'
      end
    end

    redirect '/'
  end

  def del_keyword(keyword)
    session[:hot_keywords].delete(keyword)
    redirect '/'
  end

  def count_article(tag, articles)
    @keyword = tag
    @article = articles
    @count_data = [
      { "keyword": "#{@keyword}" },
      { "data": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] }
    ]
    for i in 0...@article.length
      article_belong_which_month = Time.parse(@article[i]['date']).strftime('%m').to_i
      @count_data[1][:data][article_belong_which_month - 1] += 1
    end
    @count_data.to_json
  end
end

{'fraction_non_alphanumeric': 0.13876651982378854, 'fraction_numerical': 0.014684287812041116, 'mean_word_length': 2.7461044912923924, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 1, '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': '6319754', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1407, 'n_words': 335}