diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Main.soda b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Main.soda index 37e7171..64104b5 100644 --- a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Main.soda +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Main.soda @@ -14,6 +14,8 @@ class Main yaml_parser = YamlParser .mk + yaml_serializer = YamlSerializer .mk + operation_parser = OperationParser .mk operation_processor = OperationProcessor .mk @@ -26,17 +28,9 @@ class Main ) ) - _serialize_market (m : Market) : String = - "Account balances:\n" + - (m .accounts .map (lambda account --> account .toString) .mkString (", ") ) + "\n\n" + - "Items:\n" + - (m .items .map (lambda item --> - "(" + item .owner .toString + ", " + item .price .toString + ")" ) .mkString (" , ") ) + - "\n\n" - serialize_market (maybe_market : Option [Market] ) : String = match maybe_market - case Some (market) ==> _serialize_market (market) + case Some (market) ==> yaml_serializer .serialize_market (market) case None ==> "Undefined market" execute (arguments : List [String] ) : Unit = diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.scala b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.scala index acb3270..aa73488 100644 --- a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.scala +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.scala @@ -14,6 +14,7 @@ import soda.se.umu.cs.soda.prototype.example.market.core.Money import soda.se.umu.cs.soda.prototype.example.market.core.OperationProcessor import soda.se.umu.cs.soda.prototype.example.market.parser.OperationParser import soda.se.umu.cs.soda.prototype.example.market.parser.YamlParser +import soda.se.umu.cs.soda.prototype.example.market.serializer.YamlSerializer /** * This is the main entry point. @@ -31,6 +32,8 @@ trait Main lazy val yaml_parser = YamlParser .mk + lazy val yaml_serializer = YamlSerializer .mk + lazy val operation_parser = OperationParser .mk lazy val operation_processor = OperationProcessor .mk @@ -43,17 +46,9 @@ trait Main ) ) - private def _serialize_market (m : Market) : String = - "Account balances:\n" + - (m .accounts .map ( account => account .toString) .mkString (", ") ) + "\n\n" + - "Items:\n" + - (m .items .map ( item => - "(" + item .owner .toString + ", " + item .price .toString + ")" ) .mkString (" , ") ) + - "\n\n" - def serialize_market (maybe_market : Option [Market] ) : String = maybe_market match { - case Some (market) => _serialize_market (market) + case Some (market) => yaml_serializer .serialize_market (market) case None => "Undefined market" } diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.soda b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.soda index 27ec32a..7a0759a 100644 --- a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.soda +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/main/Package.soda @@ -15,3 +15,4 @@ import soda.se.umu.cs.soda.prototype.example.market.core.OperationProcessor soda.se.umu.cs.soda.prototype.example.market.parser.OperationParser soda.se.umu.cs.soda.prototype.example.market.parser.YamlParser + soda.se.umu.cs.soda.prototype.example.market.serializer.YamlSerializer diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/MarketSerializer.soda b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/MarketSerializer.soda new file mode 100644 index 0000000..6152b9f --- /dev/null +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/MarketSerializer.soda @@ -0,0 +1,27 @@ + +class MarketSerializer + + abstract + + serialize_accounts (accounts : List [Money] ) : List [Operation] = + accounts + .zipWithIndex + .map (lambda pair --> OpDeposit .mk (pair ._2) (pair ._1) ) + + serialize_items (items : List [Item] ) : List [Operation] = + items + .zipWithIndex + .flatMap (lambda pair --> + List [Operation] ( + OpAssign .mk (pair ._2) (pair ._1 .owner) , + OpPrice .mk (pair ._2) (pair ._1 .price) + ) + ) + + serialize (m : Market) : List [Operation] = + serialize_accounts (m .accounts) .++ ( + serialize_items (m .items) + ) + +end + diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.scala b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.scala index ca32cef..5035d9e 100644 --- a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.scala +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.scala @@ -1,7 +1,8 @@ package soda.se.umu.cs.soda.prototype.example.market.serializer -import soda.se.umu.cs.soda.prototype.example.market.core.Operation -import soda.se.umu.cs.soda.prototype.example.market.core.OperationEnum +import soda.se.umu.cs.soda.prototype.example.market.core.Item +import soda.se.umu.cs.soda.prototype.example.market.core.Market +import soda.se.umu.cs.soda.prototype.example.market.core.Money import soda.se.umu.cs.soda.prototype.example.market.core.OpAssign import soda.se.umu.cs.soda.prototype.example.market.core.OpAssign_ import soda.se.umu.cs.soda.prototype.example.market.core.OpDeposit @@ -12,9 +13,47 @@ import soda.se.umu.cs.soda.prototype.example.market.core.OpSell import soda.se.umu.cs.soda.prototype.example.market.core.OpSell_ import soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined import soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined_ +import soda.se.umu.cs.soda.prototype.example.market.core.Operation +import soda.se.umu.cs.soda.prototype.example.market.core.OperationEnum +import soda.se.umu.cs.soda.prototype.example.market.core.OperationProcessor + + + + +trait MarketSerializer +{ + + + + def serialize_accounts (accounts : List [Money] ) : List [Operation] = + accounts + .zipWithIndex + .map ( pair => OpDeposit .mk (pair ._2) (pair ._1) ) + def serialize_items (items : List [Item] ) : List [Operation] = + items + .zipWithIndex + .flatMap ( pair => + List [Operation] ( + OpAssign .mk (pair ._2) (pair ._1 .owner) , + OpPrice .mk (pair ._2) (pair ._1 .price) + ) + ) + def serialize (m : Market) : List [Operation] = + serialize_accounts (m .accounts) .++ ( + serialize_items (m .items) + ) + +} + +case class MarketSerializer_ () extends MarketSerializer + +object MarketSerializer { + def mk : MarketSerializer = + MarketSerializer_ () +} trait OperationSerializer @@ -50,3 +89,36 @@ object OperationSerializer { OperationSerializer_ () } + +trait YamlSerializer +{ + + + + lazy val market_serializer = MarketSerializer .mk + + lazy val operation_serializer = OperationSerializer .mk + + def serialize_operations (operations : List [Operation] ) : String = + "operations:" + + "\n- " + + operations + .map ( operation => operation_serializer .serialize (operation) ) + .mkString ("\n- ") + + "\n\n" + + def serialize_market (m : Market) : String = + "---\n" + + serialize_operations ( + market_serializer .serialize (m) + ) + +} + +case class YamlSerializer_ () extends YamlSerializer + +object YamlSerializer { + def mk : YamlSerializer = + YamlSerializer_ () +} + diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.soda b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.soda index 138103e..6aa4e85 100644 --- a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.soda +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/Package.soda @@ -1,8 +1,9 @@ package soda.se.umu.cs.soda.prototype.example.market.serializer import - soda.se.umu.cs.soda.prototype.example.market.core.Operation - soda.se.umu.cs.soda.prototype.example.market.core.OperationEnum + soda.se.umu.cs.soda.prototype.example.market.core.Item + soda.se.umu.cs.soda.prototype.example.market.core.Market + soda.se.umu.cs.soda.prototype.example.market.core.Money soda.se.umu.cs.soda.prototype.example.market.core.OpAssign soda.se.umu.cs.soda.prototype.example.market.core.OpAssign_ soda.se.umu.cs.soda.prototype.example.market.core.OpDeposit @@ -13,4 +14,7 @@ import soda.se.umu.cs.soda.prototype.example.market.core.OpSell_ soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined_ + soda.se.umu.cs.soda.prototype.example.market.core.Operation + soda.se.umu.cs.soda.prototype.example.market.core.OperationEnum + soda.se.umu.cs.soda.prototype.example.market.core.OperationProcessor diff --git a/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/YamlSerializer.soda b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/YamlSerializer.soda new file mode 100644 index 0000000..d8a3dc1 --- /dev/null +++ b/core/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/serializer/YamlSerializer.soda @@ -0,0 +1,25 @@ + +class YamlSerializer + + abstract + + market_serializer = MarketSerializer .mk + + operation_serializer = OperationSerializer .mk + + serialize_operations (operations : List [Operation] ) : String = + "operations:" + + "\n- " + + operations + .map (lambda operation --> operation_serializer .serialize (operation) ) + .mkString ("\n- ") + + "\n\n" + + serialize_market (m : Market) : String = + "---\n" + + serialize_operations ( + market_serializer .serialize (m) + ) + +end + diff --git a/core/src/test/resources/example/example0.yaml b/core/src/test/resources/example/example0.yaml index 7db7d58..6841a89 100644 --- a/core/src/test/resources/example/example0.yaml +++ b/core/src/test/resources/example/example0.yaml @@ -39,64 +39,64 @@ operations: - deposit 24 1750 - deposit 25 2350 - assign 0 12 -- assign 1 7 -- assign 2 20 -- assign 3 15 -- assign 4 8 -- assign 5 23 -- assign 6 14 -- assign 7 2 -- assign 8 19 -- assign 9 5 -- assign 10 22 -- assign 11 13 -- assign 12 4 -- assign 13 18 -- assign 14 9 -- assign 15 24 -- assign 16 11 -- assign 17 3 -- assign 18 17 -- assign 19 10 -- assign 20 21 -- assign 21 16 -- assign 22 1 -- assign 23 25 -- assign 24 6 -- assign 25 0 -- assign 26 15 -- assign 27 10 -- assign 28 20 -- assign 29 5 - price 0 40 +- assign 1 7 - price 1 50 +- assign 2 20 - price 2 25 +- assign 3 15 - price 3 70 +- assign 4 8 - price 4 100 +- assign 5 23 - price 5 60 +- assign 6 14 - price 6 30 +- assign 7 2 - price 7 40 +- assign 8 19 - price 8 25 +- assign 9 5 - price 9 20 +- assign 10 22 - price 10 90 +- assign 11 13 - price 11 50 +- assign 12 4 - price 12 100 +- assign 13 18 - price 13 150 +- assign 14 9 - price 14 30 +- assign 15 24 - price 15 30 +- assign 16 11 - price 16 25 +- assign 17 3 - price 17 200 +- assign 18 17 - price 18 20 +- assign 19 10 - price 19 30 +- assign 20 21 - price 20 20 +- assign 21 16 - price 21 100 +- assign 22 1 - price 22 100 +- assign 23 25 - price 23 20 +- assign 24 6 - price 24 30 +- assign 25 0 - price 25 20 +- assign 26 15 - price 26 25 +- assign 27 10 - price 27 40 +- assign 28 20 - price 28 80 +- assign 29 5 - price 29 100 - sell 10 25 diff --git a/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0Instance.soda b/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0Instance.soda index 8021dcc..60d1139 100644 --- a/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0Instance.soda +++ b/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0Instance.soda @@ -34,64 +34,64 @@ class Example0Instance "deposit 24 1750" , "deposit 25 2350" , "assign 0 12" , - "assign 1 7" , - "assign 2 20" , - "assign 3 15" , - "assign 4 8" , - "assign 5 23" , - "assign 6 14" , - "assign 7 2" , - "assign 8 19" , - "assign 9 5" , - "assign 10 22" , - "assign 11 13" , - "assign 12 4" , - "assign 13 18" , - "assign 14 9" , - "assign 15 24" , - "assign 16 11" , - "assign 17 3" , - "assign 18 17" , - "assign 19 10" , - "assign 20 21" , - "assign 21 16" , - "assign 22 1" , - "assign 23 25" , - "assign 24 6" , - "assign 25 0" , - "assign 26 15" , - "assign 27 10" , - "assign 28 20" , - "assign 29 5" , "price 0 40" , + "assign 1 7" , "price 1 50" , + "assign 2 20" , "price 2 25" , + "assign 3 15" , "price 3 70" , + "assign 4 8" , "price 4 100" , + "assign 5 23" , "price 5 60" , + "assign 6 14" , "price 6 30" , + "assign 7 2" , "price 7 40" , + "assign 8 19" , "price 8 25" , + "assign 9 5" , "price 9 20" , + "assign 10 22" , "price 10 90" , + "assign 11 13" , "price 11 50" , + "assign 12 4" , "price 12 100" , + "assign 13 18" , "price 13 150" , + "assign 14 9" , "price 14 30" , + "assign 15 24" , "price 15 30" , + "assign 16 11" , "price 16 25" , + "assign 17 3" , "price 17 200" , + "assign 18 17" , "price 18 20" , + "assign 19 10" , "price 19 30" , + "assign 20 21" , "price 20 20" , + "assign 21 16" , "price 21 100" , + "assign 22 1" , "price 22 100" , + "assign 23 25" , "price 23 20" , + "assign 24 6" , "price 24 30" , + "assign 25 0" , "price 25 20" , + "assign 26 15" , "price 26 25" , + "assign 27 10" , "price 27 40" , + "assign 28 20" , "price 28 80" , + "assign 29 5" , "price 29 100" , "sell 10 25" ) diff --git a/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0OperationList.soda b/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0OperationList.soda index 9d71ca3..dc3d5df 100644 --- a/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0OperationList.soda +++ b/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Example0OperationList.soda @@ -32,64 +32,64 @@ class Example0OperationList OpDeposit .mk (24) (1750) , OpDeposit .mk (25) (2350) , OpAssign .mk (0) (12) , - OpAssign .mk (1) (7) , - OpAssign .mk (2) (20) , - OpAssign .mk (3) (15) , - OpAssign .mk (4) (8) , - OpAssign .mk (5) (23) , - OpAssign .mk (6) (14) , - OpAssign .mk (7) (2) , - OpAssign .mk (8) (19) , - OpAssign .mk (9) (5) , - OpAssign .mk (10) (22) , - OpAssign .mk (11) (13) , - OpAssign .mk (12) (4) , - OpAssign .mk (13) (18) , - OpAssign .mk (14) (9) , - OpAssign .mk (15) (24) , - OpAssign .mk (16) (11) , - OpAssign .mk (17) (3) , - OpAssign .mk (18) (17) , - OpAssign .mk (19) (10) , - OpAssign .mk (20) (21) , - OpAssign .mk (21) (16) , - OpAssign .mk (22) (1) , - OpAssign .mk (23) (25) , - OpAssign .mk (24) (6) , - OpAssign .mk (25) (0) , - OpAssign .mk (26) (15) , - OpAssign .mk (27) (10) , - OpAssign .mk (28) (20) , - OpAssign .mk (29) (5) , OpPrice .mk (0) (40) , + OpAssign .mk (1) (7) , OpPrice .mk (1) (50) , + OpAssign .mk (2) (20) , OpPrice .mk (2) (25) , + OpAssign .mk (3) (15) , OpPrice .mk (3) (70) , + OpAssign .mk (4) (8) , OpPrice .mk (4) (100) , + OpAssign .mk (5) (23) , OpPrice .mk (5) (60) , + OpAssign .mk (6) (14) , OpPrice .mk (6) (30) , + OpAssign .mk (7) (2) , OpPrice .mk (7) (40) , + OpAssign .mk (8) (19) , OpPrice .mk (8) (25) , + OpAssign .mk (9) (5) , OpPrice .mk (9) (20) , + OpAssign .mk (10) (22) , OpPrice .mk (10) (90) , + OpAssign .mk (11) (13) , OpPrice .mk (11) (50) , + OpAssign .mk (12) (4) , OpPrice .mk (12) (100) , + OpAssign .mk (13) (18) , OpPrice .mk (13) (150) , + OpAssign .mk (14) (9) , OpPrice .mk (14) (30) , + OpAssign .mk (15) (24) , OpPrice .mk (15) (30) , + OpAssign .mk (16) (11) , OpPrice .mk (16) (25) , + OpAssign .mk (17) (3) , OpPrice .mk (17) (200) , + OpAssign .mk (18) (17) , OpPrice .mk (18) (20) , + OpAssign .mk (19) (10) , OpPrice .mk (19) (30) , + OpAssign .mk (20) (21) , OpPrice .mk (20) (20) , + OpAssign .mk (21) (16) , OpPrice .mk (21) (100) , + OpAssign .mk (22) (1) , OpPrice .mk (22) (100) , + OpAssign .mk (23) (25) , OpPrice .mk (23) (20) , + OpAssign .mk (24) (6) , OpPrice .mk (24) (30) , + OpAssign .mk (25) (0) , OpPrice .mk (25) (20) , + OpAssign .mk (26) (15) , OpPrice .mk (26) (25) , + OpAssign .mk (27) (10) , OpPrice .mk (27) (40) , + OpAssign .mk (28) (20) , OpPrice .mk (28) (80) , + OpAssign .mk (29) (5) , OpPrice .mk (29) (100) , OpSell .mk (10) (25) ) diff --git a/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Package.scala b/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Package.scala index 5c734f2..604d1b5 100644 --- a/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Package.scala +++ b/core/src/test/scala/soda/se/umu/cs/soda/prototype/example/market/parser/Package.scala @@ -52,64 +52,64 @@ trait Example0Instance "deposit 24 1750" , "deposit 25 2350" , "assign 0 12" , - "assign 1 7" , - "assign 2 20" , - "assign 3 15" , - "assign 4 8" , - "assign 5 23" , - "assign 6 14" , - "assign 7 2" , - "assign 8 19" , - "assign 9 5" , - "assign 10 22" , - "assign 11 13" , - "assign 12 4" , - "assign 13 18" , - "assign 14 9" , - "assign 15 24" , - "assign 16 11" , - "assign 17 3" , - "assign 18 17" , - "assign 19 10" , - "assign 20 21" , - "assign 21 16" , - "assign 22 1" , - "assign 23 25" , - "assign 24 6" , - "assign 25 0" , - "assign 26 15" , - "assign 27 10" , - "assign 28 20" , - "assign 29 5" , "price 0 40" , + "assign 1 7" , "price 1 50" , + "assign 2 20" , "price 2 25" , + "assign 3 15" , "price 3 70" , + "assign 4 8" , "price 4 100" , + "assign 5 23" , "price 5 60" , + "assign 6 14" , "price 6 30" , + "assign 7 2" , "price 7 40" , + "assign 8 19" , "price 8 25" , + "assign 9 5" , "price 9 20" , + "assign 10 22" , "price 10 90" , + "assign 11 13" , "price 11 50" , + "assign 12 4" , "price 12 100" , + "assign 13 18" , "price 13 150" , + "assign 14 9" , "price 14 30" , + "assign 15 24" , "price 15 30" , + "assign 16 11" , "price 16 25" , + "assign 17 3" , "price 17 200" , + "assign 18 17" , "price 18 20" , + "assign 19 10" , "price 19 30" , + "assign 20 21" , "price 20 20" , + "assign 21 16" , "price 21 100" , + "assign 22 1" , "price 22 100" , + "assign 23 25" , "price 23 20" , + "assign 24 6" , "price 24 30" , + "assign 25 0" , "price 25 20" , + "assign 26 15" , "price 26 25" , + "assign 27 10" , "price 27 40" , + "assign 28 20" , "price 28 80" , + "assign 29 5" , "price 29 100" , "sell 10 25" ) @@ -161,64 +161,64 @@ trait Example0OperationList OpDeposit .mk (24) (1750) , OpDeposit .mk (25) (2350) , OpAssign .mk (0) (12) , - OpAssign .mk (1) (7) , - OpAssign .mk (2) (20) , - OpAssign .mk (3) (15) , - OpAssign .mk (4) (8) , - OpAssign .mk (5) (23) , - OpAssign .mk (6) (14) , - OpAssign .mk (7) (2) , - OpAssign .mk (8) (19) , - OpAssign .mk (9) (5) , - OpAssign .mk (10) (22) , - OpAssign .mk (11) (13) , - OpAssign .mk (12) (4) , - OpAssign .mk (13) (18) , - OpAssign .mk (14) (9) , - OpAssign .mk (15) (24) , - OpAssign .mk (16) (11) , - OpAssign .mk (17) (3) , - OpAssign .mk (18) (17) , - OpAssign .mk (19) (10) , - OpAssign .mk (20) (21) , - OpAssign .mk (21) (16) , - OpAssign .mk (22) (1) , - OpAssign .mk (23) (25) , - OpAssign .mk (24) (6) , - OpAssign .mk (25) (0) , - OpAssign .mk (26) (15) , - OpAssign .mk (27) (10) , - OpAssign .mk (28) (20) , - OpAssign .mk (29) (5) , OpPrice .mk (0) (40) , + OpAssign .mk (1) (7) , OpPrice .mk (1) (50) , + OpAssign .mk (2) (20) , OpPrice .mk (2) (25) , + OpAssign .mk (3) (15) , OpPrice .mk (3) (70) , + OpAssign .mk (4) (8) , OpPrice .mk (4) (100) , + OpAssign .mk (5) (23) , OpPrice .mk (5) (60) , + OpAssign .mk (6) (14) , OpPrice .mk (6) (30) , + OpAssign .mk (7) (2) , OpPrice .mk (7) (40) , + OpAssign .mk (8) (19) , OpPrice .mk (8) (25) , + OpAssign .mk (9) (5) , OpPrice .mk (9) (20) , + OpAssign .mk (10) (22) , OpPrice .mk (10) (90) , + OpAssign .mk (11) (13) , OpPrice .mk (11) (50) , + OpAssign .mk (12) (4) , OpPrice .mk (12) (100) , + OpAssign .mk (13) (18) , OpPrice .mk (13) (150) , + OpAssign .mk (14) (9) , OpPrice .mk (14) (30) , + OpAssign .mk (15) (24) , OpPrice .mk (15) (30) , + OpAssign .mk (16) (11) , OpPrice .mk (16) (25) , + OpAssign .mk (17) (3) , OpPrice .mk (17) (200) , + OpAssign .mk (18) (17) , OpPrice .mk (18) (20) , + OpAssign .mk (19) (10) , OpPrice .mk (19) (30) , + OpAssign .mk (20) (21) , OpPrice .mk (20) (20) , + OpAssign .mk (21) (16) , OpPrice .mk (21) (100) , + OpAssign .mk (22) (1) , OpPrice .mk (22) (100) , + OpAssign .mk (23) (25) , OpPrice .mk (23) (20) , + OpAssign .mk (24) (6) , OpPrice .mk (24) (30) , + OpAssign .mk (25) (0) , OpPrice .mk (25) (20) , + OpAssign .mk (26) (15) , OpPrice .mk (26) (25) , + OpAssign .mk (27) (10) , OpPrice .mk (27) (40) , + OpAssign .mk (28) (20) , OpPrice .mk (28) (80) , + OpAssign .mk (29) (5) , OpPrice .mk (29) (100) , OpSell .mk (10) (25) ) diff --git a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Main.soda b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Main.soda index 1a752db..c0e26ab 100644 --- a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Main.soda +++ b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Main.soda @@ -24,20 +24,12 @@ class Main operation_generator = OperationGenerator .mk - operation_serializer = OperationSerializer .mk + yaml_serializer = YamlSerializer .mk generate_operations (accounts : Nat) (items : Nat) (transactions : Nat) : List [Operation] = operation_generator .generate (accounts) (items) (transactions) - serialize_operations (operations : List [Operation] ) : String = - "operations:" + - "\n- " + - operations - .map (lambda operation --> operation_serializer .serialize (operation) ) - .mkString ("\n- ") + - "\n\n" - to_nat (n : Int) : Nat = if n < 0 then 0 @@ -66,7 +58,7 @@ class Main create_output (accounts : Nat) (items : Nat) (transactions : Nat) : String = (create_header (accounts) (items) (transactions) ) + - serialize_operations ( + yaml_serializer .serialize_operations ( generate_operations (accounts) (items) (transactions) ) diff --git a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/OperationGenerator.soda b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/OperationGenerator.soda index f58b227..fdc6b7a 100644 --- a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/OperationGenerator.soda +++ b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/OperationGenerator.soda @@ -55,16 +55,13 @@ class OperationGenerator OpDeposit .mk (user_id) (deposit_of_user (user_id) ) ) - make_items (accounts : Nat) (items : Nat) : List [Operation] = + make_items_with_prices (accounts : Nat) (items : Nat) : List [Operation] = Range .mk .apply (items) - .map (lambda item_id --> - OpAssign .mk (item_id) (owner_of_item (item_id) (accounts) ) - ) - - put_prices (items : Nat) : List [Operation] = - Range .mk .apply (items) - .map (lambda item_id --> - OpPrice .mk (item_id) (price_of_item (item_id) ) + .flatMap (lambda item_id --> + List [Operation] ( + OpAssign .mk (item_id) (owner_of_item (item_id) (accounts) ) , + OpPrice .mk (item_id) (price_of_item (item_id) ) + ) ) make_transactions (accounts : Nat) (items : Nat) (transactions : Nat) : List [Operation] = @@ -80,10 +77,8 @@ class OperationGenerator if (accounts > 0) and (items > 0) and (transactions > 0) then make_deposits (accounts) .++ ( - make_items (accounts) (items) .++ ( - put_prices (items) .++ ( - make_transactions (accounts) (items) (transactions) - ) + make_items_with_prices (accounts) (items) .++ ( + make_transactions (accounts) (items) (transactions) ) ) else List [Operation] () diff --git a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.scala b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.scala index 528a4a0..8a46d31 100644 --- a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.scala +++ b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.scala @@ -5,22 +5,12 @@ package soda.se.umu.cs.soda.prototype.example.market.measurement * */ -import soda.se.umu.cs.soda.prototype.example.market.core.Market -import soda.se.umu.cs.soda.prototype.example.market.core.Operation -import soda.se.umu.cs.soda.prototype.example.market.core.OperationProcessor import soda.se.umu.cs.soda.prototype.example.market.core.Operation import soda.se.umu.cs.soda.prototype.example.market.core.OpAssign -import soda.se.umu.cs.soda.prototype.example.market.core.OpAssign_ import soda.se.umu.cs.soda.prototype.example.market.core.OpDeposit -import soda.se.umu.cs.soda.prototype.example.market.core.OpDeposit_ import soda.se.umu.cs.soda.prototype.example.market.core.OpPrice -import soda.se.umu.cs.soda.prototype.example.market.core.OpPrice_ import soda.se.umu.cs.soda.prototype.example.market.core.OpSell -import soda.se.umu.cs.soda.prototype.example.market.core.OpSell_ -import soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined -import soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined_ -import soda.se.umu.cs.soda.prototype.example.market.core.OperationEnum -import soda.se.umu.cs.soda.prototype.example.market.serializer.OperationSerializer +import soda.se.umu.cs.soda.prototype.example.market.serializer.YamlSerializer @@ -93,20 +83,12 @@ trait Main lazy val operation_generator = OperationGenerator .mk - lazy val operation_serializer = OperationSerializer .mk + lazy val yaml_serializer = YamlSerializer .mk def generate_operations (accounts : Nat) (items : Nat) (transactions : Nat) : List [Operation] = operation_generator .generate (accounts) (items) (transactions) - def serialize_operations (operations : List [Operation] ) : String = - "operations:" + - "\n- " + - operations - .map ( operation => operation_serializer .serialize (operation) ) - .mkString ("\n- ") + - "\n\n" - def to_nat (n : Int) : Nat = if ( n < 0 ) 0 @@ -135,7 +117,7 @@ trait Main def create_output (accounts : Nat) (items : Nat) (transactions : Nat) : String = (create_header (accounts) (items) (transactions) ) + - serialize_operations ( + yaml_serializer .serialize_operations ( generate_operations (accounts) (items) (transactions) ) @@ -226,16 +208,13 @@ trait OperationGenerator OpDeposit .mk (user_id) (deposit_of_user (user_id) ) ) - def make_items (accounts : Nat) (items : Nat) : List [Operation] = - Range .mk .apply (items) - .map ( item_id => - OpAssign .mk (item_id) (owner_of_item (item_id) (accounts) ) - ) - - def put_prices (items : Nat) : List [Operation] = + def make_items_with_prices (accounts : Nat) (items : Nat) : List [Operation] = Range .mk .apply (items) - .map ( item_id => - OpPrice .mk (item_id) (price_of_item (item_id) ) + .flatMap ( item_id => + List [Operation] ( + OpAssign .mk (item_id) (owner_of_item (item_id) (accounts) ) , + OpPrice .mk (item_id) (price_of_item (item_id) ) + ) ) def make_transactions (accounts : Nat) (items : Nat) (transactions : Nat) : List [Operation] = @@ -251,10 +230,8 @@ trait OperationGenerator if ( (accounts > 0) && (items > 0) && (transactions > 0) ) make_deposits (accounts) .++ ( - make_items (accounts) (items) .++ ( - put_prices (items) .++ ( - make_transactions (accounts) (items) (transactions) - ) + make_items_with_prices (accounts) (items) .++ ( + make_transactions (accounts) (items) (transactions) ) ) else List [Operation] () diff --git a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.soda b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.soda index 848c007..0bc847e 100644 --- a/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.soda +++ b/measurement/src/main/scala/soda/se/umu/cs/soda/prototype/example/market/measurement/Package.soda @@ -6,20 +6,10 @@ package soda.se.umu.cs.soda.prototype.example.market.measurement */ import - soda.se.umu.cs.soda.prototype.example.market.core.Market - soda.se.umu.cs.soda.prototype.example.market.core.Operation - soda.se.umu.cs.soda.prototype.example.market.core.OperationProcessor soda.se.umu.cs.soda.prototype.example.market.core.Operation soda.se.umu.cs.soda.prototype.example.market.core.OpAssign - soda.se.umu.cs.soda.prototype.example.market.core.OpAssign_ soda.se.umu.cs.soda.prototype.example.market.core.OpDeposit - soda.se.umu.cs.soda.prototype.example.market.core.OpDeposit_ soda.se.umu.cs.soda.prototype.example.market.core.OpPrice - soda.se.umu.cs.soda.prototype.example.market.core.OpPrice_ soda.se.umu.cs.soda.prototype.example.market.core.OpSell - soda.se.umu.cs.soda.prototype.example.market.core.OpSell_ - soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined - soda.se.umu.cs.soda.prototype.example.market.core.OpUndefined_ - soda.se.umu.cs.soda.prototype.example.market.core.OperationEnum - soda.se.umu.cs.soda.prototype.example.market.serializer.OperationSerializer + soda.se.umu.cs.soda.prototype.example.market.serializer.YamlSerializer