AJAX scores.log parser/score tracker

Discuss anything to do with Nexuiz here.

Moderators: Nexuiz Moderators, Moderators

Postby [-z-] » Tue Oct 30, 2007 5:41 am

[TSA] Psychiccyberfreak wrote:I think a group of us should get together and write a really kick ass stats parser with a subversion repo or something..


I'm down for this. A few weeks ago I was having a look at the server log parser that look likes the one you based your script off of... and after commenting the crap out of / redesigning the front end, I decided a mysql solution would be better.

I talked to my buddy about this and he said he knew a great way, using a fifo file to be a liaison between the server and the database. Long story short, it's been over 2 weeks since he last worked on it and it'd be great if we could get some community solution.

Here is a (I believe to be working) class file he wrote to parse the stats... however, I think he was having trouble with actually inserting the data to the database.

Code: Select all
class NexuizStats {
        function processMatch($data) {
                $match = array();
                foreach ($data as $score_line) {
                        $info = explode(":",trim($score_line,":"));
                        switch ($info[0]) {
                                case "scores":
                                        $match['match']['map'] = $info[1];
                                $match['match']['length'] = $info[2];
                                break;
                                case "player":
                                        $match['players'][] = self::playerStats($info);
                                break;
                                default:
                                break;
                        }
                }
                foreach ($match['players'] as $p) {
                        $positions_arr[$p['frags']] = $p['name'];
                }
                krsort($positions_arr);
                $match['game']['first_place'] = array_shift($positions_arr);
                $match['game']['second_place'] = array_shift($positions_arr);
                $match['game']['third_place'] = array_shift($positions_arr);
                return $match;
        }

        function playerStats($info) {
                $player=array();
                $player['name'] = $info[5];
                $player['team'] = self::translateTeam($info[4]);
                $player['frags'] = $info[1];
                $player['deaths'] = $info[2];
                $player['playtime'] = $info[3];
                return $player;
        }

        function translateTeam($team_id) {
                $teams = array(5 => "Red", 14 => "Blue");
                if (!isset($teams[$team_id])) {
                        return FALSE;
                }
                return $teams[$team_id];
        }

        function addMatch($match) {
                $db = new DB();
                $SQL = "INSERT INTO matches(mid, map, gametime) VALUES ('', '" . mysql_escape_string($match['map']) . "','" . mysql_escape_string($match['length']) . "')";
                $mid = $db->insert($SQL);
                echo $mid;
                return $mid;
        }
        function addPlayers($players) {
                $db = new DB("nn_stats");
                foreach ($players as $p) {
                        if (self::findPlayer($p['name'])) {
                                self::updatePlayer($p['name']);
                        } else {
                                $SQL = "INSERT INTO players(uid, player_name, playtime, matches, total_frags, total_deaths) VALUES ('','" . mysql_escape_string($p['name'])
                                        . "','" . mysql_escape_string($p['playtime'])
                                        . "','1','" . mysql_escape_string($p['frags'])
                                        . "','" . mysql_escape_string($p['deaths'])
                                        . "')";
                                $uid = $db->insert($SQL);
                                self::updateLastGame($uid, $p);
                        }
                }
        }

        function updateLastGame($uid, $p) {
                return false;
        }

        function findPlayer($pid) {
                return FALSE;
        }

        function updatePlayer($pid) {
                return TRUE;
        }
        // END nexstats-functions


I would love to ask him where he's at in the code but he's being a bit of a dolt right now, so I figured I'd share this with the group.

Here's a basic function I wrote to color the names, it doesn't close the tags and therefore doesn't validate but I didn't really care to putting much thought into parsing it properly as it probably requires exploding by some crazy regex.

Code: Select all
// Converts ^0 to Black etc.
// cheap hack
function colorsToCss($string) {
   $nexuiz = array('^0','^1','^2','^3','^4','^5','^6','^7','^8','^9');
   $css = array(
   '<span style="color:#000;">',
   '<span style="color:#f00;">',
   '<span style="color:#0f0;">',
   '<span style="color:#ff0;">',
   '<span style="color:#00f;">',
   '<span style="color:#3ff;">',
   '<span style="color:#f0f;">',
   '<span style="color:#fff;">',
   '<span style="color:#bbb;">',
   '<span style="color:#777;">'
   );
   return str_replace($nexuiz, $css, $string);
}


Lastly, here's the code I use on www.nexuizninjaz.com, which looked good until some jackass with a long name broke the floats :-P.

And here's the map images if you need/want them.
[-z-]
Site Admin and Nexuiz Ninja
 
Posts: 1794
Joined: Mon Nov 13, 2006 12:20 am
Location: Florida

Postby [-z-] » Fri Nov 02, 2007 9:36 pm

really? no feedback? are we loosing momentum already?
[-z-]
Site Admin and Nexuiz Ninja
 
Posts: 1794
Joined: Mon Nov 13, 2006 12:20 am
Location: Florida

Postby Psychcf » Fri Nov 02, 2007 11:14 pm

I'm glad to see your contribution. Since I know PHP I can translate this into javascript pretty easily. I'll set up a subversion repo and post the data up once it's done.
Psychcf
Forum addon
 
Posts: 1554
Joined: Sun Dec 03, 2006 11:38 pm
Location: NY, USA

Postby Psychcf » Fri Nov 02, 2007 11:49 pm

Ok, here it is:

address: http://svn.psychdesigns.net/nexuiz_scores/

PM/Email me if you want an account to check stuff in
Psychcf
Forum addon
 
Posts: 1554
Joined: Sun Dec 03, 2006 11:38 pm
Location: NY, USA

Postby [-z-] » Sat Nov 03, 2007 6:32 pm

[TSA] Psychiccyberfreak wrote:Ok, here it is:

address: http://svn.psychdesigns.net/nexuiz_scores/

PM/Email me if you want an account to check stuff in


Awesome, I'll get setup just as soon as you give me an account. pming...
[-z-]
Site Admin and Nexuiz Ninja
 
Posts: 1794
Joined: Mon Nov 13, 2006 12:20 am
Location: Florida

Postby Psychcf » Sun Nov 04, 2007 2:23 am

Ok, I made a new thread for this discussion:
http://forums.alientrap.local/viewtopic.php?t=2356
Psychcf
Forum addon
 
Posts: 1554
Joined: Sun Dec 03, 2006 11:38 pm
Location: NY, USA

Previous

Return to Nexuiz - General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron