Author Topic: Decimal Data Types  (Read 4706 times)

0 Members and 2 Guests are viewing this topic.

DHHJ

  • $upporter
  • Contributor
  • *****
  • Posts: 62
  • Karma: 1
    • View Profile
Decimal Data Types
« on: March 26, 2014, 05:22:03 PM »
Is there a way I can "pass" a decimal number to a python script/file? Is there a VC Method that can be used?

I assume payload range is integer only? What is the upper range of the payload range- I don't think this is the way to go, just curious.

I'd like to build a VC calculator........building on this example http://voxcommando.com/forum/index.php?topic=73.msg385#msg385 and adding some scientific functions, trig, etc.

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Decimal Data Types
« Reply #1 on: March 26, 2014, 05:36:21 PM »
A concrete example would help me to understand what you need.  5 is a decimal number, so payload range can give you a range of decimal numbers, that happen to be integers as well.

You can call a python function with a payload using PY.ExecString   myFunc({1})

If your payload {1} = 10 then it will be treated as a number.  Python will only treat it as a string if you put quotes around it like this:
myFunc("{1}")

If you want to be able to say any number with decimal points or fractional values then you are going to need to get pretty creative.

DHHJ

  • $upporter
  • Contributor
  • *****
  • Posts: 62
  • Karma: 1
    • View Profile
Re: Decimal Data Types
« Reply #2 on: March 27, 2014, 12:02:53 PM »
Yes, that's my question/issue. How can I do something like....

"Calculate 12% of 65.7" or "What's the square root of 78.9"

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Decimal Data Types
« Reply #3 on: March 27, 2014, 12:50:17 PM »
Can I ask, what is the ultimate goal? Do you want to then do something with the calculated values in subsequent commands, or do you just want to be able to have VC verbally give you answers to math problems?
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

jitterjames

  • Administrator
  • Hero Member
  • *****
  • Posts: 7714
  • Karma: 116
    • View Profile
    • VoxCommando
Re: Decimal Data Types
« Reply #4 on: March 27, 2014, 01:12:22 PM »
"Calculate 12% of 65.7" or "What's the square root of 78.9"

You are not going to have much fun trying to come up with all the possible ways people can say numbers.  I think it is a wasted effort, but you can try to use the Wolfram Alpha commands that we previously posted.

Wolfram Alpha does a pretty good job of converting words from free dictation to numbers when appropriate.  So VC will understand you saying: "Wolfram, What's the square root of seventy eight point nine" and Wolfram will give you the answer.
« Last Edit: March 27, 2014, 01:21:37 PM by jitterjames »

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Decimal Data Types
« Reply #5 on: March 27, 2014, 04:33:29 PM »
Yes, that's my question/issue. Hjavascript:void(0);ow can I do something like....

"Calculate 12% of 65.7" or "What's the square root of 78.9"

The W\A commands work quite well for this sort of thing, as long as open dictation works decently for you. Here you can see it in action:
http://www.screencast.com/t/QTyDT3t4BlS


We've already posted the xml for Wolfram Alpha commands a few times, but here is a version I re-created specifically for the video demo above. This particular xml requires VC2, because I'm using the new and improved regular expression syntax. It can be done as well the old way with little difficulty; it's just different.
Code: [Select]
<?xml version="1.0" encoding="utf-16"?>
<command id="625" name="wolfram" enabled="true" alwaysOn="False" confirm="False" requiredConfidence="0" loop="False" loopDelay="0" loopMax="0" description="">
  <action>
    <cmdType>Scrape</cmdType>
    <cmdString>http://api.wolframalpha.com/v2/query?appid=YOUR_API_KEY&amp;input={1}&amp;format=plaintext</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <action>
    <cmdType>Results.RegExSingle</cmdType>
    <cmdString>Input.*?&lt;plaintext&gt;([^&lt;].*?)&lt;/plaintext&gt;.*?[Result|Definition|approximation].*?&lt;plaintext&gt;([^&lt;].*?)&lt;/plaintext&gt;</cmdString>
    <cmdRepeat>1</cmdRepeat>
  </action>
  <if ifBlockDisabled="False" ifNot="False">
    <ifType>LastActionSuccess</ifType>
    <ifParams>&amp;&amp;</ifParams>
    <then>
      <action>
        <cmdType>Results.SetLastResult</cmdType>
        <cmdString>You asked for: {Match.1.1}. {Cr}The answer is: {Match.1.2}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.RegExReplace</cmdType>
        <cmdString>sqrt\((.*?)\)&amp;&amp;square root of $1</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.Replace</cmdType>
        <cmdString> × &amp;&amp; times </cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>Results.Replace</cmdType>
        <cmdString> | &amp;&amp;, </cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <cmdString>{LastResult}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <cmdString>{LastResult}</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </then>
    <else>
      <action>
        <cmdType>TTS.Speak</cmdType>
        <cmdString>I'm sorry, I don't know the answer to: {1} Could you speak more clearly, or perhaps try to rephrase your question.</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
      <action>
        <cmdType>OSD.ShowText</cmdType>
        <cmdString>I'm sorry, I don't know the answer to: {CR}{1}{CR}Could you speak more clearly, or perhaps try to rephrase your question.</cmdString>
        <cmdRepeat>1</cmdRepeat>
      </action>
    </else>
  </if>
  <phrase>Wolfram</phrase>
  <payloadDictation>payloadDictation: Regular</payloadDictation>
</command>
« Last Edit: March 14, 2015, 10:08:09 AM by nime5ter »
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

nime5ter

  • Administrator
  • Hero Member
  • *****
  • Posts: 1999
  • Karma: 61
    • View Profile
    • Getting Started with VoxCommando
Re: Decimal Data Types
« Reply #6 on: March 27, 2014, 04:39:32 PM »
With the above command, I also had good success with queries such as:

Convert x to y
What is [value]Fahrenheit in [value]Celsius (etc.)
What's the square root of x

How far is point A from point B

... And so on.
TIPS: POST VC VERSION #. Explain what you want VC to do. Say what you've tried & what happened, or post a video demo. Attach VC log. Link to instructions followed.  Post your command (xml)

DHHJ

  • $upporter
  • Contributor
  • *****
  • Posts: 62
  • Karma: 1
    • View Profile
Re: Decimal Data Types
« Reply #7 on: March 27, 2014, 06:17:32 PM »
Thanks- that seems to meet the need. I'll play with it and let you know!