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

feat: Incorporate "Gas Scheme" feature in reaction variations table #2250

Open
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
@@ -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),
Copy link

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|
Copy link

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]

Copy link

github-actions bot commented Dec 3, 2024

LCOV of commit 807bd3d during Continuous Integration #4189

Summary coverage rate:
  lines......: 65.5% (14049 of 21453 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

Copy link

LCOV of commit 2efc953 during Continuous Integration #4258

Summary coverage rate:
  lines......: 66.7% (14339 of 21495 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

@JanCBrammer JanCBrammer force-pushed the reaction-variations-gas-phase branch from 2efc953 to c02afd0 Compare December 19, 2024 06:27
Copy link
Contributor

@adambasha0 adambasha0 left a 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
Copy link
Contributor

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

Copy link
Collaborator Author

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')
Copy link
Contributor

@adambasha0 adambasha0 Dec 20, 2024

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]

Copy link
Collaborator Author

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.

app/api/entities/reaction_variation_entity.rb Outdated Show resolved Hide resolved
end

class AddGasMaterialsToReactionVariations < ActiveRecord::Migration[6.1]
def up
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

Copy link
Contributor

@adambasha0 adambasha0 Jan 10, 2025

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

Copy link
Collaborator Author

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?

Copy link
Contributor

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?

Copy link
Collaborator Author

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')
Copy link
Contributor

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?

Copy link
Collaborator Author

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,
Copy link
Contributor

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

Copy link
Collaborator Author

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.

Copy link
Contributor

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?"

Copy link
Collaborator Author

@JanCBrammer JanCBrammer Jan 10, 2025

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you check this error? , it happens when I click on duration button: cellData undefined

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean the duration entry of a gaseous product?

image

What data resulted in the error? For existing data, you might need to run the migration (the one that's part of this PR).

@JanCBrammer JanCBrammer force-pushed the reaction-variations-gas-phase branch from c02afd0 to bf86a76 Compare January 9, 2025 11:41
@@ -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),
Copy link

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]

Copy link

github-actions bot commented Jan 9, 2025

LCOV of commit bf86a76 during Continuous Integration #4290

Summary coverage rate:
  lines......: 66.9% (14431 of 21587 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

@PiTrem PiTrem added this to the v2.0.0 milestone Jan 21, 2025
@JanCBrammer JanCBrammer force-pushed the reaction-variations-gas-phase branch from bf86a76 to 90944aa Compare January 24, 2025 07:09
(v[:aux][:isReference] ? '; Ref' : '')
end
end
variation[type].map do |_, vi|

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]

Copy link

LCOV of commit 90944aa during Continuous Integration #4353

Summary coverage rate:
  lines......: 66.9% (14443 of 21581 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

Copy link

LCOV of commit 63c42a7 during Continuous Integration #4360

Summary coverage rate:
  lines......: 66.8% (14426 of 21582 lines)
  functions..: no data found
  branches...: no data found

Files changed coverage rate: n/a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reaction Variations: Incorporate "Gas Scheme" feature
3 participants