Skip to content

Commit bd052f3

Browse files
committed
[IMP] base_wamas_ubl: simulate partial reception
1 parent 561c832 commit bd052f3

File tree

6 files changed

+34
-9
lines changed

6 files changed

+34
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wamas2wamas_input_wea.wamas
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
WAMAS ODOO 00000120231220091116WEAKQ0051000130377 HOST 19700101010000 19700101010000 20231220091116 0001040
2+
WAMAS ODOO 00000220231220091116WEAPQ0050000130377 000130377 HOST 000020 0001151 00000DISPONIBLE 000000001000000000000000 BOUT N
3+
WAMAS ODOO 00000320231220091116WEAPQ0050000130377 000130377 HOST 000030 0001156 00000DISPONIBLE 000000001000000000000000 PET N
4+
WAMAS ODOO 00000420231220091116WEAPQ0050000130377 000130377 HOST 000040 0001160 00000DISPONIBLE 000000001000000000000000 BOUT N
5+
WAMAS ODOO 00000520231220091116WEAPQ0050000130377 000130377 HOST 000050 0001162 00000DISPONIBLE 000000001000000000000000 PET N
6+
WAMAS ODOO 00000620231220091116WEAPQ0050000130377 000130377 HOST 000060 0001176 00000DISPONIBLE 000000001000000000000000 PET N

base_wamas_ubl/lib/wamas/tests/test_wamas2wamas.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,25 @@ class TestWamas2wamas(unittest.TestCase):
1010

1111
maxDiff = None
1212

13-
def _test(self, filename):
13+
def _test(self, filename, partial_qty=False):
1414
with file_open(
1515
file_path("tests/samples/wamas2wamas_input_%s.wamas" % filename)
1616
) as infile, file_open(
1717
file_path("tests/samples/wamas2wamas_output_%s.wamas" % filename)
1818
) as outfile:
1919
str_input = infile.read()
20-
output = wamas2wamas(str_input)
20+
output = wamas2wamas(str_input, partial_qty=partial_qty)
2121
expected_output = outfile.read()
2222
self.assertEqual(output, expected_output)
2323

2424
@freeze_time("2023-12-20 09:11:16")
25-
def testWamas2wamas(self):
25+
def testWamas2wamas_full(self):
2626
self._test("wea")
2727

28+
@freeze_time("2023-12-20 09:11:16")
29+
def testWamas2wamas_partial(self):
30+
self._test("wea_partial", partial_qty=True)
31+
2832

2933
if __name__ == "__main__":
3034
unittest.main()

base_wamas_ubl/lib/wamas/utils.py

+7
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ def get_current_datetime(val=0):
7979
return datetime.utcnow()
8080

8181

82+
def get_quantity_done(quantity, partial=False):
83+
return quantity if not partial else 1
84+
85+
8286
def _set_string(val, length, dp, **kwargs):
8387
return str(val or "").ljust(length)[:length]
8488

@@ -327,6 +331,9 @@ def generate_wamas_dict(dict_item, grammar, **kwargs): # noqa: C901
327331
args = (kwargs.get("idx_loop", 0),)
328332
elif df_func == "get_random_str_num":
329333
args = (length,)
334+
elif df_func == "get_quantity_done":
335+
quantity = dict_item.get("BestMng", 0)
336+
args = (quantity, kwargs.get("partial_qty"))
330337
elif "get_date_from_field" in df_func:
331338
args = (dict_wamas_out,)
332339
args += ast.literal_eval(re.search(r"\((.*?)\)", df_func).group(0))

base_wamas_ubl/lib/wamas/wamas2wamas.py

+11-4
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import logging
66
from pprint import pformat
77

8+
from freezegun import freeze_time
9+
810
from . import const, utils
911
from .wamas2ubl import wamas2dict
1012

1113
_logger = logging.getLogger("wamas2wamas")
1214

1315

14-
def simulate_response(dict_wamas_in):
16+
def simulate_response(dict_wamas_in, partial_qty=False):
1517
res = []
1618
line_idx = 0
1719
dict_parent_id = {}
@@ -27,24 +29,29 @@ def simulate_response(dict_wamas_in):
2729
dict_parent_id=dict_parent_id,
2830
telegram_type_out=telegram_type_out,
2931
do_wamas2wamas=True,
32+
partial_qty=partial_qty,
3033
)
3134
if line:
3235
res.append(line)
3336
return res
3437

3538

36-
def wamas2wamas(infile):
39+
def wamas2wamas(infile, partial_qty=False):
3740
data = wamas2dict(infile)
3841
_logger.debug(pformat(data))
39-
wamas_lines = simulate_response(data)
42+
wamas_lines = simulate_response(data, partial_qty=partial_qty)
4043
return "\n".join(wamas_lines)
4144

4245

46+
@freeze_time("2023-12-20 09:11:16")
4347
def main():
4448
parser = argparse.ArgumentParser(
4549
description="Converts a wamas message into wamas response.",
4650
)
4751
parser.add_argument("-v", "--verbose", action="store_true", help="enable debug log")
52+
parser.add_argument(
53+
"-p", "--partial", action="store_true", help="simulate partial quantity"
54+
)
4855
parser.add_argument(
4956
"-o", "--output", dest="outputfile", help="write result in this file"
5057
)
@@ -53,7 +60,7 @@ def main():
5360
if args.verbose:
5461
logging.basicConfig(level=logging.DEBUG)
5562
infile = utils.file_open(args.inputfile).read()
56-
res = wamas2wamas(infile)
63+
res = wamas2wamas(infile, args.partial)
5764
if args.outputfile:
5865
fd = utils.file_open(args.outputfile, "w")
5966
fd.write(res)

base_wamas_ubl/lib/wamas/wamas_grammar/weapq.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@
142142
"type": "float",
143143
"length": 12,
144144
"dp": 3,
145-
"dict_key": "BestMng",
145+
"dict_key": False,
146146
"df_val": False,
147-
"df_func": False,
147+
"df_func": "get_quantity_done",
148148
},
149149
"IvWevp_LiefMngs_Gew": {
150150
"type": "float",

0 commit comments

Comments
 (0)