-
Notifications
You must be signed in to change notification settings - Fork 11
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
Use Geoweaver API + Better UI Response (Pandas + IPython Widgets) #24
base: main
Are you sure you want to change the base?
Changes from 15 commits
3430c30
4ec0add
380c1ce
4881ae1
8bc1391
26614b5
eaa115f
09321ef
ad2a4c6
e4021d2
959034e
c4533e9
f34cd1f
02df3d8
5ec3e74
e8a9817
b99f19c
a07a48c
5242736
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,81 @@ | ||
""" | ||
Detail subcommand | ||
""" | ||
import json | ||
|
||
import subprocess | ||
|
||
import pandas as pd | ||
import requests | ||
from pygeoweaver.constants import * | ||
|
||
from pygeoweaver.utils import ( | ||
download_geoweaver_jar, | ||
get_geoweaver_jar_path, | ||
get_java_bin_path, | ||
get_root_dir, | ||
create_table, | ||
) | ||
import ipywidgets as widgets | ||
from IPython.display import display, HTML | ||
|
||
|
||
def detail_workflow(workflow_id): | ||
if not workflow_id: | ||
raise RuntimeError("Workflow id is missing") | ||
download_geoweaver_jar() | ||
subprocess.run( | ||
[ | ||
get_java_bin_path(), | ||
"-jar", | ||
get_geoweaver_jar_path(), | ||
"detail", | ||
f"--workflow-id={workflow_id}", | ||
], | ||
cwd=f"{get_root_dir()}/", | ||
) | ||
url = f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/detail" | ||
headers = {'Content-Type': 'application/x-www-form-urlencoded'} | ||
form_data = {'type': 'workflow', 'id': workflow_id} | ||
d = requests.post(url=url, data=form_data, headers=headers) | ||
d = d.json() | ||
d['nodes'] = json.loads(d['nodes']) | ||
try: | ||
from IPython import get_ipython | ||
if 'IPKernelApp' in get_ipython().config: | ||
table_html = create_table([d]) | ||
table_output = widgets.Output() | ||
with table_output: | ||
display(HTML(table_html)) | ||
display(table_output) | ||
except: | ||
return pd.DataFrame([d]) | ||
|
||
|
||
def detail_process(process_id): | ||
if not process_id: | ||
raise RuntimeError("Process id is missing") | ||
download_geoweaver_jar() | ||
subprocess.run( | ||
[ | ||
get_java_bin_path(), | ||
"-jar", | ||
get_geoweaver_jar_path(), | ||
"detail", | ||
f"--process-id={process_id}", | ||
], | ||
cwd=f"{get_root_dir()}/", | ||
) | ||
url = f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/detail" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this whole section is repeated multiple times. Need to Create a utility function and reduce the redundancy please |
||
headers = {'Content-Type': 'application/x-www-form-urlencoded'} | ||
form_data = {'type': 'process', 'id': process_id} | ||
d = requests.post(url=url, data=form_data, headers=headers) | ||
d = d.json() | ||
try: | ||
from IPython import get_ipython | ||
if 'IPKernelApp' in get_ipython().config: | ||
table_html = create_table([d]) | ||
table_output = widgets.Output() | ||
with table_output: | ||
display(HTML(table_html)) | ||
display(table_output) | ||
except: | ||
return pd.DataFrame([d]) | ||
|
||
|
||
def detail_host(host_id): | ||
if not host_id: | ||
raise RuntimeError("Host id is missing") | ||
download_geoweaver_jar() | ||
subprocess.run( | ||
[ | ||
get_java_bin_path(), | ||
"-jar", | ||
get_geoweaver_jar_path(), | ||
"detail", | ||
f"--host-id={host_id}", | ||
], | ||
cwd=f"{get_root_dir()}/", | ||
) | ||
url = f"{GEOWEAVER_DEFAULT_ENDPOINT_URL}/web/detail" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundancy section of code. Use utility function. |
||
headers = {'Content-Type': 'application/x-www-form-urlencoded'} | ||
form_data = {'type': 'host', 'id': host_id} | ||
d = requests.post(url=url, data=form_data, headers=headers).json() | ||
try: | ||
from IPython import get_ipython | ||
if 'IPKernelApp' in get_ipython().config: | ||
table_html = create_table([d]) | ||
table_output = widgets.Output() | ||
with table_output: | ||
display(HTML(table_html)) | ||
display(table_output) | ||
except: | ||
return pd.DataFrame([d]) | ||
|
||
|
||
def get_process_code(process_id): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,3 +146,28 @@ def copy_files(source_folder, destination_folder): | |
) | ||
os.makedirs(os.path.dirname(destination_file), exist_ok=True) | ||
shutil.copy2(source_file, destination_file) | ||
|
||
|
||
def create_table(data, max_length=100): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure this is a good idea. Also, a table is not Overall, people like interactive experiences. Not just a static table. If it is only a simple HTML table, the pandas dataframe output will do it. |
||
table_html = "<table><tr>" | ||
|
||
# Create table headers | ||
if len(data) > 0: | ||
for key in data[0].keys(): | ||
table_html += f"<th>{key}</th>" | ||
table_html += "</tr>" | ||
|
||
# Create table rows | ||
for row in data: | ||
table_html += "<tr>" | ||
for value in row.values(): | ||
# Truncate and add ellipses if the value is too long | ||
display_value = str(value)[:max_length] + '...' if len(str(value)) > max_length else str(value) | ||
table_html += f"<td>{display_value}</td>" | ||
table_html += "</tr>" | ||
else: | ||
table_html += "<td>No Data</td></tr>" | ||
|
||
table_html += "</table>" | ||
|
||
return table_html |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this section of code is repeated in all the places. Can you make it a function and reuse it when being used?