-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #143 from DARPA-ASKEM/4003-bug-dataset-created-fro…
…m-transform-dataset-has-no-column-info 4003 bug dataset created from transform dataset has no column info
- Loading branch information
Showing
3 changed files
with
49 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/askem_beaker/contexts/dataset/procedures/python3/hmi_create_csv_dataset.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import requests | ||
import tempfile | ||
|
||
from json import JSONDecodeError | ||
|
||
with tempfile.TemporaryFile() as temp_csv_file: | ||
{{ var_name|default("df") }}.to_csv(temp_csv_file, index=False, header=True) | ||
temp_csv_file.seek(0) | ||
# Set the HMI_SERVER endpoint | ||
hmi_server = "{{dataservice_url}}" | ||
|
||
# Define the id and filename dynamically | ||
id = "{{id}}" | ||
filename = "{{filename}}" | ||
|
||
# Prepare the request payload | ||
payload = {'id': id, 'filename': filename} | ||
files = {'file': temp_csv_file} | ||
|
||
# Set the headers with the content type | ||
# headers = {} | ||
|
||
# Make the HTTP PUT request to upload the file bytes | ||
url = f'{hmi_server}/datasets/{id}/upload-csv' | ||
response = requests.put(url, data=payload, files=files, auth=("{{username}}", "{{password}}")) | ||
|
||
# Check the response status code | ||
if response.status_code < 300: | ||
try: | ||
message = response.json() | ||
except JSONDecodeError: | ||
message = f'File uploaded successfully with status code {response.status_code}.' | ||
else: | ||
message = f'File upload failed with status code {response.status_code}.' | ||
if response.text: | ||
message += f' Response message: {response.text}' | ||
|
||
message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters