Skip to content

Commit

Permalink
Manage sub-optimization disipline in json push/pull (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
relf authored Aug 29, 2024
1 parent e8d66e0 commit 6bf30c3
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions app/controllers/api/v1/analyses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def update
json_response @mda
elsif import
if @mda.packaged? || @mda.operated?
p @mda.packaged?
p @mda.operated?
json_response @mda, :forbidden
else
fromAnalysis = Analysis.find(import[:analysis])
Expand Down Expand Up @@ -135,10 +133,12 @@ def mda_params
import: [:analysis, disciplines: [] ],
disciplines_attributes: [
:name,
:type,
variables_attributes: [
:name, :io_mode, :type, :shape, :units, :desc,
:name, :io_mode, :type, :shape, :units, :desc, :active,
parameter_attributes: [:lower, :upper, :init],
scaling_attributes: [:ref, :ref0, :res_ref]
scaling_attributes: [:ref, :ref0, :res_ref],
distributions_attributes: {}
],
sub_analysis_attributes: {}
]
Expand Down
10 changes: 6 additions & 4 deletions app/models/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def to_xdsm(name = "root")
name: i == 0 ? "_U_" : n[:name],
type: i == 0 ? "driver" : n[:type]
}
node[:subxdsm] = n[:link][:name] if n[:type] == "group" && n[:link]
node[:subxdsm] = n[:link][:name] if (n[:type] == "group" || n[:type] == "sub-optimization") && n[:link]
node
},
edges: build_edges.map { |e|
Expand All @@ -358,6 +358,7 @@ def build_nodes
# TODO: if XDSM v2 accepted migrate database to take into account XDSM v2 new types
# mda -> group
node[:type] = "group" if node[:type] == "mda"
node[:type] = "sub-optimization" if node[:type] == "mdo"
# analysis -> function
# not required as function and analysis are considered synonymous in XDSMjs for XDSM v2
node[:type] = "function" if node[:type] == "analysis"
Expand Down Expand Up @@ -816,19 +817,20 @@ def self.create_nested_analyses(mda_attrs)
end

# create disciplines
# Rails.logger.info "################ BEFORE CREATE #{mda_attrs["name"]}"
# Rails.logger.info "################ BEFORE CREATE #{mda_attrs}"
mda = Analysis.create(mda_attrs)
# Rails.logger.info "################ AFTER CREATE #{mda_attrs["name"]}"
# Rails.logger.info ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #{mda.name}"
Variable.of_analysis(mda).each do |v|
# Variable.of_analysis(mda).each do |v|
# Rails.logger.info ">>> #{v.discipline.name}(#{v.discipline.id}) #{v.name} #{v.io_mode}"
end
# end
# Connection.of_analysis(mda).each do |c|
# # Rails.logger.info "CCCCCCCCCCCCCCC #{c.from.discipline.name} -> #{c.to.discipline.name} #{c.from.name}(#{c.from.id})"
# end
# link disciplines and sub analyses
subs.each.with_index do |submda, i|
if submda
# Rails.logger.info "before DISCIPLINE TYPE #{mda.disciplines[i].type}"
mda.disciplines[i].create_sub_analysis_discipline!(submda)
# Rails.logger.info "DISCIPLINE TYPE #{mda.disciplines[i].type}"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/discipline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def build_sub_analysis(mda_params)
end

def create_sub_analysis_discipline!(innermda)
self.type = Discipline::ANALYSIS
self.type = Discipline::ANALYSIS if self.type != Discipline::ANALYSIS && self.type != Discipline::OPTIMIZATION
self.name = innermda.name
self.save!
ad = self.build_analysis_discipline(analysis: innermda)
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/analysis_attrs_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AnalysisAttrsSerializer < ActiveModel::Serializer

def disciplines_attributes
object.disciplines.filter_map { |disc|
if disc.type == Discipline::ANALYSIS
if disc.type == Discipline::ANALYSIS or disc.type == Discipline::OPTIMIZATION
{
"name" => disc.name,
"type" => disc.type,
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/analysis_diff_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AnalysisDiffSerializer < ActiveModel::Serializer

def disciplines
object.disciplines.filter_map { |disc|
if disc.type == Discipline::ANALYSIS
if disc.type == Discipline::ANALYSIS or disc.type == Discipline::OPTIMIZATION
{
"name": disc.name,
"sub_analysis": AnalysisDiffSerializer.new(disc.sub_analysis).as_json
Expand Down

0 comments on commit 6bf30c3

Please sign in to comment.