<commit_before>require_relative '../models/user'
require_relative '../models/message'

module Komonjo
  module Gateway
    # Merge history and users
    class MessagesGateway
      def initialize(history, users)
        @history = history
        @users = users
        @history = @history.map { |h| Hash[h.map { |k, v| [k.to_sym, v] }] }
        @users = @users.map do |h|
          ret = Hash[h.map { |k, v| [k.to_sym, v] }]
          ret[:profile] = Hash[ret[:profile].map { |k, v| [k.to_sym, v] }]
          ret
        end
      end

      def messages
        @history.map do |h|
          next h unless h[:user]
          Komonjo::Model::Message.create(h).tap do |message|
            message.user = find_user h[:user]
          end
        end
      end

      private

      def find_user(user_id)
        user = @users.find { |u| u[:id] == user_id }
        fail "unknown user: #{user_id}" unless user
        Komonjo::Model::User.create(user)<commit_msg>remove unnecessary assingment / #6<commit_after>require_relative '../models/user'
require_relative '../models/message'

module Komonjo
  module Gateway
    # Merge history and users
    class MessagesGateway
      def initialize(history, users)
        @history = history
        @history = @history.map { |h| Hash[h.map { |k, v| [k.to_sym, v] }] }
        @users = users.map do |h|
          ret = Hash[h.map { |k, v| [k.to_sym, v] }]
          ret[:profile] = Hash[ret[:profile].map { |k, v| [k.to_sym, v] }]
          ret
        end
      end

      def messages
        @history.map do |h|
          next h unless h[:user]
          Komonjo::Model::Message.create(h).tap do |message|
            message.user = find_user h[:user]
          end
        end
      end

      private

      def find_user(user_id)
        user = @users.find { |u| u[:id] == user_id }
        fail "unknown user: #{user_id}" unless user
        Komonjo::Model::User.create(user)
{'fraction_non_alphanumeric': 0.1344058121432278, 'fraction_numerical': 0.0005189413596263622, 'mean_word_length': 1.9984447900466562, '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': '3691519', 'n_tokens_mistral': 635, 'n_tokens_neox': 625, 'n_words': 162}