<commit_before> # Yogo Data Management Toolkit
 # Copyright (c) 2010 Montana State University
 #
 # License -> see license.txt
 #
 # FILE: project.rb
 # The project model is where the action starts.  Every yogo instance starts with a 
 # a project and the project is where the models and data will be namespaced.
 #

class Project
  include DataMapper::Resource
  
  property :id, Serial
  property :name, String, :required => true, :unique => true
  property :description, Text, :required => false
  
  validates_is_unique   :name
  
  before :destroy, :delete_models!

  # @return [String] the project namespaced name
  #
  def namespace
    Extlib::Inflection.classify(path)
  end
  
  # @return [String] the project path name
  #
  def path
    name.downcase.gsub(/[^\w]/, '_')
  end
  
  # to_param is called by rails for routing and such
  # 
  def to_param
    id.to_s
  end
  
  # Creates a model and imports data from a CSV file
  #
  # @param [String] datafile A path to the CSV file to read in
  # @param [String] model_name the desired name of the model to be created
  #
  # @returns [Array] Returns empty array if successful or an array of error messages if unsuccessful.
  #
  # * The csv datafile must be in the following format: 
  #   1. row 1 -> field names
  #   2. row 2 -> type, 
  #   3. row 3 -> units
  #   4. rows 4+ -> data
  # 
  def process_csv(datafile, model_name)
    # Read the data in
    csv_data = FasterCSV.read(datafile)

    errors = Yogo::CSV.validate_csv(csv_data)
    
    if errors.empty?
      # Look to see if there is already one of these models.
      model = get_model(model_name)

      # Process the contents
      if model.nil?
        # Get Model name
        model_name = "Yogo::#{namespace}::#{model_name}"
        model = DataMapper::Factory.instance.make_model_from_csv(model_name, csv_data[0..2])
        model.send(:include,Yogo::DataMethods) unless model.included_modules.include?(Yogo::DataMethods)
        model.auto_migrate!
      end
      
      # Load data
      Yogo::CSV.load_data(model, csv_data)
    end<commit_msg>Fixed a test with renamed method<commit_after> # Yogo Data Management Toolkit
 # Copyright (c) 2010 Montana State University
 #
 # License -> see license.txt
 #
 # FILE: project.rb
 # The project model is where the action starts.  Every yogo instance starts with a 
 # a project and the project is where the models and data will be namespaced.
 #

class Project
  include DataMapper::Resource
  
  property :id, Serial
  property :name, String, :required => true, :unique => true
  property :description, Text, :required => false
  
  validates_is_unique   :name
  
  before :destroy, :delete_models!

  # @return [String] the project namespaced name
  #
  def namespace
    Extlib::Inflection.classify(path)
  end
  
  # @return [String] the project path name
  #
  def path
    name.downcase.gsub(/[^\w]/, '_')
  end
  
  # to_param is called by rails for routing and such
  # 
  def to_param
    id.to_s
  end
  
  # Creates a model and imports data from a CSV file
  #
  # @param [String] datafile A path to the CSV file to read in
  # @param [String] model_name the desired name of the model to be created
  #
  # @returns [Array] Returns empty array if successful or an array of error messages if unsuccessful.
  #
  # * The csv datafile must be in the following format: 
  #   1. row 1 -> field names
  #   2. row 2 -> type, 
  #   3. row 3 -> units
  #   4. rows 4+ -> data
  # 
  def process_csv(datafile, model_name)
    # Read the data in
    csv_data = FasterCSV.read(datafile)

    errors = Yogo::CSV.validate_csv(csv_data)
    
    if errors.empty?
      # Look to see if there is already one of these models.
      model = get_model(model_name)

      # Process the contents
      if model.nil?
        # Get Model name
        model_name = "Yogo::#{namespace}::#{model_name}"
        model = DataMapper::Factory.instance.make_model_from_array(model_name, csv_data[0..2])
        model.send(:include,Yogo::DataMethods) unless model.included_modules.include?(Yogo::DataMethods)
        model.auto_migrate!
      end
      
      # Load data
      Yogo::CSV.load_data(model, csv_data)
    end
{'fraction_non_alphanumeric': 0.09023633325375985, 'fraction_numerical': 0.0066841728336118405, 'mean_word_length': 2.836996336996337, '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': '7619882', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1303, 'n_words': 454}