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

first child value derived variable #33

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions schema/library.raml
Original file line number Diff line number Diff line change
Expand Up @@ -3038,6 +3038,7 @@ types:
subsetMembership: SubsetMembershipConfig
advancedSubset: AdvancedSubsetConfig
unitConversion: UnitConversionConfig
firstChildValue: FirstChildValueConfig
bodyMassIndex: BodyMassIndexConfig
categoricalRecoding: CategoricalRecodingConfig
continuousToOrdinal: ContinuousNumericRecodingConfig
Expand Down Expand Up @@ -3106,6 +3107,10 @@ types:
properties:
inputVariable: VariableSpec
outputUnits: string
FirstChildValueConfig:
type: object
properties:
inputVariable: VariableSpec
SetOperation:
type: string
enum:
Expand Down
1 change: 1 addition & 0 deletions schema/url/merge/derived-variable-metadata.raml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ types:
subsetMembership: SubsetMembershipConfig
advancedSubset: AdvancedSubsetConfig
unitConversion: UnitConversionConfig
firstChildValue: FirstChildValueConfig
bodyMassIndex: BodyMassIndexConfig
categoricalRecoding: CategoricalRecodingConfig
continuousToOrdinal: ContinuousNumericRecodingConfig
Expand Down
4 changes: 4 additions & 0 deletions schema/url/merge/derived-variables.raml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ types:
inputVariable: VariableSpec
outputUnits: string

FirstChildValueConfig:
properties:
inputVariable: VariableSpec

SetOperation:
type: string
enum: [ 'intersect', 'union', 'minus' ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import org.veupathdb.service.eda.merge.core.derivedvars.DerivedVariableFactory;
import org.veupathdb.service.eda.merge.core.derivedvars.Reduction;
import org.veupathdb.service.eda.merge.plugins.reductions.Mean;
import org.veupathdb.service.eda.merge.plugins.reductions.RelativeObservationAggregator;
import org.veupathdb.service.eda.merge.plugins.reductions.SubsetMembership;
import org.veupathdb.service.eda.merge.plugins.reductions.Sum;
import org.veupathdb.service.eda.merge.plugins.reductions.*;

import static org.veupathdb.service.eda.merge.core.derivedvars.DerivedVariableFactory.pluginsOf;

Expand All @@ -19,7 +16,8 @@ public static DerivedVariableFactory.PluginMap<Reduction> getPlugins() {
Sum.class,
Mean.class,
SubsetMembership.class,
RelativeObservationAggregator.class
RelativeObservationAggregator.class,
FirstChildValue.class
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package org.veupathdb.service.eda.merge.plugins.reductions;

import org.gusdb.fgputil.validation.ValidationException;
import org.veupathdb.service.eda.common.model.VariableDef;
import org.veupathdb.service.eda.generated.model.APIVariableDataShape;
import org.veupathdb.service.eda.generated.model.APIVariableType;
import org.veupathdb.service.eda.generated.model.FirstChildValueConfig;
import org.veupathdb.service.eda.generated.model.VariableSpec;
import org.veupathdb.service.eda.merge.core.derivedvars.Reduction;

import java.util.List;
import java.util.Map;

public class FirstChildValue extends Reduction<FirstChildValueConfig> {

private VariableSpec _childVariable;
private String _childVariableColumnName;
private VariableDef _childVariableDef;

@Override
public String getFunctionName() {
return "firstChildValue";
}

@Override
protected Class<FirstChildValueConfig> getConfigClass() {
return FirstChildValueConfig.class;
}

@Override
protected void acceptConfig(FirstChildValueConfig config) throws ValidationException {
_childVariable = config.getInputVariable();
_childVariableColumnName = VariableDef.toDotNotation(_childVariable);
}

@Override
protected void performSupplementalDependedVariableValidation() throws ValidationException {
// metadata populated now; get def to return type and shape
_childVariableDef = _metadata.getVariable(_childVariable).get(); // already validated
}

@Override
public List<VariableSpec> getRequiredInputVars() {
return List.of(_childVariable);
}

@Override
public APIVariableType getVariableType() {
return _childVariableDef.getType();
}

@Override
public APIVariableDataShape getDataShape() {
return _childVariableDef.getDataShape();
}

@Override
public Reducer createReducer() {
return new Reducer() {

private String _firstValue;

@Override
public void addRow(Map<String, String> nextRow) {
// only set the first value returned
if (_firstValue == null)
_firstValue = nextRow.get(_childVariableColumnName);
}

@Override
public String getResultingValue() {
return _firstValue == null ? "" : _firstValue;
}
};
}
}