<commit_before>module Sync
  class Fetch  < Mutations::Command
    API_VERSION = ENV.fetch("HEROKU_SLUG_COMMIT", `git log --pretty=format:"%h" -1`)
    COMPAT_NUM  = 1

    required do
      model :device, class: Device
    end

    def validate
      maybe_initialize_a_tool_bay
    end

    def execute
      return { api_version:   API_VERSION[0,7],
               compat_num:    COMPAT_NUM,
               device:        device,
               users:         users,
               sequences:     sequences,
               regimens:      regimens,
               peripherals:   peripherals,
               regimen_items: regimen_items,
               plants:        plants,
               points:        points,
               tool_bays:     tool_bays,
               tool_slots:    tool_slots,
               tools:         tools,
               logs:          logs,
               images:        images,
               farm_events:   farm_events }
    end

  private

    def farm_events
      @farm_events ||= ActiveModel::ArraySerializer.new(FarmEvent.where(device: device),
                                                        each_serializer: FarmEventSerializer)
    end

    def images
      @images ||= ActiveModel::ArraySerializer
                    .new(Images::Fetch.run!(device: device),
                         each_serializer: ImageSerializer)
    end

    def tools
      @tools = ActiveModel::ArraySerializer.new(Tool.where(device: device),
                                                each_serializer: ToolSerializer)
    end

    def tool_slots
      @tool_slots ||= ActiveModel::ArraySerializer
                        .new(ToolSlot.where(tool_bay_id: tool_bays.pluck(:id)),
                             each_serializer: ToolSlotSerializer)
    end

    def tool_bays
      []
      # @tool_bays ||= device.tool_bays
    end

    def plants<commit_msg>Unstub tool_bay in sync object (sorry)<commit_after>module Sync
  class Fetch  < Mutations::Command
    API_VERSION = ENV.fetch("HEROKU_SLUG_COMMIT", `git log --pretty=format:"%h" -1`)
    COMPAT_NUM  = 1

    required do
      model :device, class: Device
    end

    def validate
      maybe_initialize_a_tool_bay
    end

    def execute
      return { api_version:   API_VERSION[0,7],
               compat_num:    COMPAT_NUM,
               device:        device,
               users:         users,
               sequences:     sequences,
               regimens:      regimens,
               peripherals:   peripherals,
               regimen_items: regimen_items,
               plants:        plants,
               points:        points,
               tool_bays:     tool_bays,
               tool_slots:    tool_slots,
               tools:         tools,
               logs:          logs,
               images:        images,
               farm_events:   farm_events }
    end

  private

    def farm_events
      @farm_events ||= ActiveModel::ArraySerializer.new(FarmEvent.where(device: device),
                                                        each_serializer: FarmEventSerializer)
    end

    def images
      @images ||= ActiveModel::ArraySerializer
                    .new(Images::Fetch.run!(device: device),
                         each_serializer: ImageSerializer)
    end

    def tools
      @tools = ActiveModel::ArraySerializer.new(Tool.where(device: device),
                                                each_serializer: ToolSerializer)
    end

    def tool_slots
      @tool_slots ||= ActiveModel::ArraySerializer
                        .new(ToolSlot.where(tool_bay_id: tool_bays.pluck(:id)),
                             each_serializer: ToolSlotSerializer)
    end

    def tool_bays
      @tool_bays ||= device.tool_bays
    end

    def plants
{'fraction_non_alphanumeric': 0.0716931216931217, 'fraction_numerical': 0.0021164021164021165, 'mean_word_length': 1.433075933075933, 'pattern_counts': {'":': 0, '<': 5, '<?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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4121678', 'n_tokens_mistral': 1013, 'n_tokens_neox': 983, 'n_words': 208}