<commit_before>module Money 

	def self.get_base
		Currency.find_by_is_base(true).code
	end

	def self.set_base(sym)	 
		currency = Currency.find_by_code(sym)
		unless (currency.nil? || get_base == sym)
		  currency.is_base = true
		  currency.save
		end	
	end

	def self.set_currency(options = {}) 
		from = Currency.find_by_code(options[:from])
		to = Currency.find_by_is_base(true)		
		rate = options[:rate]
		CalculatedExchangeRate.create(from_currency_id: from.id, to_currency_id: to.id, rate: rate) unless from.id == to.id 
	end

	def self.calculate
		base = Currency.find_by_is_base(true)
		cur_base = base.exchange_rates.last
		@curriencies = Currency.all.includes(:exchange_rates)
		@curriencies.each do |cur|
			cur_from = cur.exchange_rates.last			
			set_currency(from: cur.code, rate: (cur_from.rate/cur_base.rate).to_f.round(4))
		end
	end

	def self.get_currency(options={})
		from = Currency.find_by_code(options[:from])
		to = options[:to] ? Currency.find_by_code(options[:to]) : Currency.find_by_is_base(true)
		datetime = options[:datetime] ? options[:datetime] : DateTime.now

		unless from.id == to.id  
			currencyfrom = CalculatedExchangeRate.where("from_currency_id = ? and created_at < ?", from.id, datetime).last
			currencyto = CalculatedExchangeRate.where("from_currency_id = ? and created_at < ?", to.id, datetime).last
			(currencyfrom.rate/currencyto.rate).to_f.round(4) 
		else
			1.0
		end
	end
end
<commit_msg>Money get_currency update<commit_after>module Money 

	def self.get_base
		Currency.find_by_is_base(true).code
	end

	def self.set_base(sym)	 
		currency = Currency.find_by_code(sym)
		unless (currency.nil? || get_base == sym)
		  currency.is_base = true
		  currency.save
		end	
	end

	def self.set_currency(options = {}) 
		from = Currency.find_by_code(options[:from])
		to = Currency.find_by_is_base(true)		
		rate = options[:rate]
		CalculatedExchangeRate.create(from_currency_id: from.id, to_currency_id: to.id, rate: rate) unless from.id == to.id 
	end

	def self.calculate
		base = Currency.find_by_is_base(true)
		cur_base = base.exchange_rates.last
		@curriencies = Currency.all.includes(:exchange_rates)
		@curriencies.each do |cur|
			cur_from = cur.exchange_rates.last			
			set_currency(from: cur.code, rate: (cur_from.rate/cur_base.rate).to_f.round(4))
		end
	end

	def self.get_currency(options={})
		from = Currency.find_by_code(options[:from])
		to = options[:to] ? Currency.find_by_code(options[:to]) : Currency.find_by_is_base(true)
		datetime = options[:datetime] ? options[:datetime] : DateTime.now

		if from.id == to.id
			1.0
		elsif to.code == get_base 
			CalculatedExchangeRate.where("from_currency_id = ? and created_at < ?", from.id, datetime).last.rate
		elsif from.code == get_base
			currencyto = CalculatedExchangeRate.where("from_currency_id = ? and created_at < ?", to.id, datetime).last
			(1/currencyto.rate).to_f.round(4) 						
		else
			currencyfrom = CalculatedExchangeRate.where("from_currency_id = ? and created_at < ?", from.id, datetime).last
			currencyto = CalculatedExchangeRate.where("from_currency_id = ? and created_at < ?", to.id, datetime).last
			(currencyfrom.rate/currencyto.rate).to_f.round(4) 
		end
	end
end

{'fraction_non_alphanumeric': 0.12394892556835876, 'fraction_numerical': 0.003114294612270321, 'mean_word_length': 4.407407407407407, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5163220', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1149, 'n_words': 198}