<commit_before># Delete existing fields as they will be re-created below
Field.where(owner_type: "Target").delete_all

# Key the target types by database ID so we maintain existing relations
{
    1 => { name: "Android APK", icon: "android", requires_build: true, fields: {} },
    2 => { name: "iOS IPA", icon: "apple", requires_build: true, fields: {} },
    3 => { name: "Mobile Browser", icon: "globe", requires_build: false, fields: { url: :string} },
    4 => { name: "TAL TV App", icon: "desktop", requires_build: false, fields: { application_url: :string, application_url_parameters: :string } },
    5 => { name: "Shell Script", icon: "file-text-o", requires_build: false, fields: {} }
}.each_pair do |target_id, target_attributes|
  fields=target_attributes.delete(:fields)

  target = Target.find_or_create_by(id: target_id)
  target.update!(target_attributes)
  target.fields.delete_all

  fields.each_pair do |field_name, field_value|
    target.fields << Field.create(name: field_name, field_type: field_value)
  end
end

# For dummy data uncomment these lines before running bin/rake db:seed
#rspec_script = Script.create!(
#  name: 'Rspec tests',
#  target_id: 5,
#  template: <<TEMPLATE
#bundle install
#rspec
#TEMPLATE
#)
#
#cucumber_script = Script.create!(
#  name: 'Cucumber tests',
#  target_id: 5,
#  template: <<TEMPLATE
## This presumes that the Gemfile includes the line: gem 'res'
#bundle install
#bundle exec cucumber -f Res::Formatters::RubyCubumber -o $HIVE_RESULTS/out.res -f pretty `retry_args`
#TEMPLATE
#)
#
#project = Project.create!(
#  name: 'Hive Runner rspec',
#  repository: '<EMAIL>:bbc/hive-runner.git',
#  builder_name: Builders::ManualBuilder.builder_name,
#  script: rspec_script
#)<commit_msg>Capture rspec coverage in example script, if present<commit_after># Delete existing fields as they will be re-created below
Field.where(owner_type: "Target").delete_all

# Key the target types by database ID so we maintain existing relations
{
    1 => { name: "Android APK", icon: "android", requires_build: true, fields: {} },
    2 => { name: "iOS IPA", icon: "apple", requires_build: true, fields: {} },
    3 => { name: "Mobile Browser", icon: "globe", requires_build: false, fields: { url: :string} },
    4 => { name: "TAL TV App", icon: "desktop", requires_build: false, fields: { application_url: :string, application_url_parameters: :string } },
    5 => { name: "Shell Script", icon: "file-text-o", requires_build: false, fields: {} }
}.each_pair do |target_id, target_attributes|
  fields=target_attributes.delete(:fields)

  target = Target.find_or_create_by(id: target_id)
  target.update!(target_attributes)
  target.fields.delete_all

  fields.each_pair do |field_name, field_value|
    target.fields << Field.create(name: field_name, field_type: field_value)
  end
end

# For dummy data uncomment these lines before running bin/rake db:seed
#rspec_script = Script.create!(
#  name: 'Rspec tests',
#  target_id: 5,
#  template: <<TEMPLATE
#bundle install
#rspec
#if [ -e coverage ]
#then
#  tar -czf $HIVE_RESULTS/coverage.gz coverage
#fi
#TEMPLATE
#)
#
#cucumber_script = Script.create!(
#  name: 'Cucumber tests',
#  target_id: 5,
#  template: <<TEMPLATE
## This presumes that the Gemfile includes the line: gem 'res'
#bundle install
#bundle exec cucumber -f Res::Formatters::RubyCubumber -o $HIVE_RESULTS/out.res -f pretty `retry_args`
#TEMPLATE
#)
#
#project = Project.create!(
#  name: 'Hive Runner rspec',
#  repository: '<EMAIL>:bbc/hive-runner.git',
#  builder_name: Builders::ManualBuilder.builder_name,
#  script: rspec_script
#)
{'fraction_non_alphanumeric': 0.13856427378964942, 'fraction_numerical': 0.0038953811908736783, 'mean_word_length': 5.042016806722689, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '2163804', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1194, 'n_words': 344}