Skip to content

Oltrino useful queries

Pietro edited this page Jun 3, 2019 · 4 revisions

This is a list of useful queries for getting data related to OltrEconomia Festival 2019

Setup

oef = Group.find ID
oltrino = Currency.find ID
# To avoid database logs
old_logger = ActiveRecord::Base.logger
ActiveRecord::Base.logger = nil

Total # of Sellers (used also for other roles)

Membership.where(group: oef, role: 'editor').count

# of people that have activated the account or have associated their ◎ wallet to an existing account on June 1st 2019

oef.memberships.where('updated_at > ?', DateTime.new(2019, 6, 1, 0, 0, 0).in_time_zone).where('updated_at < ?', DateTime.new(2019, 6, 2, 0, 0, 0).in_time_zone).count

# of ◎ Wallets with at least 1 transaction (including sellers’ and issuer’s wallets)

Wallet.where(currency: oltrino).select{|wallet| wallet.transactions.count > 0}.count

Total # of ◎ transactions

Transaction.select {|t| t.to_wallet.currency == oltrino}.count

# of ◎ transactions before June 3rd 2019 at 2:00 am.

Transaction.where('created_at < ?', DateTime.new(2019, 6, 3, 2, 0, 0).in_time_zone).select {|t| t.to_wallet.currency == oltrino}.count

Total ◎ amount exchanged

Transaction.select {|t| t.to_wallet.currency == oltrino}.map(&:amount).reduce(&:+).to_f
Clone this wiki locally