<commit_before>#!/usr/bin/env ruby

$:.push(File.expand_path(File.join(__FILE__, '..', 'lib')))

require 'sinatra'
require 'influx'
require 'haml'
require 'date'
require 'highcharts'
require 'uri'

influxdb = Influx::Db.new

get '/' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/#{today}/#{today}"
end

get '/alert-frequency/?' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/alert-frequency/#{today}/#{today}"
end

get '/alert-response/?' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/alert-response/#{today}/#{today}"
end

get '/noise-candidates/?' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/noise-candidates/#{today}/#{today}"
end

def search_precondition
  return "" unless @search
  @search = URI.escape(@search)
  "and incident_key =~ /.*#{@search}.*/i"
end

get '/:start_date/:end_date' do
  @categories = [
    'not set',
    'real',
    'improved',
    'self recovered',
    'needs documentation',
    'unclear, needs discussion'
  ]
  @start_date = params["start_date"]
  @end_date   = params["end_date"]
  @search     = params["search"]
puts search_precondition
  @incidents = influxdb.find_incidents(@start_date, @end_date, {:conditions => search_precondition })
  haml :"index"
end

get '/alert-frequency/:start_date/:end_date' do
  @start_date = params["start_date"]<commit_msg>Remove debugging code<commit_after>#!/usr/bin/env ruby

$:.push(File.expand_path(File.join(__FILE__, '..', 'lib')))

require 'sinatra'
require 'influx'
require 'haml'
require 'date'
require 'highcharts'
require 'uri'

influxdb = Influx::Db.new

get '/' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/#{today}/#{today}"
end

get '/alert-frequency/?' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/alert-frequency/#{today}/#{today}"
end

get '/alert-response/?' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/alert-response/#{today}/#{today}"
end

get '/noise-candidates/?' do
  today = Time.now.strftime("%Y-%m-%d")
  redirect "/noise-candidates/#{today}/#{today}"
end

def search_precondition
  return "" unless @search
  @search = URI.escape(@search)
  "and incident_key =~ /.*#{@search}.*/i"
end

get '/:start_date/:end_date' do
  @categories = [
    'not set',
    'real',
    'improved',
    'self recovered',
    'needs documentation',
    'unclear, needs discussion'
  ]
  @start_date = params["start_date"]
  @end_date   = params["end_date"]
  @search     = params["search"]
  @incidents = influxdb.find_incidents(@start_date, @end_date, {:conditions => search_precondition })
  haml :"index"
end

get '/alert-frequency/:start_date/:end_date' do
  @start_date = params["start_date"]
{'fraction_non_alphanumeric': 0.19479048697621745, 'fraction_numerical': 0.0, 'mean_word_length': 4.206286836935167, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5235197', 'n_tokens_mistral': 995, 'n_tokens_neox': 965, 'n_words': 191}