Rothamsted-Ecoinformatics / farm_rothamsted

Custom farmOS features for Rothamsted Research.
GNU General Public License v2.0
6 stars 1 forks source link

Experiment Module: Flagging plots with restrictions #231

Closed aislinnpearson closed 2 years ago

aislinnpearson commented 2 years ago

When submitting a new experiment, it is common for the scientists to set restrictions on inputs and other management attributes. The restrictions usually apply to the whole experiment, but occasionally they relate only to certain plots (for example, only the bean plots in a rotation experiment).

Restriction types include:

Pesticide and Input Restrictions

Watering Restrictions:

Nutrient Restrictions

Drilling Restrictions:

Other useful flag types might include:

Ideally these would eventually link to a cropping plan for the experiments (see #230), but for now I think being able to flag specific plots would be ideal. These restrictions would ideally also show up on the quick forms when selecting plots, but perhaps with an abbreviation (ideas for which are in brackets next to the type of restriction, but I'm open to alternatives as I don't think they are all that great)

paul121 commented 2 years ago

The machine name for these flags can be restriction_{name}

aislinnpearson commented 2 years ago

Following discussion with @paul121 we agreed that although flags are a short term solution, there should be a better way of assigning these kinds of restrictions in FarmOS. I've created a second issue for this here (#238) so that we don't lose track of the issue once this one is closed.

paul121 commented 2 years ago

The machine name for these flags can be restriction_{name}

I actually prefixed these with plot_restriction_{name} since they are all specific to plots.

Since there were so many I created a little script to create the flags and then export config using drush. Tthis might be useful in the future:

drush scr flag_create.php
drush cex --destination flag-create
<?php
// flag_create.php

// Array of flags keyed by id suffix.
$flags = [
  // Pesticide and input.
  'fungicide' => 'Fungicide restrictions (F)',
  'insecticide' => 'Insecticide restrictions (I)',
  'herbicide' => 'Herbicide restrictions (H)',
  'nematicide' => 'Nematicide restrictions (N)',
  'molluscicides' => 'Molluscicides restrictions (M)',
  'plant_growth_regulator' => 'Plant growth regulator restrictions (PGR)',

  // Watering.
  'irrigation' => 'Irrigation/watering restrictions (W)',

  // Nutrient.
  'nitrogen' => 'Nitrogen restrictions (N)',
  'potassium' => 'Potassium restrictions (P)',
  'phosphorous' => 'Phosphorous restrictions (K)',
  'sulphur' => 'Sulphur restrictions (S)',
  'magnesium' => 'Magnesium restrictions (Mg)',
  'liming' => 'Liming restrictions (pH)',
  'micronutrient' => 'Micronutrient restrictions (mn)',

  // Drilling.
  'drilling_date' => 'Drilling date restrictions (dd)',
  'seed_rate' => 'Seed rate restrictions (sr)',
  'variety' => 'Variety restrictions (var)',
  'seed_treatments' => 'Seed treatments restrictions (st)',

  // Other.
  'physical' => 'Physical obstructions (obst)',
  'gm_material' => 'GM Material (GM)',
  'pre_harvest_sampling'=> 'Pre-harvest Sampling (Pre)',
  'post_harvest_sampling' => 'Post-harvest Sampling (Post)',
];

// Create or delete all flags.
$create = TRUE;
foreach ($flags as $id => $label) {
  $flag_id = "plot_restriction_$id";
  if ($create) {
    $flag = \Drupal\farm_flag\Entity\FarmFlag::create([
      'id'  => $flag_id,
      'label'  => $label,
      'entity_types' => [
        'asset' => ['plot'],
      ],
      'dependencies' => [
        'enforced' => [
          'module' => ['farm_rothamsted_experiment'],
        ],
      ],
    ]);
    $flag->save();
  }
  elseif ($flag = \Drupal\farm_flag\Entity\FarmFlag::load($flag_id)) {
    $flag->delete();
  }
}
paul121 commented 2 years ago

These restrictions would ideally also show up on the quick forms when selecting plots, but perhaps with an abbreviation (ideas for which are in brackets next to the type of restriction, but I'm open to alternatives as I don't think they are all that great)

Opening a new issue for this #241