<commit_before>require_relative '../SQL/db_helper'
require_relative '../model/containers'

class MasterDataSource
  @db_Helper
  @master_server
  @observers

  @user_id
  @username

  def initialize (master_server)
    @db_Helper = DbHelper.new
    @master_server = master_server

    @observers = []
  end

  # @param [String] username
  # @param [String] password
  # @return [bool]
  def login(username, password)
    begin
      @user_id = @db_Helper.get_user_id(username, password)
      @username = username
      return true if @user_id
      return false
    rescue RuntimeError => e
        puts "ERROR: Could not log in: #{e.error}"
    end
  end

  def open_games
    begin
      Marshal.load(@master_server.get_waiting_games())
    rescue Errno::ECONNREFUSED => e
      puts "Error Getting open games! : #{e.error}"
    end
  end

  def saved_games()

  end

  def start_saved_game(id)

  end

  def add_observer(obs)
    @observers << obs
  end

  private
  def update_observers
    @observers.each {|observer| observer.update}
  end




end<commit_msg>Added xmlrpc and sql wrapper methods<commit_after>require_relative '../SQL/db_helper'
require_relative '../model/containers'

class MasterDataSource
  @db_Helper
  @master_server
  @observers

  @user_id
  @username

  def initialize (master_server)
    @db_Helper = DbHelper.new
    @master_server = master_server

    @observers = []
  end

  # @param [String] username
  # @param [String] password
  # @return [bool]
  def login(username, password)
    db_operation('Could not login') do
      @user_id = @db_Helper.get_user_id(username, password)
      @username = username
      return true if @user_id
      return false
    end
  end

  def open_games
    make_server_communication('couldnt get open games') {Marshal.load(@master_server.get_waiting_games())}
  end

  def saved_games()

  end

  def start_saved_game(id)

  end

  def add_observer(obs)
    @observers << obs
  end

  private
  def update_observers
    @observers.each {|observer| observer.update}
  end

  def make_server_communication(msg, &block)
    begin
      block.call
    rescue Errno::ECONNREFUSED => e
      puts "ERROR: #{msg} : #{e.error}"
    end
  end

  def db_operation(msg)
    begin
      yield
    rescue RuntimeError => e
      puts "Error: #{msg} : #{e.error}"
    end
  end


end
{'fraction_non_alphanumeric': 0.09611277231952157, 'fraction_numerical': 0.0, 'mean_word_length': 3.0449050086355784, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, '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': '1533213', 'n_tokens_mistral': 797, 'n_tokens_neox': 772, 'n_words': 195}