Page 1 of 1

Server Statistics patch

Posted: 07 Jun 2006 08:44
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

Posted: 10 Jun 2006 18:30
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

Posted: 10 Jun 2006 19:38
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?

Posted: 16 Jun 2006 20:48
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!

Posted: 16 Jun 2006 23:57
by Darkvater
You should use RRDTool :)

Posted: 17 Jun 2006 16:59
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 ;)

Posted: 05 Jul 2006 20:28
by Artea
good job :)

MySQL

Posted: 08 Jul 2006 05:19
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 :)

Re: MySQL

Posted: 08 Jul 2006 08:40
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)

Posted: 08 Jul 2006 09:06
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. (:

Re: MySQL

Posted: 08 Jul 2006 10:38
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 :(

Re: Server Statistics patch

Posted: 07 Dec 2007 12:07
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.