Changeset 379:dfe775e5d7fc

Show
Ignore:
Timestamp:
05/18/2009 10:59:47 PM (3 years ago)
Author:
Dmitry Nezhevenko <dion@…>
Branch:
default
Message:

Calculate sentences statistic

Files:
4 modified

Legend:

Unmodified
Added
Removed
  • sql/update/pgsql/00374.sql

    r378 r379  
    88  lastaction int NOT NULL default '0', 
    99  lastreason varchar(200) NULL, 
     10 
     11  msg_count int NOT NULL default 0, 
     12  msg_chars int NOT NULL default 0, 
     13  msg_words int NOT NULL default 0, 
     14  msg_sentences int NOT NULL default 0, 
     15  msg_me int NOT NULL default 0, 
     16  msg_reply int NOT NULL default 0, 
    1017 
    1118  cnt_join int NOT NULL default 0, 
  • src/plugins/muc/jidstat.cpp

    r378 r379  
    2626#include <QSqlError> 
    2727#include <QVariant> 
     28#include <QRegExp> 
    2829 
    2930JidStat::JidStat(int jidId) 
     
    197198 
    198199} 
     200 
     201void JidStat::statMessage(const QString& message) 
     202{ 
     203        if (id_ <= 0) 
     204                return; 
     205        QString msg = message.trimmed(); 
     206        int msgChars = msg.length(); 
     207        int msgWords = 0; 
     208        int msgSentences = 0; 
     209        int msgMe = 0; 
     210        if (msg.toLower().startsWith("/me ")) 
     211                msgMe = 1; 
     212        bool hasWord = false; 
     213        for (int i = 0; i < msgChars; ++i ) 
     214        { 
     215                QChar chr = msg[i]; 
     216                if (chr == '.' || chr == '?' || chr == '!') 
     217                { 
     218                        if (hasWord) 
     219                        { 
     220                                ++msgSentences; 
     221                                ++msgWords; 
     222                        } 
     223                        hasWord = false; 
     224                        continue; 
     225                } 
     226                else if (chr.isSpace()) 
     227                { 
     228                        if (hasWord) 
     229                                ++msgWords; 
     230                        hasWord = false; 
     231                        continue; 
     232                } 
     233                hasWord = true; 
     234        } 
     235        if (hasWord) 
     236        { 
     237                ++msgWords; 
     238                ++msgSentences; 
     239        } 
     240 
     241        QSqlQuery q = DataStorage::instance()->prepareQuery( 
     242                "UPDATE conference_jidstat SET msg_count = msg_count + 1," 
     243                " msg_chars = msg_chars + ?, msg_words = msg_words + ?," 
     244                " msg_sentences = msg_sentences + ?, msg_me = msg_me + ? WHERE id=?"); 
     245        q.addBindValue(msgChars); 
     246        q.addBindValue(msgWords); 
     247        q.addBindValue(msgSentences); 
     248        q.addBindValue(msgMe); 
     249        q.addBindValue(id_); 
     250        if (!q.exec()) 
     251        { 
     252                qDebug() << "ERROR: Unable to stat sentence: " << q.lastError().text(); 
     253        } 
     254} 
     255 
     256void JidStat::statReply() 
     257{ 
     258        if (id_ <= 0) 
     259                return; 
     260 
     261        QSqlQuery q = DataStorage::instance()->prepareQuery( 
     262                "UPDATE conference_jidstat SET msg_reply = msg_reply + 1 WHERE id=?"); 
     263        q.addBindValue(id_); 
     264        if (!q.exec()) 
     265        { 
     266                qDebug() << "ERROR: Unable to stat reply: " << q.lastError().text(); 
     267        } 
     268} 
     269 
  • src/plugins/muc/jidstat.h

    r378 r379  
    5555        void setVersion(const QString& version); 
    5656        void updateOnlineTime(); 
     57        void statMessage(const QString& msg); 
     58        void statReply(); 
    5759private: 
    5860        int id_; 
  • src/plugins/muc/mucplugin.cpp

    r377 r379  
    532532        nick->updateLastActivity(); 
    533533        nick->commit(); 
     534 
     535        QString msgBody = QString::fromStdString(s->body()); 
     536        JidStat *stat = nick->jidStat(); 
     537        if (stat) 
     538                stat->statMessage(msgBody); 
     539 
     540        if (msgBody.contains(':')) 
     541        { 
     542                // Calc also highlights 
     543                QString dstNickStr = msgBody.section(':', 0, 0); 
     544                Nick *dstNick=conf->nicks()->byName(dstNickStr); 
     545                if (dstNick && nick != dstNick && dstNick->jidStat()) 
     546                        dstNick->jidStat()->statReply(); 
     547        } 
    534548 
    535549        checkMember(s, conf, nick);