Skip to content

Commit d4158a7

Browse files
Modification
+ modified telegram operation
1 parent 6c21db6 commit d4158a7

File tree

3 files changed

+103
-6
lines changed

3 files changed

+103
-6
lines changed

system_entity/structure_attribute.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ def insert_coupling(self, src, dst):
9494
self.internal_coupling_map_entity[src_entity]=[[src_port, dst_lst]]
9595

9696
def remove_coupling(self, src, dst):
97-
# TODO: Implement
9897
src_entity, src_port = src
9998
dst_entity, dst_port = dst
10099
dst_lst = [dst_entity, dst_port]

telegram_control/telegram_manager.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ def start(update, context):
3535
update.message.reply_text("0. Exit")
3636
else:
3737
Remote_control.STATUS = ""
38+
update.message.reply_text("System Management System")
39+
update.message.reply_text("1. Entity Management")
40+
update.message.reply_text("2. Model Management")
41+
update.message.reply_text("3. Model Synthesis")
42+
update.message.reply_text("4. Execution Management")
43+
update.message.reply_text("0. Exit")
3844

3945

4046

@@ -69,7 +75,7 @@ def echo(update, context):
6975
Remote_control.STATUS = Remote_control.STATUS[:-1]
7076
Remote_control.print_current_menu(update, 0)
7177
else:
72-
Remote_control.setting_step(update)
78+
update.message.reply_text("please type right number")
7379

7480
def load_ses():
7581
global sm

telegram_control/telegram_menu.py

Lines changed: 96 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@ def __init__(self):
66
self.STATUS = ""
77
self.operation_count = 0
88
self.glob_lst = {}
9+
self.entity_path = "./sample/ses_db"
10+
11+
self.sm = SystemManager("./sample/ses_db", "./sample/model_db", './sample/pes_db')
12+
13+
self.entity_db = []
14+
self.model_db = {}
15+
self.make_db()
16+
17+
def make_db(self):
18+
self. entity_db = [f for f in listdir(self.entity_path) if isfile(join(self.entity_path, f))]
19+
for _file in self.entity_db:
20+
self.model_db[_file[:-5]] = os.path.join(os.path.abspath(self.entity_path), _file)
21+
22+
def clear_system(self):
23+
self.glob_lst = {}
24+
self.operation_count = 0
925

1026
def print_current_menu(self, update, current_num):
1127
if current_num == 1:
@@ -16,8 +32,16 @@ def print_current_menu(self, update, current_num):
1632
update.message.reply_text("4. Delete Entity")
1733
update.message.reply_text("0. Exit")
1834
elif len(self.STATUS) == 2:
19-
if self.STATUS == "11":
20-
self.create_option(update)
35+
if self.STATUS[0] == "1":
36+
self.setting_step(update)
37+
elif current_num == 2:
38+
if len(self.STATUS) == 1:
39+
#model management
40+
update.message.reply_text(self.STATUS)
41+
elif len(self.STATUS) == 2:
42+
if self.STATUS[0] == "1":
43+
self.setting_step(update)
44+
2145
elif current_num == "0":
2246
if self.STATUS == "":
2347
update.message.reply_text("over")
@@ -27,6 +51,8 @@ def print_current_menu(self, update, current_num):
2751
def setting_step(self, update):
2852
if self.STATUS == "11":
2953
self.create_option(update)
54+
if self.STATUS == "12":
55+
self.read_option(update)
3056

3157
def YN_again_menu(self, update, restart_num):
3258
if update.message.text == "y":
@@ -58,8 +84,22 @@ def Chk_int(self, update, _num):
5884
update.message.reply_text("please type int")
5985
return False
6086

87+
def print_entity_db(self,update):
88+
fmt = "{0: <13}\t{1: <13}"
89+
for k,v in self.model_db.items():
90+
update.message.reply_text(fmt.format(k,v))
91+
92+
def print_entity_information(self, update, target):
93+
fmt = "{0: <10}{name: <15}\t{arity: <5}\t{opt: <5}"
94+
_str = ""
95+
_str += "Name: " + target.entity_name + "\n"
96+
_str += fmt.format("Entities: ", name="Name", arity="Arity", opt="Optional") + "\n"
97+
entities = target.core_attribute.retrieve_entities()
6198

99+
for idx, entity in enumerate(entities):
100+
_str += "\t" + fmt.format(idx+1, name=entity[0], arity=entity[1], opt=entity[2]) + "\n"
62101

102+
update.message.reply_text(_str)
63103

64104

65105
def create_option(self, update):
@@ -299,8 +339,60 @@ def create_option(self, update):
299339
elif self.operation_count == 23:
300340
print(self.glob_lst)
301341
if self.YN_again_menu(update, 4):
302-
pass
342+
esm = EntityManager()
343+
msa = ModelStructuralAttribute()
344+
entity = esm.create_entity_structure()
345+
entity.set_name(self.glob_lst["name"])
346+
if int(self.glob_lst["num_input_port"]) >0:
347+
for i in range(int(self.glob_lst["num_input_port"])):
348+
nm = "in"+str(i+1)
349+
msa.insert_input_port(nm)
350+
if int(self.glob_lst["num_output_port"]) > 0:
351+
for i in range(int(self.glob_lst["num_output_port"])):
352+
nm = "out"+str(i+1)
353+
msa.insert_input_port(nm)
354+
for i in range(len(self.glob_lst["entities name"])):
355+
msa.insert_entity(self.glob_lst["entities name"][i], self.glob_lst["attribute number"][i],
356+
self.glob_lst["optional"][i])
357+
if len(self.glob_lst["ex_in_portnum"]) > 0:
358+
for i in range(len(self.glob_lst["ex_in_portnum"])):
359+
msa.insert_coupling(("", self.glob_lst["ex_in_portnum"][i]), (self.glob_lst["ex_in_entity"][i],
360+
self.glob_lst["ex_in_portenti"][i]))
361+
if len(self.glob_lst["ex_out_portnum"]) > 0:
362+
for i in range(len(self.glob_lst["ex_out_portnum"])):
363+
msa.insert_coupling((self.glob_lst["ex_out_entity"][i], self.glob_lst["ex_out_portenti"][i]),
364+
("", self.glob_lst["ex_out_portnum"][i]))
365+
if len(self.glob_lst["internal_out_entity"]) > 0:
366+
for i in range(len(self.glob_lst["internal_out_entity"])):
367+
msa.insert_coupling((self.glob_lst["internal_out_entity"][i],
368+
self.glob_lst["internal_out_port"][i]),
369+
(self.glob_lst["internal_in_entity"][i],
370+
self.glob_lst["internal_in_port"][i]))
371+
entity.set_core_attribute(msa)
372+
esm.create_system(entity)
373+
esm.export_system_entity_structure(entity, self.entity_path, str(self.glob_lst["name"]) + ".json")
374+
375+
self.clear_system()
376+
303377
else:
304378
if update.message.text == "y":
305379
update.message.reply_text("created entities: " + str(self.glob_lst["entities name"]))
306-
update.message.reply_text("choose first entity out to other")
380+
update.message.reply_text("choose first entity out to other")
381+
382+
def read_option(self, update):
383+
if self.operation_count == 0:
384+
self.print_entity_db(update)
385+
update.message.reply_text("Type name of Entity")
386+
self.operation_count += 1
387+
elif self.operation_count == 1:
388+
if update.message.text in self.model_db.keys():
389+
model = self.sm.esm.import_system_entity_structure(self.model_db[update.message.text])
390+
print(model)
391+
self.print_entity_information(update, model)
392+
#update.message.reply_text(model)
393+
self.clear_system()
394+
else:
395+
update.message.reply_text("[ERR] Entity Not Found")
396+
update.message.reply_text("Type name of Entity")
397+
398+

0 commit comments

Comments
 (0)