Skip to content

Commit

Permalink
feat: add conversion rate to reactions samples table and reaction scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
adambasha0 committed Oct 14, 2024
1 parent 8501ec5 commit 3f82f54
Show file tree
Hide file tree
Showing 25 changed files with 276 additions and 104 deletions.
1 change: 1 addition & 0 deletions app/api/entities/reaction_material_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ class ReactionMaterialEntity < ApplicationEntity
expose! :waste
expose! :gas_type
expose! :gas_phase_data
expose! :conversion_rate
end
end
2 changes: 2 additions & 0 deletions app/api/helpers/report_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ def build_sql_reaction_sample(columns, c_id, ids, checkedAll = false)
# reactions_sample:
equivalent: ['r_s.equivalent', '"r eq"', 10],
reference: ['r_s.reference', '"r ref"', 10],
conversion_rate: ['r_s.conversion_rate', '"r conversion rate"', 10],
},
analysis: {
name: ['anac."name"', '"name"', 10],
Expand Down Expand Up @@ -723,6 +724,7 @@ def force_molfile_selection
equivalent
reference
type
conversion_rate
],
sample: %i[
sample_svg_file
Expand Down
2 changes: 2 additions & 0 deletions app/models/reaction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
# variations :jsonb
# plain_text_description :text
# plain_text_observation :text
# gaseous :boolean default(FALSE)
# vessel_size :jsonb
#
# Indexes
#
Expand Down
25 changes: 14 additions & 11 deletions app/models/reactions_product_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#
# Table name: reactions_samples
#
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# gas_type :integer default("off")
# gas_phase_data :jsonb
# conversion_rate :float
#
# Indexes
#
Expand Down
25 changes: 14 additions & 11 deletions app/models/reactions_purification_solvent_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#
# Table name: reactions_samples
#
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# gas_type :integer default("off")
# gas_phase_data :jsonb
# conversion_rate :float
#
# Indexes
#
Expand Down
25 changes: 14 additions & 11 deletions app/models/reactions_reactant_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#
# Table name: reactions_samples
#
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# gas_type :integer default("off")
# gas_phase_data :jsonb
# conversion_rate :float
#
# Indexes
#
Expand Down
25 changes: 14 additions & 11 deletions app/models/reactions_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#
# Table name: reactions_samples
#
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# gas_type :integer default("off")
# gas_phase_data :jsonb
# conversion_rate :float
#
# Indexes
#
Expand Down
25 changes: 14 additions & 11 deletions app/models/reactions_solvent_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#
# Table name: reactions_samples
#
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# gas_type :integer default("off")
# gas_phase_data :jsonb
# conversion_rate :float
#
# Indexes
#
Expand Down
25 changes: 14 additions & 11 deletions app/models/reactions_starting_material_sample.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
#
# Table name: reactions_samples
#
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# id :integer not null, primary key
# reaction_id :integer
# sample_id :integer
# reference :boolean
# equivalent :float
# position :integer
# type :string
# deleted_at :datetime
# waste :boolean default(FALSE)
# coefficient :float default(1.0)
# show_label :boolean default(FALSE), not null
# gas_type :integer default("off")
# gas_phase_data :jsonb
# conversion_rate :float
#
# Indexes
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default class NumeralInputWithUnitsCompo extends Component {

togglePrefix(currentUnit) {
const units = ['TON/h', 'TON/m', 'TON/s', '°C', '°F', 'K', 'h', 'm', 's'];
const excludedUnits = ['ppm', 'TON'];
const excludedUnits = ['ppm', 'TON', '%'];
const { onMetricsChange, unit } = this.props;
if (units.includes(currentUnit)) {
// eslint-disable-next-line no-unused-expressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ export default class ReactionDetails extends Component {
offColor="#d3d3d3"
tooltipOn="Click to enable Default mode"
tooltipOff="Click to enable Gas mode"
fontSize="14px"
fontWeight="normal"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class Material extends Component {
this.gasFieldsUnitsChanged = this.gasFieldsUnitsChanged.bind(this);
this.handleCoefficientChange = this.handleCoefficientChange.bind(this);
this.debounceHandleAmountUnitChange = debounce(this.handleAmountUnitChange, 500);
this.yieldOrConversionRate = this.yieldOrConversionRate.bind(this);
}

handleMaterialClick(sample) {
Expand Down Expand Up @@ -241,35 +242,65 @@ class Material extends Component {
return result > 1 ? '100%' : `${(result * 100).toFixed(0)}%`;
}

equivalentOrYield(material) {
const { reaction, materialGroup } = this.props;
if (materialGroup === 'products') {
const refMaterial = reaction.getReferenceMaterial();
let calculateYield = material.equivalent;
if (material.gas_type === 'gas') {
calculateYield = this.recalculateYieldForGasProduct(material, reaction);
} else if (reaction.hasPolymers()) {
calculateYield = `${((material.equivalent || 0) * 100).toFixed(0)}%`;
} else if (refMaterial && (refMaterial.decoupled || material.decoupled)) {
calculateYield = 'n.a.';
} else if (material.purity < 1 && material.equivalent > 1) {
calculateYield = `${((material.purity / 100 * (material.amount_g * 1000)) * 100).toFixed(1)}%`;
} else {
calculateYield = `${((material.equivalent <= 1 ? material.equivalent || 0 : 1) * 100).toFixed(0)}%`;
}
calculateYield(material, reaction) {
const refMaterial = reaction.getReferenceMaterial();
let calculateYield = material.equivalent;
if (material.gas_type === 'gas') {
calculateYield = this.recalculateYieldForGasProduct(material, reaction);
} else if (reaction.hasPolymers()) {
calculateYield = `${((material.equivalent || 0) * 100).toFixed(0)}%`;
} else if (refMaterial && (refMaterial.decoupled || material.decoupled)) {
calculateYield = 'n.a.';
} else if (material.purity < 1 && material.equivalent > 1) {
calculateYield = `${((material.purity / 100 * (material.amount_g * 1000)) * 100).toFixed(1)}%`;
} else {
calculateYield = `${((material.equivalent <= 1 ? material.equivalent || 0 : 1) * 100).toFixed(0)}%`;
}
return calculateYield;
}

conversionRateField(material) {
const { reaction } = this.props;
const condition = material.conversion_rate / 100 > 1;
const allowedConversionRateValue = material.conversion_rate && condition
? 100 : material.conversion_rate;
return (
<div>
<NumeralInputWithUnitsCompo
precision={4}
value={allowedConversionRateValue || 'n.d.'}
unit="%"
disabled={!permitOn(reaction)}
onChange={(e) => this.handleConversionRateChange(e)}
/>
</div>
);
}

yieldOrConversionRate(material) {
const { reaction, displayYieldField } = this.props;
if (displayYieldField) {
return (
<div>
<FormControl
name="yield"
type="text"
bsClass="bs-form--compact form-control"
bsSize="small"
value={calculateYield || 'n.d.'}
value={this.calculateYield(material, reaction) || 'n.d.'}
disabled
/>
</div>
);
}
return this.conversionRateField(material);
}

equivalentOrYield(material) {
const { materialGroup } = this.props;
if (materialGroup === 'products') {
return this.yieldOrConversionRate(material);
}
return (
<NumeralInputWithUnitsCompo
precision={4}
Expand Down Expand Up @@ -520,6 +551,20 @@ class Material extends Component {
}
}

handleConversionRateChange(e) {
const { onChange, materialGroup } = this.props;
const conversionRate = e.value;
if (onChange && e) {
const event = {
type: 'conversionRateChanged',
materialGroup,
sampleID: this.materialId(),
conversionRate
};
onChange(event);
}
}

handleGasFieldsChange(field, e, currentValue) {
const { materialGroup, onChange } = this.props;
if (onChange && e.value !== undefined && e.unit !== undefined && e.value !== currentValue) {
Expand Down Expand Up @@ -1071,4 +1116,5 @@ Material.propTypes = {
canDrop: PropTypes.bool,
isOver: PropTypes.bool,
lockEquivColumn: PropTypes.bool.isRequired,
displayYieldField: PropTypes.bool,
};
Loading

0 comments on commit 3f82f54

Please sign in to comment.