-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from OneraHub/ft-mdajson
export analysis in pushable json format
- Loading branch information
Showing
10 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module WhatsOpt | ||
class MdajsonGenerator | ||
|
||
def initialize(mda) | ||
@mda = mda | ||
end | ||
|
||
def generate | ||
as_json = AnalysisAttrsSerializer.new(@mda).as_json | ||
|
||
as_json.to_json | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnalysisAttrsSerializer < ActiveModel::Serializer | ||
attributes :name, :disciplines_attributes | ||
|
||
def disciplines_attributes | ||
object.disciplines.map { |disc| | ||
if disc.type == Discipline::ANALYSIS | ||
{ | ||
"name" => disc.name, | ||
"type" => disc.type, | ||
"sub_analysis_attributes": AnalysisAttrsSerializer.new(disc.sub_analysis) | ||
} | ||
else | ||
DisciplineAttrsSerializer.new(disc) | ||
end | ||
}.compact | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class DisciplineAttrsSerializer < ActiveModel::Serializer | ||
attributes :name, :type | ||
|
||
has_many :variables, key: :variables_attributes | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Api::V1::ExportsControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@auth_headers = { "Authorization" => "Token " + TEST_API_KEY } | ||
@mda = analyses(:cicav) | ||
end | ||
|
||
test "should dump analysis as json" do | ||
get api_v1_mda_exports_new_url(@mda, format: :mdajson), as: :json, headers: @auth_headers | ||
assert_response :success | ||
resp = JSON.parse(response.body) | ||
expected = sample_file("cicav_mda.json").read.chomp | ||
assert_equal expected, resp.to_json.to_s | ||
end | ||
|
||
test "should dump nested analysis as json" do | ||
mda = analyses(:outermda) | ||
get api_v1_mda_exports_new_url(mda, format: :mdajson), as: :json, headers: @auth_headers | ||
assert_response :success | ||
resp = JSON.parse(response.body) | ||
expected = sample_file("outer_mda.json").read.chomp | ||
assert_equal expected, resp.to_json.to_s | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"CICAV","disciplines_attributes":[{"name":"__DRIVER__","type":"null_driver","variables_attributes":[{"name":"obj","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"x1","io_mode":"out","shape":"1","type":"Float","active":true,"parameter_attributes":{"init":"3.14","lower":"1","upper":"10"},"distributions_attributes":[]},{"name":"y2","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"out","shape":"(2,)","type":"Float","active":true,"parameter_attributes":{"init":"3.14","lower":"1","upper":"10"},"distributions_attributes":[]}]},{"name":"Geometry","type":"analysis","variables_attributes":[{"name":"obj","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"x1","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"ya","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"yg","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"in","shape":"(2,)","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"Aerodynamics","type":"analysis","variables_attributes":[{"name":"y2","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"ya","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"yg","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"in","shape":"(2,)","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"Propulsion","type":"analysis","variables_attributes":[]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name":"OUTER","disciplines_attributes":[{"name":"__DRIVER__","type":"null_driver","variables_attributes":[{"name":"x1","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"x2","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y1","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y2","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"Disc","type":"analysis","variables_attributes":[{"name":"x1","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y1","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y2","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"InnerMdaDiscipline","type":"mda","sub_analysis_attributes":{"name":"INNER","disciplines_attributes":[{"name":"__DRIVER__","type":"null_driver","variables_attributes":[{"name":"x2","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y1","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y2","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"PlainDiscipline","type":"analysis","variables_attributes":[{"name":"x2","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y1","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"y2","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]}]}]}},{"name":"VacantDiscipline","type":"analysis","variables_attributes":[]}]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class MdajsonGeneratorTest < ActiveSupport::TestCase | ||
def setup | ||
@mda = analyses(:cicav) | ||
@jsongen = WhatsOpt::MdajsonGenerator.new(@mda) | ||
end | ||
|
||
test "should generate mda json" do | ||
content = @jsongen.generate | ||
expected = sample_file("cicav_mda.json").read.chomp | ||
assert_equal expected, content | ||
end | ||
end |