<commit_before><commit_msg>initial predictions interface<commit_after>require APP_ROOT.join('app', 'models', 'transit')

class Prediction # CURRENTLY NOT INHERITING FROM AR::BASE

  ### class ###

  def self.resource
    'getpredictions'
  end

  extend TransitHelpers

  ### instance ###
  attr_reader :data, :time
  def initialize(stop_id, num_of_preds="4")
    @data = prettify(Prediction.get([{ :key => 'stpid', :val => stop_id }, { :key => 'top', :val => num_of_preds }])['bustime_response']['prd'])

    @time = SystemTime.get
  end

  private
  def prettify(ugly) # the CTA naming conventions are bad; make them nicer
    unless ugly.is_a? Array # wrap in array if not already
      ugly = [ugly]
    end

    # I only care about arrivals, so ignore departures
    ugly.select { |pred| pred['typ'] == 'A' }.
    map do |pred|
      { :type => 'arrival',
        :name => pred['stpnm'],
        :stop_id => pred['stpid'], # in DB for Stop is 'number', but this is Prediction
        :route_number => pred['rt'],
        :direction => pred['rtdir'],
        :destination => pred['des'],
        :timestamp => pred['tmstmp'],
        :arrival_time => pred['prdtm'] }
    end
  end
end

{'fraction_non_alphanumeric': 0.15306980656013458, 'fraction_numerical': 0.0008410428931875525, 'mean_word_length': 3.219858156028369, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1039316', 'n_tokens_mistral': 401, 'n_tokens_neox': 389, 'n_words': 109}