Ommiting quotes around scenario string variables in a Freemarker email template

Registered Posts: 7 ✭✭✭

Hi, I have a scheduled project scenario that sends an email on some condition. The scenario contains a step that sets scenario variables based on values in a dataset. Here's that step:

import dataiku
import dataiku.scenario

# Read the dataset
df = dataiku.Dataset("node-disk-usage").get_dataframe()

use_percentage_threshold = df["use_percentage_threshold"].max()  # All the thresholds are the same; we could have used min() and it would have made no difference
# Check if any row in column "over_threshold" is True
disk_usage_is_over_threshold = df["over_threshold"].any()

print(f"Disk usage is over the threshold: {disk_usage_is_over_threshold}")

# Set the flag to be used in the scenario
scenario = dataiku.scenario.Scenario()
scenario.set_scenario_variables(
    use_percentage_threshold=use_percentage_threshold,
    disk_usage_is_over_threshold=str(disk_usage_is_over_threshold).lower(),  # "true" or "false"
    first_mount_path=df["mount_path"][0],
    first_mount_path_usage=df["use_percentage"][0],
    second_mount_path=df["mount_path"][1],
    second_mount_path_usage=df["use_percentage"][1]
)

The values in the mount_path column are strings.

As part of the scenario's mail report, I have this Freemarker template snippet:

    <table border="1">
        <tr>
            <th>Mount path</th>
            <th>Use percentage</th>
        </tr>
        <tr>
            <td>${first_mount_path}</td>
            <td>${first_mount_path_usage}%</td>
        </tr>
        <tr>
            <td>${second_mount_path}</td>
            <td>${second_mount_path_usage}%</td>
        </tr>
    </table>

The issue is that the first_mount_path and second_mount_path values are rendered in sent emails with their surrounding Python quotes. Here's an example:

Mount path	Use percentage
"/"	        50.00%
"/data"	        50.00%

How to remove the rendered quotes in the Mount path table column?

Operating system used: Amazon Linux 2

Best Answer

  • Registered Posts: 7 ✭✭✭
    Answer ✓

    I found I can remove the extra quote characters (") with Apache Freemarker's replace function. Here's the updated snippet:

        <table border="1">
            <tr>
                <th>Mount path</th>
                <th>Use percentage</th>
            </tr>
            <tr>
                <td>${first_mount_path?replace('"', '')}</td>
                <td>${first_mount_path_usage}%</td>
            </tr>
            <tr>
                <td>${second_mount_path?replace('"', '')}</td>
                <td>${second_mount_path_usage}%</td>
            </tr>
        </table>

Answers

  • PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 103 ✭✭✭✭✭✭

    Hello @Edvin

    How problematic is your issue ? I don't think it's about python.

    If you provide your reporter with a dataset with a column for mount paths, will you get this without quotes ? Otherwise, if you want to set dataiku scenario's variables and then call them in html, I'm afraid you'll have to use these strings. May you could check encoding or a method at this level.

  • PartnerApplicant, Dataiku DSS Core Designer, Dataiku DSS ML Practitioner, Dataiku DSS Adv Designer, Registered Posts: 103 ✭✭✭✭✭✭

    Okay

    this method at html level fits your need.

    Best,

Welcome!

It looks like you're new here. Sign in or register to get started.

Welcome!

It looks like you're new here. Sign in or register to get started.