Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REQUEST: args delete and delete_all for not connected but opened model #22

Closed
damianbobrowski opened this issue Jun 27, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@damianbobrowski
Copy link

Is your feature request related to a problem? Please describe.
delete and delete_all for not connected but opened model do not work right now.:

Model(True, model_name, delete=True, delete_all=True)

As result server raises errors for incoming requests when object IDs already exists.

Describe the solution you'd like
At initModel.py:
https://github.com/Dlubal-Software/RSTAB_Python_Client/blob/main/RSTAB/initModel.py#L117

add code block:

                ### START:: New code block   ###
                if model_name in modelLst:
                    if delete:
                        print('Deleting results...')
                        cModel.service.delete_all_results()
                    if delete_all:
                        print('Delete all...')
                        cModel.service.delete_all()
                ### END:: New code block   ###

Is now:

        else:
            # Requested model which was already connected
            assert model_name in self.clientModelDct or model_name in modelLst, 'WARNING: '+model_name +' is not connected neither opened in RFEM.'

            if model_name in self.clientModelDct:
                cModel = self.clientModelDct[model_name]
            elif model_name in modelLst:
                id = 0
                for i,j in enumerate(modelLst):
                    if modelLst[i] == model_name:
                        id = i
                modelPath =  client.service.get_model(id)
                modelPort = modelPath[-5:-1]
                modelUrlPort = url+':'+modelPort
                modelCompletePath = modelUrlPort+'/wsdl'

                session = requests.Session()
                adapter = requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=1)
                session.mount('http://', adapter)
                trans = RequestsTransport(session)

                cModel = Client(modelCompletePath, transport=trans, location = modelUrlPort, cache=ca)

                self.clientModelDct[model_name] = cModel

Would like to have:

            else:
                modelPath = ''
                # Requested new model, model with given name was NOT connected yet but file with the same name was opened
                if model_name in modelLst:
                    id = 0
                    for i,j in enumerate(modelLst):
                        if modelLst[i] == model_name:
                            id = i
                    modelPath =  client.service.get_model(id)
                else:
                    modelPath =  client.service.new_model(original_model_name)
                modelPort = modelPath[-5:-1]
                modelUrlPort = url+':'+modelPort
                modelCompletePath = modelUrlPort+'/wsdl'

                session = requests.Session()
                adapter = requests.adapters.HTTPAdapter(pool_connections=1, pool_maxsize=1)
                session.mount('http://', adapter)
                trans = RequestsTransport(session)

                cModel = Client(modelCompletePath, transport=trans, location = modelUrlPort, cache=ca)
                
                ### START:: New code block   ###
                if model_name in modelLst:
                    if delete:
                        print('Deleting results...')
                        cModel.service.delete_all_results()
                    if delete_all:
                        print('Delete all...')
                        cModel.service.delete_all()
                ### END:: New code block   ###

                self.clientModelDct[model_name] = cModel

Describe alternatives you've considered
It won't work in provided context:

Model(True, model_name, delete=True, delete_all=True)

then I am forced to use:

Model(True, model_name)
cModel = Model.clientModelDct[model_name]
cModel.service.delete_all_results()
cModel.service.delete_all()

Additional context
Right now we use model with same name for better performance. Model is not connected but oppened between requests.
Some time we need to restart solution. We would like to use native options.

@damianbobrowski damianbobrowski added enhancement New feature or request question Further information is requested labels Jun 27, 2023
@OndraMichal
Copy link
Contributor

OndraMichal commented Jun 27, 2023

Hi @damianbobrowski ,
I think it is a bug. It should be carried forward so it can be applied to both cases (new_model==True || False). This fix was pushed to main branch.

            else:
                print('Model name "'+model_name+'" is not created in RFEM. Consider changing new_model parameter in Model class from False to True.')
                sys.exit()

        if delete:
            print('Deleting results...')
            cModel.service.delete_all_results()
        if delete_all:
            print('Delete all...')
            cModel.service.delete_all()

        # when using multiple instances/model
        self.clientModel = cModel
        # when using only one instance/model
        Model.clientModel = cModel

@damianbobrowski
Copy link
Author

Yes, it will work, but I am not sure it was a bug. I thought you would like to create granular workflow, and call delete whatever it is necessary.

With bdd81fa

when Model(True, model_name, delete=True, delete_all=True)

because of

        if new_model:
            # Requested new model but the model with given name was already connected
            if model_name in self.clientModelDct:
                cModel = self.clientModelDct[model_name]
                cModel.service.delete_all_results()
                cModel.service.delete_all()
               

cModel.service.delete_all and cModel.service.delete_all_results are called twice.

Here:
https://github.com/Dlubal-Software/RSTAB_Python_Client/blob/bdd81fa506e48a0659b33f04e9ec4d7140a428b1/RSTAB/initModel.py#L109-L114
and here:
https://github.com/Dlubal-Software/RSTAB_Python_Client/blob/bdd81fa506e48a0659b33f04e9ec4d7140a428b1/RSTAB/initModel.py#L169-L174

@OndraMichal
Copy link
Contributor

Yes, but if the delete or delete_all variables are set to True and the block of code is put into if new_model: the behavior does not change. It will still be called twice. There is no difference. Assuming if model_name in self.clientModelDct: condition is evaluated as True.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants