Page 4 of 8

Re: Battery Charting Script

PostPosted: Fri Apr 15, 2016 7:00 pm
by DaveL17
I thought that might be the case. You'll need to also use the code in post #1 on this thread which includes changes to specifically address the error you were seeing. Sorry if that wasn't clear in my earlier post--I was rushing to get you something before I jumped on a plane.

If you have any questions, please do let me know!
Dave

Re: Battery Charting Script

PostPosted: Sat Apr 16, 2016 12:30 pm
by stuartcolman
Dave,

Thanks for the update, however I am the bearer of bad news. I updated the script as mentioned and get the following error:

Code: Select all
Script Error                    embedded script: unsupported operand type(s) for +: 'int' and 'str'
  Script Error                    Exception Traceback (most recent call shown last):

     embedded script, line 117, at top level
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/pyplot.py", line 2107, in barh
       ret = ax.barh(bottom, width, height, left, **kwargs)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 4902, in barh
       orientation='horizontal', **kwargs)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 4784, in bar
       self.add_patch(r)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 1489, in add_patch
       self._update_patch_limits(p)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/axes.py", line 1507, in _update_patch_limits
       xys = patch.get_patch_transform().transform(vertices)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/patches.py", line 547, in get_patch_transform
       self._update_patch_transform()
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/patches.py", line 543, in _update_patch_transform
       bbox = transforms.Bbox.from_bounds(x, y, width, height)
     File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/matplotlib/transforms.py", line 745, in from_bounds
       return Bbox.from_extents(x0, y0, x0 + width, y0 + height)
TypeError: unsupported operand type(s) for +: 'int' and 'str'


I had a brief look, but it started to get a bit over my head.

Thanks

Stuart

Re: Battery Charting Script

PostPosted: Sat Apr 16, 2016 3:35 pm
by DaveL17
Hi Stuart - Please PM me the entire code block you're running. Your line 117 is not the same as mine and I don't know which part of code is barfing.

Thanks,
Dave

Re: Battery Charting Script

PostPosted: Sat Apr 16, 2016 3:40 pm
by stuartcolman
PM'd

Re: Battery Charting Script

PostPosted: Sat Apr 16, 2016 4:55 pm
by DaveL17
I have updated the master script to address the 'str + int' error. See post #1 in this thread.

Dave

Re: Battery Charting Script

PostPosted: Wed May 04, 2016 8:55 am
by Different Computers
Looking at the code, I see the background is specified as a RGB value.

Is there a way to specify a transparent background?

I found
Code: Select all
plotly_fig = tls.mpl_to_plotly( mpl_fig )
plotly_fig["layout"].update({
                             "plot_bgcolor":"rgba(0, 0, 0, 0)",
                             "paper_bgcolor":"rgba(0,0,0,0)"
                             })
at https://plot.ly/matplotlib/backgrounds/ but that code doesn't look like it would just drop in to replace what's in the script.

Re: Battery Charting Script

PostPosted: Wed May 04, 2016 10:13 am
by DaveL17
Different Computers wrote:
Looking at the code, I see the background is specified as a RGB value.

Is there a way to specify a transparent background?


Try changing the plot settings kwargs to this:
Code: Select all
k_plot_fig = {'bbox_extra_artists': None,
              'bbox_inches': 'tight',
              'dpi': 100,
              'format': None,
              'frameon': None,
              'orientation': None,
              'pad_inches': 0.1,
              'papertype': None,
              'transparent': True,
              }

This deletes the 'facecolor' and 'edgecolor' arguments. It should work.
Dave

Re: Battery Charting Script

PostPosted: Wed May 04, 2016 8:58 pm
by ryanbuckner
need a little assistance here

Tested the imports and they work.
1) Copied your code into pico and output to battery.py file.
2) Created schedule in Indigo to execute battery.py and click on Execute Action Now.
3) Event log has schedule executing but no image in static dir and no errors

Thoughts?

Re: Battery Charting Script

PostPosted: Thu May 05, 2016 3:43 am
by DaveL17
ryanbuckner wrote:
need a little assistance here

Tested the imports and they work.
1) Copied your code into pico and output to battery.py file.
2) Created schedule in Indigo to execute battery.py and click on Execute Action Now.
3) Event log has schedule executing but no image in static dir and no errors

Thoughts?

Copy the code from post #1 in this thread and paste it into an Indigo scripting shell (you may have to hit return to get the last line to execute) and let me know if that works. This should also present you with any User Warnings that may be suppressed when the script is run as a linked script.

Dave

Re: Battery Charting Script

PostPosted: Fri May 06, 2016 6:49 am
by Different Computers
I was a little nervous about replacing the code, but it worked perfectly the first time. Thanks Dave!

I stared at the rest of the code for about 10 minutes and could not figure out how to get rid of the thin black line that frames the graph. What code creates that?

Re: Battery Charting Script

PostPosted: Fri May 06, 2016 9:13 am
by DaveL17
Good deal. Glad that worked.

Can you please post a screen shot of what you're looking at? It will help me figure out what line you're seeing.

Dave

Re: Battery Charting Script

PostPosted: Fri May 06, 2016 10:58 am
by stuartcolman
Some of my devices which have the battery at zero are still showing. Is there a way to filter certain devices out?

Re: Battery Charting Script

PostPosted: Fri May 06, 2016 11:44 am
by DaveL17
stuartcolman wrote:
Some of my devices which have the battery at zero are still showing. Is there a way to filter certain devices out?

There sure is, but I wouldn't want to make it a part of the "official" script because I think a lot of users would want battery devices with 0 to show up. Here is one way. The script creates a list of device names (technically it's called a dictionary) that looks like this:
Code: Select all
device_dict = {"Device Name 1": 100, "Device Name 2": 75, "Device Name 3": 0}

Just above the line in the script that looks like this:
Code: Select all
# Parse the battery device dict into X and Y values

You'll want to add this:
Code: Select all
device_dict.pop("Name of Device You Want to Remove")
device_dict.pop("Name of Another Device You Want to Remove")

And repeat for each device you want to hide. This is completely inelegant because you'll have to go back and add new devices later when you add them to your system--and if you change a device's name the script will break, but it should work for you now right out of the gate.
Dave

p.s. I'll add a TODO to change the script to work with device IDs instead of names to fix the second problem.

Re: Battery Charting Script

PostPosted: Fri May 06, 2016 1:22 pm
by Different Computers
Here's a screenshot. I'm talking about the thin black line that surrounds the graph.

Battery Charting Script

PostPosted: Fri May 06, 2016 1:39 pm
by DaveL17
Different Computers wrote:
Here's a screenshot. I'm talking about the thin black line that surrounds the graph.

Try adding this:

plt.axis("off")

Before the "savefig" command.