Server Help

Bot Questions - java eclapsed time.

BDwinsAlt - Mon Sep 19, 2005 7:55 pm
Post subject: java eclapsed time.
I've looked around forever and i can't seem to get this right.

I want !buptime to display how long the bot has been up.

Lets Say:
BDwinsAlt> !buptime
ST 2.3> Bot up for 2 day(s) 11 hour(s) 10 second(s). [Since 09/19/2005 at 7:00]

Please help icon_eek.gif
Contempt+ - Mon Sep 19, 2005 8:30 pm
Post subject:
I was gonna start working on that one soon. Just gotta get around to doing it. I've got a lot of other stuff I'm working on at the same time, so I don't have the time to do it, lol.
BDwinsAlt - Mon Sep 19, 2005 10:26 pm
Post subject:
sa_tongue.gif .

I bet it will be harder than you think. I've looked around but nothing gives me a good awnser. icon_eek.gif

Make a really cool bot and webiste then release it for public use.

I'm going to buy a book on java.

Anyone got suggestions?

tell me if http://bots.sscentral.com/bdwinsalt looks ok.
Cyan~Fire - Mon Sep 19, 2005 10:54 pm
Post subject:
That's really loud.
Dr Brain - Tue Sep 20, 2005 9:15 am
Post subject:
http://javaalmanac.com/egs/java.util/CompDates.html
Donkano - Tue Sep 20, 2005 6:17 pm
Post subject:
Contempt+ wrote:
I was gonna start working on that one soon. Just gotta get around to doing it. I've got a lot of other stuff I'm working on at the same time, so I don't have the time to do it, lol.


Easy, just get the bot to do: ?usage

Then get it to return that string to the player requesting.
Solo Ace - Tue Sep 20, 2005 6:20 pm
Post subject:
That's the most ugly solution, though, Donk.
Maverick - Tue Sep 20, 2005 6:23 pm
Post subject:
Yea, even Mervbot doesn't do it that way sa_tongue.gif
Bak - Tue Sep 20, 2005 6:49 pm
Post subject:
it also doesn't solve the problem, donk.

In general, I don't recommend coding if you have trouble spelling words, like the title of your topic. It just leads to syntax errors.
BDwinsAlt - Tue Sep 20, 2005 10:36 pm
Post subject:
Did i ask you how to spell it? sa_tongue.gif
Contempt+ - Tue Sep 20, 2005 10:47 pm
Post subject:
It might be hard, but you could get MERV's code for !uptime and see how they do it. Sure Java is different from C++, but you can at least get a basic idea, right?
Bak - Wed Sep 21, 2005 12:13 am
Post subject:
it's not a difficult algorithm


record time when the bot is started

when !uptime is called print out the difference in time.
BDwinsAlt - Wed Sep 21, 2005 8:10 am
Post subject:
I just don't know how to record the time when the bot was started. That's where my probelm is. I know how to subtract time into days/hours/minutes now.

I just need that start time.
Maverick - Wed Sep 21, 2005 8:53 am
Post subject:
Quote:
public static long currentTimeMillis()
Returns the current time in milliseconds. Note that while the unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
See the description of the class Date for a discussion of slight discrepancies that may arise between "computer time" and coordinated universal time (UTC).

CypherJF - Wed Sep 21, 2005 10:27 am
Post subject:
I really wish java would have an option for comparing against the uptime of the system - not a clock. The system clock changes for various reasons, out of sync with UTC, daylight savings time, etc. With that issue imports an instability into the timer scheduler of Java - which I have already discussed. Had they used the uptime of the OS, it'll never go backwards, nor massively forward into the future. A bit more stable. :/
BDwinsAlt - Wed Sep 21, 2005 9:01 pm
Post subject:
Agreed. And i'll try and see if it lets me send the currentMillis ina private message. Last time it said it couldn't do somethign with int.

I dunno, ill figure it out.
D1st0rt - Thu Sep 22, 2005 3:05 am
Post subject:
Cyph, you mean like System.currentTimeMillis()?
CypherJF - Thu Sep 22, 2005 8:18 am
Post subject:
System.currentTimeMillis() depends on the current system time, not the uptime of the OS. They also say a lot of 'beware' statements in the API about it.

Looking though,nanoTime() looks more or less what I think, I would use. the API states "Returns the current value of the most precise available system timer, in nanoseconds." - not sure. It has the guarantee of precision but not accuracy. :/

:shrug:
Dr Brain - Thu Sep 22, 2005 10:13 am
Post subject:
From what I've gathered, he's not concerned about OS uptime. Only finding bot uptime.
CypherJF - Thu Sep 22, 2005 10:22 am
Post subject:
I know that. But, the "elapsed" (current_time - old_time) time will change when daylight savings time, etc. occur, does it not?

That's why you need an independent timing system such as the uptime of the OS where it'll never go backwards/forwards based on any specific day (or time).

I feel this appropriate quote fits well:

"Time line?!?!? This is no time to argue about time! We don't HAVE the time! ... what was I saying?" -- Troi, Star Trek: First Contact. icon_smile.gif icon_smile.gif
Bak - Thu Sep 22, 2005 10:35 am
Post subject:
I don't think an hour inaccuracy twice a year is anything to worry about for this application
CypherJF - Thu Sep 22, 2005 12:30 pm
Post subject:
technically 'yes', you "should" worry about it.
Bak - Thu Sep 22, 2005 12:57 pm
Post subject:
why? He wants a way to see if his bot is staying online for a long time.

It's not a life or death application, any effort to avoid things like daylight savings time is not worth the time spent implementing.
Dr Brain - Thu Sep 22, 2005 1:48 pm
Post subject:
I would think with a definition like "the number of milliseconds elapsed since 12:00, midnight, Jan 1 1970", that DST would already be factored in. I could be wrong, of course.
Cyan~Fire - Thu Sep 22, 2005 4:09 pm
Post subject:
Seeing as a long will overflow in 49.7 days, I'd say using a GetTickCount-like function would be more reliable than this currentTimeMillis().
Mr Ekted - Thu Sep 22, 2005 8:32 pm
Post subject:
Easy answer: write your bots in a real language. icon_cool.gif
Dr Brain - Thu Sep 22, 2005 9:48 pm
Post subject:
It uses the same operating system calls as the C equivelent, Ekted. So quit your moaning.
Mr Ekted - Fri Sep 23, 2005 10:41 am
Post subject:
Then why are we having this discussion? Just use GetTickCount(). Problem solved. End of thread.
Anonymous - Fri Sep 23, 2005 11:09 am
Post subject:
Theyre debating the usefullness of the system tick count vs system time. Java 1.5 seems to be able to get both, but 1.4.x and prior only have the system time available.

As its already been said, stop worrying about a few isolated cases where the system clock will change and just implement the basic uptime.

Code: Show/Hide

long lngStart = System.currentTimeMillis();

public long getUptime() { return System.currentTimeMillis() - lngStart; }

Bak - Fri Sep 23, 2005 12:32 pm
Post subject:
in C/C++ I'd just use time(0) to get the seconds, since he's uninteresting in milliseconds and this value won't overflow for many years.
Cyan~Fire - Fri Sep 23, 2005 3:52 pm
Post subject:
I had the same idea myself. You might want to give that sig an alpha layer though.
Bak - Fri Sep 23, 2005 8:16 pm
Post subject:
any open source Transparent GIF editor (or PNG, I suppose)? I wish I could do it in paint, but I suppose no program's perfect. GIMP refuses to install on my computer.
Cyan~Fire - Fri Sep 23, 2005 10:06 pm
Post subject:
Sorry, I couldn't get it exactly right, but this one should be better. (Works in FF, but IE still can't handle PNG transparency.)
Anonymous - Fri Sep 23, 2005 10:49 pm
Post subject:
You can make transparent PNGs easily w/ php w/ use of the GD2 extension; which is pretty sweet. icon_smile.gif
Bak - Sat Sep 24, 2005 4:08 am
Post subject:
Good work. Windows still craps out trying to preview it, but it works on Firefox. What did you use to create it?
Cyan~Fire - Sat Sep 24, 2005 10:31 am
Post subject:
GIMP. icon_biggrin.gif You should really get that to install...
BDwinsAlt - Mon Sep 26, 2005 8:17 am
Post subject:
I figured it out on my own. It looked to simple so i thought it was wrong.
icon_redface.gif

Heres my code.
Code: Show/Hide

long startTime = System.currentTimeMillis();
..........................................
..........................................
public void buptime(String name, String msg){
            long difference = System.currentTimeMillis() - startTime;
            int days = (int)(Math.floor(difference/1000/60/60/24));
         int hours = (int)(Math.round( (difference/60/60 % 24000)/1000));
            int minutes = (int)Math.round( (difference/60 % 60000)/1000 );
            int seconds = (int)Math.round( (difference % 60000)/1000 );
            m_botAction.sendPrivateMessage( name, "Bot has been up for " + days + " day(s) " + hours + " hour(s) " + minutes + " minute(s) and " + seconds + " second(s)." );
            }


Thanks guys.

P.S.: When my new pc comes in and I install my Visual C++ CD i will use c++.

I'll still use java to but i'll give C++ a chance.
Dr Brain - Mon Sep 26, 2005 9:10 am
Post subject:
Let me just be clear and say that the Java language cannot be held responsible for the above code.
Solo Ace - Mon Sep 26, 2005 10:02 am
Post subject:
Indeed, don't blame the languages for your sucking on programming.
BDwinsAlt - Mon Sep 26, 2005 7:59 pm
Post subject:
sa_tongue.gif LOL.

What ever. It works...
Bak - Mon Sep 26, 2005 8:25 pm
Post subject:
yeah, it works fine. no need to wrap Dates around something as simple as this
BDwinsAlt - Mon Sep 26, 2005 10:49 pm
Post subject:
I agree with Bak.
Unless he's being sarcastic icon_lol.gif ...

Im still new to java so if their's an easier way to do something let me know. I plan to actually stop and buy a few books around Chirstmas. Right now all i know is wha i've learned in about 2 months i guess. icon_redface.gif

Im used to doing things with Trial and Error. icon_rolleyes.gif
Cerium - Tue Sep 27, 2005 2:13 am
Post subject:
Add in a touch of common sense and youll be a lot better off. For instance, most people hate doing lots of pointless repetitive math problems; the same can be said about computers.

Im kind of suprised ekted hasnt thrown up on his keyboard and posted something explaining how he was daming your name while cleaning it up.
Bak - Tue Sep 27, 2005 3:11 am
Post subject:
even Java should be able to optimize

difference/1000/60/60/24

to

difference/86400000
Cerium - Tue Sep 27, 2005 2:56 pm
Post subject:
Do you always rely on the compiler to optimize your code?

BD shouldnt get in the habit (or impression) that the compiler can/will always clean up his code.
Mr Ekted - Tue Sep 27, 2005 3:28 pm
Post subject:
Cerium wrote:
Im kind of suprised ekted hasnt thrown up on his keyboard and posted something explaining how he was daming your name while cleaning it up.


I don't do Java, and haven't been keeping up with this thread. icon_smile.gif

But I will chime in here a bit. I expect the compiler to optimize from line to line. I write code that makes sense, and it will do what is fastest/smallest (based on my compile settings). For example, if I'm multiplying by 4 because that is the formula for something, I prefer to use "* 4" in the code instead of "<< 2". All compilers will handle that. However, you should not expect a compiler to handle optimizations of large blocks where the actual operations are different. For example:

Code: Show/Hide
// this is inferior code

for (i = 0; i < size; i++)
   {
   a = array + i;
   // do something with a
   }

// this is much better

a = array;

for (i = 0; i < size; i++)
   {
   // do something with a
   a++;
   }

Cyan~Fire - Tue Sep 27, 2005 7:03 pm
Post subject:
Ekted wrote:
For example, if I'm multiplying by 4 because that is the formula for something, I prefer to use "* 4" in the code instead of "<< 2".

Ahh, thank goodness. I get so tired of seeing that shifting crap in people's code.
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group