FoxSoft Calgary User Group - Puzzles

FoxSoft Calgary Puzzle One

Home

Training

Member Solutions

Code Samples

Puzzles

FoxPro Links

Description:

This puzzle has to do with the calculation of Nitrous Oxide emissions (for example). Samples are taken on a regular basis and whenever the emissions exceed 70 we need to know the start time (sample value 70 or above), when it ended (next sample below 70), the maximum level reached over the period and the elapsed time for the period that the emissions were 70 or over.

Included below is the VISUAL FOXPRO code to create the sample data and the required results.

The result set was produced from a SINGLE Visual Foxpro 7.0 SQL Statement.

Listing 1:

Create Table and sample data

CREATE TABLE Samples ;
( ;
sample_ts TIME NOT NULL ,;
NOx INTEGER NOT NULL;
)

INSERT INTO Samples VALUES({^2002/05/15 11:35:00.000}, 13)
INSERT INTO Samples VALUES({^2002/05/15 11:35:10.000}, 77)
INSERT INTO Samples VALUES({^2002/05/15 11:35:20.000}, 81)
INSERT INTO Samples VALUES({^2002/05/15 11:35:30.000}, 19)
INSERT INTO Samples VALUES({^2002/05/15 11:35:40.000}, 25)
INSERT INTO Samples VALUES({^2002/05/15 11:35:50.000}, 24)
INSERT INTO Samples VALUES({^2002/05/15 11:36:00.000}, 45)
INSERT INTO Samples VALUES({^2002/05/15 11:36:25.000}, 44)
INSERT INTO Samples VALUES({^2002/05/15 11:37:35.000}, 75)
INSERT INTO Samples VALUES({^2002/05/15 11:38:15.000}, 82)
INSERT INTO Samples VALUES({^2002/05/15 11:38:45.000}, 92)
INSERT INTO Samples VALUES({^2002/05/15 11:39:01.000}, 50)
INSERT INTO Samples VALUES({^2002/05/15 11:39:22.000}, 73)
INSERT INTO Samples VALUES({^2002/05/15 11:39:52.000}, 74)
INSERT INTO Samples VALUES({^2002/05/15 11:40:22.000}, 75)
INSERT INTO Samples VALUES({^2002/05/15 11:40:52.000}, 65)

Listing 2:

The magical result set:

STARTTIME ENDTIME ELAPSED MAX_NOX
02/05/15 11:35:10 AM 02/05/15 11:35:30 AM 00:00:20 81
02/05/15 11:37:35 AM 02/05/15 11:39:01 AM 00:01:26 92
02/05/15 11:39:22 AM 02/05/15 11:40:52 AM 00:01:30 75


Web Master

     

Copyright © 2003 FoxSoft Calgary. All rights reserved.