<commit_before>class AdminController < ApplicationController
  respond_to :html

  before_filter :authenticate, :setup_i18n

  helper_method :current_user, :current_ability

  # GET /admin/index
  def index
    @status_codes = Notification::VALID_STATUSES 
    @delivery_methods = Notification::VALID_DELIVERY_METHODS
    @notifiers = current_user.notifiers.active.reorder(:name)

    # move the internal notifier to the end
    internal_username = Notifier.internal.try(:username)
    if internal_pos = @notifiers.index {|n| n.username == internal_username }
      @notifiers << @notifiers.delete_at(internal_pos)
    end

    status_data = @notifiers.map do |notifier|
      #notif_time = Notifier.where(:username=>'balaka-notifier').first.last_status_req_at
      #notif_hours_ago = ((Time.now - time)/3600).to_i
      notif_hours_ago = rand(60); notif_time = Time.zone.now - notif_hours_ago.hours  #DEMO only to check class helper

      #TODO:  get last report sync from contents ot mtime of report file
      last_report_sync = Date.today.beginning_of_month + 5.days
      [notifier.username, {'hours_ago'=>notif_hours_ago, 'last_notif_sync'=>notif_time, 'last_notif_hours_ago'=>notif_hours_ago, 'last_report_sync'=>last_report_sync} ]
    end

    @status = Hash[status_data]
    
    short_fmt='%d%b'
    url_fmt='%Y-%m-%d'
    @date_range_data = {
      'today'     => {'start' => Date.today,           'end' => Date.today},<commit_msg>Real data for notifier & report dashboard status<commit_after>class AdminController < ApplicationController
  respond_to :html

  before_filter :authenticate, :setup_i18n

  helper_method :current_user, :current_ability

  REPORT_PATH = '/var/www/apps/hms-deploy-ccpf/hms-hub/reports/'
  # GET /admin/index
  def index
    @status_codes = Notification::VALID_STATUSES 
    @delivery_methods = Notification::VALID_DELIVERY_METHODS
    @notifiers = current_user.notifiers.active.reorder(:name)

    # move the internal notifier to the end
    internal_username = Notifier.internal.try(:username)
    if internal_pos = @notifiers.index {|n| n.username == internal_username }
      @notifiers << @notifiers.delete_at(internal_pos)
    end

    status_data = @notifiers.map do |notifier|
      notif_time = Notifier.where(:username=>notifier.username).first.last_status_req_at
      notif_hours_ago = ((Time.now - notif_time)/3600).to_i

      begin
        last_report_sync = File.mtime(REPORT_PATH+notifier.username)
      rescue Exception => e
        logger.warn "Error getting mtime of #{REPORT_PATH+notifier.username}: #{e.inspect}"
        last_report_sync = 'unknown'
      end
      [notifier.username, {'last_notif_sync'=>notif_time, 'last_notif_hours_ago'=>notif_hours_ago, 'last_report_sync'=>last_report_sync} ]
    end

    @status = Hash[status_data]
    
    short_fmt='%d%b'
    url_fmt='%Y-%m-%d'
    @date_range_data = {
      'today'     => {'start' => Date.today,           'end' => Date.today},
{'fraction_non_alphanumeric': 0.11366711772665765, 'fraction_numerical': 0.005074424898511502, 'mean_word_length': 3.9119601328903655, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '3379837', 'n_tokens_mistral': 1018, 'n_tokens_neox': 965, 'n_words': 176}