Skip to content

Reporting Script #28

@krowvin

Description

@krowvin

CLI Script

Other

Feature Proposal

Talking with @DanielTOsborne about reports

Integrating Report Generation (repgen) into cwms-cli

What are our thoughts on creating the following

cwms-cli reporting --engine repgen5 --output=myfile.txt --input=mytemplate.txt ..args
or
cwms-cli reporting --engine jinja3 --output=myfile.html --input=myfile.html.j2 ..args

Idea is to make re-use of the existing click arg handling, the same package distribution, and provide users with the ability to have a one stop shop for their scripting needs.

We talked briefly about if it made sense to GitHub sub module these, i.e. keep them in their own repos. But this has potential to archive the existing repgen5 repo?

Another thought, for down the road is we could add a .pdf output and make it use itext (with jpype) with input template libraries.

Details

Repgen would be updated to use cwms-python and jinja and the pdf option later could also use jinja.

This combines the DEF and FORM tags and makes for highly dynamic reports and outsources template documentation to Jinja while making use of the enterprise data fetch library and exposing it's mathematical capabilities straight in the template.

Things like JSON, HTML, TXT, and many other formats are dynamically opened with built-in vscode syntax highlighters.

@NobuNobuu has had success using Jinja + Cwms-Python to generate reports at SWF

Examples:

<!-- templates/_table.html.j2 -->
<div class="table-responsive plot-container mb-5">
  <table class="table align-middle table-hover table-bordered mb-0 data-table">
    <thead>
      <tr class="first-row">
        <th rowspan="1">Reservoir</th>
        <th colspan="2">Pool Elevation (ft)</th>
      </tr>
      <tr class="second-row">
        <th rowspan="2"></th>
        <th rowspan="2">8AM<br>FT-NGVD</th>
      </tr>
    </thead>
    <tbody>
      {% for basin_name, reservoirs in basins.items() %}
      <tr class="table-secondary">
        <th colspan="17" class="text-start">{{ basin_name }}</th>
      </tr>
      {% for prefix, name in reservoirs %}
      <tr class="table-light">
        <td class="text-start">{{ name }}</td>
        <td>{{ ts(name="keys.elev.inst.1Hour.0.Ccp-Rev", office="SWT") }}</td>
      </tr>
      {% endfor %}
      {% endfor %}
    </tbody>
  </table>
</div>

Additional thoughts

If we are looking at a whole rewrite of repgen for the new engine in addition to what exists, it was thought we could do that in the repgen repo. But perhaps some change to add it to cwms-cli would help with adoption and get most districts using the same report generation methods.

Going a step further (in the future) we can define standard template types that regions might need. For example

cwms-cli reporting --template-theme=USACE-WM ...args

Related Context or Links

https://jinja.palletsprojects.com/en/stable/

https://github.com/USACE-WaterManagement/repgen5

https://github.com/HydrologicEngineeringCenter/cwms-python/

http://www.jpype.org/

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions