Processing a subset of records correctly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Processing a subset of records correctly

Bob M
I have just realized that I am processing the subset in reverse order (i.e. latest date backwards)

I want to process in earliest date forwards direction

The subset should consist of 102 records
I ignore the most recent
I look at the earliest - and record the prediction only
For the rest I record the current class and compare it with the prediction from the previous record

My code is as follows:-

try
{
rs = s.executeQuery("SELECT * FROM xxx WHERE TRADE_NO <>0 ORDER BY Trading_Date DESC,"
        + " Trading_Time DESC FETCH NEXT 101 ROWS ONLY");
// myConsole.getOut().println("Successfully retrieved 101 records from xxx table: ");

int k = 0;
while (k < 100) {
// for k = 0 record, just get predictions
rs.next();
String Date5 = rs.getString("Trading_Date");
int Time5 = rs.getInt("Trading_Time");

if (k < 1) {
pred_test1 = rs.getString("Class1_Predicted");

if (j == 0) { pred_test = pred_test1;}
}

if (k > 0) {
// get class_current and profit from (k)th record
class_current = rs.getString("class_current");
test_profit = rs.getDouble("Profit_Loss");

[some calculations............]

pred_test = "";
class_current = "";
test_profit = 0;

pred_test1 = rs.getString("Class1_Predicted");

if (j == 0) { pred_test = pred_test1;}

}
 k++;
}
}
catch (SQLException e)
{
    myConsole.getOut().println(e);
} // end of simulation - 100 simulation records
-------------------------------------------------------
If you could indicate code changes to reverse the handling direction I would be delighted

Thank you

Bob M
Reply | Threaded
Open this post in threaded view
|

Re: Processing a subset of records correctly

John English-3
On 05/04/2016 08:45, Bob M wrote:
> I have just realized that I am processing the subset in reverse order (i.e.
> latest date backwards)
>
> I want to process in earliest date forwards direction
> rs = s.executeQuery("SELECT * FROM xxx WHERE TRADE_NO <>0 ORDER BY
> Trading_Date DESC,"
>          + " Trading_Time DESC FETCH NEXT 101 ROWS ONLY");

One way would be to wrap the first query inside another one: something
like This:

   SELECT * FROM (SELECT * FROM xxx WHERE TRADE_NO <>0
                  ORDER BY Trading_Date DESC, Trading_Time DESC
                  FETCH NEXT 101 ROWS ONLY) AS x
            ORDER BY Trading_Date ASC

but I'm sure there must be a more elegant way to do it...
--
John English
Reply | Threaded
Open this post in threaded view
|

Re: Processing a subset of records correctly

Bob M
Thank you John............

I shall try your suggestion

Functionality is more important than elegance for me :)

Bob M