<commit_before>class Ship < ActiveRecord::Base
    
  has_many :facility_instances, dependent: :destroy
  has_many :facilities, :through => :facility_instances
  has_one :user_ship
  has_one :user, :through => :user_ships
  has_many :ships_stations
  has_many :stations, :through => :ships_stations
  after_initialize :create_stations, if: :new_record?

  def update_resources
  	last_checked = self.lastChecked
		self.ships_stations.each do |station|
        if station.station_id == 2001	#metal
          self.metal += get_collect_difference(station.level, station.station_id, last_checked)
          #self.metal=0
        end
        if station.station_id == 2002	#cristal
          self.cristal += get_collect_difference(station.level, station.station_id, last_checked)
          #self.cristal=0
        end
        if station.station_id == 2003	#fuel
          self.fuel += get_collect_difference(station.level, station.station_id, last_checked)
          #self.fuel=0
        end
        
	end
    
    self.lastChecked = Time.now.getutc
    self.save
    
  end

  

  private
  def create_stations
    Station.all.each do |station|
      self.ships_stations.build(ship: self, station: station, level: station.initial_level)
      end
      self.metal=0
      self.cristal=0
      self.fuel=0
      self.lastChecked = Time.now.getutc
      return self.id
  end

  private
  def get_collect_difference(level, id, last_update)
  	if id==2001 || id==2002
  		start = 2000.0
    end
  	if(id==2003) 
  		start = 1000.0
		end
		start /= 3600.0
		time = Time.now.getutc
		start = start.to_f
		elapsed_seconds = time - last_update
		produktion = (start* (1.5 ** level))*(elapsed_seconds)
		return produktion
  end

 
end<commit_msg>Add function is_building and init to shib.rb<commit_after>class Ship < ActiveRecord::Base
    
  has_many :facility_instances, dependent: :destroy
  has_many :facilities, :through => :facility_instances
  has_one :user_ship
  has_one :user, :through => :user_ships
  has_many :ships_stations
  has_many :stations, :through => :ships_stations
  after_initialize :create_stations, if: :new_record?

  def is_building()
    facility_instances.each do |instance|
      if not(instance.start_time.nil?)
        return true
      end
    end
    return false
  end

  def update_resources
  	last_checked = self.lastChecked
		self.ships_stations.each do |station|
        if station.station_id == 2001	#metal
          self.metal += get_collect_difference(station.level, station.station_id, last_checked)
          #self.metal=0
        end
        if station.station_id == 2002	#cristal
          self.cristal += get_collect_difference(station.level, station.station_id, last_checked)
          #self.cristal=0
        end
        if station.station_id == 2003	#fuel
          self.fuel += get_collect_difference(station.level, station.station_id, last_checked)
          #self.fuel=0
        end
        
	end
    
    self.lastChecked = Time.now.getutc
    self.save
    
  end

  

  private
  def create_stations
    Station.all.each do |station|
      self.ships_stations.build(ship: self, station: station, level: station.initial_level)
      end
      self.metal=0
      self.cristal=0
      self.fuel=0
      self.lastChecked = Time.now.getutc
      return self.id
  end

  private
  def get_collect_difference(level, id, last_update)
  	if id==2001 || id==2002
  		start = 2000.0
    end
  	if(id==2003) 
  		start = 1000.0
		end
		start /= 3600.0
		time = Time.now.getutc
		start = start.to_f
		elapsed_seconds = time - last_update
		produktion = (start* (1.5 ** level))*(elapsed_seconds)
		return produktion
  end

      def init
      Facility.all.each do |facility|
        if not(facility_instances.exists?(:facility_id => facility.id, :ship_id => self.id))
          facility_instances.build(facility: facility, count: 0)
        end
      end
    end

 
end
{'fraction_non_alphanumeric': 0.09076923076923077, 'fraction_numerical': 0.02435897435897436, 'mean_word_length': 2.7509615384615387, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7203759', 'n_tokens_mistral': 1406, 'n_tokens_neox': 1286, 'n_words': 280}