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

get_datastack_info from tgz returns an unusable args dictionary #1308

Closed
davemfish opened this issue May 4, 2023 · 3 comments · Fixed by #1428
Closed

get_datastack_info from tgz returns an unusable args dictionary #1308

davemfish opened this issue May 4, 2023 · 3 comments · Fixed by #1428
Assignees
Labels
bug Something isn't working in progress This issue is actively being worked on workbench For issues relating to the workbench front-end of invest

Comments

@davemfish
Copy link
Contributor

As Stacie pointed out,

when I drag and drop the .tgz or "Load parameters from file" into Workbench, the entries that it fills the UI in with give "file not found" errors. But, when I drag in the parameter .json file within the archive, it populates correctly.

This amounts to the fact that datastack.get_datastack_info('some.tgz') seems to extract only the .json file to a temp directory, but not the rest of the data from the archive. So it defaults to returning an args dict with the paths from the .json, which are relative paths. They would only be valid paths if the rest of the archive was extracted.

As far as I can tell, we don't have a use-case for needing an args dict from an archive unless we are also extracting all the data from that archive.

It might be a bad idea to have datastack.get_datastack_info return something different depending on the type of datastack. So maybe we leave that as-is, but follow it up with a call to extract_datastack_archive, which also returns the args dict. And I believe the only place where we use this is in ui_server.py

@app.route(f'/{PREFIX}/post_datastack_file', methods=['POST'])
def post_datastack_file():
    """Extracts InVEST model args from json, logfiles, or datastacks.

    Body (JSON string): path to file

    Returns:
        A JSON string.
    """
    filepath = request.get_json()
    stack_type, stack_info = datastack.get_datastack_info(
        filepath)
    model_name = PYNAME_TO_MODEL_NAME_MAP[stack_info.model_name]
    result_dict = {
        'type': stack_type,
        'args': stack_info.args,
        'module_name': stack_info.model_name,
        'model_run_name': model_name,
        'model_human_name': MODEL_METADATA[model_name].model_title,
        'invest_version': stack_info.invest_version
    }
    return json.dumps(result_dict)

Implementing this for use by the Workbench will also require asking the user to choose a location to extract to, so might necessitate a new UI component for that.

@davemfish davemfish added bug Something isn't working workbench For issues relating to the workbench front-end of invest labels May 4, 2023
@dcdenu4
Copy link
Member

dcdenu4 commented May 5, 2023

I was also looking at this briefly yesterday before getting distracted by something else. Do we remember if the Classic UI handled this correctly and how it did so?

I do think that having the Workbench be able to handle this would be nice for the user, but an alternative is to change the instructions on how to use the data archive, which is, have the user extract it and then drop in the JSON file. I guess this is the workaround for now as is.

@davemfish
Copy link
Contributor Author

davemfish commented May 5, 2023

I was also looking at this briefly yesterday before getting distracted by something else. Do we remember if the Classic UI handled this correctly and how it did so?

I don't know, I don't think I ever tried it.

I do think that having the Workbench be able to handle this would be nice for the user, but an alternative is to change the instructions on how to use the data archive, which is, have the user extract it and then drop in the JSON file. I guess this is the workaround for now as is.

Agreed. The first, easiest thing we can do is remove the UI's suggestion to use a tgz. Beyond that, I could also see it as convenient to have the Workbench do the extraction.

@phargogh
Copy link
Member

I believe the classic UI did handle this issue. When a datastack archive is loaded, it would prompt the user to provide an extraction directory. After extraction, the args json would be loaded. So there was a 2-step process:

  1. Determine what type of args we have (logfile? args json? archive?)
  2. If it's not an archive, load the parameters directly.
  3. If it's an archive, prompt the user to define where to extract the data
  4. Once the data are extracted from the archive, load the contained parameters file.

@emlys emlys self-assigned this Oct 16, 2023
@emlys emlys added the in progress This issue is actively being worked on label Oct 16, 2023
emlys added a commit to emlys/invest that referenced this issue Oct 16, 2023
emlys added a commit to emlys/invest that referenced this issue Oct 16, 2023
emlys added a commit to emlys/invest that referenced this issue Oct 17, 2023
emlys added a commit to emlys/invest that referenced this issue Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working in progress This issue is actively being worked on workbench For issues relating to the workbench front-end of invest
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants