<commit_before>module Anyquestion
  class Room
    @id : Int64
    @name : String
    @time_start : Time

    getter :id
    getter :name
    getter :time_start

    def initialize(name)
      @name = name
      @time_start = Time.now
      @id = Time.new.epoch + Random.new.rand(1000)
      @questions = {} of Int64 => Question
      @sockets = [] of HTTP::WebSocket
    end

    def nb_questions
      @questions.size
    end

    def nb_users
      @sockets.size
    end

    def handle(socket)
      @sockets.push socket

      socket.send questions_in_order

      socket.on_message do |message|
        if message == "bye"
        elsif message == "hi"
        else
          parts = message.split(/----/)
          if parts.size > 1
            questionId, voter = parts
            @questions[questionId.to_i].vote(voter.to_i)
          else
            author, text = message.split(/::::/)
            question = Question.new text, author.to_i
            @questions[question.id] = question
          end
        end
        @sockets.each do |s|
          begin
            s.send questions_in_order
          rescue ex
            @sockets.delete s
          end
        end
      end

      socket.on_close do |socket|
        @sockets.delete socket<commit_msg>remove questions with zero votes<commit_after>module Anyquestion
  class Room
    @id : Int64
    @name : String
    @time_start : Time

    getter :id
    getter :name
    getter :time_start

    def initialize(name)
      @name = name
      @time_start = Time.now
      @id = Time.new.epoch + Random.new.rand(1000)
      @questions = {} of Int64 => Question
      @sockets = [] of HTTP::WebSocket
    end

    def nb_questions
      @questions.size
    end

    def nb_users
      @sockets.size
    end

    def handle(socket)
      @sockets.push socket

      socket.send questions_in_order

      socket.on_message do |message|
        if message == "bye"
        elsif message == "hi"
        else
          parts = message.split(/----/)
          if parts.size > 1
            questionId, voter = parts
            @questions[questionId.to_i].vote(voter.to_i)
            @questions.delete questionId.to_i if @questions[questionId.to_i].votes < 1
          else
            author, text = message.split(/::::/)
            question = Question.new text, author.to_i
            @questions[question.id] = question
          end
        end
        @sockets.each do |s|
          begin
            s.send questions_in_order
          rescue ex
            @sockets.delete s
          end
        end
      end

      socket.on_close do |socket|
        @sockets.delete socket
{'fraction_non_alphanumeric': 0.08943396226415094, 'fraction_numerical': 0.007169811320754717, 'mean_word_length': 1.6273538156590683, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 7, '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': '4704109', 'n_tokens_mistral': 817, 'n_tokens_neox': 775, 'n_words': 200}