AJAX scores.log parser/score tracker

Discuss anything to do with Nexuiz here.

Moderators: Nexuiz Moderators, Moderators

Mon Mar 12, 2007 2:07 am

Sun Oct 28, 2007 11:46 pm

  • PCF, this is awesome. Thanks :) Working to hack it into my site now.
    cat /dev/urandom > /dev/mem
    John Galt
    Alien
     
    Posts: 166
    Joined: Thu Jul 19, 2007 9:20 pm
    Location: Washington, DC

Mon Oct 29, 2007 1:56 am

Mon Oct 29, 2007 4:11 am

  • Cool -- keep us posted. I'm surprised nobody else seemed to have noticed this.

    There isn't much else in the way of this out there that I was able to find and I'm not much of a coder yet, so building it from scratch and patchwork with qstat isn't really viable for me.

    :)
    cat /dev/urandom > /dev/mem
    John Galt
    Alien
     
    Posts: 166
    Joined: Thu Jul 19, 2007 9:20 pm
    Location: Washington, DC

Mon Oct 29, 2007 4:23 am

  • Also, can you think of any easy way to get this working with multiple score files? Xeno also mentioned a de-facto per player opt out by prepending the string

    Code: Select all
    ^4^2

    to your name. Does this take that into account? A cursory look at the source doesn't appear to have any checks for that string, but I may be missing something.

    Thanks again for the great little tracker.
    cat /dev/urandom > /dev/mem
    John Galt
    Alien
     
    Posts: 166
    Joined: Thu Jul 19, 2007 9:20 pm
    Location: Washington, DC

Mon Oct 29, 2007 4:41 am

  • Thanks for bringing that up, John.

    Psych, it would be appreciated if you could add that to the source code.
    Xeno
    peregrinus originis incognitae
     
    Posts: 396
    Joined: Wed Nov 15, 2006 10:42 pm

Mon Oct 29, 2007 4:48 am

  • John Galt wrote:There isn't much else in the way of this out there that I was able to find and I'm not much of a coder yet, so building it from scratch and patchwork with qstat isn't really viable for me.


    qstat is for getting current server status, it's not really designed for server stats.

    also, server stats aren't really an interactive thing; is ajax best for this?
    I say that because I can't even try this out because of the cpu load.
    :)
    Keyboard killer
     
    Posts: 590
    Joined: Tue Feb 28, 2006 9:09 pm

Mon Oct 29, 2007 1:41 pm

  • qstat is for getting current server status, it's not really designed for server stats.


    Yeah, I'm aware. I was just envisioning a kind of panel in my head that tied qstat into it all as well to get current activity, etc. The rest, I wasn't sure how to approach.

    Good point about ajax as well. I hadn't thought about your poor old pII.

    For now, I think it'll do. Any one playing Nex will probably have a machine with enough oomph to do the processing client side anyway.

    You just have to get your mobo (case?) fixed, Dave ;)

    We'll see. This is all just the "coming together" phase :)
    cat /dev/urandom > /dev/mem
    John Galt
    Alien
     
    Posts: 166
    Joined: Thu Jul 19, 2007 9:20 pm
    Location: Washington, DC

Mon Oct 29, 2007 2:42 pm

  • well, what's probably causing the massive cpu loads is dom transformations, I have learned a lot about dom optimization since I wrote that. Dojo 0.9 features huge amounts of optimizations as well. Dave PMed me about it, I think a group of us should get together and write a really kick ass stats parser with a subversion repo or something.

    Here's some of the really cool things I think we can incorperate into it:
    * Dojo 3d charting: http://download.dojotoolkit.org/release ... _bars.html
    * Tree widget, grouping clan tags
    * Advanced dojo.data API functions such as lazy loading. This significantly increases responsiveness of the application.

    there are some other things too, I'm just loosing my head...
    Last edited by Psychcf on Wed Oct 31, 2007 11:41 pm, edited 1 time in total.
    User avatar
    Psychcf
    Forum addon
     
    Posts: 1554
    Joined: Sun Dec 03, 2006 11:38 pm
    Location: NY, USA

Mon Oct 29, 2007 11:09 pm

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.
    User avatar
    [-z-]
    Site Admin and Nexuiz Ninja
     
    Posts: 1794
    Joined: Mon Nov 13, 2006 12:20 am
    Location: Florida

Fri Nov 02, 2007 9:36 pm

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.
    User avatar
    Psychcf
    Forum addon
     
    Posts: 1554
    Joined: Sun Dec 03, 2006 11:38 pm
    Location: NY, USA

Fri Nov 02, 2007 11:49 pm

Sat Nov 03, 2007 6:32 pm

Sun Nov 04, 2007 2:23 am



Return to Nexuiz - General Discussion




Information
  • Who is online
  • Users browsing this forum: No registered users and 1 guest