Jump to content

Issue when generating organizers with png graphs from a template


Recommended Posts

Main Issue: generating an organizer with png graphs from a custom template

I am trying to programmatically setup an Organizer from Python using spy. The pipeline I am trying to have is as follows:

1. Manually build a Organizer and add curly braces variables, save this organizer as Organizer_Template

image.png.46969e3def5402d97020db5679c8b12b.png

2. From python, pull the organizer and save it as a zip template

reload_templates = True
if reload_templates:
    organizer_ids = {
        "Template_Organizer": "0EEDAD9D-B7EC-6220-8BF9-1BED3C3ED8B3",
    }
    for key in organizer_ids.keys():
        topic_search = spy.workbooks.search({"ID": organizer_ids[key]})
        topic = spy.workbooks.pull(topic_search)
        print(type(topic))
        spy.workbooks.save(topic, template_save_folder + key + ".zip")

3. Load the zip as template

# Load template
workbooklist = spy.workbooks.load(
    template_save_folder + "Template_Organizer.zip",
    as_template_with_label="Template Organizer",
)
organizer = workbooklist["Organizer_Template"] 
print(organizer.documents)

Output:

Success
[Worksheet "Template" (0EEDAD9D-BBB0-77D0-9C47-E014E0E3DB83 Template Organizer)]

4. Rename organizer and document name (the goal here is to keep the template as is in Seeq and generate a new populated organizer )

# Change the name of the organizer 
organizer.name = "Production Organizer"
# Change the name of the organizer document
organizer.documents["Template"].name = "Prod"

print(organizer.documents["Prod"].code)

Output:

document.parameters = {
    "Title": None,
    "[Image] cell1": None,
    "[AltText] cell1": None,
    "[Image] cell2": None,
    "[AltText] cell2": None
}

5. Populate the parameters

organizer.documents["Prod"].parameters = {
    "Title": "Prod 1",
    "[Image] cell1": os.path.join(
            plot_path, "G1", "long_term", "z_score_max.png"
        ),
    "[AltText] cell1": "G1 long_term z_score_max",
    "[Image] cell2": os.path.join(
            plot_path, "G2", "long_term", "z_score_max.png"
        ),
    "[AltText] cell2": "G1 long_term z_score_max"
}
print(organizer.documents["Prod"].parameters)

Output:

{'Title': 'Prod 1',
 '[Image] cell1': '/home/datalab/pdm/vibration_models/dashboard/docs/_contents/G1/long_term/z_score_max.png',
 '[AltText] cell1': 'G1 long_term z_score_max',
 '[Image] cell2': '/home/datalab/pdm/vibration_models/dashboard/docs/_contents/G2/long_term/z_score_max.png',
 '[AltText] cell2': 'G1 long_term z_score_max'}

6. Push the workbook back to Seeq

spy.workbooks.push(organizer,path=path)

Output:

ID	Name	Type	Workbook Type	Count	Time	Result	Pushed Workbook ID	URL
0	0EEDAD9D-B7EC-6220-8BF9-1BED3C3ED8B3 Template ...	Production Organizer	Workbook	Topic	1	0:00:00.151992	Success	... ... 

All seems good but then when I go to the organizer that I see:

image.png.57fd0d809ad38087c75220ef5037ec01.png

Note:

- The path the the png is correct, if not an error appears when trying to push the notebook

So Seeq does find the path, processes the png but they do not appear correctly on the Organizer. Anyone knows what the issue is?

Secondary Issue: Generating multiple Organizers from a single template

The main reason for defining manually a template is so I can generate multiple organizers from the same template but showing different data.

In this case if I rerun exactly the same steps but in step 4 I write

organizer.name = "Production Organizer 2"

And for consistency I change the title of the document and paths to the plots in step 5 (G1-G2 to G3-G4)

organizer.documents["Prod"].parameters = {
    "Title": "Prod 2",
    "[Image] cell1": os.path.join(
            plot_path, "G3", "long_term", "z_screore_max.png"
        ),
    "[AltText] cell1": "G3 long_term z_score_max",
    "[Image] cell2": os.path.join(
            plot_path, "G4", "long_term", "z_score_max.png"
        ),
    "[AltText] cell2": "G4 long_term z_score_max"
}
organizer.documents["Prod"].parameters

Then, when I push back the organizer to Seeq, the changes have been taken into account Production Organizer 2 is in the folder defined by the path but it overwrote my first organizer. Note that when I push Production Organizer it does not overwrite Organizer_Template even though they are both in the same folder. How can I circumvent this issue?

Thank you in advance for your help!

 

 

Link to comment
Share on other sites

  • 3 weeks later...
  • Seeq Team
Posted (edited)

Hi Martin, 

Here's the full script that I did to replicate the issue. The organizer topic template require dummy image for an image content. 

Step 1. Build a organizer topic template. For a text, add curly braces, and for an image content/chart, add dummy image then set the image text alternative with curly braces and save this organizer topic as Organizer_Template.

image.png

Step 2. Search, pull and save the Organizer_Template in a zip file. (e.g.: Template_20March.zip)

workbooks_df = spy.workbooks.search({'ID':'0EEE504F-96B9-6030-9FA3-1612720FB9B9'})
workbooks = spy.workbooks.pull(workbooks_df)
spy.workbooks.save(workbooks,'Template_20March.zip', overwrite=True)
workbooklist = spy.workbooks.load('Template_20March.zip', as_template_with_label=f'{spy.user.username} Template_20March')

Step 3. Load the zip file 

workbooklist = spy.workbooks.load('Template_20March.zip', as_template_with_label=f'{spy.user.username} Template_20March')

Step 4. Use the template and define it as data_lab_visualization_template. Then look at the code for the parameters

data_lab_visualization_template = workbooklist['Organizer_Template'] #this need to be the same as topic name 
print(data_lab_visualization_template.code)

output :

topic.parameters = {
    "Title": None,
    "[Image] cell1": None,
    "[AltText] cell1": None,
    "[Image] Chart1": None,
    "[AltText] Chart1": None,
    "[Image] Chart2": None,
    "[AltText] Chart2": None
}

Step 5. Populate the parameters

data_lab_visualization_template.parameters = {
    "Title": "Prod1",
    "[Image] cell1": "./Support Files/charts/Area E Histogram.png",
    "[AltText] cell1": "Area E Histogram",
    "[Image] Chart1": "./Support Files/charts/Area G Histogram.png",
    "[AltText] Chart1": "Area G Histogram",
    "[Image] Chart2": "./Support Files/charts/Area H Histogram.png",
    "[AltText] Chart2": "Area H Histogram"
}
print(data_lab_visualization_template.parameters)

output

{'Title': 'Prod1', 
'[Image] cell1': './Support Files/charts/Area E Histogram.png', 
'[AltText] cell1': 'Area E Histogram', 
'[Image] Chart1': './Support Files/charts/Area G Histogram.png', 
'[AltText] Chart1': 'Area G Histogram', 
'[Image] Chart2': './Support Files/charts/Area H Histogram.png', 
'[AltText] Chart2': 'Area H Histogram'}

Step 6. Push the organizer topic to Seeq

spy.workbooks.push(data_lab_visualization_template)

image.png

Creating a second topic using the same template. (Repeat step 3 until 6)

Step 3

#load the template zip file
workbooklist = spy.workbooks.load('Template_20March.zip', as_template_with_label=f'{spy.user.username} Template_20March')

Step 4

#Use the template and define it as data_lab_visualization_template2, Then look at the code for the parameters
data_lab_visualization_template2 = workbooklist['Organizer_Template'] #this need to be the same as topic name 
print(data_lab_visualization_template2.code)

Step 5

#populate the parameters
data_lab_visualization_template2.parameters = {
    "Title": "Prod2",
    "[Image] cell1": "./Support Files/Area A Histogram1.png",
    "[AltText] cell1": "Area A Histogram",
    "[Image] Chart1": "./Support Files/Area C Histogram1.png",
    "[AltText] Chart1": "Area C Histogram",
    "[Image] Chart2": "./Support Files/Area D Histogram1.png",
    "[AltText] Chart2": "Area D Histogram"
}
print(data_lab_visualization_template2.parameters)

Step 6

#push the organizer to seeq
spy.workbooks.push(data_lab_visualization_template2)

image.png

Edited by Siti Tay
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...