<commit_before>require "sosick/utils/version"
require "yaml"
require "sosick/utils/photo"
require "sosick/utils/favorite"
require "sosick/utils/validator"

module Sosick
  module Utils
    
    # get connection to database
    def self.initialize(mode)
      $sosick_utils_home=ENV['SOSICK_UTILS_HOME']
      $mode   = mode
      Validator::validate_arguments(mode)
      $config = self.load_configuration

      self.connect_to_sosick
    end

    # get configuration
    def self.load_configuration
      yaml_path = "#{$sosick_utils_home}/config/database.yml"
      yaml = YAML::load(File::open(yaml_path, 'r')::read)

      return yaml
    end

    # connect to a database
    def self.connect_to_sosick
      ActiveRecord::Base.establish_connection(
        :adapter  => 'mysql2',
        :database => $config[$mode]["database"],
        :host     => $config[$mode]["host"],
        :username => $config[$mode]["username"],
        :password => $config[$mode]["username"]
      )
    end

    def self.update
      # search updated records
      @favorites = Favorite.where(:is_updated => "1")

      # by each record, update photo score
      @favorites.each do |favorite|
        @favorite = Favorite.where(:id => favorite)

        @photo = Photo.where(:id => favorite.photo_id)
        @photo.favorite_number += favorite.favor_diff_number

        @favorite.favorite_diff_number = 0
        @favorite.is_updated = "0"

        @favorite.save
        @photo.save
      end
    end

  end
end<commit_msg>modify column name<commit_after>require "sosick/utils/version"
require "yaml"
require "sosick/utils/photo"
require "sosick/utils/favorite"
require "sosick/utils/validator"

module Sosick
  module Utils
    
    # get connection to database
    def self.initialize(mode)
      $sosick_utils_home=ENV['SOSICK_UTILS_HOME']
      $mode   = mode
      Validator::validate_arguments(mode)
      $config = self.load_configuration

      self.connect_to_sosick
    end

    # get configuration
    def self.load_configuration
      yaml_path = "#{$sosick_utils_home}/config/database.yml"
      yaml = YAML::load(File::open(yaml_path, 'r')::read)

      return yaml
    end

    # connect to a database
    def self.connect_to_sosick
      ActiveRecord::Base.establish_connection(
        :adapter  => 'mysql2',
        :database => $config[$mode]["database"],
        :host     => $config[$mode]["host"],
        :username => $config[$mode]["username"],
        :password => $config[$mode]["username"]
      )
    end

    def self.update
      # search updated records
      @favorites = Favorite.where(:is_updated => "1")

      # by each record, update photo score
      @favorites.each do |favorite|
        @favorite = Favorite.where(:id => favorite)

        @photo = Photo.where(:id => favorite.photo_id)
        @photo.favarited_number += favorite.favor_diff_number

        @favorite.favor_diff_number = 0
        @favorite.is_updated = "0"

        @favorite.save
        @photo.save
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11838624338624339, 'fraction_numerical': 0.0026455026455026454, 'mean_word_length': 2.7531017369727047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '7277570', 'n_tokens_mistral': 979, 'n_tokens_neox': 944, 'n_words': 187}