Author Topic: How to make VC to read a list or array returned by py script?  (Read 5636 times)

0 Members and 4 Guests are viewing this topic.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
This is probably a question to James, not sure if anyone else has been able to try that before.

The list contains basically the data needed to generate a new payload xml. Before I go and make a function on python that will create a standard payload xml file from scratch, I would like to check if it is possible to do that with an action on VC?

The list that is returning from my python script contains the results from a database query, so many lines of value/phrases can return on that list.

If I'm able to take that return from VC and transform that data on a payload xml, that's wonderful, but I don't know how to do it. So I'm asking for help on that.
If it can't currently be done, then I'm going to create the payload file directly from the py script, which seems easy but then if you guys change anything in the xml format in the future releases, I'll need to go back to this script and change it accordingly. I would like to avoid it if possible.

The screenshots show what I'm talking about.
Thanks!

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #1 on: June 11, 2015, 06:11:01 PM »
Hi Marcus,


if your Data is stored in {LastResult}, you can use the RegEx actions in VC - maybe this will help you.


Kalle
***********  get excited and make things  **********

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #2 on: June 11, 2015, 07:56:23 PM »

The list that is returning from my python script contains the results from a database query, so many lines of value/phrases can return on that list.


rule #1
is that database is a VC map? simply: Map.ExportPayloadXML

rule#2
if not ... you can write the list to a temporary map.. then refer to rule #1
 ;D ;D
When Voice command gets tough, use hand gestures

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #3 on: June 12, 2015, 12:50:45 AM »
Hi Marcus,


if your Data is stored in {LastResult}, you can use the RegEx actions in VC - maybe this will help you.


Kalle
thanks. Could you please give me an example so I can try?
As you can see from the screenshots, I tried using osd directly on lastresult to no success.

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #4 on: June 12, 2015, 01:22:46 AM »
rule #1
is that database is a VC map? simply: Map.ExportPayloadXML

rule#2
if not ... you can write the list to a temporary map.. then refer to rule #1
 ;D ;D
answer1: it's not a standard map table,  but it's a table that is inside the same DB where the map tables are stored.
When and if James implement the map.query as discussed in another thread, then maybe I can run more advanced queries with the results going directly to a payload xml, in other words, not needing to use python for this.

Answer 2: I thought about it, but then it seemed more like a workaround than a solution. I also considered that it would take less machine resources by doing it another way.
But thinking about it better now,  I think it would work properly and with best performance than the other way.
Thanks!

Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #5 on: June 12, 2015, 02:13:19 AM »
answer1: it's not a standard map table,  but it's a table that is inside the same DB where the map tables are stored.

that confused me even more .. maps are simple DB tables with 2 columns only key and value... can you post a screen shot of your table/map?

P.S. James did apply some improvements to map.query in 2.148 ... now the query return multiple matches, where match x.1 will be the key and match x.2 contains the value ... match x gives you both
« Last Edit: June 12, 2015, 02:17:06 AM by Haddood »
When Voice command gets tough, use hand gestures

Kalle

  • $upporter
  • Hero Member
  • *****
  • Posts: 2320
  • Karma: 47
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #6 on: June 12, 2015, 05:28:31 AM »
Ok, forget the RegEx at this moment.
If I understand you correct and from your pictures, there is not the expected data in the {LastResult} available.


Did you tried this: http://voxcommando.com/mediawiki/index.php?title=Python#Returning_a_Result


Maybe this give you an idea: http://voxcommando.com/forum/index.php?topic=1548.msg13508#msg13508

***********  get excited and make things  **********

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: How to make VC to read a list or array returned by py script?
« Reply #7 on: June 12, 2015, 07:48:29 AM »
When and if James implement the map.query as discussed in another thread, then maybe I can run more advanced queries with the results going directly to a payload xml, in other words, not needing to use python for this.


Already done in 2.1.4.8  !

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #8 on: June 12, 2015, 10:43:27 AM »
Already done in 2.1.4.8  !
Thanks! You guys rock!

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #9 on: June 12, 2015, 11:00:03 AM »
that confused me even more .. maps are simple DB tables with 2 columns only key and value... can you post a screen shot of your table/map?

P.S. James did apply some improvements to map.query in 2.148 ... now the query return multiple matches, where match x.1 will be the key and match x.2 contains the value ... match x gives you both
All this stuff is for the My Sensors controller that I'm developing in python for integration with VC.

I'm manipulating a standard sqlite database directly with python. The DB where the maps are stored is the same that I'm using to store my custom tables. That way, when and if needed, I can access those tables from inside VC. By saying custom tables, I mean I have tables with more than 2 columns that don't have the standard fields (fromKey, toValue).

The custom tables are used to save sensor history, sensor names, etc. The python program does the hard work so VC can then have nice payload xmls that will automatically update once a sensor is added or removed.
I still need to research for a way to show a nice graphical chart of sensor history, got from a query on one of those custom tables. This is in my pending list, suggestions are welcome.

Notice it is extremely not recommended to play with this if you are not sure what you are doing.


Haddood

  • $upporter
  • Hero Member
  • *****
  • Posts: 688
  • Karma: 22
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #10 on: June 13, 2015, 06:25:33 AM »
All this stuff is for the My Sensors controller that I'm developing in python for integration with VC.

I'm manipulating a standard sqlite database directly with python. The DB where the maps are stored is the same that I'm using to store my custom tables. That way, when and if needed, I can access those tables from inside VC. By saying custom tables, I mean I have tables with more than 2 columns that don't have the standard fields (fromKey, toValue).

The custom tables are used to save sensor history, sensor names, etc. The python program does the hard work so VC can then have nice payload xmls that will automatically update once a sensor is added or removed.
I still need to research for a way to show a nice graphical chart of sensor history, got from a query on one of those custom tables. This is in my pending list, suggestions are welcome.

Notice it is extremely not recommended to play with this if you are not sure what you are doing.

that puts things in perspective for me...  maybe others would have a different approach but what I would do probably;  at the same time I manipulate the original table, I would write a separate "standard VC" table for the purpose of generating payloads. and make python raise an event in VC, that the table has been changed... and use that event to run classical VC macro with Map.ExportPayloadXML...

as for the charting, a while ago I was working on a very similar project (that is halted for the time being, like all my VC projects  :-\), at the time I started to play with

dashboards
https://freeboard.io/  (one display type offer history data)
https://dweet.io/follow/garrulous-able

if you are looking for complex charting look at
online: https://public.tableau.com/s/gallery
offline: http://www.gapminder.org/downloads/
When Voice command gets tough, use hand gestures

marcusvdt

  • Sr. Member
  • ****
  • Posts: 152
  • Karma: 6
  • Researching
    • View Profile
Re: How to make VC to read a list or array returned by py script?
« Reply #11 on: June 13, 2015, 05:34:55 PM »
@Haddood, thanks!
That's exactly what I'm doing, but it is not needed to fire an event. I'm using vc.callAction from inside the python script, and within the this call, there it is the Map.ExportPayloadXML that is generating a payload xml.

When I started this thread I was wondering if another strategy would be better, but then I figured out this is the best one indeed.

Regarding the chats, I'll look at those you posted, thanks. I've been planning to research about something like this: https://linil.wordpress.com/2008/09/16/cairoplot-11/