This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Statistics from file

Old posts that have not been replied to for several years.
Locked
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Statistics from file

Post by Buffy_25 »

Hello all,

I have a question with the contents of a file:

I have my bot that write downs the following info into a file:
(the txt file contains the uptime of my ftp's in my channel)

<ftpname> was online for <time d h m s>

Those info lines are under each other in the txt file.
So for example:

Master-ftp was online for 10h 25min 12sec
Erlend was online for 12h 45min 32sec
Erick was online for 1day 13h 45min 3sec
Master-ftp was online for 2days 3h 12min 5sec
Bryan was online for 4d 5h 47min 3sec
Erlend was online for 2d 8h 8min 7sec
...

Now is my question:

I would like to have a script that react when i type in my #channel:

!Statistics_ftp

When i type this, then my bot will read the current txt file, with the current ftp's time in it and he will look for same ftp's name, he will take into account all those hours for that same ftpname, and he will make a totaltime of those times (ftp_totaltime) for example...
So i will have only each ftpname once in my channel written, with the total ftpuptime till now...

Can some1 help me with this plz?

Thnx a lot!

See u later.

Buffy
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

I have already the following, BUT i'm stuck with the "string" part

bind pub - "!Statistics_ftp" ftp:stat

proc ftp:stat {nick uhost hand chan arg}
set file [open ftpsuptime.txt r]
set buf [read $file]
set ftp [lindex [split [lindex [split $buf /n] 0] " "] 0]

This catches already the first ftp_name that is written in my file (this would be in my example "Master-ftp").
But now i will need to see all the lines that contains "Master-ftp" and then i need to make the subtotal of all the times that is at the end of those lines.
Once that is done, i need to put that into a new variable : example ftptime($ftp) so that later on it can be showed in the room once all the ftp-names have been taken in charge (and time has been calculated).
And then i need to take the second ftp-name that appears in the file and make again for this one the subtotal time.
etc...

Can some1 help me a bit more with this plz?

Thnx.

Kindest regards,

Buffy
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Try this:

Code: Select all

proc sumStuff {file} {
	# open, read and close the file, split the returned data on line breaks and loop
	# through the returned list...
	foreach line [split [read [set f [open $file]]][close $f] \n] {
		# extract the name and online time
		if {[scan $line {%s was online for %[^z]} name time]!=2} {
			continue;# ignore invalid/empty lines
		}
		# convert the duration to number of seconds ('clock scan' doesn't interpret 
		# "d" and "h" as "day" and "hour", so this 'string map' is used to translate 
		# your duration to something 'clock scan' can understand :)
		set time [clock scan [string map {"d " "day " "h " "hour "} $time] -base 0]
		if {[info exists names($name)]} {
			incr names($name) $time
		} {
			set names($name) $time
		}
	}
	array get names
}
You can loop through the returned list to display it or create an array or whatever you like. Eg:

Code: Select all

array set ftptime [sumStuff your_list.txt]
(use 'duration' (provided by eggdrop) to format the seconds returned by my proc)
Have you ever read "The Manual"?
B
Buffy_25
Halfop
Posts: 63
Joined: Sat Nov 22, 2003 6:36 am

Post by Buffy_25 »

Thnx a lot!

Best regards,

Buffy
Locked