Skip to content

Commit

Permalink
Updates for datastack bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
dcdenu4 committed Nov 26, 2024
1 parent b67aacb commit 9034a52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/natcap/invest/ui_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ def get_args_enabled():
def post_datastack_file():
"""Extracts InVEST model args from json, logfiles, or datastacks.
Body (JSON string): path to file
Body (JSON string):
filepath: string, path to file
Returns:
A JSON string.
Expand Down
9 changes: 7 additions & 2 deletions workbench/src/renderer/components/SetupTab/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,13 @@ class SetupTab extends React.Component {
async saveDatastack(datastackPath) {
const {
pyModuleName,
modelId,
} = this.props;
const args = argsDictFromObject(this.state.argsValues);
const payload = {
filepath: datastackPath,
moduleName: pyModuleName,
modelId: modelId,
args: JSON.stringify(args),
};
const key = window.crypto.getRandomValues(new Uint16Array(1))[0].toString();
Expand Down Expand Up @@ -282,7 +284,7 @@ class SetupTab extends React.Component {
}

async loadParametersFromFile(filepath) {
const { pyModuleName, switchTabs, t } = this.props;
const { pyModuleName, modelId, switchTabs, t } = this.props;
let datastack;
try {
if (filepath.endsWith('gz')) { // .tar.gz, .tgz
Expand All @@ -292,13 +294,16 @@ class SetupTab extends React.Component {
);
if (extractLocation.filePath) {
datastack = await fetchDatastackFromFile({
modelId: modelId,
filepath: filepath,
extractPath: extractLocation.filePath});
} else {
return;
}
} else {
datastack = await fetchDatastackFromFile({ filepath: filepath });
datastack = await fetchDatastackFromFile({
modelId: modelId,
filepath: filepath });
}
} catch (error) {
logger.error(error);
Expand Down
13 changes: 9 additions & 4 deletions workbench/src/renderer/server_requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export async function fetchArgsEnabled(payload) {
*
* @param {object} payload {
* model_module: string (e.g. natcap.invest.carbon)
* modelId: string (e.g. carbon)
* args: JSON string of InVEST model args keys and values
* }
* @returns {Promise} resolves array
Expand All @@ -146,11 +147,14 @@ export async function fetchValidation(payload) {
/**
* Load invest arguments from a datastack-compliant file.
*
* @param {string} payload - path to file
* @param {object} payload {
* filepath: string, path to file
* modelId: string (e.g. carbon)
* }
* @returns {Promise} resolves undefined
*/
export async function fetchDatastackFromFile(payload) {
const port = await getCorePort();
const port = await getPort(payload.modelId);
return (
window.fetch(`${HOSTNAME}:${port}/${PREFIX}/post_datastack_file`, {
method: 'post',
Expand All @@ -172,7 +176,7 @@ export async function fetchDatastackFromFile(payload) {
* @returns {Promise} resolves undefined
*/
export async function saveToPython(payload) {
const port = await getCorePort();
const port = await getPort(payload.modelname);
return (
window.fetch(`${HOSTNAME}:${port}/${PREFIX}/save_to_python`, {
method: 'post',
Expand All @@ -194,12 +198,13 @@ export async function saveToPython(payload) {
* @param {object} payload {
* filepath: string
* moduleName: string (e.g. natcap.invest.carbon)
* modelId: string (e.g. carbon)
* args_dict: JSON string of InVEST model args keys and values
* }
* @returns {Promise} resolves undefined
*/
export async function archiveDatastack(payload) {
const port = await getCorePort();
const port = await getPort(payload.modelId);
return (
window.fetch(`${HOSTNAME}:${port}/${PREFIX}/build_datastack_archive`, {
method: 'post',
Expand Down

0 comments on commit 9034a52

Please sign in to comment.