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

require 'dm-core'
require 'dm-validations'
require 'dm-types'
require 'dm-timestamps'

Dir.glob(File.join(File.dirname(__FILE__), 'models', '*.rb')).each do |model|
  require model
end

module Flapjack
  module CheckBackends
    class Datamapper
      def initialize(options={})
        @options = options
        @config = OpenStruct.new(options)
      end
    end<commit_msg>filled in datamapper backend<commit_after>#!/usr/bin/env ruby 

require 'dm-core'
require 'dm-validations'
require 'dm-types'
require 'dm-timestamps'

Dir.glob(File.join(File.dirname(__FILE__), 'models', '*.rb')).each do |model|
  require model
end

module Flapjack
  module CheckBackends
    class Datamapper
      def initialize(options={})
        @options = options
        @config = OpenStruct.new(options)
        @log = @config.log
        connect
      end

      def any_parents_failed?(result)
        check = Check.get(result.id)
        check.worst_parent_status != 0
      end

      def save(result)
        check = Check.get(result.id)
        check.status = result.status
        check.save
      end

      def create_event(result)
        event = Event.new(:check_id => result.id)
        event.save
      end

      private 
      def connect
        raise ArgumentError, "Database URI wasn't specified" unless @config.uri
        DataMapper.setup(:default, @config.uri)
        validate
      end

      def validate
        begin
          DataMapper.repository(:default).adapter.execute("SELECT 'id' FROM 'checks';")
        rescue Sqlite3Error => e
          @log.warning("The specified database doesn't appear to have any structure!")
          @log.warning("Exiting.")
          raise
        end
      end
    end
{'fraction_non_alphanumeric': 0.10610382201939532, 'fraction_numerical': 0.0011409013120365088, 'mean_word_length': 2.452755905511811, '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': '3950138', 'n_tokens_mistral': 531, 'n_tokens_neox': 515, 'n_words': 129}