ruby Comandos varios para los contadores de Networking

Para rearmar los contadores basados en las citas ya pre-cargadas o para resetearlos de nuevo a cero

networking_counters.rb
conference_id = 286
BusinessConference.find(conference_id).business_conference_participants.each do |participant|
  accepted_to_me = BusinessConferenceMeeting.where(archived: false, status: 2, business_conference_id: conference_id, host_participant_id: participant.id).size
  rejected_to_me = BusinessConferenceMeeting.where(status: 3, business_conference_id: conference_id, host_participant_id: participant.id).size
  requested_to_me = BusinessConferenceMeeting.where(archived: false, status: 1, business_conference_id: conference_id, host_participant_id: participant.id).size

  accepted_by_me = BusinessConferenceMeeting.where(archived: false, status: 2, business_conference_id: conference_id, participant_id: participant.id).size
  rejected_by_me = BusinessConferenceMeeting.where(status: 3, business_conference_id: conference_id, participant_id: participant.id).size
  requested_by_me = BusinessConferenceMeeting.where(archived: false, status: 1, business_conference_id: conference_id, participant_id: participant.id).size
  participant.update_columns(meetings_confirmed_requested_to_me: accepted_to_me,
                            meetings_rejected_requested_to_me: rejected_to_me,
                            meetings_pending_confirmation_requested_to_me: requested_to_me,
                            meetings_confirmed_requested_by_me: accepted_by_me,
                            meetings_rejected_requested_by_me: rejected_by_me,
                            meetings_pending_confirmation_requested_by_me: requested_by_me
                          )
end


UPDATE business_conference_participants
SET meetings_confirmed_requested_to_me = 0,
    meetings_rejected_requested_to_me = 0,
    meetings_pending_confirmation_requested_to_me = 0,
    meetings_confirmed_requested_by_me = 0,
    meetings_rejected_requested_by_me = 0,
    meetings_pending_confirmation_requested_by_me = 0
WHERE business_conference_id = 286;

ruby 在不同的插槽中重新分配会议

Cuando hay reuniones en slots que van a ser restringidos

reassign_meeting_blocked_slot.rb
meetings = BusinessConferenceMeeting.where(business_conference_id: 4172).where.not(status: 3).where("start_date = '2018-10-25 11:50:00'").where("end_date = '2018-10-25 12:10:00'")
meetings.each do |meeting|
  host_participant_id = meeting.host_participant_id
  participant_id = meeting.participant_id
  #available_slots = get_available_slots_for_meeting(host_participant_id, participant_id)
  participant = BusinessConferenceParticipant.find(participant_id)
  host_participant = BusinessConferenceParticipant.find(host_participant_id)
  common_agenda = participant.participant_type.agenda.values & host_participant.participant_type.agenda.values

  cnn = ActiveRecord::Base.connection
  unavailable_agenda = cnn.execute("SELECT DISTINCT start_date, end_date FROM 
                      business_conference_meetings WHERE business_conference_id = 4172 AND 
                      ( host_participant_id = #{host_participant_id} OR participant_id = #{host_participant_id} 
                      OR host_participant_id = #{participant_id} OR participant_id = #{participant_id} ) 
                      AND archived = false AND status != 3 order by start_date;").to_a
  available_slots = common_agenda - unavailable_agenda


  available_slots.each do |available_slot|
    meeting.update_columns(status: 3, archived: true)
    r = BusinessConferenceMeeting.add_new(4172, host_participant_id, participant_id, available_slot[0], '', nil, BusinessConferenceMeeting::SOURCE[:admin], true, false)
    break if r[0].present?
  end
end

ruby 报告评估台面

meeting_evaluations_report.rb
# Reporte de mesas con encuestas calificadas y pendientes por calificar
select m.location, count(sa.id) as evaluated,
((select count(m2.id) from business_conference_meetings m2 where m2.business_conference_id = 3983 and m2.location = m.location and m2.end_date <= '2018-08-30 12:30:00') - count(sa.id)) as pending
from business_conference_meetings m
left join survey_answers sa on m.id = sa.related_entity_id
where m.business_conference_id = 3983 and sa.survey_id = 2561
and m.end_date <= '2018-08-30 12:30:00'
group by m.location
order by m.location asc;

ruby 在任何时区解析日期时间

在任何已知时区解析任何日期时间字符串

datetime.rb
# Fetch a Rails timezone, and use it to parse a string
ActiveSupport::TimeZone[time_zone].parse(str)

# For example:
ActiveSupport::TimeZone['Madrid'].parse('2018-08-30 14:36')
# Thu, 30 Aug 2018 14:36:00 CEST +02:00

ruby 在任何ruby(bundle)控制台上使用任何gem

下载并使用任何所需的ruby控制台,即使它正在使用bundle。

console.rb
# Install the gem
system 'gem install <gemname> -v <version>'

# Require its load path (depends on the gem file tree)
$LOAD_PATH << "#{`gem env gemdir`.strip}/gems/<gemname-version>/lib"

# Require the gem file
require '<gemname>'


# For example:
system 'gem install differ -v 0.1.2'
$LOAD_PATH << "#{`gem env gemdir`.strip}/gems/differ-0.1.2/lib"
require 'differ'

ruby Gemfile github

Gemfile
git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  #"https://github.com/#{repo_name}.git"
  "git@github.com:#{repo_name}.git"
end

ruby 类继承

类继承

.rb
# Our Lion Class Inherits All the stuff from our Animal Class
class Animal
  attr_accessor :color, :name
  def initialize ( name, color )
    @name = name
    @color = color
  end
end
 
class Lion < Animal		# Inherit by using < Animal 
  def speak
    return "RAWR!"
  end
end
 
#  Instantiate our class
lion = Lion.new( "lion", "golden" )
 
# Inspect
puts lion.inspect
 
# Speak
puts lion.speak
 
# Color inherited from Animal class!
puts lion.color

ruby 类 - attr_accessor

类 - attr_accessor

.rb
# Delete the Getter and Setter from above, replace it with attr_accessor
# Note: Doesn't write your initialize method instance variables!
class Product
  attr_accessor :description
 
 
  # Always Initialize It First
  def initialize( description, price)
    @id = rand(100...999)
    @description = description
    @price = price
  end
 
  
  def to_s
    # return by rewriting to_s :-p and add tabs with \t
    return "#{@id}\t#{@description}\t#{@price}"
  end
end
 
# Set it up... Instantiate our class
book = Product.new( "Ruby On Rails For Web Development", 26.95 )
book2 = Product.new( "Intro To Ruby", 25.95 )
 
# Call the thing!
puts book
puts book2
 
# Call The Description Getter
puts book.description
# Call the Setter, set a different Description
puts book.description= "I Like Cheese!"

ruby 类 - attr_accessor

类 - attr_accessor

.rb
# Delete the Getter and Setter from above, replace it with attr_accessor
# Note: Doesn't write your initialize method instance variables!
class Product
  attr_accessor :description
 
 
  # Always Initialize It First
  def initialize( description, price)
    @id = rand(100...999)
    @description = description
    @price = price
  end
 
  
  def to_s
    # return by rewriting to_s :-p and add tabs with \t
    return "#{@id}\t#{@description}\t#{@price}"
  end
end
 
# Set it up... Instantiate our class
book = Product.new( "Ruby On Rails For Web Development", 26.95 )
book2 = Product.new( "Intro To Ruby", 25.95 )
 
# Call the thing!
puts book
puts book2
 
# Call The Description Getter
puts book.description
# Call the Setter, set a different Description
puts book.description= "I Like Cheese!"

ruby 类 - attr_accessor

类 - attr_accessor

.rb
# Delete the Getter and Setter from above, replace it with attr_accessor
# Note: Doesn't write your initialize method instance variables!
class Product
  attr_accessor :description
 
 
  # Always Initialize It First
  def initialize( description, price)
    @id = rand(100...999)
    @description = description
    @price = price
  end
 
  
  def to_s
    # return by rewriting to_s :-p and add tabs with \t
    return "#{@id}\t#{@description}\t#{@price}"
  end
end
 
# Set it up... Instantiate our class
book = Product.new( "Ruby On Rails For Web Development", 26.95 )
book2 = Product.new( "Intro To Ruby", 25.95 )
 
# Call the thing!
puts book
puts book2
 
# Call The Description Getter
puts book.description
# Call the Setter, set a different Description
puts book.description= "I Like Cheese!"