Skip to content

Commit

Permalink
Merge pull request #214 from leondavi/jsonGenerator
Browse files Browse the repository at this point in the history
[JSONGEN] Complete workers section
  • Loading branch information
leondavi authored Jul 13, 2023
2 parents 7071566 + 3bad3a0 commit 4c180ab
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
1 change: 1 addition & 0 deletions src_py/nerlPlanner/Definitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@
KEY_WORKERS_BUTTON_VIEW = '-KEY-WORKERS-BUTTON-VIEW-'
KEY_WORKERS_BUTTON_REMOVE = '-KEY-WORKERS-BUTTON-REMOVE-'
KEY_WORKERS_LIST_BOX = '-KEY-WORKERS-LIST-BOX-'
KEY_WORKERS_INFO_BAR = '-KEY-WORKERS-INFO-BAR-'
33 changes: 24 additions & 9 deletions src_py/nerlPlanner/Handlers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json

from collections import OrderedDict
from JsonElements import *
from JsonElementWorker import *
from JsonArchitecture import JsonArchitecture
Expand All @@ -17,11 +18,12 @@
nerl_gui_inst = None

# workers
workers_list = []
workers_dict = OrderedDict()
workers_load_worker_path = None
workers_new_worker = None
workers_new_worker_name = None
workers_new_worker_dict = None
worker_name_selection = None

def reset_instances():
json_architecture_instance = JsonArchitecture()
Expand Down Expand Up @@ -78,35 +80,48 @@ def workers_handler(window, event, values):
global workers_new_worker
global workers_new_worker_name
global workers_new_worker_dict
global worker_name_selection

if event == KEY_WORKERS_INPUT_LOAD_WORKER_PATH:
workers_load_worker_path = values[KEY_WORKERS_INPUT_LOAD_WORKER_PATH]
with open(workers_load_worker_path) as jsonFile:
workers_new_worker_dict = json.load(jsonFile)
(workers_new_worker , _, _, _, _, _, _, _, _, _, _, _, _) = Worker.load_from_dict(workers_new_worker_dict)
print("New worker: "+str(workers_new_worker)) # TODO remove - just for debug
window[KEY_WORKERS_LIST_BOX].update(workers_list)
window[KEY_WORKERS_INFO_BAR].update(f'loaded from file: {workers_new_worker}')
window[KEY_WORKERS_LIST_BOX].update(workers_dict.keys())

if event == KEY_WORKERS_NAME_INPUT:
workers_new_worker_name = values[KEY_WORKERS_NAME_INPUT] if values[KEY_WORKERS_NAME_INPUT] not in workers_list else None
workers_new_worker_name = values[KEY_WORKERS_NAME_INPUT] if values[KEY_WORKERS_NAME_INPUT] not in workers_dict else None

if workers_new_worker_name and (workers_new_worker is not None):
if workers_new_worker_name and (workers_new_worker_name not in workers_dict) and\
(workers_new_worker is not None):
workers_new_worker.set_name(workers_new_worker_name)

if event == KEY_WORKERS_BUTTON_ADD and workers_load_worker_path and (workers_new_worker is not None):
if event == KEY_WORKERS_BUTTON_ADD and (workers_new_worker is not None):
if not workers_new_worker.get_name():
sg.popup_ok(f"Cannot add - Name is missing!", keep_on_top=True, title="Loading Issue")
elif json_architecture_instance.add_worker(workers_new_worker):
workers_list.append(workers_new_worker_name)
window[KEY_WORKERS_LIST_BOX].update(workers_list)
workers_dict[workers_new_worker_name] = workers_new_worker
window[KEY_WORKERS_LIST_BOX].update(workers_dict.keys())
# Clear fields after successful add
window[KEY_WORKERS_INFO_BAR].update(f'{workers_new_worker_name} added, {workers_new_worker}')
workers_new_worker_name = ''
window[KEY_WORKERS_NAME_INPUT].update(workers_new_worker_name)
workers_load_worker_path = ''
window[KEY_WORKERS_INPUT_LOAD_WORKER_PATH].update(workers_load_worker_path)
workers_new_worker = None

if event == KEY_WORKERS_LIST_BOX:
print("List box")
worker_name_selection = values[KEY_WORKERS_LIST_BOX][0]
print(f"List box {worker_name_selection}")

if event == KEY_WORKERS_LOAD_FROM_LIST_WORKER_BUTTON:
if (worker_name_selection in workers_dict) and workers_new_worker_name:
workers_new_worker = workers_dict[worker_name_selection].copy(workers_new_worker_name)
window[KEY_WORKERS_INFO_BAR].update(f'{workers_new_worker_name} loaded, {workers_new_worker}')
else:
sg.popup_ok(f"selection or name issue", keep_on_top=True, title="Loading Issue")


def update_current_json_file_path(jsonPath):
print(jsonPath)
13 changes: 13 additions & 0 deletions src_py/nerlPlanner/JsonElementWorker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ def __init__(self, name, LayersSizesList : str, ModelTypeStr : str, ModelType :
list_of_lengths = [len(x) for x in lists_for_length]
self.lengths_validation = all([x == list_of_lengths[0] for x in list_of_lengths])

def set_pooling_list(self, PoolingList):
self.PoolingList = PoolingList

def set_scaling_list(self, ScalingList):
self.ScalingList = ScalingList

def copy(self, name):
newWorker = Worker(name, self.LayersSizesList, self.ModelTypeStr, self.ModelType , self.OptimizationTypeStr, self.OptimizationType,
self.LossMethodStr, self.LossMethod, self.LearningRate, self.ActivationLayersList, self.LayerTypesList)
newWorker.set_pooling_list(self.PoolingList)
newWorker.set_scaling_list(self.ScalingList)
return newWorker

def __str__(self):
return f"LSizes: {self.LayersSizesList}, model {self.ModelTypeStr}, using optimizer {self.OptimizationTypeStr}, loss method: {self.LossMethodStr}, lr: {self.LearningRate}"

Expand Down
5 changes: 3 additions & 2 deletions src_py/nerlPlanner/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
# Workers
workersNamesList = []
workersListFields = [[sg.Text("Workers List")],
[sg.Listbox(workersNamesList, size=(90,6), key=KEY_WORKERS_LIST_BOX, enable_events=True), sg.Button("Load", size=8, key=KEY_WORKERS_LOAD_FROM_LIST_WORKER_BUTTON, enable_events=True) ]]
[sg.Listbox(workersNamesList, size=(90,6), key=KEY_WORKERS_LIST_BOX, enable_events=True), sg.Button("Load", size=8, key=KEY_WORKERS_LOAD_FROM_LIST_WORKER_BUTTON, enable_events=True)],
[sg.Text("",enable_events=True, key=KEY_WORKERS_INFO_BAR)]]
workersListFrame = sg.Frame("", workersListFields)
workersFields = [
[sg.Button("Add", size=(10),key=KEY_WORKERS_BUTTON_ADD,enable_events=True),
Expand Down Expand Up @@ -97,7 +98,7 @@

# Entities Frame
EntitiesFieldsFrame = sg.Frame("", layout=[[ClientsFieldsFrames, RoutersFieldsFrame],[SourcesFieldsFrame]], expand_x=True)
EntitiesFrame = sg.Frame("Entities - HTTP instances",layout=[[EntitiesFieldsFrame]], expand_x=True)
EntitiesFrame = sg.Frame("Entities - HTTP Cowboy instances",layout=[[EntitiesFieldsFrame]], expand_x=True)


# Json File Control
Expand Down

0 comments on commit 4c180ab

Please sign in to comment.