<commit_before>require "sinatra"
require "dotenv"
require "logger"
require "fileutils"
require "sequel"

Dotenv.load

require_relative "lib/database"


require_relative "lib/recondb"
require_relative "routes/average"
require_relative "routes/solve"
require_relative "routes/field"
require_relative "routes/auth"
require_relative "routes/contributors"

use Rack::Session::Cookie, secret: ENV.fetch("SECRET") { "Hidden!" }
use Rack::Flash

helpers RCDB::ViewHelpers
helpers RCDB::Helpers
helpers RCDB::FormattingUtils
helpers Padrino::Helpers

get "/" do
  # only check searches for non-logged in users
  if !params.empty? && current_user.nil?
    DB[:searches].insert(
      timestamp: Time.now.utc.to_i,
      solver: params["solver"],
      competition: params["competition"],
      puzzle: params["puzzle"],
      time_specifier: params["time_specifier"],
      time_value: params["time_value"],
      tags: params["tags"],
      ip_hash: Digest::SHA1.hexdigest(request.ip)
    )
  end
  @solves = RCDB::Solve.request(params).order_by(Sequel.desc(:date_added))
  erb :index
end

# HACK...
get "/stats" do
  authenticate!
  erb :search_stats, locals: { searches: DB[:searches] }
end

not_found do<commit_msg>changing the page is not a search<commit_after>require "sinatra"
require "dotenv"
require "logger"
require "fileutils"
require "sequel"

Dotenv.load

require_relative "lib/database"


require_relative "lib/recondb"
require_relative "routes/average"
require_relative "routes/solve"
require_relative "routes/field"
require_relative "routes/auth"
require_relative "routes/contributors"

use Rack::Session::Cookie, secret: ENV.fetch("SECRET") { "Hidden!" }
use Rack::Flash

helpers RCDB::ViewHelpers
helpers RCDB::Helpers
helpers RCDB::FormattingUtils
helpers Padrino::Helpers

get "/" do
  # only check searches for non-logged in users which are actually searches
  if params.has_key?("solver") && current_user.nil?
    DB[:searches].insert(
      timestamp: Time.now.utc.to_i,
      solver: params["solver"],
      competition: params["competition"],
      puzzle: params["puzzle"],
      time_specifier: params["time_specifier"],
      time_value: params["time_value"],
      tags: params["tags"],
      ip_hash: Digest::SHA1.hexdigest(request.ip)
    )
  end
  @solves = RCDB::Solve.request(params).order_by(Sequel.desc(:date_added))
  erb :index
end

# HACK...
get "/stats" do
  authenticate!
  erb :search_stats, locals: { searches: DB[:searches] }
end

not_found do
{'fraction_non_alphanumeric': 0.12959224868792896, 'fraction_numerical': 0.0008074283407347598, 'mean_word_length': 4.971084337349398, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5018733', 'n_tokens_mistral': 837, 'n_tokens_neox': 851, 'n_words': 185}