<commit_before>include OAuth::Helper
include EtradeHelper

require 'bigdecimal'

require 'stripe'
require 'oauth'

class Share < ActiveRecord::Base
	validates :stripe_balance, :presence => true
	validates :etrade_balance, :presence => true

	def fee_price
		self.grant_price
	end

	class << self

		def shares_outstanding(datetime=nil)
			if datetime.nil?
				datetime=Time.now
			end
			d=Donation.where("created_at <= ?", datetime).sum(:shares_added)
			g=Grant.where("created_at <= ? AND (status = ? OR status = ?)", datetime, "accepted", "pending_acceptance").sum(:shares_subtracted)
			f=Fee.where("created_at <= ?", datetime).sum(:shares_subtracted)
			d-g-f
		end

		def compute_share_price

      begin
        stripe_balance = get_stripe_balance
        etrade_balance = get_etrade_balance
        dwolla_balance = get_dwolla_balance
        transit_balance = get_transit_balance
      rescue Exception => e
        ap e
      end

      current_balance = stripe_balance + etrade_balance + dwolla_balance + transit_balance - 478.02
    
      last_share = Share.order("created_at DESC").first

      begin
        share_total_beginning = last_share.share_total_end # share total at last calculation
        last_share_created_at = last_share.created_at
      rescue
        share_total_beginning = 0
        last_share_created_at = DateTime.new(2001,2,3) 
      end

      # shares added by donation
      shares_added_by_donation = Donation.where("created_at >= ?", last_share_created_at).sum(:shares_added)

      # shares removed by grant
      shares_subtracted_by_grants = Grant.where("created_at >= ? AND (status = ? OR status = ?)", last_share_created_at, 'accepted', 'pending_acceptance').sum(:shares_subtracted)

      # shares removed by fees
      shares_subtracted_by_fees = Fee.where("created_at >= ?", last_share_created_at).sum(:shares_subtracted)

      share_total_end = (BigDecimal(share_total_beginning.to_s) + BigDecimal(shares_added_by_donation.to_s) - BigDecimal(shares_subtracted_by_grants.to_s) - BigDecimal(shares_subtracted_by_fees.to_s))

      # get donation share price
      # current_balance / shares_outstanding
      preliminary_share_price = (BigDecimal(current_balance.to_s) / BigDecimal(share_total_end.to_s)).to_f
<commit_msg>478.02 stock donation transferred to giv2giv inc checking at DuPont Credit Union<commit_after>include OAuth::Helper
include EtradeHelper

require 'bigdecimal'

require 'stripe'
require 'oauth'

class Share < ActiveRecord::Base
	validates :stripe_balance, :presence => true
	validates :etrade_balance, :presence => true

	def fee_price
		self.grant_price
	end

	class << self

		def shares_outstanding(datetime=nil)
			if datetime.nil?
				datetime=Time.now
			end
			d=Donation.where("created_at <= ?", datetime).sum(:shares_added)
			g=Grant.where("created_at <= ? AND (status = ? OR status = ?)", datetime, "accepted", "pending_acceptance").sum(:shares_subtracted)
			f=Fee.where("created_at <= ?", datetime).sum(:shares_subtracted)
			d-g-f
		end

		def compute_share_price

      begin
        stripe_balance = get_stripe_balance
        etrade_balance = get_etrade_balance
        dwolla_balance = get_dwolla_balance
        transit_balance = get_transit_balance
      rescue Exception => e
        ap e
      end

      current_balance = stripe_balance + etrade_balance + dwolla_balance + transit_balance
    
      last_share = Share.order("created_at DESC").first

      begin
        share_total_beginning = last_share.share_total_end # share total at last calculation
        last_share_created_at = last_share.created_at
      rescue
        share_total_beginning = 0
        last_share_created_at = DateTime.new(2001,2,3) 
      end

      # shares added by donation
      shares_added_by_donation = Donation.where("created_at >= ?", last_share_created_at).sum(:shares_added)

      # shares removed by grant
      shares_subtracted_by_grants = Grant.where("created_at >= ? AND (status = ? OR status = ?)", last_share_created_at, 'accepted', 'pending_acceptance').sum(:shares_subtracted)

      # shares removed by fees
      shares_subtracted_by_fees = Fee.where("created_at >= ?", last_share_created_at).sum(:shares_subtracted)

      share_total_end = (BigDecimal(share_total_beginning.to_s) + BigDecimal(shares_added_by_donation.to_s) - BigDecimal(shares_subtracted_by_grants.to_s) - BigDecimal(shares_subtracted_by_fees.to_s))

      # get donation share price
      # current_balance / shares_outstanding
      preliminary_share_price = (BigDecimal(current_balance.to_s) / BigDecimal(share_total_end.to_s)).to_f

{'fraction_non_alphanumeric': 0.09104737070838766, 'fraction_numerical': 0.005432420686657975, 'mean_word_length': 3.997828447339848, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3993868', 'n_tokens_mistral': 1571, 'n_tokens_neox': 1484, 'n_words': 270}