Raised This Month: $51 Target: $400
 12% 

Map Rate v0.10 (6/30)


Post New Thread Reply   
 
Thread Tools Display Modes
Terrorkarotte
Junior Member
Join Date: Apr 2009
Old 05-07-2009 , 07:38   Re: Map Rate v0.10 (6/30)
Reply With Quote #271

I want to turn the rating system. Menaning pushing the button 1 is 5 stars now. What do i have to do?
I tried it by changing the phrases.txt So far so bad. But the php page is still ordering it starting with the highest. What do i have to change there? I tried it with
PHP Code:
$reverse = (isset($_GET['reverse']) ? $_GET['reverse'] : 'yes'); 
The problem ist it reverses also the name and the order by number of ratings.
All i want to reverse is the average rating list.

Last edited by Terrorkarotte; 05-07-2009 at 07:44.
Terrorkarotte is offline
SuperShadow
SourceMod Donor
Join Date: Jun 2008
Location: Westminster, MD
Old 05-07-2009 , 07:54   Re: Map Rate v0.10 (6/30)
Reply With Quote #272

Quote:
Originally Posted by thegtz View Post
Does this plugin still work with CSS?
Yes, my clan has it running on a CSS server. That server is also running the Eventscripts WCS mod, but Map rates works there with no problems.
SuperShadow is offline
Terrorkarotte
Junior Member
Join Date: Apr 2009
Old 05-07-2009 , 13:53   Re: Map Rate v0.10 (6/30)
Reply With Quote #273

Another question/Idea:
Is it possible to play a sound in the moment the rating starts?
like "choose now"
Terrorkarotte is offline
-Sky
Member
Join Date: May 2009
Old 05-12-2009 , 01:52   Re: Map Rate v0.10 (6/30)
Reply With Quote #274

aint working
__________________

-Sky is offline
SuperShadow
SourceMod Donor
Join Date: Jun 2008
Location: Westminster, MD
Old 05-12-2009 , 07:51   Re: Map Rate v0.10 (6/30)
Reply With Quote #275

Quote:
Originally Posted by -Sky View Post
aint working
Actually, this plugin does work. I have it working on both CS:S and TF2 servers. I haven't put it on our L4D server because were're only running stock maps. I followed the directions provided in the first post for installation.

Your verbose error description should have people flocking to help you get it working too.
SuperShadow is offline
-Sky
Member
Join Date: May 2009
Old 05-12-2009 , 11:10   Re: Map Rate v0.10 (6/30)
Reply With Quote #276

l4d are sourcemods; aint it?
__________________

-Sky is offline
Solltex
Member
Join Date: Dec 2004
Old 05-31-2009 , 14:47   Re: Map Rate v0.10 (6/30)
Reply With Quote #277

how add pictures to web ?
Solltex is offline
noremac430
Member
Join Date: Mar 2009
Old 06-01-2009 , 23:30   Re: Map Rate v0.10 (6/30)
Reply With Quote #278

I can't seem to get the colored bars to work on my PHP site.

Here is the code:

PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Clan-FC Map Ratings</title>
<?php

define
('MR_DBHOST''myserver');
define('MR_DBUSER''myuserid');
define('MR_DBPASS''mypassword');
define('MR_DBNAME''maprating');
define('MR_TABLENAME''ThunderDome');
define('MR_THRESHOLD'0);
define('MR_COLUMNS'3);
define('MR_LEFTWIDTH'200);
define('MR_RIGHTWIDTH'100);

$sort = (isset($_GET['sort']) ? $_GET['sort'] : 'rating');
$reverse = (isset($_GET['reverse']) ? $_GET['reverse'] : 'no');
?>
<html>
<head>
    <style type="text/css">
        body {
            font-family: Trebuchet MS, Helvetica, sans-serif;
            margin-left: auto;
            margin-right: auto;
            width: <?php echo MR_COLUMNS * (MR_LEFTWIDTH MR_RIGHTWIDTH); ?>;
        }

        div.title {
            margin: 0px;
            padding: 10px;
            color: white;
            background-color: #000066;;
        }
        div.title span.title {
            font-weight: bold;
            font-size: 18pt;
        }

        div.title a, a:visited, a:hover, a:link {
            color: white;
        }

        div.ratings {
        }

        table.map_rating {
            border: 2px solid DarkBlue;
            background-color: white;
            margin: 0;
        }

        table.map_rating span.map_name {
            font-weight: bold;
        }

        table.rating_graph {
            background-color: Lavender;
        }
        table.rating_graph td {
            font-size: 10pt;
        }
        table.rating_graph tr.bars td {
            vertical-align: bottom;
        }
        table.rating_graph tr.labels td {
            text-align: center;
            font-weight: bold;
            font-size: 8pt;
        }
        table.rating_graph div.rating_1 {
            background-color: #B80000;
        }
        table.rating_graph div.rating_2 {
            background-color: #B85800;
        }
        table.rating_graph div.rating_3 {
            background-color: #B89800;
        }
        table.rating_graph div.rating_4 {
            background-color: #99CC33;
        }
        table.rating_graph div.rating_5 {
            background-color: #33CC00;
        }
    </style>

</head>
<body>

<?php
class MapRating {
    public 
$name;
    public 
$num_ratings 0;
    public 
$ratings = array(=> 0=> 0=> 0=> 0=> 0);
    private 
$max_ratings 0;

    function 
__construct($name) {
        
$this->name $name;
    }

    function 
add_rating($rating$count) {
        if (!isset(
$this->ratings[$rating])) {
            throw new 
Exception('Invalid rating');
        }
        
$this->ratings[$rating] += $count;
        
$this->num_ratings += $count;
        
$this->max_ratings max($this->max_ratings$count);
    }

    function 
get_graph($width 300$height 100) {
        
$row_bars = array();
        
$row_labels = array();
        for (
$i 1$i <= 5$i++) {
            
/* The weird comment inside the DIV is a fix for IE which renders
             * 20px height minimum without the comment */
            
array_push($row_bars
                
"\t\t<td width=\"20%\"><div class=\"rating_$i\" style=\"height: "
                
.$this->get_rating_height($i$height)
                .
"\"><!-- --></div></td>\n"
            
);
            
array_push($row_labels"\t\t<td>{$this->ratings[$i]}</td>\n");
        }

        
        return 
"<table class=\"rating_graph\" width=\"$width\" height=\"$height\">\n".
            
"\t<tr class=\"bars\">\n".implode($row_bars)."\t</tr>\n".
            
"\t<tr class=\"labels\" height=\"15\">\n".implode($row_labels)."\t</tr>\n".
            
"</table>\n";
    }

    function 
get_average() {
        if (
$this->num_ratings) {
            
$rating_sum 0;
            foreach (
array_keys($this->ratings) as $key) {
                
$rating_sum += $key $this->ratings[$key];
            }
            return 
round($rating_sum $this->num_ratings2);
        }
        else {
            return 
0;
        }
    }

    private function 
get_rating_height($rating$height) {
        if (
$this->max_ratings) {
            return (int)(
$this->ratings[$rating] / $this->max_ratings $height);
        }
        else {
            return 
$height;
        }
    }

    function 
get_num_ratings() {
        return 
"{$this->num_ratings} rating".($this->num_ratings == '' 's');
    }

    function 
get_table() {
        return 
"<table class=\"map_rating\">\n"
            
."\t<tr>\n"
            
."\t\t<td width=\"".MR_LEFTWIDTH."\"><span class=\"map_name\">{$this->name}</span><br/>{$this->get_average()} "
            
."({$this->get_num_ratings()})</td>\n"
            
."\t\t<td>{$this->get_graph(MR_RIGHTWIDTH30)}</td>\n"
            
."\t</tr>\n"
            
."</table>\n";
    }
}

class 
MapRatings {
    private 
$map_ratings;
    private 
$maps;
    private 
$db;

    function 
__construct() {
        
$this->db mysql_pconnect(MR_DBHOSTMR_DBUSERMR_DBPASS);
        if (!
$this->db|| !mysql_select_db(MR_DBNAME)) {
            throw new 
Exception('Could not establish connection to the database');
        }
        
$this->populate_ratings();
    }

    private function 
populate_ratings() {
        
$sort 'ORDER BY rating DESC';
            
$query 'SELECT map, rating, COUNT(*) AS count FROM '.MR_TABLENAME.' GROUP BY map, rating';
            
$result mysql_query($query);

        
$this->map_ratings = array();
        while (
$row mysql_fetch_object($result)) {
            if (!isset(
$this->map_ratings[$row->map])) {
                
$this->map_ratings[$row->map] = new MapRating($row->map);
            }
            
$this->map_ratings[$row->map]->add_rating($row->rating$row->count);
        }

        foreach (
array_keys($this->map_ratings) as $key) {
            if (
$this->map_ratings[$key]->num_ratings MR_THRESHOLD) {
                unset(
$this->map_ratings[$key]);
            }
        }

        
$this->maps array_keys($this->map_ratings);
    }

    function 
get_links($sort='name'$dir='no') {
        
$sort_types = array('rating' => 'Rating''name' => 'Map Name''ratings' => 'Number of Ratings');

        
$links = array();
        foreach (
array_keys($sort_types) as $sort_type) {
            
$link '';
            if (
$sort_type == $sort) {
                
$link "<strong>{$sort_types[$sort_type]}</strong>";
            }
            else {
                
$link "<a href=\"{$_SERVER['PHP_SELF']}?sort=$sort_type\">{$sort_types[$sort_type]}</a>";
            }
            
array_push($links$link);
        }

        return 
'<strong>Order By: </strong>'.implode(' | '$links);
    }

    function 
set_sort($sort='rating'$dir='no') {
        
$rating = array();
        
$ratings = array();
        foreach (
array_values($this->map_ratings) as $mr) {
            
array_push($rating$mr->get_average());
            
array_push($ratings$mr->num_ratings);
        }
        if (
$sort == "name") {
            
sort($this->maps);
        }
        else if (
$sort == "rating") {
            
array_multisort($ratingSORT_DESC$this->maps);
        }
        else if (
$sort == "ratings") {
            
array_multisort($ratingsSORT_DESC$this->maps);
        }

        if (
$dir == "yes") {
            
$this->maps array_reverse($this->maps);
        }
    }

    function 
get_ratings_table() {
        
ob_start();
        echo 
"<table>\n";
            
$cell 0;
            echo 
"\t<tr>\n";
        foreach (
$this->maps as $map) {
            
$mr $this->map_ratings[$map];
            if (!
$cell) {
                echo 
"\t</tr>\n";
                echo 
"\t<tr>\n";
            }
            echo 
"\t\t<td>".$mr->get_table()."</td>\n";
            
$cell = ($cell 1) % MR_COLUMNS;
        }
        while (
$cell) {
            echo 
"\t\t<td>&nbsp;</td>\n";
            
$cell = ($cell 1) % MR_COLUMNS;
        }
        echo 
"\t</tr>\n";
        echo 
"</table>\n";

        
$table ob_get_contents();
        
ob_end_clean();
        return 
$table;
    }
}

$mr = new MapRatings();
echo 
"<div class=\"title\"><span class=\"title\">Map Ratings</span><br/>";
echo 
"<span class=\"links\">".$mr->get_links($sort$reverse)."</span></div>\n";
echo 
"<div class=\"ratings\">\n";
$mr->set_sort($sort$reverse);
echo 
$mr->get_ratings_table();
echo 
"</div>\n";
?>
</body>
</html>
All the information shows up correctly, but the colored bars are not appearing. Any ideas?
It's a straight copy/paste from post #1 with my info added, so I'm not sure what the problem is.

*Edit*
I used the code from this post to correct the problem. Not sure why the other wasn't working. but it is now. Thanks!!
Quote:
Originally Posted by zeros View Post
For those of you without PHP5 I rewrote the script to be compatible with PHP4

Code:
<?php
/**
 * Map Rate Viewer
 * Copyright 2008 Ryan Mannion. All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * Modified for PHP4 Compatibility by zeros</at/>0sanity.com
 */
define('MR_DBHOST', 'localhost');
define('MR_DBUSER', 'dbusername');
define('MR_DBPASS', 'dbpassword');
define('MR_DBNAME', 'database');
define('MR_TABLENAME', 'map_ratings');
define('MR_THRESHOLD', 0);
define('MR_COLUMNS', 3);
define('MR_LEFTWIDTH', 200);
define('MR_RIGHTWIDTH', 100);
$sort = (isset($_GET['sort']) ? $_GET['sort'] : 'rating');
$reverse = (isset($_GET['reverse']) ? $_GET['reverse'] : 'no');
?>
<html>
<head>
    <style type="text/css">
        body {
            font-family: Trebuchet MS, Helvetica, sans-serif;
            margin-left: auto;
            margin-right: auto;
            width: <?php echo MR_COLUMNS * (MR_LEFTWIDTH + MR_RIGHTWIDTH); ?>;
        }
        div.title {
            margin: 0px;
            padding: 10px;
            color: white;
            background-color: #000066;;
        }
        div.title span.title {
            font-weight: bold;
            font-size: 18pt;
        }
        div.title a, a:visited, a:hover, a:link {
            color: white;
        }
        div.ratings {
        }
        table.map_rating {
            border: 2px solid DarkBlue;
            background-color: white;
            margin: 0;
        }
        table.map_rating span.map_name {
            font-weight: bold;
        }
        table.rating_graph {
            background-color: Lavender;
        }
        table.rating_graph td {
            font-size: 10pt;
        }
        table.rating_graph tr.bars td {
            vertical-align: bottom;
        }
        table.rating_graph tr.labels td {
            text-align: center;
            font-weight: bold;
            font-size: 8pt;
        }
        table.rating_graph div.rating_1 {
            background-color: #B80000;
        }
        table.rating_graph div.rating_2 {
            background-color: #B85800;
        }
        table.rating_graph div.rating_3 {
            background-color: #B89800;
        }
        table.rating_graph div.rating_4 {
            background-color: #99CC33;
        }
        table.rating_graph div.rating_5 {
            background-color: #33CC00;
        }
    </style>
</head>
<body>
<?php
class MapRating {
    var $name;
    var $num_ratings = 0;
    var $ratings = array(1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0);
    var $max_ratings = 0;
    function MapRating($name) {
        $this->name = $name;
    }
    function add_rating($rating, $count) {
        if (!isset($this->ratings[$rating])) {
            //throw new Exception('Invalid rating');
        }
        $this->ratings[$rating] += $count;
        $this->num_ratings += $count;
        $this->max_ratings = max($this->max_ratings, $count);
    }
    function get_graph($width = 300, $height = 100) {
        $row_bars = array();
        $row_labels = array();
        for ($i = 1; $i <= 5; $i++) {
            /* The weird comment inside the DIV is a fix for IE which renders
             * 20px height minimum without the comment */
            array_push($row_bars,
                "\t\t<td width=\"20%\"><div class=\"rating_$i\" style=\"height: "
                .$this->get_rating_height($i, $height)
                ."\"><!-- --></div></td>\n"
            );
            array_push($row_labels, "\t\t<td>{$this->ratings[$i]}</td>\n");
        }

        return "<table class=\"rating_graph\" width=\"$width\" height=\"$height\">\n".
            "\t<tr class=\"bars\">\n".implode($row_bars)."\t</tr>\n".
            "\t<tr class=\"labels\" height=\"15\">\n".implode($row_labels)."\t</tr>\n".
            "</table>\n";
    }
    function get_average() {
        if ($this->num_ratings) {
            $rating_sum = 0;
            foreach (array_keys($this->ratings) as $key) {
                $rating_sum += $key * $this->ratings[$key];
            }
            return round($rating_sum / $this->num_ratings, 2);
        }
        else {
            return 0;
        }
    }
    function get_rating_height($rating, $height) {
        if ($this->max_ratings) {
            return (int)($this->ratings[$rating] / $this->max_ratings * $height);
        }
        else {
            return $height;
        }
    }
    function get_num_ratings() {
        return $this->num_ratings." rating".($this->num_ratings == 1 ? '' : 's');
    }
    function get_table() {
        return "<table class=\"map_rating\">\n"
            ."\t<tr>\n"
            ."\t\t<td width=\"".MR_LEFTWIDTH."\"><span class=\"map_name\">".$this->name."</span><br/>".$this->get_average()." "
            ."(".$this->get_num_ratings().")</td>\n"
            ."\t\t<td>".$this->get_graph(MR_RIGHTWIDTH, 30)."</td>\n"
            ."\t</tr>\n"
            ."</table>\n";
    }
}
class MapRatings {
    var $map_ratings;
    var $maps;
    var $db;
    function MapRatings() {
        $this->db = mysql_pconnect(MR_DBHOST, MR_DBUSER, MR_DBPASS);
        if (!$this->db|| !mysql_select_db(MR_DBNAME)) {
//            throw new Exception('Could not establish connection to the database');
        }
        $this->populate_ratings();
    }
    function populate_ratings() {
        $sort = 'ORDER BY rating DESC';
            $query = 'SELECT map, rating, COUNT(*) AS count FROM '.MR_TABLENAME.' GROUP BY map, rating';
            $result = mysql_query($query);
        $this->map_ratings = array();
        while ($row = mysql_fetch_object($result)) {
            if (!isset($this->map_ratings[$row->map])) {
                $this->map_ratings[$row->map] = new MapRating($row->map);
            }
            $this->map_ratings[$row->map]->add_rating($row->rating, $row->count);
        }
        foreach (array_keys($this->map_ratings) as $key) {
            if ($this->map_ratings[$key]->num_ratings < MR_THRESHOLD) {
                unset($this->map_ratings[$key]);
            }
        }
        $this->maps = array_keys($this->map_ratings);
    }
    function get_links($sort='name', $dir='no') {
        $sort_types = array('rating' => 'Rating', 'name' => 'Map Name', 'ratings' => 'Number of Ratings');
        $links = array();
        foreach (array_keys($sort_types) as $sort_type) {
            $link = '';
            if ($sort_type == $sort) {
                $link = "<strong>{$sort_types[$sort_type]}</strong>";
            }
            else {
                $link = "<a href=\"{$_SERVER['PHP_SELF']}?sort=$sort_type\">{$sort_types[$sort_type]}</a>";
            }
            array_push($links, $link);
        }
        return '<strong>Order By: </strong>'.implode(' | ', $links);
    }
    function set_sort($sort='rating', $dir='no') {
        $rating = array();
        $ratings = array();
        foreach (array_values($this->map_ratings) as $mr) {
            array_push($rating, $mr->get_average());
            array_push($ratings, $mr->num_ratings);
        }
        if ($sort == "name") {
            sort($this->maps);
        }
        else if ($sort == "rating") {
            array_multisort($rating, SORT_DESC, $this->maps);
        }
        else if ($sort == "ratings") {
            array_multisort($ratings, SORT_DESC, $this->maps);
        }
        if ($dir == "yes") {
            $this->maps = array_reverse($this->maps);
        }
    }
    function get_ratings_table() {
        ob_start();
        echo "<table>\n";
            $cell = 0;
            echo "\t<tr>\n";
        foreach ($this->maps as $map) {
            $mr = $this->map_ratings[$map];
            if (!$cell) {
                echo "\t</tr>\n";
                echo "\t<tr>\n";
            }
            echo "\t\t<td>".$mr->get_table()."</td>\n";
            $cell = ($cell + 1) % MR_COLUMNS;
        }
        while ($cell) {
            echo "\t\t<td>&nbsp;</td>\n";
            $cell = ($cell + 1) % MR_COLUMNS;
        }
        echo "\t</tr>\n";
        echo "</table>\n";
        $table = ob_get_contents();
        ob_end_clean();
        return $table;
    }
}
$mr = new MapRatings();
echo "<div class=\"title\"><span class=\"title\">Map Ratings</span><br/>";
echo "<span class=\"links\">".$mr->get_links($sort, $reverse)."</span></div>\n";
echo "<div class=\"ratings\">\n";
$mr->set_sort($sort, $reverse);
echo $mr->get_ratings_table();
echo "</div>\n";
?>
</body>
</html>

Last edited by noremac430; 06-02-2009 at 08:30.
noremac430 is offline
Johnny_Napalm
Member
Join Date: Apr 2009
Old 06-04-2009 , 13:57   Re: Map Rate v0.10 (6/30)
Reply With Quote #279

So, for us noobish types - is post #19 really all we have to do to use the sqlite db that's in SourceMod? No other configurations? I only ask because it sounds too easy...
Johnny_Napalm is offline
Sillium
AlliedModders Donor
Join Date: Sep 2008
Location: Germany
Old 06-05-2009 , 01:11   Re: Map Rate v0.10 (6/30)
Reply With Quote #280

And configure the plugin itself ;-)
__________________
brb, dishes have developed their own language and are talking to the garbage about overthrowing me... i must correct this

www.unterwasserpyromanen.de
Sillium is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode