tBKwtWS před 7 roky
rodič
revize
2963820603

+ 6 - 5
irc/commands/games.py

@@ -177,9 +177,11 @@ def do_command(self, connection, event):
                 print("XP < 10: " + str(xp < 10))
                 if xp < 10:
                     connection.privmsg(replyto, "Insuficcient XP, you need at least 10.")
+                elif ap < 1:
+                    connection.privmsg(replyto, "Insuficcient AP, you need at least 1.")
                 else:
                     self.db.run("UPDATE users SET level=level+1, xp_spent=xp_spent+10 WHERE LOWER(name)=%s AND network=%s", (user, self.network, ))
-                    self.db.run("UPDATE users SET coin=coin+0.3 WHERE level>0")
+                    self.db.run("UPDATE users SET coin=coin+0.3 WHERE level>0 AND network=%s", (self.network, ))
             elif len(command.split()) == 2:
                 try:
                     levels = int(command.split()[1])
@@ -191,12 +193,11 @@ def do_command(self, connection, event):
                     connection.privmsg(replyto, "Invalid amount.")
                 elif xp < levels * 10:
                     connection.privmsg(replyto, "Insuficcient XP, you need at least " + str(levels * 10) + ".")
-                if ap < 1:
+                elif ap < levels:
                     connection.privmsg(replyto, "Insufficient AP, you need at least 1.")
-                    return
                 else:
-                    self.db.run("UPDATE users SET level=level+%s, xp_spent=xp_spent+%s, ap_spent=ap_spent-1 WHERE LOWER(name)=LOWER(%s) AND network=%s", (levels, levels * 10, user, self.network, ))
-                    self.db.run("UPDATE users SET coin=coin+%s WHERE level>0", (self.network, ))
+                    self.db.run("UPDATE users SET level=level+%s, xp_spent=xp_spent+%s, ap_spent=ap_spent+%s WHERE LOWER(name)=LOWER(%s) AND network=%s", (levels, levels * 10, levels, user, self.network, ))
+                    self.db.run("UPDATE users SET coin=coin+%s WHERE level>0 AND network=%s", (levels * 0.3, self.network, ))
             else:
                 connection.privmsg(replyto, "Too many arguments. For help type " + blue + self.helpchar + "levelup " + reset + ".")
     

+ 19 - 12
webgui/stats/templates/stats/network.html

@@ -131,9 +131,8 @@
             </div>
         </section>
     </article>
-    <div class="ui divider"></div>
-    <div class="ui center aligned container">
-         <article class="ui stackable cards">
+    <div class="ui segment">
+         <article class="ui centered stackable cards">
             <script type="text/javascript">
                 google.charts.load("current", {packages:["corechart"]});
                 google.charts.setOnLoadCallback(drawChart0);
@@ -297,6 +296,7 @@
                         pieHole: 0.1,
                         'chartArea': {'width': '95%', 'height': '100%'},
                         pieSliceText: 'label',
+                        sliceVisibilityThreshold: 1,
                     };
                     var chart = new google.visualization.PieChart(document.getElementById('userjoinschart'));
                     chart.draw(data, options);
@@ -444,8 +444,7 @@
                             pieHole: 0.1,
                             'chartArea': {'width': '95%', 'height': '100%'},
                             pieSliceText: 'label',
-                            sliceVisibilityThreshold: 10
-
+                            sliceVisibilityThreshold: 10,
                         };
                         var chart = new google.visualization.PieChart(document.getElementById('usercoinschart'));
                         chart.draw(data, options);
@@ -466,14 +465,16 @@
                     </div>
                 </section>
             {% endif %}
-            {% if totalcoingiven != 0 and totalcoinspent != 0 %}
+            {% if coingiven != 0 and totalcoinspent != 0 %}
                 <script type="text/javascript">
                     google.charts.load("current", {packages:["corechart"]});
                     google.charts.setOnLoadCallback(drawChart8);
                     function drawChart8() {
                         var data = google.visualization.arrayToDataTable([
-                            ['Coin spent', 'Coin given'],
-                            ['{{ totalcoinspent }}',     {{ totalcoingiven }}],
+                            ['Network', 'Coin given'],
+                            {% for network in networkslist.items %}
+                                ['{{ network.0|escapejs }}',     {{ network.1.coinspentcount }} / {{ network.1.coingivencount }}],
+                            {% endfor %}
                         ]);
                         var options = {
                             legend: 'none',
@@ -483,7 +484,7 @@
                             'chartArea': {'width': '95%', 'height': '100%'},
                             pieSliceText: 'label',
                         };
-                        var chart = new google.visualization.PieChart(document.getElementById('spenvsgivenchart'));
+                        var chart = new google.visualization.PieChart(document.getElementById('spentvsgivenchart'));
                         chart.draw(data, options);
                     }
                 </script>
@@ -491,14 +492,20 @@
                     <div title="Coin spent vs given" class="content">
                         <div class="header">
                             <div>
-                                <i class="ui money icon"></i>
+                                <i class="icons">
+                                    <i class="ui in chart icon">
+                                    <i class="ui corner money icon">
+                                </i>
                                 /
-                                <i class="ui user icon"></i>
+                                <i class="icons">
+                                    <i class="ui sent icon">
+                                    <i class="ui corner money icon">
+                                </i>
                             </div>
                         </div>
                     </div>
                     <div class="content">
-                        <div id="spentvssgivenchart"></div>
+                        <div id="spentvsgivenchart"></div>
                     </div>
                 </section>
             {% endif %}

+ 83 - 2
webgui/stats/templates/stats/networks.html

@@ -180,7 +180,7 @@
                         pieHole: 0.1,
                         'chartArea': {'width': '95%', 'height': '100%'},
                     };
-                    var chart = new google.visualization.PieChart(document.getElementById('networkschart'));
+                    var chart = new google.visualization.PieChart(document.getElementById('channelschart'));
                     chart.draw(data, options);
                 }
             </script>
@@ -195,9 +195,90 @@
                     </div>
                 </div>
                 <div class="content">
-                    <div id="networkschart"></div>
+                    <div id="channelschart"></div>
                 </div>
             </section>
+            {% if isxpspent > 1 %}
+            <script type="text/javascript">
+                google.charts.load("current", {packages:["corechart"]});
+                google.charts.setOnLoadCallback(drawChart2);
+                function drawChart2() {
+                    var data = google.visualization.arrayToDataTable([
+                        ['Network', 'XP spent'],
+                            {% for network in networkslist.items %}
+                                ['{{ network.0|escapejs }}',     {{ network.1.xpspentcount }}],
+                            {% endfor %}
+                        ]);
+                    var options = {
+                        legend: 'none',
+                        pieSliceText: 'label',
+                        height: '275',
+                        pieHole: 0.1,
+                        'chartArea': {'width': '95%', 'height': '100%'},
+                        sliceVisibilityThreshold: 0,
+                    };
+                    var chart = new google.visualization.PieChart(document.getElementById('xpspentchart'));
+                    chart.draw(data, options);
+                }
+            </script>
+            <section class="ui card">
+                <div class="content" title="XP spent per network">
+                    <div class="header">
+                        <div>
+                            <i class="ui dashboard icon"></i>
+                            /
+                            <i class="ui sitemap icon"></i>
+                        </div>
+                    </div>
+                </div>
+                <div class="content">
+                    <div id="xpspentchart"></div>
+                </div>
+            </section>
+                <script type="text/javascript">
+                    google.charts.load("current", {packages:["corechart"]});
+                    google.charts.setOnLoadCallback(drawChart3);
+                    function drawChart3() {
+                        var data = google.visualization.arrayToDataTable([
+                            ['Coin spent', 'Coin given'],
+                            {% for network in networkslist.items %}
+                                ['{{ network.0|escapejs }}',     {{ network.1.xpspentcount }}],
+                            {% endfor %}
+                        ]);
+                        var options = {
+                            legend: 'none',
+                            pieSliceText: 'label',
+                            height: '275',
+                            pieHole: 0.1,
+                            'chartArea': {'width': '95%', 'height': '100%'},
+                            pieSliceText: 'label',
+                            sliceVisibilityThreshold: 0,
+                        };
+                        var chart = new google.visualization.PieChart(document.getElementById('spentvsgivenchart'));
+                        chart.draw(data, options);
+                    }
+                </script>
+                <section class="ui card">
+                    <div title="Coin spent vs given" class="content">
+                        <div class="header">
+                            <div>
+                                <i class="icons">
+                                    <i class="ui cart icon"></i>
+                                    <i class="top right corner money icon"></i>
+                                </i>
+                                /
+                                <i class="icons">
+                                    <i class="ui send icon"></i>
+                                    <i class="left top corner money icon"></i>
+                                </i>
+                            </div>
+                        </div>
+                    </div>
+                    <div class="content">
+                        <div id="spentvsgivenchart"></div>
+                    </div>
+                </section>
+            {% endif %}
         </article>
     </div>
 {% endblock content %}

+ 10 - 1
webgui/stats/views.py

@@ -15,9 +15,15 @@ def networks(request):
     totalusers = convert_units.shorten_number(len(users))
     networkslist = {}
     for network in networks:
-        networkslist[network.name] = {'channelcount': 0, 'usercount': 0, 'messagecount': 0}
+        networkslist[network.name] = {'channelcount': 0, 'usercount': 0, 'messagecount': 0, 'xpspentcount': 0, 'coinspentcount': 0, 'coingivencount': 0}
+    isxpspent = False
     for user in users:
         networkslist[user.network.name]['usercount'] += 1
+        if user.xp_spent > 1: 
+            isxpspent = True
+        networkslist[user.network.name]['xpspentcount'] += user.xp_spent
+        networkslist[user.network.name]['coinspentcount'] += user.coin_spent
+        networkslist[user.network.name]['coingivencount'] += user.coin_given
     for channel in channels:
         networkslist[channel.network.name]['channelcount'] += 1
     totalmessages = 0
@@ -36,6 +42,7 @@ def networks(request):
         'totalusers': totalusers,
         'totalmessages': totalmessages,
         'networkslist': networkslist,
+        'isxpspent': isxpspent, 
     }
     return render(request, 'stats/networks.html', context)
 
@@ -76,6 +83,8 @@ def network(request, network_name):
             isxpspent = True
         totalxpstats += user.xp_spent
         totalcoinstats += user.coin
+    totalcoinstats = convert_units.shorten_number(totalcoinstats)
+    totalxpstats = convert_units.shorten_number(totalxpstats)
     for record in joins:
         channelslist[record[0]]['joincount'] += 1
         userslist[record[1]]['joincount'] += 1