Skip to content

Previous Data Analytics description

Fabio Lima edited this page Apr 24, 2022 · 2 revisions

We have two models related to data analytics:

  • Analytic
  • ListedOption

Analytic

Has many ListedOptions

  create_table "analytics", force: :cascade do |t|
    t.string   "sessionID"
    t.datetime "time"
    t.string   "cookieID"
    t.string   "service",                    null: false
    t.decimal  "lat",                        null: false
    t.decimal  "long",                       null: false
    t.decimal  "facility"
    t.boolean  "dirClicked", default: false
    t.string   "dirType"
  end

ListedOption

Belongs to Analytic

 create_table "listed_options", force: :cascade do |t|
    t.integer  "analytic_id"
    t.string   "sessionID",   null: false
    t.datetime "time",        null: false
    t.string   "facility",    null: false
    t.decimal  "position",    null: false
    t.decimal  "total",       null: false
  end

Unused Database Tables

Current the database has 2 tables that are not currently in use. They don't have implemented models and are just empty tables.

  create_table "anaylitics", force: :cascade do |t|
    t.decimal  "lat"
    t.decimal  "long"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

  create_table "impressions", force: :cascade do |t|
    t.string   "impressionable_type"
    t.integer  "impressionable_id"
    t.integer  "user_id"
    t.string   "controller_name"
    t.string   "action_name"
    t.string   "view_name"
    t.string   "request_hash"
    t.string   "ip_address"
    t.string   "session_hash"
    t.text     "message"
    t.text     "referrer"
    t.datetime "created_at"
    t.datetime "updated_at"
  end

Data collection

When a user sees a list of facilities, either by searching or by clicking in a specific service:

  • Collects latitude/longitude or sets them as 0.
  • Checks cookies for a non_data_user key.
  • If non_data_user is blank:
    • Sets a UUID to session[:id] if not present;
    • Sets UUID to session[:userid] if not present;
    • Creates an Analytic;
    • Set session[:current_data] to the new analytic id;
    • Creates a ListedOption for each Facility selected to be displayed to the user.
      if !cookies[:non_data_user].present?
        if !session[:id].present?
          session[:id] = SecureRandom.uuid
        end
        if !cookies[:userid].present?
          cookies[:userid] = SecureRandom.uuid
        end

        @analytic = Analytic.new do |a|
          a.sessionID = session[:id]
          a.time = Time.new
          a.cookieID = cookies[:userid]
          a.service = params[:scope]
          a.lat = @latitude
          a.long = @longitude
        end

        if @analytic.save
          session[:current_data] = @analytic.id
          puts "Test"
          @facilities_near_yes.each_with_index do |f, i|
            @option = ListedOption.new do |o|
              o.analytic_id = @analytic.id
              o.sessionID = session[:id]
              o.time = @analytic.time
              o.facility = f.name
              o.position = i + 1
              o.total = @facilities_near_yes.length
            end
            @option.save
          end
        end
      end

When a user clicks on a facility to see the facility's details:

  • If session[:current_data] is present:
    • Find the Analytic (using current_data which was set as the analytic id);
    • Sets the Analytic's facility attribute to the current facility id.
  def show
    @facility = Facility.find(params[:id])

    if session['facilities_category']
      add_breadcrumb session['facilities_category'], session['facilities_list']
    end
    add_breadcrumb @facility.name
    
    if session[:current_data].present?
      @analytic = Analytic.find(session[:current_data])
      @analytic.facility = @facility.id
      @analytic.save
    else
      puts 'ERROR DATA NOT FOUND'
    end
  end

When a user clicks on directions in a facility:

  • If session[:current_data] is present:
    • Find the Analytic;
    • Sets the Analytic's attributes: dirClicked to true, dirType to 'Walking'.
  def directions
    @facility = Facility.find(params[:id])
    if session[:current_data].present?
      @analytic = Analytic.find(session[:current_data])
      @analytic.dirClicked = true
      @analytic.dirType = "Walking"
      @analytic.save
    end
  end
Clone this wiki locally