<commit_before>module ASM
  module Console
    def help
      puts
      puts "#{'add_monthly_financials'.green} product, eom_date, revenue_in_cents, expenses_in_cents"
      puts "  example: add_monthly_financials 'runbook', '30-jun-2015', 2138, 4995"
      puts
      puts "#{'coin_balance'.green} wallet"
      puts "  example: balance 'whatupdave'"
      puts "  example: balance 'firesize'"
      puts
      puts "#{'change_slug'.green} from, to"
      puts
      puts "#{'mint_new_coins'.green} product, coins"
      puts "  creates new coins for a product"
      puts "  example: mint_new_coins 'firesize', 150_000"
      puts
      puts "#{'remove_from_core_team'.green} product, user"
      puts
      puts "#{'rename_repo'.green} product, from, to"
      puts "  example: rename_repo 'firesize', 'asm-products/firesize', 'asm-products/firesize-web'"
      puts
      puts "#{'repos'.green} product"
      puts
      puts "#{'transactions'.green} product"
      puts
      puts "#{'transfer_coins'.green} product, from, to, coins"
      puts "  transfer coins from one wallet to another"
      puts "  example: transfer_coins 'firesize', 'firesize', 'whatupdave', 150_000"
      puts
      puts "#{'unlink_github'.green} user"
      puts
      puts "#{'unlink_twitter'.green} user"
      puts

      # github repo commands
    end

    def add_monthly_financials(slug, date, revenue, expenses)
      product = prod!(slug)

      raise "revenue should be in cents" unless revenue.is_a? Fixnum
      raise "expenses should be in cents" unless expenses.is_a? Fixnum

      ProfitReport.create!(
        product: product,
        end_at: Date.parse(date),
        revenue: revenue,
        expenses: expenses,
        annuity: 0
      )

      puts ["revenue:", "$%.02f" % (revenue / 100.0), "  expenses:", "$%.02f" % (expenses / 100.0)].join(' ')
    end

    def change_slug(from, to)
      product = Product.find_by!(slug: from)
      product.update!(slug: to)

      if room = ChatRoom.find_by(slug: from)
        room.update!(slug: to)
      end
      puts "Changed to #{app.url_for(product.url_params)}"
    end

    def coin_balance(wallet_name)
      wallet = (prod(wallet_name) || u!(wallet_name)).id

      balances = TransactionLogEntry.where(wallet_id: wallet).group(:product_id).sum(:cents)
      slugs = Product.find(balances.keys).each_with_object({}){|p, h| h[p.id] = p.slug}
      col = slugs.values.map(&:length).max
      balances.sort_by{|k,v| -v}.each do |product_id, coins|
        puts "#{slugs[product_id].rjust(col)}: #{coins}"
      end; nil
    end

    def mint_new_coins(slug, coins)
      product = prod!(slug)

      TransactionLogEntry.minted!(
        SecureRandom.uuid,
        Time.now,
        product,
        product.id,
        coins,
        comment: 'additional coins'
      )

      unallocated = TransactionLogEntry.where(wallet_id: product.id).sum(:cents)
      puts "minted #{coins} new coins on #{slug}. There are #{unallocated} coins unallocated"
    end

    def remove_from_core_team(slug, username)
      product = prod!(slug)
      user = u!(username)

      membership = product.team_memberships.find_by!(user: user)
      membership.upate!(is_core: false)<commit_msg>fix bug in remove_from_core_team helper<commit_after>module ASM
  module Console
    def help
      puts
      puts "#{'add_monthly_financials'.green} product, eom_date, revenue_in_cents, expenses_in_cents"
      puts "  example: add_monthly_financials 'runbook', '30-jun-2015', 2138, 4995"
      puts
      puts "#{'coin_balance'.green} wallet"
      puts "  example: balance 'whatupdave'"
      puts "  example: balance 'firesize'"
      puts
      puts "#{'change_slug'.green} from, to"
      puts
      puts "#{'mint_new_coins'.green} product, coins"
      puts "  creates new coins for a product"
      puts "  example: mint_new_coins 'firesize', 150_000"
      puts
      puts "#{'remove_from_core_team'.green} product, user"
      puts
      puts "#{'rename_repo'.green} product, from, to"
      puts "  example: rename_repo 'firesize', 'asm-products/firesize', 'asm-products/firesize-web'"
      puts
      puts "#{'repos'.green} product"
      puts
      puts "#{'transactions'.green} product"
      puts
      puts "#{'transfer_coins'.green} product, from, to, coins"
      puts "  transfer coins from one wallet to another"
      puts "  example: transfer_coins 'firesize', 'firesize', 'whatupdave', 150_000"
      puts
      puts "#{'unlink_github'.green} user"
      puts
      puts "#{'unlink_twitter'.green} user"
      puts

      # github repo commands
    end

    def add_monthly_financials(slug, date, revenue, expenses)
      product = prod!(slug)

      raise "revenue should be in cents" unless revenue.is_a? Fixnum
      raise "expenses should be in cents" unless expenses.is_a? Fixnum

      ProfitReport.create!(
        product: product,
        end_at: Date.parse(date),
        revenue: revenue,
        expenses: expenses,
        annuity: 0
      )

      puts ["revenue:", "$%.02f" % (revenue / 100.0), "  expenses:", "$%.02f" % (expenses / 100.0)].join(' ')
    end

    def change_slug(from, to)
      product = Product.find_by!(slug: from)
      product.update!(slug: to)

      if room = ChatRoom.find_by(slug: from)
        room.update!(slug: to)
      end
      puts "Changed to #{app.url_for(product.url_params)}"
    end

    def coin_balance(wallet_name)
      wallet = (prod(wallet_name) || u!(wallet_name)).id

      balances = TransactionLogEntry.where(wallet_id: wallet).group(:product_id).sum(:cents)
      slugs = Product.find(balances.keys).each_with_object({}){|p, h| h[p.id] = p.slug}
      col = slugs.values.map(&:length).max
      balances.sort_by{|k,v| -v}.each do |product_id, coins|
        puts "#{slugs[product_id].rjust(col)}: #{coins}"
      end; nil
    end

    def mint_new_coins(slug, coins)
      product = prod!(slug)

      TransactionLogEntry.minted!(
        SecureRandom.uuid,
        Time.now,
        product,
        product.id,
        coins,
        comment: 'additional coins'
      )

      unallocated = TransactionLogEntry.where(wallet_id: product.id).sum(:cents)
      puts "minted #{coins} new coins on #{slug}. There are #{unallocated} coins unallocated"
    end

    def remove_from_core_team(slug, username)
      product = prod!(slug)
      user = u!(username)

      membership = product.team_memberships.find_by!(user: user)
      membership.update!(is_core: false)
{'fraction_non_alphanumeric': 0.12721939169368535, 'fraction_numerical': 0.012042612320518759, 'mean_word_length': 2.7510133178922986, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1320864', 'n_tokens_mistral': 2170, 'n_tokens_neox': 2154, 'n_words': 499}