<commit_before>require 'mutations'
require 'ostruct'
#  ______   ___   ___     ___
# |      | /   \ |   \   /   \  __
# |      ||     ||    \ |     ||  | This file is a work in progress. Needs:
# |_|  |_||  O  ||  D  ||  O  ||__|  * Break down into individual files
#   |  |  |     ||     ||     | __   * Remove case statement SequenceStep#call()
#   |  |  |     ||     ||     ||  |  * DRY StepValidator::COMMANDS into 1 place.
#   |__|   \___/ |_____| \___/ |__|

class SequenceStep < OpenStruct
  def initialize(hash = nil)
    super
    self[:command] = OpenStruct.new(self[:command])
  end

  def call(bot)
    botcmd, cmd = bot.commands, command
    case message_type
    when "move_relative"
      botcmd.move_relative(x: cmd.x, y: cmd.y, z: cmd.z)
    when "move_absolute"
      botcmd.move_absolute(x: cmd.x, y: cmd.y, z: cmd.z)
    when "pin_write"
      botcmd.pin_write(pin: cmd.pin, value: cmd.value, mode: cmd.mode)
    else
      bot.log "Unknown message #{message_type}"
    end
  end
end

# Builds a validated sequence (and collection of steps)
class SequenceFactory < Mutations::Command
  class StepValidator < Mutations::Command
    COMMANDS = %w(emergency_stop home_all home_x home_y home_z move_absolute
      move_relative pin_write read_parameter read_status write_parameter)

    required do
      string :message_type, in: COMMANDS
      hash :command do
        optional do
          [:x, :y, :z, :speed, :pin, :value, :mode].each do |f|
            integer f, default: nil
          end
        end
      end
    end

    def execute
      SequenceStep.new(inputs)<commit_msg>Hotfix for nil exception<commit_after>require 'mutations'
require 'ostruct'
#  ______   ___   ___     ___
# |      | /   \ |   \   /   \  __
# |      ||     ||    \ |     ||  | This file is a work in progress. Needs:
# |_|  |_||  O  ||  D  ||  O  ||__|  * Break down into individual files
#   |  |  |     ||     ||     | __   * Remove case statement SequenceStep#call()
#   |  |  |     ||     ||     ||  |  * DRY StepValidator::COMMANDS into 1 place.
#   |__|   \___/ |_____| \___/ |__|

class SequenceStep < OpenStruct
  def initialize(hash = nil)
    super
    self[:command] = OpenStruct.new(self[:command])
  end

  def call(bot)
    botcmd, cmd = bot.commands, command
    case message_type
    when "move_relative"
      coords = {x: cmd.x || 0, y: cmd.y || 0, z: cmd.z || 0}
      botcmd.move_relative(coords)
    when "move_absolute"
      coords = {x: cmd.x || bot.current_position.x,
                y: cmd.y || bot.current_position.y,
                z: cmd.z || bot.current_position.z}
      botcmd.move_absolute(coords)
    when "pin_write"
      botcmd.pin_write(pin: cmd.pin, value: cmd.value, mode: cmd.mode)
    else
      bot.log "Unknown message #{message_type}"
    end
  end
end

# Builds a validated sequence (and collection of steps)
class SequenceFactory < Mutations::Command
  class StepValidator < Mutations::Command
    COMMANDS = %w(emergency_stop home_all home_x home_y home_z move_absolute
      move_relative pin_write read_parameter read_status write_parameter)

    required do
      string :message_type, in: COMMANDS
      hash :command do
        optional do
          [:x, :y, :z, :speed, :pin, :value, :mode].each do |f|
            integer f, default: nil
          end
        end
      end
    end

    def execute
      SequenceStep.new(inputs)
{'fraction_non_alphanumeric': 0.1180637544273908, 'fraction_numerical': 0.0014757969303423849, 'mean_word_length': 2.264932562620424, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3359129', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1125, 'n_words': 284}