<commit_before>require "rubygems"
require "sequel"
require "pinger/version"

module Pinger
  class Pinger::DatabaseError < StandardError; end
  
  class << self
    
    def connection
      return @connection if @connection
      begin
        @connection = Sequel.connect ENV["PINGER_DB"]
      rescue Exception => e
        puts "*" * 88
        puts "Error while connecting to database"
        puts e.message
        puts "*" * 88
      end
      @connection
    end
    alias :db :connection
    
    def connect
      raise Pinger::DatabaseError if connection.nil?
    end
    
    def create_schema
      
      unless db.table_exists?(:domains)
        db.create_table :domains do
          primary_key :id
          String      :domain, :unique => true, :null => false
          DateTime    :created_at
          index       :created_at
        end        
      end
      
      unless db.table_exists?(:pings)
        db.create_table :pings do
          primary_key :id
          foreign_key :domain_id, :domains, :key => :id
          String      :status
          column      :response, :text
          Float       :response_time
          DateTime    :created_at
          index       :created_at
        end
      end
      
    end
        
    def init!
      connect
      create_schema
    end
    
  end
  
end

Pinger.init!

require "pinger/domain"
require "pinger/ping"
<commit_msg>add require models method in pinger#init<commit_after>require "rubygems"
require "sequel"
require "pinger/version"

module Pinger
  class Pinger::DatabaseError < StandardError; end
  
  class << self
    
    def connection
      return @connection if @connection
      begin
        @connection = Sequel.connect ENV["PINGER_DB"]
      rescue Exception => e
        puts "*" * 88
        puts "Error while connecting to database"
        puts e.message
        puts "*" * 88
      end
      @connection
    end
    alias :db :connection
    
    def connect
      raise Pinger::DatabaseError if connection.nil?
    end
    
    def create_schema
      
      unless db.table_exists?(:domains)
        db.create_table :domains do
          primary_key :id
          String      :domain, :unique => true, :null => false
          DateTime    :created_at
          index       :created_at
        end        
      end
      
      unless db.table_exists?(:pings)
        db.create_table :pings do
          primary_key :id
          foreign_key :domain_id, :domains, :key => :id
          String      :status
          column      :response, :text
          Float       :response_time
          DateTime    :created_at
          index       :created_at
        end
      end
      
    end
    
    def require_models
      require "pinger/domain"
      require "pinger/ping"
    end
        
    def init!
      connect
      create_schema
      require_models
    end
    
  end
  
end

Pinger.init!

{'fraction_non_alphanumeric': 0.06643717728055078, 'fraction_numerical': 0.002753872633390706, 'mean_word_length': 1.618018018018018, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '6559928', 'n_tokens_mistral': 828, 'n_tokens_neox': 821, 'n_words': 231}