Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

656 add collectionpurpose to all old hemlock beech ash observations in which collectionpurpose doesnt already exist #662

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions app/Console/Commands/AddCollectionPurpose.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\Observation;


class AddCollectionPurpose extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'observations:add-collection-purpose {category}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Add collectionPurpose to older observations.';

/**
* Execute the console command.
*/
public function handle()
{
// update observations to include collectionPurpose
$category = $this->argument('category');
$this->addCollectionPurpose($category);
}

public function addCollectionPurpose($category)
{
$categories = Observation::select('observation_category')->distinct()->get();
if(!$categories->contains('observation_category',$category)){
$this->info("Invalid category/species.\r\nNo changes made.");
}
//for each observation
Observation::where("observation_category", $category)
//200 observations at a time
->chunk(200, function ($observations) use ($category) {

$collectionPurpose = array(
"collectionPurpose" => "Not Available",
);
$ashCollectionPurpose = array(
"ashCollectionPurpose" => "Not Available",
);
$i = 0;
foreach ($observations as $observation) {
//...if collectionPurpose isn't set, add that field to data
if(!isset($observation->data['collectionPurpose']) && $category !== 'Ash'){
$i++;
$observation->data = array_merge($observation->data, $collectionPurpose);
$observation->save();
}
//...if ashCollectionPurpose isn't set, add that field to data
elseif(!isset($observation->data['ashCollectionPurpose']) && $category == 'Ash'){
$i++;
$observation->data = array_merge($observation->data, $ashCollectionPurpose);
$observation->save();
}
}
$this->info($category);
if($i==1){
$this->info($i.' entry has been updated.');
}
else{
$this->info($i.' entries have been updated.');
}

});
}
}
1 change: 1 addition & 0 deletions app/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class Filter extends Model
protected static $filterMapper = [
'Ash' => 'ash',
'American Chestnut' => 'americanChestnut',
'American Beech' => 'americanBeech',
'Hemlock' => 'hemlock',
'White Oak' => 'whiteOak',
'American Elm' => 'americanElm',
Expand Down
4 changes: 2 additions & 2 deletions app/Services/MetaLabels.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public function __construct()
'madroneDisease' => 'Disease',
'mamaLocationCharacteristics' => 'Habitat',
'moreThanTenHemlocks' => 'Comment on Quantity',
'naturallyOccuring' => 'Naturally Occuring',
'naturallyOccuringV2' => 'Naturally Occuring',
'naturallyOccurring' => 'Naturally Occurring',
'naturallyOccurringV2' => 'Naturally Occurring',
'nearByHemlock' => 'Nearby Hemlocks',
'nearbyTrees' => 'Nearby Trees',
'ashNearbyTrees' => 'Trees Nearby',
Expand Down
17 changes: 17 additions & 0 deletions resources/assets/js/components/AdvancedFiltersModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'
import ButtonList from './ButtonList'
import AmericanChestnutFilters from './subcomponents/AmericanChestnutFilters'
import AshFilters from './subcomponents/AshFilters'
import AmericanBeechFilters from './subcomponents/AmericanBeechFilters'
import HemlockFilters from './subcomponents/HemlockFilters'
import AmericanElmFilters from './subcomponents/AmericanElmFilters'
import WhiteOakFilters from './subcomponents/WhiteOakFilters'
Expand Down Expand Up @@ -32,6 +33,7 @@ export default class AdvancedFiltersModal extends Component {
filterName : '',
americanChestnut : {},
ash : {},
americanBeech : {},
hemlock : {},
americanElm : {},
whiteOak : {},
Expand Down Expand Up @@ -107,6 +109,7 @@ export default class AdvancedFiltersModal extends Component {
name : this.state.filterName,
categories : this.state.selectedCategories,
ash : this.state.ash,
americanBeech : this.state.americanBeech,
americanChestnut: this.state.americanChestnut,
hemlock : this.state.hemlock,
americanElm : this.state.americanElm,
Expand Down Expand Up @@ -191,6 +194,7 @@ export default class AdvancedFiltersModal extends Component {
axios.post('/web/filter/count', {
categories : filters.selectedCategories,
ash : filters.ash,
americanBeech : filters.americanBeech,
americanChestnut: filters.americanChestnut,
hemlock : filters.hemlock,
americanElm : filters.americanElm,
Expand Down Expand Up @@ -278,6 +282,19 @@ export default class AdvancedFiltersModal extends Component {
)
}

renderAmericanBeechFilters() {
return (
<div className="column is-12">
<h3 className="title is-4 mb-0">American Beech Filters (Optional)</h3>
<div className="bordered">
<AmericanBeechFilters
defaultFilters={this.state.americanBeech}
onChange={(americanBeech) => this.count({americanBeech})}/>
</div>
</div>
)
}

renderHemlockFilters() {
return (
<div className="column is-12">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import React, {Component} from 'react'
import PropTypes from 'prop-types'
import ButtonList from '../ButtonList'
import Utils from '../../helpers/Utils'
import FiltersBase from './FiltersBase'

export default class AmericanBeechFilters extends FiltersBase {
constructor(props) {
super(props)

this.state = {
collectionPurpose: [],
locationCharacteristics: [],
nearbyTrees: [],
flowersBinary: []
}
}

_update(key, value) {
this.setState({[key]: value})

this.props.onChange(Object.assign({}, this.state, {[key]: value}))
}

render() {
return (
<div className="columns is-multiline">
<div className="column is-6">
<div className="field">
<label className="label">Collection Purpose</label>
<ButtonList
value={this.state.collectionPurpose}
list={['Landscape Genomics Project with University of Connecticut','Other Research Project','Personal Use','Not Available']}
onChange={collectionPurpose => this._update('collectionPurpose', collectionPurpose)}/>
</div>
</div>
<div className="column is-6">
<div className="field">
<label className="label">Habitat</label>
<ButtonList
value={this.state.locationCharacteristics}
list={[
'Forest',
'Wetland',
'Field',
'Roadside, urban, suburban, or park'
]}
onChange={locationCharacteristics => this._update('locationCharacteristics', locationCharacteristics)}/>
</div>
</div>
<div className="column is-6">
<div className="field">
<label className="label">Trees Nearby</label>
<ButtonList
value={this.state.nearbyTrees}
list={[
'Dead and/or dying',
'Healthy and large',
'Healthy and small',
'No trees of this species nearby',
'Not sure'
]}
onChange={nearbyTrees => this._update('nearbyTrees', nearbyTrees)}/>
</div>
</div>
<div className="column is-6">
<div className="field">
<label className="label">Flowers</label>
<ButtonList
value={this.state.flowersBinary}
list={[
'Yes',
'No'
]}
onChange={flowersBinary => this._update('flowersBinary', flowersBinary)}/>
</div>
</div>
</div>
)
}
}

AmericanBeechFilters.propTypes = {
onChange: PropTypes.func.isRequired
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class AshFilters extends FiltersBase {
<label className="label">Collection Purpose</label>
<ButtonList
value={this.state.ashCollectionPurpose}
list={['(MaMA Protocol) Lingering Ash Search', '(MaMA Protocol) EAB Sighting', 'Other Research Project', 'Personal Use']}
list={['(MaMA Protocol) Lingering Ash Search', '(MaMA Protocol) EAB Sighting', 'Other Research Project', 'Personal Use', 'Not Available']}
onChange={ashCollectionPurpose => this._update('ashCollectionPurpose', ashCollectionPurpose)}/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export default class HemlockFilters extends FiltersBase {
'Lingering hemlock(s) data reporting',
'Landscape Genomics project with University of Connecticut',
'Other Research Project',
'Personal use'
'Personal use',
'Not Available',
]}
onChange={collectionPurpose => this._update('collectionPurpose', collectionPurpose)}/>
</div>
Expand Down