Author Topic: For those with no patience...  (Read 7026 times)

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
For those with no patience...
« on: January 06, 2016, 09:56:17 PM »
I got tired of seeing "Rain: 0.00 in" along with "Rain rate: 0.00 in" for this day (Current Conditions)/week (Weekly stats). So I checked to see if a meager bit of php could be added to check for anything more than 0 before printing the amount. Basically, if rain amount is > zero, print the amount (and the rate), else, don't waste electrons on printing "0.00".

Of course, we're supposed to get some rain tonight, so I can't double-check that things will work correctly after that...

Still, it's good to know that we can take the inputs from WC and use them for just about anything we want, without reverting to javascript (which is often blocked) or even AppleScript. [cheer]

The following is in a small table on my index page (Current Conditions):
Code: [Select]
<?php
$rainstring 
"STAT$RAIN:TOTAL:TODAY$ RAINUNITS$";
$rain chop($rainstring,"in");
$amount 0.01;

if (
$rain $amount) {
echo  '<td class="right">No rain during this period.</td>';
} else {
echo  '<tr>
    <td class="right">Total Rain:</td>
    <td class="left">' 
$rainstring '</td>
       </tr>
       <tr>
    <td class="right">Rain Rate:</td>
    <td class="left">CR$</td>
       </tr>'
;
}
?>
Nothing earth-shaking here! [blush] I might find more use by making a "0" wind indicate "Calm" (with or without a direction [lol] ).
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

TechnoMonkey

  • Strong Breeze
  • ***
  • Posts: 127
    • EW9323
    • KTXARANS6
    • TechnoMonkeys Weather
  • Station Details: La Crosse WS-2315 / High Sierra Server / Mac Mini 2.3 GHz Intel Core i5/ 8GB Ram / OS 120GB SSD / Home Folder 500GB FireWire / DATA 8TB RAID 5 / 1TB TIME CAPSULE
Re: For those with no patience...
« Reply #1 on: January 07, 2016, 05:52:42 AM »
The wind speed took a bit of work, bit I got it.  I am thinking of changing all the wind speed to this chart.

http://www.weather.gov/media/iwx/webpages/skywarn/Beaufort_Wind_Chart.pdf

www.technomonkeys.com

Here it is.  I jacked up my hourly changes while debugging.

Don't know if it works yet.  The winds are calm for tonight.  Now I need to change the wind direction to some null when it is calm.

Code: [Select]
<?php
$light_air "1";
$light_breeze "4";
$gentle_breeze "8";
$moderate_breeze "14";
$fresh_breeze "19";
$strong_breeze "25";
$near_gale "32";
$severe_gale "47";
$storm "55";
$violent_storm "64";
$hurricane "74";
$windstring "CW$";
$pos strpos($windstring,'MPH');
$wind substr($windstring0$pos);

if ($wind $light_air)
{
echo "Calm";
}
else if ($wind $light_breeze)
{
echo "Light air";
}
else if ($wind $gentle_breeze)
{
echo "Light breeze";
}
else if ($wind $moderate_breeze)
{
echo "Gentle breeze ";
}
else if ($wind $fresh_breeze)
{
echo "Moderate breeze";
}
else if ($wind $strong_breeze)
{
echo "Fresh breeze";
}
else if ($wind $near_gale)
{
echo "Strong breeze";
}
else if ($wind $severe_gale)
{
echo "Near gale";
}
else if ($wind $storm)
{
echo "Severe gale";
}
else if ($wind $violent_storm)
{
echo "Storm";
}
else if ($wind $hurricane)
{
echo "Violent storm";
}
else
{
echo "Hurricane";
}
?>


xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #2 on: January 07, 2016, 03:48:05 PM »
Nice improvement! [tup]

I was thinking about something similar, using 'case' statements. ;) You could also have a small, horizontal image, with color coding, displayed along with the Beaufort text. OTOH, not sure anyone around our rather land-locked area would know what that scale means. [blush] We'd probably get more benefit from words like: "Get the clothes off the clothes line", "Nailed down objects may move", "Put more concrete blocks on the icebox on the porch", "Bring in the chickens, NOW".

If I did write some code, I'd probably not bother with "Hurricane". Even those back in the farthest hills would already know that! [rolleyes2] Most people around here have never heard of any kind of "Gale", either... unless that's part of the name of one of their lady friends... Barbara Gail, Honey Gail, Nite N. Gale (spellin' ain't always cornsis tent, neither!  [blush]

Since most of my data is displayed as a simple two-column table, I simply left out the 'direction' row when the wind value was zero/calm. That row is only inserted when the wind exists. Same for the 'rain rate' row; if there has been no rain, there's probably not much of a 'rate'! :o
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #3 on: January 12, 2016, 12:23:20 AM »
After being shamed by an AppleScript guru (who shall remain unnamed) living on the Left Coast, I decided to tackle the task of including the run time of the WC computer. Stu already makes including the elapsed running time of WC this trivial. I also hoped to learn something along the way. I have accomplished my goal but I'm not sure I learned anything particularly useful.

The 4 easy steps:
  • Buy/use an Apple computer and WeatherCat.
  • Use AppleScript to run the Unix "uptime" command, and edit that text to appropriate bits of text and write it to a text file.
  • Create a method to run the AS at a desired interval.
  • Use a PHP (or other server-side language) to read the file and display the information
In summary, all you need is AppleScript, Terminal (to access Unix underpinnings of the OS), WeatherCat (does the uploading), and a bit of PHP on the web page (to display the info). PHP, Terminal, and AppleScript are "free", being included with every Apple computer. Most hosting services include PHP at no extra cost. The computer and WeatherCat are well worth their costs! [cheer]

I also decided to break down the WC app run time into its three parts to allow it to look similar to the newly created computer run time display. You can see this info outstandingly boring display on my ?Station" page. The computer run time updates every 15 minutes, the app's time updates with the timing set in WC (every two minutes, I think. Times are small now due to backing up the updating the OS, first to 10.10.5 and then to El Capitan .

After looking at the output, with very low times (less than an hour), I think I'll change the AS to do nothing more than upload the result of the Unix "uptime" command. The length of the text is too variable and the string functions of PHP are so much more powerful. Oh well, I guess I did learn something...
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #4 on: January 13, 2016, 12:15:23 AM »
Working on making the computer uptime more robust and complete. I have completed some of the following testing using actual output from the "uptime" command.
Test strings:
    minutes < 10 only.........................WORKS->16:40  up 3 mins, 3 users, load averages: 1.73 1.10 0.48
    minutes > 9 only...........................WORKS->16:50  up 13 mins, 3 users, load averages: 1.75 1.51 1.00
    no days, hours < 10 , no minutes
    no days, hours > 9, no minutes
    hours > 9, minutes < 10................WORKS->13:11  up 1:01, 2 users, load averages: 1.29 1.31 1.31
    no days, hours > 9 minutes > 9......WORKS->13:11  up 10:46, 2 users, load averages: 1.29 1.31 1.31
    no days, hours < 10 minutes > 9....WORKS->13:11  up 09:46, 2 users, load averages: 1.29 1.31 1.31   
    day = 1 - 9, hours < 9, minutes > 9   
    day = 1 - 9, hours < 9, minutes < 10
    day = 1 - 9, hours > 9, minutes > 9   
    day = 1 - 9, hours > 9, minutes < 10
    days > 9, hours < 9, minutes > 9   
    days > 9, hours < 9, minutes < 10
    days > 9, hours > 9, minutes > 9   
    days > 9, hours > 9, minutes < 10
Many of these strings will be seen only for 60 seconds, but I detest texts such as "1 days", "1 minutes", etc. That always looks like Windos output!  [banghead] "If it takes longer, that's always my choice!" Or maybe it's; "If it's worth doing, it's worth doing the hard way!" [lol]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6496
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Glutton for punishment . . . (Re: For those with no patience...)
« Reply #5 on: January 13, 2016, 12:50:38 AM »
Dear X-Air and WeatherCat Scripters, . . .

After being shamed by an AppleScript guru (who shall remain unnamed) living on the Left Coast, I decided to tackle the task of including the run time of the WC computer.

In the ominous voice of some game show from the 1950s . . .

 [wink] . . . . Remember, you are askin' for it!!! . . . .

It turns out to be a lot harder to get than you would imagine.  Here is the "method" (subroutine to us FORTRAN types) that I use to get it:

Code: [Select]
on getMacUpTime()
-- - - - - -
-- Function to get time Macintosh has been running.
-- This information can be displayed on a website
-- for computers left running 24/7
-- - - - - -
local periodString, resultString, resultContent, bootTimeSeconds, UTCtimeSeconds, timeSeconds, uptimeSeconds
-- Set a default value in case there is a problem getting UNIX data
set periodString to "N/A"
try
-- Use system call to get boot time in UNIX seconds.
set resultString to do shell script "sysctl kern.boottime"
on error
-- If can't make UNIX call - return "N/A"
return (periodString)
end try

-- Breakup sysctl command to extract time.  Time is 4th item.
set resultContent to words of resultString
set bootTimeSeconds to item 4 of resultContent as integer

-- Get current time as universal time and adjust it to UNIX epoch
set UTCtimeSeconds to (current date) - (time to GMT)
set timeSeconds to UTCtimeSeconds - (date ("1/1/1970"))

-- Compute difference to get uptime in seconds, then covert to elapsed time.
set uptimeSeconds to timeSeconds - bootTimeSeconds
tell WChelperTools to set periodString to seconds2Elapse(uptimeSeconds, false)

return (periodString)

end getMacUpTime

To use it you would need my collection of helper routines as well.  If you want to dive into that let me know.  I could probably fish out the relevant bits.

Cheers, Edouard  [cheers1]

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #6 on: January 13, 2016, 02:30:49 AM »
If it were simply the number of seconds since 1900 (or even 2000, when all computers were supposed to crash!), it would be a lot simpler! [tup] Unfortunately, the result of the "uptime" command is 'manipulated' from such a basic value before we get the result. If you look at the string offered by the OS, you'll note that there are not the 'standard' 3 sets of numbers Stu kindly provides for the WC uptime. [banghead]

Instead, there are a variety of formats. On each(?) hour, there will be a one or two digit value, along with the "hour/s" text, but there seems to be no "0 minutes". I think an exact 1 day result (again, with no hours or minutes) will simply appear as "1 day" (or X number of 'days'), instead of the WC 'standard' of "01:00:00". At least that's the formula for "1 hour", it is not presented as "1:00" or even as "00:01:00".

My solution is to chop the first part of any result, the local (24 hour) time,  and the "  up " from the original string. That leaves the 'uptime' as the next few characters. The job then becomes how many characters make up that days (if any), the hour (if any), and the minutes... (if any)! The rest of the text, I couldn't care less about.

So far, my line of attack has been to next find where the "," is and use that character position as the end of the needed text, with position of the "  up " as the beginning. This allows me to use the php 'explode' function (with ":" as the dellmiter) to create a one, two, or three part array depending on how many ":" are found. After that, it is basically testing for the integer values of the one, two, or three parts of the array.

For example, if the uptime is "3 mins", there will be only one item in the array; there is really nothing to 'explode', so "3 mins" gets written into array[0]. But now we have a number and some non-numeric characters! Fortunately, with only one array item, the length of the entire array is usually (so far!) much more than one would need for 1 or 2 numbers. This means it is possible to figure out what the actual number is. I haven't got to the case where there are only hours with no minutes, but I think the same format will appear; only one array[0] item which will most likely have something like " hour" sitting in it along with the actual number.

In the meantime, I'm watching the temperature change 1 degree an hour.  [lol2] Actually, I'm waiting to catch the mini at whole day intervals, along with single and double-digit hours (with no minutes), and single and double minutes (without hours) to verify the output.
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6496
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Goin' about it da' HARD way! (Re: For those with no patience...)
« Reply #7 on: January 13, 2016, 10:23:27 PM »
Dear X-Air and WeatherCat scripters,

I repeat from my previous post . . . . .

In the ominous voice of some game show from the 1950s . . .

 [wink] . . . . Remember, you are askin' for it!!! . . . .

If it were simply the number of seconds since 1900 (or even 2000, when all computers were supposed to crash!), it would be a lot simpler! [tup]

Okay, I can't give you the time in seconds with one call, but you get getting the boot time in seconds as the 4th item of this UNIX call:



In my AppleScript I get back that string, convert it into words (that end up in an array.)  Once I have that, I grab the 4th item of the array, convert the string to a number and finally convert the number in seconds back to an elapsed time string (using one of my subroutines in a shared library.)

I think it is truly easier do to it all in AppleScript . . . Especially since I already have!  [biggrin]

Cheers, Edouard  [cheers1]

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #8 on: January 14, 2016, 12:02:01 AM »
I'm still watching/trapping the "uptime" output string to be sure I have as many of the possibilities as possible. I suspicion that the OS simply "memorizes" the start up time in seconds from some date (used to be 1900, back in the pre-X days, I think). Then it just computes the run time based on the current time in seconds and converts the difference just like you suggest. Unfortunately, it then reformats this into a slightly more human readable string. WC probably does the same thing but formats it in a more concise string.

My first assumption was that it would be similar to how Stu does it in WC; DD:HH:MM. However, it's beginning to look like it uses numbers (without leading zeros) and adds the "day(s)", "hour(s)", "minute(s)" text as needed. I am now waiting to get a more complete set of the possible strings before proceeding. It will be much easier to do the scripting if there is only one format to deal with. With the WC run time, all that is needed is the 'explode' function using the ":" to divide the WC tag into days, hours, and minutes.

I could use your AS to create my own version of what the OS is already doing. I'm sure there is a PHP script already available to do the same thing. But why buy a wheel when it's so much fun to re-invent one?! [banghead] [biggrin]

As I write...
Here is one cross-over point:
"... 1 day, 12 mins... " becomes " ...1 day, 1 hr... " 48 minutes later. Which becomes " ...1 day, 1 hr... " becomes " ...1 day,  1:01... " in another minute. What I need to know is to the output at the start of each new 24 hour period. Does it return to the " ...D days, M mins... " until the 25th hour and then to the " ...D days, H hours... " for the next 60 seconds and then reverts to the " ...D days, HH:MM... "? I wonder if I cane get my wife to run the little AS every 59 seconds, 1 hour, and once more a second later...   

OTOH, it just might be possible to find the various formatting possibilities at Apple.com, maybe even in the Man description of the "uptime" command. [banghead]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6496
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Three times a "charm" ? (Re: For those with no patience...)
« Reply #9 on: January 15, 2016, 12:21:23 AM »
Dear X-Air and WeatherCat wheel "reinventors" . . . . .

I could use your AS to create my own version of what the OS is already doing. I'm sure there is a PHP script already available to do the same thing. But why buy a wheel when it's so much fun to re-invent one?! [banghead] [biggrin]

As long as I'm on a winning streak . . . 

In the ominous voice of some game show from the 1950s . . .

 [wink] . . . . Remember, you are askin' for it!!! . . . .

Still looks to me like you are goin' about it da' hard way! . . .   [banghead]

Cheers, Edouard  [cheers1]

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #10 on: January 15, 2016, 02:43:00 AM »
Thanks Edouard, that "sysctl kern.boottime" was what I needed. I had found the current time in epoc seconds with "date +%s". But I needed the start up seconds to do the simple math!

I was a bit confused, at first, about your "4th item" in post #7 above. Now I get it! duh! [goofy]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6496
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Ye' of little faith . . . . . (Re: For those with no patience...)
« Reply #11 on: January 15, 2016, 10:21:18 PM »
Dear X-Air and WeatherCat users . . . . of "little faith" . . . .

Thanks Edouard, that "sysctl kern.boottime" was what I needed. I had found the current time in epoc seconds with "date +%s". But I needed the start up seconds to do the simple math!

I was a bit confused, at first, about your "4th item" in post #7 above. Now I get it! duh! [goofy]

A a voice from a great movie that I have long since forgotten . . . . .

 . . . . Would I lie to you about a thing like this!! . . . .  [biggrin]

Cheers, Edouard  [cheers1]

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #12 on: January 16, 2016, 04:51:56 AM »
I think it's working right now. A minor tweak to remove the leading zero on the day value. Whatever I did on The WC tag should work there, as well.

I've already shut down the access to my apple scripting mini, so I'll have to check to morrow. My question is if AS is still 32 bits? I had trouble getting it to write a "small" value to the text file without converting it to scientific notation. Setting a variable to the value 'as integer' or 'as text' still converted it. Even had trouble with 'as string', but by adding a tiny piece of text to it, it was forced to stay as i wanted it. I'll check the numbers tomorrow...
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

xairbusdriver

  • Storm
  • *****
  • Posts: 3128
Re: For those with no patience...
« Reply #13 on: January 16, 2016, 05:39:01 PM »
Here's a little script that demonstrates my question about how AS handles numbers as large as 327495:
-- Easier to work with epoc seconds (seconds since 1/1/1970) for all times
--
set now_time to do shell script "date +%s"
-- Output-> "1452896555"

set boot_time to do shell script "sysctl kern.boottime"
-- Output->"kern.boottime: { sec = 1452638263, usec = 0 } Tu..."

set run_time to (characters 24 thru 33 of boot_time) as text
-- or string (OK), can't use integer

set running_string to (now_time - run_time) as string
set running_text to running_string as text
set running_integer to running_string as integer

set result to "STRING -->" & running_string & "
TEXT -->" & running_text & "
INTEGER --> " & running_integer
As you'll see, the output is:
    STRING -->3.27495E+5
    TEXT -->3.27495E+5
    INTEGER --> 327495
It's probably my not 'casting' the variables correctly, along with my lack of AS knowledge! [blush]
THERE ARE TWO TYPES OF COUNTRIES
Those that use metric = #1 Measurement system
And the United States = The Banana system

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 6496
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
AppleScript handles this calculation correctly (Re: . . with no patience...)
« Reply #14 on: January 16, 2016, 10:17:30 PM »
Dear X-Air and WeatherCat fans of "big numbers" (besides powerball . . .  ;D )

I've already shut down the access to my apple scripting mini, so I'll have to check to morrow. My question is if AS is still 32 bits? I had trouble getting it to write a "small" value to the text file without converting it to scientific notation. Setting a variable to the value 'as integer' or 'as text' still converted it. Even had trouble with 'as string', but by adding a tiny piece of text to it, it was forced to stay as i wanted it. I'll check the numbers tomorrow...

I see what you are saying, but even with the conversion to scientific notation, AppleScript appears to preserve the data of integers that large.  I cut and paste my own solution into something that just runs from the Script Editor.  It is attached to this posting and the code is below:

Code: [Select]
-- *** Applescript code snippet to compute system uptime ***


-- Use system call to get boot time in UNIX seconds.
set resultString to do shell script "sysctl kern.boottime"


-- Breakup sysctl command to extract time.  Time is 4th item.
set resultContent to words of resultString
set bootTimeSeconds to item 4 of resultContent as integer

-- Get current time as universal time and adjust it to UNIX epoch
set UTCtimeSeconds to (current date) - (time to GMT)
set timeSeconds to UTCtimeSeconds - (date ("1/1/1970"))

-- Compute difference to get uptime in seconds, then covert to elapsed time.
set uptimeSeconds to timeSeconds - bootTimeSeconds
seconds2Elapse(uptimeSeconds, false)

on seconds2Elapse(totalSeconds, countSeconds)
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- Function to convert elapsed seconds into a string
-- describing the amount of time that has passed in days,
-- hours, minutes, and optionally seconds
--
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- 3600 seconds in an hour
-- 86400 seconds in a day

set elapsedTime to " "
set elapsedDays to 0
set elapsedhours to 0
set elapsedMinutes to 0
set elapsedSeconds to 0
set needComma to false

-- Catch limiting case of no elapsed time and return a "reasonable answer"
if (totalSeconds = 0) then
return ("0 seconds")
end if

-- Compute the number of days since event started.
if (totalSeconds is greater than 86400) then
set elapsedDays to totalSeconds div 86400
set totalSeconds to totalSeconds mod 86400
end if

-- Compute the number of hours rain has fallen (after removing days.)
if (totalSeconds is greater than 3600) then
set elapsedhours to totalSeconds div 3600
set totalSeconds to totalSeconds mod 3600
end if

-- Compute number of minutes rain has fallen (after removing hours)
if (totalSeconds is greater than 60) then
set elapsedMinutes to totalSeconds div 60
set elapsedSeconds to totalSeconds mod 60
else
-- if nothing else, their must be seconds

set elapsedSeconds to totalSeconds as integer

end if

-- If countSeconds flag is false ignore leftover seconds.
if (not countSeconds) then
set elapsedSeconds to 0
end if

-- Now create a human readable string by assembling the "pieces."
if (elapsedDays is greater than 0) then
set elapsedTime to elapsedTime & elapsedDays & " " & makePlural(elapsedDays, "day", "days")
set needComma to true
end if

if (elapsedhours is greater than 0) then
if (needComma) then
set elapsedTime to elapsedTime & ", "
end if
set elapsedTime to elapsedTime & elapsedhours & " " & makePlural(elapsedhours, "hour", "hours")
set needComma to true
end if

if (elapsedMinutes is greater than 0) then
if (needComma) then
set elapsedTime to elapsedTime & ", "
end if
set elapsedTime to elapsedTime & elapsedMinutes & " " & makePlural(elapsedMinutes, "minute", "minutes")
set needComma to true
end if

if (elapsedSeconds is greater than 0) then
if (needComma) then
set elapsedTime to elapsedTime & ", "
end if
set elapsedTime to elapsedTime & elapsedSeconds & " " & makePlural(elapsedSeconds, "second", "seconds")
end if

return (elapsedTime)
end seconds2Elapse

on makePlural(value, singularUnit, pluralUnit)
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-- Function to add an 's' to the end of text if the value is greater
-- than one.  It is a simple-minded way to get the tense of the unit
-- correct
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if ((value is greater than 1) or (value = 0)) then
return (localized string pluralUnit)
else
return (localized string singularUnit)
end if
end makePlural

If you load the script into the Script Editor it will run and give the correct value for uptime.

Cheers, Edouard