Server Statistics patch

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Server Statistics patch

Post by Sebastiaan »

Basicly this patch writes the following data every month for every player:
company name, manager name and all data in _score_part (although money and loan are done separate to get up-to-date data. The php file then just parses this and puts in into a table.

Included features C-part:
- print out quarterly statistics, including all _score_part info
- include company name, manager name and company color.
- split up vehicles into trains, roadvehs, ships, planes
- active both in single and in multiplayer.
- statistics can be made live, during game.
- result is a xml-file
- load the xml file associated with a savegame and automatically saves the xml file under the same name as the savegame. Feature disabled for autosaves.

Known issues C-part:
- if the player on the server (or an AI) does not change his manager name, it becomes a random name which tends to be A. A. Adams most of the time.
- Same with company name, which tends to be Ivenville Transport.
- The is no global xml tag, therefore <xml> and </xml> should be added before parsing.

Included features PHP-part:
- make graphs of all numerical data available.
- automaticly scale graphs.
- can grab the statistics.xml file from the openttd directory, when adressable by local path.

Known issues PHP-part:
- not a nice browsable webpage (ameliorated)
- temporarily broken due to xml conversion

Upcoming features: (in expected order of fullfillment)
- support for aggregated views over decades
- include server name in statistics
- output players who played in a company
- show joining/leaving players

EDIT 14/06/06: The patch is now fully functional, apart from aforementioned minor flaws, in both single and multiplayer.

EDIT 11/07/06: After a long pause due to exams, xml conversion has started. Expect a working patch in a week. Attached files will be updated then.

I'm looking forward for any suggestions, be it coding style, technique or just improvements. :)

Attached are:
- patch to rev 5286 (Many thanks to TrueLight for helping me out!)

External links:
- An example of the results results
- The php code
Latest update links: 14/06/2006
Attachments
statistics_rev5286_5_clean.patch
(4.77 KiB) Downloaded 462 times
Last edited by Sebastiaan on 11 Jul 2006 09:02, edited 9 times in total.
klogg
Traffic Manager
Traffic Manager
Posts: 248
Joined: 10 May 2006 13:55

Post by klogg »

Looks very interesting.
In singleplayer games this could be usefull
to analyze certain strategies.

Maybe you could split the "vehicles" table into several
tables for each type of vehicle.

And maybe you could grab the yearly overview
and integrate each entry in your patch.
So one can observe the train income not only for the last
three years but for decades.

klogg
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Post by Sebastiaan »

klogg wrote:Looks very interesting.
In singleplayer games this could be usefull
to analyze certain strategies.
Will be done. I'll have to figure out how those patch buttons work though, so don't expect it tomorrow.
klogg wrote:Maybe you could split the "vehicles" table into several
tables for each type of vehicle.
Would be usefull indeed. Easy is otherwise, but it goes on the to-do list. (Got a feeling I'll get to know the ottd-code a lot better to code this ;))
klogg wrote:And maybe you could grab the yearly overview
and integrate each entry in your patch.
So one can observe the train income not only for the last
three years but for decades.
If I understand it correctly, you would want to have some aggregated view, where for instance all data from a decade are integrated into 1 entry and those plotted. correct?

This can and will be done ;)
One remark though: the reason that the graphs are limited to 3 years now is because i didn't run my testgame longer so far. atm the plotter will squeeze in ALL data (= 4 entry's a year) into the graph. Which, I agree, isn't a long-term solution.

Thanks for your suggestions!

--
Additional question: I've been thinking about getting graphs of a certain time period, user selectable. would that be usefull?
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Post by Sebastiaan »

Thanks to the help of TrueLight i was able to put a server up which brings live statistics.

version: r5286
address: openttd.mooo.com
name: Nightly Statistics Server

statistics can be seen here: http://openttd.mooo.com:8080/nightly/

Have fun!
User avatar
Darkvater
Tycoon
Tycoon
Posts: 3053
Joined: 24 Feb 2003 18:45
Location: Hong Kong

Post by Darkvater »

You should use RRDTool :)
TrueLight: "Did you bother to read any of the replies, or you just pressed 'Reply' and started typing?"
<@[R-Dk]FoRbiDDeN> "HELP, this litte arrow thing keeps following my mouse, and I can't make it go away."
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Post by Sebastiaan »

I would have been some timesave if i had known about it beforehand. Now however it seems to bring no advantage because of the following reasons:
- i wrote the function to output graphs already..
- i intend to add other types of graphs later on (pie diagrams for ownership, ...)
- i think that using the database tool everytime to output data would turn out slower than outputting the data to a textfile.

If i obviously missed some features of RRDtool or i simply miss a benefit feel free to point it out. On the other hand, you did wake me up and i did a search for graphs in php... and, of course, there is already a library available :))

So, if noone objects, i'll switch to JpGraph for the graphs ;)
Artea
Engineer
Engineer
Posts: 8
Joined: 07 Nov 2003 12:41
Contact:

Post by Artea »

good job :)
Artea
Engineer
Engineer
Posts: 8
Joined: 07 Nov 2003 12:41
Contact:

MySQL

Post by Artea »

hi here...
why u don't use MySQL DB ?
i think is more simply to log into a statistics.log, and maybe is better who was a Shell with MySQL and PHP support...
i going see some manuals and sites and try a code for it...
u can go to http://www.kitebird.com/mysql-book/ch06-3ed.pdf
reply or send a pm/mail: artea@artea.com.pt
cyaz and take care :)
gigajum
Route Supervisor
Route Supervisor
Posts: 511
Joined: 08 Mar 2006 08:33
Location: Germany

Re: MySQL

Post by gigajum »

Artea wrote:hi here...
why u don't use MySQL DB ?
i think is more simply to log into a statistics.log, and maybe is better who was a Shell with MySQL and PHP support...
i going see some manuals and sites and try a code for it...
u can go to http://www.kitebird.com/mysql-book/ch06-3ed.pdf
reply or send a pm/mail: artea@artea.com.pt
cyaz and take care :)
Openttd is a game and not a application with database access. And WHY should a game have mysql support only for stats? That is the complete wrong way. Putting all relevant information into a xml file and read it out by php is currently the best option you can get (IMO)
User avatar
Brianetta
Tycoon
Tycoon
Posts: 2567
Joined: 15 Oct 2003 22:00
Location: Jarrow, UK
Contact:

Post by Brianetta »

Another way (perhaps in addition) would be to have the dedicated console report to stdout. This way, any program handling openttd's stdio could parse it and do as it pleased - write a CSV file, commit to a database or even announce in-game which player's doing the least well. (:
PGP fingerprint: E66A 9D58 AA10 E967 41A6 474E E41D 10AE 082C F3ED
Sebastiaan
Engineer
Engineer
Posts: 110
Joined: 20 Jun 2005 19:22
Location: Leuven, Belgium

Re: MySQL

Post by Sebastiaan »

gigajum wrote:
Artea wrote:hi here...
why u don't use MySQL DB ?
i think is more simply to log into a statistics.log, and maybe is better who was a Shell with MySQL and PHP support...
i going see some manuals and sites and try a code for it...
u can go to http://www.kitebird.com/mysql-book/ch06-3ed.pdf
reply or send a pm/mail: artea@artea.com.pt
cyaz and take care :)
Openttd is a game and not a application with database access. And WHY should a game have mysql support only for stats? That is the complete wrong way. Putting all relevant information into a xml file and read it out by php is currently the best option you can get (IMO)
I completely agree. A database link is NOT going to happen. It's a big overshoot and will cause endless discussions about which db to support... XML support isn't there so far, but it's just a small step. For now i'm just writing lines, but changing format to XML isn't very difficult.

At the moment I'm rewriting the PHP code to make it a bit more intelligent, more efficient. Next is adding support to print graphs about company shares. Then XML could be next.

BTW: I'm looking for someone who is willingly to provide a server with php support to run a testgame on. My server is running on my laptop and therefore I cannot provide a permanent testserver :(
raistlin
Engineer
Engineer
Posts: 1
Joined: 07 Dec 2007 11:28

Re: Server Statistics patch

Post by raistlin »

I like this idea! I recently set up a dedicated server running 0.5.3 and I'd like some on-the-fly statistics.

Any chance this patch might be included into the program any time soon?
I'm not so interested in the php-bit, so I hope you're keeping the two aspects of the idea separated.
It might be a good idea to publish how the xml-file is built so that it's easier to parse it on our own.
I would like to have a statistics.xml-file that I can parse into my web application. :)

It would be so much fun to watch how the players are doing without having to spectate. :D

Greetings from Norway.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 2 guests