<commit_before>class RequestsController < ApplicationController
  # 10 miles = 16100 meters
  ACTIVE_RADIUS = 16100
  def index
    @songs = Song.all
    @artists = Artist.all

    return_array =[]

    @song_list = []
    @user_loc = [params[:lat], params[:long]]

    @songs.each do |song|
      array = []
      array.push(song.locations.first.lat)
      array.push(song.locations.first.long)
      if distance_between(@user_loc, array) < song.locations.first.radius
        return_array.push(song)
      else
        false
      end
    end

    render :json => return_array, :include => {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}}, :include => :locations



    # # def active_songs
    # active_songs_array = active_songs(@songs)
    # nearby_songs_array = nearby_songs(active_songs_array, @user_loc)
    # render :json => nearby_songs_array, :include {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}, :favorites, :listens}
  end

  def near
    @songs = Song.all
    @artists = Artist.all
    return_array =[]

    @song_list = []
    p"++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    p params
    @user_loc = [params[:lat], params[:long]]
    @test_loc =[40.7484, 73.9857]

    @songs.each do |song|
      array = []
      array.push(song.locations.first.lat)
      array.push(song.locations.first.long)
      if distance_between(@user_loc, array) < song.locations.first.radius*1610
        return_array.push(song)
      end
    end
    print return_array
    render :json => return_array, :include => {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}}, :include => :locations



    result = distance_between(@user_loc, @test_loc)
    puts result


  end

  def near_songs
    p"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
  end

private

  def distance_between(point_one, point_two)
    Geocoder::Calculations.distance_between(point_one, point_two)*1000
  end

  def active_songs(song_collection)
    active_songs = []
    song_collection.each do |song|
      if song.locations.first.active?
        active_songs << song
      end
    end

    print return_array
    render :json => return_array, :include => {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}}, :include => :locations<commit_msg>fix routes<commit_after>class RequestsController < ApplicationController
  # 10 miles = 16100 meters
  ACTIVE_RADIUS = 16100
  def index
    @songs = Song.all
    @artists = Artist.all

    return_array =[]

    @song_list = []
    @user_loc = [params[:lat], params[:long]]

    @songs.each do |song|
      array = []
      array.push(song.locations.first.lat)
      array.push(song.locations.first.long)
      if distance_between(@user_loc, array) < song.locations.first.radius && song.locations.first.expiration >= Time.now
        return_array.push(song)
      else
        false
      end
    end

    render :json => return_array, :include => {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}}, :include => :locations



    # # def active_songs
    # active_songs_array = active_songs(@songs)
    # nearby_songs_array = nearby_songs(active_songs_array, @user_loc)
    # render :json => nearby_songs_array, :include {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}, :favorites, :listens}
  end

  def near
    @songs = Song.all
    @artists = Artist.all
    return_array =[]

    @song_list = []
    p"++++++++++++++++++++++++++++++++++++++++++++++++++++++"
    p params
    @user_loc = [params[:lat], params[:long]]
    @test_loc =[40.7484, 73.9857]

    @songs.each do |song|
      array = []
      array.push(song.locations.first.lat)
      array.push(song.locations.first.long)
      if distance_between(@user_loc, array) < song.locations.first.radius*1610  && song.locations.first.expiration >= Time.now
        return_array.push(song)
      end
    end
    print active_songs(return_array)
    render :json => return_array, :include => {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}}, :include => :locations



    result = distance_between(@user_loc, @test_loc)
    puts result


  end

  def near_songs
    p"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
  end

private

  def distance_between(point_one, point_two)
    Geocoder::Calculations.distance_between(point_one, point_two)*1000
  end

  def active_songs(song_collection)
    active_songs = []
    song_collection.each do |song|
      if song.locations.first.active?
        active_songs << song
      end
    end

    print return_array
    render :json => return_array, :include => {:artist => {:only => [:name, :hometown, :bio, :profile_picture]}, :comments => {:only => [:content]}}, :include => :locations
{'fraction_non_alphanumeric': 0.18196392785571142, 'fraction_numerical': 0.01282565130260521, 'mean_word_length': 3.5004508566275923, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 57, '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': '1543870', 'n_tokens_mistral': 1773, 'n_tokens_neox': 1592, 'n_words': 336}