# Copyright 2013 John Reese
# Licensed under the MIT license

from ..ent import Struct, NetworkStat
from ..log import logger

log = logger(__name__)

class Plugin(Struct):
    """A pluggable class for generating and displaying message statistics."""
    def __init__(self, config):
        Struct.__init__(self,
                        config=config,
                        **config.plugins.__dict__[self.name].__dict__)

    def process(self, conversations):
        """Process a list of conversations and return a NetworkStat object."""
        network = NetworkStat()

        for channel in conversations:
            channel_stats = network.channels[channel]

            for date, conversation in conversations[channel].items():
                daily_stats = channel_stats.days[date]

                self.process_conversation(conversation,
                                          network, channel_stats, daily_stats)

        return network

    def process_conversation(self, conversation, network, channel, day):
        """Process a single conversation, with the given network, channel, and
        daily statistics objects."""

        for message in conversation.messages:
            self.process_message(message, network, channel, day)

    def process_message(self, message, network, channel, day):
        """Process an individual message, with the given network, channel, and
        daily statistics objects."""
        raise NotImplementedError()

@@ -537,24 +537,29 @@
 %22%22%22%0A        
+self.
 network = Ne
@@ -625,24 +625,28 @@
     
+self.
 channel
-_stats = 
+ = self.
 netw
@@ -758,35 +758,31 @@
     
-daily_stats = 
+self.day = self.
 channel
-_stats
 .day
@@ -789,17 +789,16 @@
 s%5Bdate%5D%0A
-%0A
         
@@ -847,87 +847,8 @@
 tion
-,%0A                                          network, channel_stats, daily_stats
 )%0A%0A 
@@ -861,16 +861,21 @@
  return 
+self.
 network%0A
@@ -922,39 +922,16 @@
 ersation
-, network, channel, day
 ):%0A     
@@ -1128,39 +1128,16 @@
 (message
-, network, channel, day
 )%0A%0A    d
@@ -1172,31 +1172,8 @@
 sage
-, network, channel, day
 ):%0A 
@@ -1323,8 +1323,1083 @@
 Error()%0A
+%0A    def inc_user_stats(self, nick, **kwargs):%0A        %22%22%22Increment user stat counters for the given key/value pairs.%22%22%22%0A        for key, value in kwargs.items():%0A            self.network.users%5Bnick%5D.stats%5Bkey%5D += value%0A            self.channel.users%5Bnick%5D.stats%5Bkey%5D += value%0A            self.day.users%5Bnick%5D.stats%5Bkey%5D += value%0A%0A    def inc_network_stats(self, **kwargs):%0A        %22%22%22Increment aggregate stat counters for the given key/value pairs.%22%22%22%0A        for key,value in kwargs.items():%0A            self.network.stats%5Bkey%5D += value%0A            self.channel.stats%5Bkey%5D += value%0A            self.day.stats%5Bkey%5D += value%0A%0A    def inc_shared_stats(self, nick, **kwargs):%0A        %22%22%22Increment shared user/aggregate stat counters.%22%22%22%0A        for key,value in kwargs.items():%0A            self.network.stats%5Bkey%5D += value%0A            self.channel.stats%5Bkey%5D += value%0A            self.day.stats%5Bkey%5D += value%0A%0A            self.network.users%5Bnick%5D.stats%5Bkey%5D += value%0A            self.channel.users%5Bnick%5D.stats%5Bkey%5D += value%0A            self.day.users%5Bnick%5D.stats%5Bkey%5D += value%0A

Modify plugin processing framework to simplify arguments and stats