-
Notifications
You must be signed in to change notification settings - Fork 55
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
feat: Incorporate "Gas Scheme" feature in reaction variations table #2250
base: main
Are you sure you want to change the base?
Conversation
@@ -60,23 +60,25 @@ def variations | |||
'startingMaterials' => variation_materials(var, :startingMaterials), | |||
'reactants' => variation_materials(var, :reactants), | |||
'solvents' => variation_materials(var, :solvents), | |||
'products' => variation_products(var), | |||
'products' => variation_materials(var, :products), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [626/200]
(v[:aux][:isReference] ? '; Ref' : '') | ||
end | ||
end | ||
variation[type].map do |_, vi| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/CyclomaticComplexity: Cyclomatic complexity for variation_materials is too high. [8/7]
LCOV of commit
|
807bd3d
to
2efc953
Compare
LCOV of commit
|
2efc953
to
c02afd0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Jan, Thanks for the feature. I posted some suggestions and potential bug that you can check later.
@@ -10,7 +10,7 @@ | |||
# | |||
# It's strongly recommended that you check this file into your version control system. | |||
|
|||
ActiveRecord::Schema.define(version: 2024_07_26_064022) do | |||
ActiveRecord::Schema.define(version: 2024_11_29_093956) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the timestamp change needed in this PR? - updating the timestamp might seem unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing the timestamp is meant to ensure that we run the migration that's necessary for this PR to work.
See db/migrate/20241129093956_add_gas_materials_to_reaction_variations.rb
.
variations.each do |variation| | ||
SAMPLES_TYPES.each do |key| | ||
variation[key].each_value do |material| | ||
material['aux'].delete('materialType') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
many repeated code in this block, especially: material.delete
suggestion: combine all keys to be deleted in one array and loop over the array to delete elements in a separate method
keys_to_delete = %w[duration temperature concentration turnoverNumber turnoverFrequency]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like a one-off migration is not the place to save LOC.
In this case I believe it doesn't hurt to keep the code explicit.
end | ||
|
||
class AddGasMaterialsToReactionVariations < ActiveRecord::Migration[6.1] | ||
def up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure what these migrations are used for, especially the down migration. can you explain the design concept here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The migration is modifying the variations
column of the reaction table.
Note that the migration does not add or remove columns in the table.
Instead it updates the existing data in the variations
column to accommodate the gas feature.
Accommodating the gas feature consists of adding new entries to materials (such as aux.gasType
).
It also means some restructuring of the materials' data to make the overall data structure more uniform.
The down migration undoes all changes related to the gas feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how did it exist at the first place? - the gas phase feature was not there before
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I don't understand the question. What's "it" referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how come these attributes (such as: turnoverFrequency, turnoverNumber, concentration, temperature, duration, and gasType) are deleted from the reactions variations, if there are not supposed to be there at the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The attributes related to the gas feature are deleted in the down
migration because the down
migration is reverting the up
migration where they're added.
material.delete('duration') | ||
material.delete('temperature') | ||
material.delete('concentration') | ||
material.delete('turnoverNumber') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it better to adhere to ruby's standard naming convention about using snake case and also to match the attribute names in the the gas_phase_data column in reactions_samples table?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reaction-variations data-structure is exclusively handled on the client (JS) side, that's why I stuck with camelCase.
@@ -27,158 +27,182 @@ | |||
variations: [{ id: '1', | |||
analyses: [1, 2], | |||
notes: '', | |||
products: { '47': { aux: { yield: 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it would be nice to have factory reaction_with_variations defined in factories/reactions.rb. This would make it easier to create reactions with variations consistently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I avoided doing this so far tbh. See bf86a76.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, good. Did I miss the utilization of reaction_with_variations to test the functionality of updating a value or unit (e.g., in the gas phase) and verifying the recalculation of affected material values or units? Additionally, do we have a validation mechanism in the backend to ensure the accuracy of values submitted from the client to the server before they are saved in the database?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did I miss the utilization of reaction_with_variations to test the functionality of updating a value or unit (e.g., in the gas phase) and verifying the recalculation of affected material values or units?
Do the tests under spec/javascripts/packs/src/apps/mydb/elements/details/reactions/variationsTab/
cover what you have in mind?
ensure the accuracy of values submitted from the client to the server before they are saved in the database?
What do you mean with "accuracy"?
} | ||
|
||
function MaterialFormatter({ value: cellData, colDef }) { | ||
const { currentEntry, displayUnit } = colDef.entryDefs; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c02afd0
to
bf86a76
Compare
@@ -60,23 +60,25 @@ def variations | |||
'startingMaterials' => variation_materials(var, :startingMaterials), | |||
'reactants' => variation_materials(var, :reactants), | |||
'solvents' => variation_materials(var, :solvents), | |||
'products' => variation_products(var), | |||
'products' => variation_materials(var, :products), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [627/200]
LCOV of commit
|
The example of the reaction variations data structure is unnecessarily verbose and prone to be outdated.
bf86a76
to
90944aa
Compare
(v[:aux][:isReference] ? '; Ref' : '') | ||
end | ||
end | ||
variation[type].map do |_, vi| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/CyclomaticComplexity: Cyclomatic complexity for variation_materials
is too high. [8/7]
LCOV of commit
|
LCOV of commit
|
This PR addresses #2213.
See also https://docs.google.com/document/d/1Jd6V5zqRv0cfw_xAJE-oHDYzSuBMQyBBz3wQQBxRGJo/edit and https://www.chemotion.net/docs/eln/ui/elements/reactions?_highlight=gas#gas-phase-reaction-scheme.