TempoQuestInc / AceCAST-Docs

Read the docs source for the AceCAST documentation webpage
2 stars 0 forks source link

Add namelist support table #1

Open sael9740 opened 2 years ago

sael9740 commented 2 years ago

Need to have a way for users to see what options are available. I have some ideas for making this into a nice interactive feature but for now we can just have an exhaustive support table. The code below can be used to generate a table that will work in rst.

@Jon-1996 - Let's start thinking about how and where to fit this into the documentation.

import tabulate
import json

with open('inc/registry.json','r') as fh:
    registry = json.load(fh)

headers = ['Variable Name', 'Namelist Section', 'Num Entries', 'Type', 'Default', 'Supported Values']

for node in registry['Type']:
    if node['name'] == 'domain':
        domain_fields = node['fields']
        break

table = []

for node in domain_fields:
    if node["node_kind"] != 4:
        continue
    table.append([node['name'], node['howset'].replace('namelist,',''), node['nentries'], node['type'], node['dflt'], node['nml_support']])

print(tabulate.tabulate(table, headers=headers, tablefmt='rst'))
Jon-1996 commented 2 years ago

Some other options:

1.) Using Google Forms (partial solution), see image below

image

2.) Having the user send their namelist in an embedded emailing feature then receiving an email back with what is and what is not supported. Could be checked with a Python dictionary

How is this support table different from our current support table, other than being slightly easier to modify?

Jon-1996 commented 2 years ago

We may be able to just use html and Python to upload files and check them. I have been playing around with this locally but have not quite got it to work yet, I believe I need to upload to a server, which local does not do.

The rst page:

HTML page
=========

.. raw:: html
   :file: myfile.html

The html page that displays a button and a submit button:

<html>
<body>
   <form enctype = "multipart/form-data" action = "python_script.py" method = "post">

<p>Upload File: <input type = "file" name = "filename" /></p>

<p><input type = "submit" value = "Upload" /></p>

</form>
</body>
</html>

The associated .py script:

"""
"This" is my example-script
===========================

"""

import os

fileitem = form['filename']

# check if the file has been uploaded
if fileitem.filename:
    # strip the leading path from the file name
    fn = os.path.basename(fileitem.filename)

   # open read and write the file into the server
   # open(fn, 'wb').write(fileitem.file.read())
    with open(fn, encoding='UTF8') as f:
    contents = f.read()
    print(contents)

From here we can add more code to check conditions in the uploaded file(s) and display back to the user if the check passed or failed and if the latter, what failed and why.