<commit_before>class Stella

  module MetricsCollector
    def rangemetrics
      @rangemetrics ||= Stella::RangeMetrics.new self.class.name, objid
    end
    def add_metrics time, metrics
      rangemetrics.metrics[metrics.to_json] = time.to_i
      # TODO: past_1hour via rangemetrics.range or call LUA script
    end
  end

  class Host
    include Stella::MetricsCollector
    alias_method :objid, :hostid
    def normalize
      update_timestamps
      self.hostname ||= Stella::Utils.host(hostname)
      self.hostid ||= gibbler
      self.custid ||= customer.custid if customer
    end
    def start! prodid=nil
      prodid ||= self.product.prodid if self.product
      self.hidden = false
      self.monitored = true
      plans = self.testplans :hidden => false, :order => [ :enabled.desc, :uri ], :limit => 1
      if plans.first && !plans.first.enabled?
        plans.first.enabled = true
        # something here?
        plans.first.save
      elsif plans.empty?
        uri = Stella::Utils.uri(hostname)
        Stella::Testplan.create :host => self, uri => uri, :enabled => true
      end
      normalize
      self.update_product prodid
      self.product.active = true
      save
      Stella::Host.schedule self
    end
    def stop!
      self.monitored = false
      normalize
      self.product.active = false if self.product
      ## don't deschedule. See Host.deschedule comment.
      save
    end
    def destroy!
      self.screenshots.destroy!
      self.contacts.destroy!
      self.checkups.screenshots.destroy!
      self.checkups.destroy!
      self.testruns.destroy!
      self.testplans.checkups.screenshots.destroy!
      self.testplans.checkups.destroy!
      self.testplans.destroy!
      super
    end
    def customer? cust
      customer == cust
    end
    def shortname
      hostname.shorten(20)
    end<commit_msg>Host#destroy should destroy product records too<commit_after>class Stella

  module MetricsCollector
    def rangemetrics
      @rangemetrics ||= Stella::RangeMetrics.new self.class.name, objid
    end
    def add_metrics time, metrics
      rangemetrics.metrics[metrics.to_json] = time.to_i
      # TODO: past_1hour via rangemetrics.range or call LUA script
    end
  end

  class Host
    include Stella::MetricsCollector
    alias_method :objid, :hostid
    def normalize
      update_timestamps
      self.hostname ||= Stella::Utils.host(hostname)
      self.hostid ||= gibbler
      self.custid ||= customer.custid if customer
    end
    def start! prodid=nil
      prodid ||= self.product.prodid if self.product
      self.hidden = false
      self.monitored = true
      plans = self.testplans :hidden => false, :order => [ :enabled.desc, :uri ], :limit => 1
      if plans.first && !plans.first.enabled?
        plans.first.enabled = true
        # something here?
        plans.first.save
      elsif plans.empty?
        uri = Stella::Utils.uri(hostname)
        Stella::Testplan.create :host => self, uri => uri, :enabled => true
      end
      normalize
      self.update_product prodid
      self.product.active = true
      save
      Stella::Host.schedule self
    end
    def stop!
      self.monitored = false
      normalize
      self.product.active = false if self.product
      ## don't deschedule. See Host.deschedule comment.
      save
    end
    def destroy!
      self.screenshots.destroy!
      self.contacts.destroy!
      self.checkups.screenshots.destroy!
      self.checkups.destroy!
      self.testruns.destroy!
      self.testplans.checkups.screenshots.destroy!
      self.testplans.checkups.destroy!
      self.testplans.destroy!
      self.products.destroy!
      super
    end
    def customer? cust
      customer == cust
    end
    def shortname
      hostname.shorten(20)
    end
{'fraction_non_alphanumeric': 0.08939434012166093, 'fraction_numerical': 0.0021158423697434543, 'mean_word_length': 2.3919282511210764, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '5252567', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1161, 'n_words': 271}