<commit_before>
require 'Files'
require 'Folders'
require 'Locking'
require 'Uuid'
require 'make_time_helper'

class DojoController < ApplicationController
  
  include MakeTimeHelper
  
  #------------------------------------------------
  
  def index
    @title = 'home'
    @id = id
  end
 
  #------------------------------------------------

  def create
    @languages = Folders::in(root_dir + '/languages').sort    
    @exercises = Folders::in(root_dir + '/exercises').sort
    @instructions = { }
    @exercises.each do |exercise|
      @instructions[exercise] = Exercise.new(root_dir, exercise).instructions
    end
    @title = 'configure'
  end
  
  #------------------------------------------------

  def save
    info = gather_info
    language = Language.new(root_dir, info[:language])
    exercise = Exercise.new(root_dir, info[:exercise])
    info[:visible_files] = language.visible_files
    info[:visible_files]['output'] = ''
    info[:visible_files]['instructions'] = exercise.instructions
    
    Kata.create_new(root_dir, info)
    
    redirect_to :action => :index, 
                :id => info[:id]
  end  
  
  #------------------------------------------------
  
  def diff_save
    kata = Kata.new(root_dir, params['id'])
    params['language'] = kata.language.name
    params['exercise'] = kata.exercise.name
    info = gather_info
    info[:diff_id] = params['id']
    info[:diff_language] = params['language']
    info[:diff_exercise] = params['exercise']
    info[:diff_avatar] = params['avatar']
    info[:diff_tag] = params['tag']      
        
    kata = Kata.new(root_dir, info[:diff_id])
    avatar = Avatar.new(kata, info[:diff_avatar])
    info[:visible_files] = avatar.visible_files(info[:diff_tag])
    
    Kata.create_new(root_dir, info)
    
    redirect_to :action => :start, 
                :id => info[:id]
  end
  <commit_msg>starting a new practice kata from a diff-view now takes you to the home page (with its id) rather than starting as an animal<commit_after>
require 'Files'
require 'Folders'
require 'Locking'
require 'Uuid'
require 'make_time_helper'

class DojoController < ApplicationController
  
  include MakeTimeHelper
  
  #------------------------------------------------
  
  def index
    @title = 'home'
    @id = id
  end
 
  #------------------------------------------------

  def create
    @languages = Folders::in(root_dir + '/languages').sort    
    @exercises = Folders::in(root_dir + '/exercises').sort
    @instructions = { }
    @exercises.each do |exercise|
      @instructions[exercise] = Exercise.new(root_dir, exercise).instructions
    end
    @title = 'configure'
  end
  
  #------------------------------------------------

  def save
    info = gather_info
    language = Language.new(root_dir, info[:language])
    exercise = Exercise.new(root_dir, info[:exercise])
    info[:visible_files] = language.visible_files
    info[:visible_files]['output'] = ''
    info[:visible_files]['instructions'] = exercise.instructions
    
    Kata.create_new(root_dir, info)
    
    redirect_to :action => :index, 
                :id => info[:id]
  end  
  
  #------------------------------------------------
  
  def diff_save
    kata = Kata.new(root_dir, params['id'])
    params['language'] = kata.language.name
    params['exercise'] = kata.exercise.name
    info = gather_info
    info[:diff_id] = params['id']
    info[:diff_language] = params['language']
    info[:diff_exercise] = params['exercise']
    info[:diff_avatar] = params['avatar']
    info[:diff_tag] = params['tag']      
        
    kata = Kata.new(root_dir, info[:diff_id])
    avatar = Avatar.new(kata, info[:diff_avatar])
    info[:visible_files] = avatar.visible_files(info[:diff_tag])
    
    Kata.create_new(root_dir, info)
    
    redirect_to :action => :index, 
                :id => info[:id]
  end
  
{'fraction_non_alphanumeric': 0.21777318522345648, 'fraction_numerical': 0.0, 'mean_word_length': 2.1301535974130963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '2867507', 'n_tokens_mistral': 1204, 'n_tokens_neox': 1162, 'n_words': 227}