Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Coding Help - BQL
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Scott B  
View profile  
 More options Sep 9 2012, 10:37 pm
From: Scott B <solar.sen...@gmail.com>
Date: Sun, 9 Sep 2012 19:37:52 -0700 (PDT)
Local: Sun, Sep 9 2012 10:37 pm
Subject: Coding Help - BQL

Ok, I'm trying to play out of my depth here again...

The following is a bit of  example code that searches through one of our
'stations' (a control system for a building), builds a table out of all the
data returned from a BQL, and then does some simple math on it.

I have managed to do a bit of tinkering to also output the number of points
it finds etc, but what I would like it to be able to do is output the name
of the points that are the Max & Min as a string.

To do this, I would assume I first need to expand the Table so that it not
only holds the value but also the name of the point (I have no Idea how to
do this), then from there it shouldn't be too hard, each time a Min Or Max
value is found I should be able to just store its point name in a similar
way to how it stores its value at the moment. Then I can just update the
output once it reaches the end of the table.

so, anyone know anything about creating tables from BQL searches?

// MinMaxAvg - Points Selected by BQL
// Daniel Drury / 2007
//
// Return BQL result with 1st column is a BStatusNumeric
// Edit property sheet with BQL, get BQL by using query builder
// Example: Avg all Numeric Points in station
//  station:|slot:/|bql:select out from control:NumericPoint
// Example: Avg all Numeric Points starting with ZN-T
//  station:|slot:/|bql:select out from control:NumericPoint where
displayName like 'ZN-T*'

public void onStart() throws Exception
{
  updateTimer();

}

public void onExecute() throws Exception
{
  String ord = getInBqlOrd();
  BStatusNumeric Value;

  double num=0;
  double avg=0;
  double min=0;
  double max=0;
  double first=1;

  updateTimer();

  BITable result = (BITable)BOrd.make(ord).resolve(Sys.getStation()).get();
  // execute bql into table

  ColumnList columns = result.getColumns();        // get table cols data
  TableCursor c = (TableCursor)result.cursor();    // setup table cursor
  first = 1;                                       // init stuff on 1st
valid found
  num = 0;                                         // init number points
found

  while (c.next())                                 // walk bql rows
  {
    Column valueColumn = columns.get(0);           // data is in 1st col
    Value = (BStatusNumeric) c.get(valueColumn);   // get BStatusNumeric
from table
    if (Value.getStatus().isValid()) {             // get Status of point,
check valid
      if (first != 0) {                            // 1st valid point, use
it for everything
        min = Value.getValue();
        max = Value.getValue();
        avg = Value.getValue();
        num = 1;                                   // Init number points
found
        first = 0;
      } else {                                     // 2nd+ valid point,
check min/max, and avg it
        if (Value.getValue() <= min) min = Value.getValue();
        if (Value.getValue() >= max) max = Value.getValue();
        avg += Value.getValue();
        num++;
      }
    }          
  }

  getNum().setValue(num);       // set number points found
  if (num > 0) {                // only use avg/min/max if something valid
found
    if (num != 0) getAvg().setValue(avg/num);
    getMin().setValue(min);
    getMax().setValue(max);  
    getNumber().setValue(num);
  } else {                      // No Valid Return, Return Default
    getAvg().setValue(getDefault().getValue());
    getMin().setValue(getDefault().getValue());
    getMax().setValue(getDefault().getValue());
  }  

}

public void onStop() throws Exception
{
  if (ticket != null) ticket.cancel();

}

void updateTimer()
{            
  if (ticket != null) ticket.cancel();
  ticket = Clock.schedule(getProgram(), getExecutePeriod(),
BProgram.execute, null);

}    

Clock.Ticket ticket;
long lastOnExecuteTicks;

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »