tBKwtWS преди 7 години
родител
ревизия
7a2487ae42
променени са 3 файла, в които са добавени 99 реда и са изтрити 218 реда
  1. 0 112
      irc/original_testbot.py
  2. 89 104
      webgui/stats/templates/stats/networks.html
  3. 10 2
      webgui/stats/views.py

+ 0 - 112
irc/original_testbot.py

@@ -1,112 +0,0 @@
-#! /usr/bin/env python
-#
-# Example program using irc.bot.
-#
-# Joel Rosdahl <joel@rosdahl.net>
-
-"""A simple example bot.
-This is an example bot that uses the SingleServerIRCBot class from
-irc.bot.  The bot enters a channel and listens for commands in
-private messages and channel traffic.  Commands in channel messages
-are given by prefixing the text by the bot name followed by a colon.
-It also responds to DCC CHAT invitations and echos data sent in such
-sessions.
-The known commands are:
-    stats -- Prints some channel information.
-    disconnect -- Disconnect the bot.  The bot will try to reconnect
-                  after 60 seconds.
-    die -- Let the bot cease to exist.
-    dcc -- Let the bot invite you to a DCC CHAT connection.
-"""
-
-import irc.bot
-import irc.strings
-from irc.client import ip_numstr_to_quad, ip_quad_to_numstr
-
-class TestBot(irc.bot.SingleServerIRCBot):
-    def __init__(self, channel, nickname, server, port=6667):
-        irc.bot.SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname)
-        self.channel = channel
-
-    def on_nicknameinuse(self, c, e):
-        c.nick(c.get_nickname() + "_")
-
-    def on_welcome(self, c, e):
-        c.join(self.channel)
-
-    def on_privmsg(self, c, e):
-        self.do_command(e, e.arguments[0])
-
-    def on_pubmsg(self, c, e):
-        a = e.arguments[0].split(":", 1)
-        if len(a) > 1 and irc.strings.lower(a[0]) == irc.strings.lower(self.connection.get_nickname()):
-            self.do_command(e, a[1].strip())
-        return
-
-    def on_dccmsg(self, c, e):
-        # non-chat DCC messages are raw bytes; decode as text
-        text = e.arguments[0].decode('utf-8')
-        c.privmsg("You said: " + text)
-
-    def on_dccchat(self, c, e):
-        if len(e.arguments) != 2:
-            return
-        args = e.arguments[1].split()
-        if len(args) == 4:
-            try:
-                address = ip_numstr_to_quad(args[2])
-                port = int(args[3])
-            except ValueError:
-                return
-            self.dcc_connect(address, port)
-
-    def do_command(self, e, cmd):
-        nick = e.source.nick
-        c = self.connection
-
-        if cmd == "disconnect":
-            self.disconnect()
-        elif cmd == "die":
-            self.die()
-        elif cmd == "stats":
-            for chname, chobj in self.channels.items():
-                c.notice(nick, "--- Channel statistics ---")
-                c.notice(nick, "Channel: " + chname)
-                users = sorted(chobj.users())
-                c.notice(nick, "Users: " + ", ".join(users))
-                opers = sorted(chobj.opers())
-                c.notice(nick, "Opers: " + ", ".join(opers))
-                voiced = sorted(chobj.voiced())
-                c.notice(nick, "Voiced: " + ", ".join(voiced))
-        elif cmd == "dcc":
-            dcc = self.dcc_listen()
-            c.ctcp("DCC", nick, "CHAT chat %s %d" % (
-                ip_quad_to_numstr(dcc.localaddress),
-                dcc.localport))
-        else:
-            c.notice(nick, "Not understood: " + cmd)
-
-def main():
-    import sys
-    if len(sys.argv) != 4:
-        print("Usage: testbot <server[:port]> <channel> <nickname>")
-        sys.exit(1)
-
-    s = sys.argv[1].split(":", 1)
-    server = s[0]
-    if len(s) == 2:
-        try:
-            port = int(s[1])
-        except ValueError:
-            print("Error: Erroneous port.")
-            sys.exit(1)
-    else:
-        port = 6667
-    channel = sys.argv[2]
-    nickname = sys.argv[3]
-
-    bot = TestBot(channel, nickname, server, port)
-    bot.start()
-
-if __name__ == "__main__":
-    main()

+ 89 - 104
webgui/stats/templates/stats/networks.html

@@ -1,49 +1,50 @@
 {% extends "base.html" %}
 {% load static %}
-{% block head %}<meta name="nonfiction" content="true">{% endblock %}
+{% block head %}
+    <meta name="nonfiction" content="true">
+    <script type="text/javascript" src="{% static "javascript/loader.js" %}"></script>
+{% endblock %}
 {% block title %}Networks{% endblock %}
 {% block description %}Configred networks{% endblock %}
 {% block keywords %}irc networks{% endblock %}
 {% block keywords-not %}{% endblock %}
 {% block content %}
-    <article class="ui container">
-        
-        <section class="ui text container">
-        <div class="ui four statistics">
-            <div class="statistic">
-                <div class="value">
-                    <i class="sitemap icon"></i> {{ networks|length }}
-                </div>
-                <div class="label">
-                    Networks
-                </div>
-            </div>
-            <div class="statistic">
-                <div class="value">
-                    <i class="hashtag icon"></i> {{ channels|length }}
-                </div>
-                <div class="label">
-                    Channels
-                </div>
-            </div>
-            <div class="statistic">
-                <div class="value">
-                    <i class="users icon"></i> {{ users|length }}
+        <article class="ui text container">
+            <header class="ui four statistics">
+                <div class="statistic">
+                    <div class="value">
+                        <i class="sitemap icon"></i> {{ networks|length }}
+                    </div>
+                    <div class="label">
+                        Networks
+                    </div>
                 </div>
-                <div class="label">
-                    Users
+                <div class="statistic">
+                    <div class="value">
+                        <i class="hashtag icon"></i> {{ channels|length }}
+                    </div>
+                    <div class="label">
+                        Channels
+                    </div>
                 </div>
-            </div>
-            <div class="statistic">
-                <div class="value">
-                    <i class="comments outline icon"></i> {{ messages|length }}
+                <div class="statistic">
+                    <div class="value">
+                        <i class="users icon"></i> {{ users|length }}
+                    </div>
+                    <div class="label">
+                        Users
+                    </div>
                 </div>
-                <div class="label">
-                    Messages
+                <div class="statistic">
+                    <div class="value">
+                        <i class="comments outline icon"></i> {{ totalmessages }}
+                    </div>
+                    <div class="label">
+                        Messages
+                    </div>
                 </div>
-            </div>
-        </div>
-            <div class="ui celled selection link list">
+            </header>
+            <section class="ui celled selection link list">
                 {% for network in networks %}
                     <a class="item" href="{% url 'stats:network' network.name %}">
                         <div class="right floated content">
@@ -61,80 +62,64 @@
                         </div>
                     </a>
                 {% endfor %}
-            </div>
-        </section>
-        
-        <section>
-            <script type="text/javascript" src="{% static "javascript/loader.js" %}"></script>
-            <script type="text/javascript">
-                google.charts.load("current", {packages:["corechart"]});
-                google.charts.setOnLoadCallback(drawChart);
-                function drawChart() {
-                    var data = google.visualization.arrayToDataTable([
-                        ['Network', 'Users'],
-                            {% for network in networklist.items %}
-                                ['{{ network.0 }}',     {{ network.1.messages }}],
-                            {% endfor %}
-                        ]);
-
-                    var options = {
-                        pieHole: 0.4,
-                        legend: 'none',
-                        pieSliceText: 'label',
-                    };
-
-                    var chart = new google.visualization.PieChart(document.getElementById('messageschart'));
-                    chart.draw(data, options);
-                }
-            </script>
-            <script type="text/javascript" src="{% static "javascript/loader.js" %}"></script>
-            <script type="text/javascript">
-            google.charts.load("current", {packages:["corechart"]});
-                google.charts.setOnLoadCallback(drawChart);
-                function drawChart() {
-                    var data = google.visualization.arrayToDataTable([
-                        ['Network', 'Users'],
-                            {% for network in networklist.items %}
-                                ['{{ network.0 }}',     {{ network.1.users }}],
-                            {% endfor %}
-                        ]);
-
-                    var options = {
-                        pieHole: 0.4,
-                        legend: 'none',
-                        pieSliceText: 'label',
-                    };
-
-                    var chart = new google.visualization.PieChart(document.getElementById('userschart'));
-                    chart.draw(data, options);
-                }
-            </script>
-            
-            <div class="ui cards">
-                <div class="ui card">
-                    <div class="content">
-                        <div class="header">
-                            <i class="users icon"></i>
-                            Messages per network
-                        </div>
-                    </div>
-                    <div class="image" id="messageschart" ></div>
+            </section>
+        </article>
+        <section class="ui padded equal width centered grid">
+            <div class="ui four wide column">
+                <div class="header">
+                    <i class="users icon"></i>
+                    Messages per network
                 </div>
-                <div class="ui card">
-                    <div class="content">
-                        <div class="header">
-                            <i class="users icon"></i>
-                            Users per network
-                        </div>
-                    </div>
-                    
-                    <div class="image" id="userschart" ></div>
+                <script type="text/javascript">
+                            google.charts.load("current", {packages:["corechart"]});
+                            google.charts.setOnLoadCallback(drawChart);
+                            function drawChart() {
+                                var data = google.visualization.arrayToDataTable([
+                                    ['Network', 'Users'],
+                                        {% for network in networklist.items %}
+                                            ['{{ network.0 }}',     {{ network.1.messages }}],
+                                        {% endfor %}
+                                    ]);
+                                var options = {
+                                    pieHole: 0.4,
+                                    legend: 'none',
+                                    pieSliceText: 'label',
+                                };
+                                var chart = new google.visualization.PieChart(document.getElementById('messageschart'));
+                                chart.draw(data, options);
+                            }
+                </script>
+                <div id="messageschart" ></div>
+            </div>
+            <div class="four wide column">
+                <div class="header">
+                    <i class="users icon"></i>
+                    Users per network
                 </div>
+                <script type="text/javascript">
+                                google.charts.load("current", {packages:["corechart"]});
+                                google.charts.setOnLoadCallback(drawChart);
+                                function drawChart() {
+                                    var data = google.visualization.arrayToDataTable([
+                                        ['Network', 'Users'],
+                                            {% for network in networklist.items %}
+                                                ['{{ network.0 }}',     {{ network.1.users }}],
+                                            {% endfor %}
+                                        ]);
+                                    var options = {
+                                        pieHole: 0.4,
+                                        legend: 'none',
+                                        pieSliceText: 'label',
+                                    };
+                                    var chart = new google.visualization.PieChart(document.getElementById('userschart'));
+                                    chart.draw(data, options);
+                                }
+                </script>
+                <div id="userschart" ></div>
             </div>
 
-
         </section>
-    </article>
+
 {% endblock content %}
 {% block breadcrumbs %}
     <i class="sitemap icon"></i>

+ 10 - 2
webgui/stats/views.py

@@ -7,26 +7,34 @@ def networks(request):
     channels = Channels.objects.all()
     users = Users.objects.all()
     db = Postgres("postgres://pyRot:4h8q(.@localhost/pyRot")
-    messages = db.all("SELECT * FROM messages")
+    messages = db.all("SELECT channel_network, messages, actions, notices FROM messages")
+    print(messages)
+    
     #foo = db.all("SELECT * FROM messages WHERE channel_network='GamerGalaxy'")
     #print(foo)
     
     networklist = {}
     for network in networks:
-        print(db.all("SELECT messages, actions, notices FROM messages WHERE channel_network='" + str(network) + "'"))
+        #print(db.all("SELECT messages, actions, notices FROM messages WHERE channel_network='" + str(network) + "'"))
         networklist[network.name] = {'channels': 0, 'users': 0, 'messages': 0}
     for user in users:
         networklist[user.network.name]['users'] += 1
     for channel in channels:
         networklist[channel.network.name]['channels'] += 1
+    totalmessages = 0
+    for record in messages:
+        totalmessages += record[1] + record[2] + record[3]
+        networklist[channel.network.name]['messages'] += record[1] + record[2] + record[3]
     
     context = {
         'networks': networks,
         'channels': channels,
         'users': users,
         'messages': messages,
+        'totalmessages': totalmessages,
         'networklist': networklist,
     }
+    print(totalmessages)
     return render(request, 'stats/networks.html', context)
 
 def network(request, network_name):