Announcement

Collapse
No announcement yet.

Scripting performance & style

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Scripting performance & style

    As I am refining stuff here to run on HS3, I am trying to improve things a bit. I have for a long time bucked what I think is a normal convention of using response.write... build a page and instead I use something like this in line as I build the page.

    <tr>
    <td class="style4">Outside Light</td>
    <td class="style5"><%=DeviceOnOff("86")%></td>
    <td class="style5"><%=DeviceLast%></td>
    </tr>

    I have always found "my way" is easier to understand and easier to write. My question is there a reason aside from style to do it one way or the other?
    Also
    When needing data from a homeseer device, is it better to query the device once, moving the information into a work variable that to make multiple calls to the device to retrieve more bits of data. Here is an example of that

    function DeviceOnOff(s)
    DeviceOnOff=""

    if hs.DeviceValue(s) > 0 then
    DeviceOnOff="<img src='Customicon\on.png'>"
    end if

    ' DeviceLast=hs.DeviceTime(s) 'This way or...
    ' days = Cstr(round(hs.DeviceTime(s)\1440,0))
    ' hours = Cstr(round((hs.DeviceTime(s)-days*1440)\60,0)+1000)

    Work=hs.DeviceTime(s) 'This way?
    days = Cstr(round(Work\1440,0))
    hours = Cstr(round((Work-days*1440)\60,0)+1000)

    if hours > "9999" then hours = "9999"

    minutes = cstr(hs.devicetime(s) MOD 60+100)
    DeviceLast=days+":"+mid(hours,3,2)+":"+mid(Minutes,2,2)
    end function

    Thanks for your time

    -r
    -Rick

  • #2
    I think quite a few people do it your way. Nothing wrong with it and if it works for you, keep doing it. I personally prefer the "other" way

    I typically use a variable if I need to retrieve/use the hs value more than once. I don't think the extra overhead is large the other way, but it's considered good coding practice. The only time I will retrieve it more often is if I think the value will change during the execution of the script and the script needs to be aware of that.

    Cheers
    Al
    HS 3.0.0.548: 1976 Devices 1156 Events
    Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

    Comment


    • #3
      I've just started scripting with Homeseer so I'm still figuring out how things even begin to work. But as my day job I write iOS & Android code, and used to do stuff on the web.

      As to part #1, I haven't gotten to response.write or building pages to figure out what is what. BUT I do know that you want logic to reside elsewhere. The pages should simply be outputting formatted data. Some other "presenter" should aggregate and format the data. It should then present the data to the page and the page should render it.
      That being said, I have written exactly one script, so that might be easier said than done.

      As to part #2: Yes, query the data once and store it locally on a per-request basis. You'll want to refresh it once for each page access, but you don't need to call it any more than that. You're saving roundtrips to the database/server/whatever which is always a good move. And you're not really saving any memory by constantly re-accessing the data instead of storing it in a local variable.

      Comment

      Working...
      X