Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 6 of 6
  1. #1
    Join Date
    Jan 2001
    Location
    Anderson Island, WA, USA
    Posts
    2,863

    SQL Data problem (Tidal data)

    I have been stairing at a problem for some time now; it's a personal project that I'm gong to release as freeware/donationware.

    Given some tide data
    and a given time "now", I need to determine the next low tide and the next high tide.

    For some reason I keep stairing at it and can't come up with a solution that reliably works.

    For each day; there are (typically) two lows & two highs; so I acn't just find teh lowest or highest value for that day; moreover, "now" could be 11pm which means that the next low or high tide could be the next day....

    Any ideas?


    (Click here to contact me)
    Providing Independent Professional Consulting Services for
    IndigoRose products, World Wide.
    Located in -8:00 (-7:00 DST) GMT Timezone (Western United States)

  2. #2
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    So is the date stored in a db like this http://co-ops.nos.noaa.gov/data_menu...rmat=View+Data
    I would store the date and time together like this 200811191630 and then format the current date and time the same way. That will make it very easy to find the next tide after the current time. You can sort the results by date/time and then grab the lowest and highest.

    Code:
    local CurrentDateTime = 200811191630
    "SELECT * FROM TideData WHERE DateTime > "..CurrentDateTime.." ORDER BY DateTime"
    Then grad the first 4 rows returned and figure out the lowest and highest.
    Dermot

    I am so out of here

  3. #3
    Join Date
    Jan 2001
    Location
    Anderson Island, WA, USA
    Posts
    2,863
    Quote Originally Posted by Dermot View Post
    So is the date stored in a db like this http://co-ops.nos.noaa.gov/data_menu...rmat=View+Data
    I would store the date and time together like this 200811191630 and then format the current date and time the same way. That will make it very easy to find the next tide after the current time. You can sort the results by date/time and then grab the lowest and highest.

    Code:
    local CurrentDateTime = 200811191630
    "SELECT * FROM TideData WHERE DateTime > "..CurrentDateTime.." ORDER BY DateTime"
    Then grad the first 4 rows returned and figure out the lowest and highest.
    I'm not sure I follow you -- that would pull out potentially 2000 records; the 1st four records are not guaranteed to be the next lowest or next highest . they could be going up or down; but not the peak or valley of the graph...


    (Click here to contact me)
    Providing Independent Professional Consulting Services for
    IndigoRose products, World Wide.
    Located in -8:00 (-7:00 DST) GMT Timezone (Western United States)

  4. #4
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    Use LIMIT to only return a set number

    "SELECT * FROM TideData WHERE DateTime > "..CurrentDateTime.." ORDER BY DateTime LIMIT 4"

    What you could do is say return the next 10 records and loop through them. Each time setting a variable to the height. On each loop you would compare the height to the variable, if it is greater then keep going, but if it is smaller then you know the last one was the next highest so break out of the loop. Do the reverse to find the next lowest.
    Dermot

    I am so out of here

  5. #5
    Join Date
    Jan 2001
    Location
    Anderson Island, WA, USA
    Posts
    2,863
    Quote Originally Posted by Dermot View Post
    Use LIMIT to only return a set number

    "SELECT * FROM TideData WHERE DateTime > "..CurrentDateTime.." ORDER BY DateTime LIMIT 4"

    What you could do is say return the next 10 records and loop through them. Each time setting a variable to the height. On each loop you would compare the height to the variable, if it is greater then keep going, but if it is smaller then you know the last one was the next highest so break out of the loop. Do the reverse to find the next lowest.
    Not bad.. I was stryiing to do it with one loop collecting both the low & high at the same time... this would be slower, but more simple.
    (See I told you I was staring at the problem too long!)
    Thanks
    -josh


    (Click here to contact me)
    Providing Independent Professional Consulting Services for
    IndigoRose products, World Wide.
    Located in -8:00 (-7:00 DST) GMT Timezone (Western United States)

  6. #6
    Join Date
    Apr 2004
    Location
    Vancouver, Canada
    Posts
    1,790
    Looping through 10 or so records is going to be very fast so doing it twice will not make much difference. Could definetly be done in one loop but it will be much easier using 2.
    Dermot

    I am so out of here

Similar Threads

  1. Problem getting HTML data from Web object
    By johnraus in forum AutoPlay Media Studio 5.0
    Replies: 28
    Last Post: 12-05-2006, 02:16 PM
  2. Get SQL data
    By markstaylor in forum AutoPlay Media Studio 6.0
    Replies: 10
    Last Post: 02-24-2006, 04:04 AM
  3. sql plugin problem
    By gnetcanada in forum AutoPlay Media Studio 5.0
    Replies: 3
    Last Post: 01-02-2006, 05:13 PM
  4. Simple Data base Help SQL
    By markstaylor in forum AutoPlay Media Studio 5.0
    Replies: 2
    Last Post: 12-20-2004, 11:22 AM
  5. AMS app that can read and write SQL data
    By sferguson in forum AutoPlay Media Studio 5.0
    Replies: 14
    Last Post: 11-03-2004, 08:20 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts