Changeset 379:dfe775e5d7fc
- Timestamp:
- 05/18/2009 10:59:47 PM (3 years ago)
- Author:
- Dmitry Nezhevenko <dion@…>
- Branch:
- default
- Message:
-
Calculate sentences statistic
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r378
|
r379
|
|
| 8 | 8 | lastaction int NOT NULL default '0', |
| 9 | 9 | 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, |
| 10 | 17 | |
| 11 | 18 | cnt_join int NOT NULL default 0, |
-
|
r378
|
r379
|
|
| 26 | 26 | #include <QSqlError> |
| 27 | 27 | #include <QVariant> |
| | 28 | #include <QRegExp> |
| 28 | 29 | |
| 29 | 30 | JidStat::JidStat(int jidId) |
| … |
… |
|
| 197 | 198 | |
| 198 | 199 | } |
| | 200 | |
| | 201 | void 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 | |
| | 256 | void 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 | |
-
|
r378
|
r379
|
|
| 55 | 55 | void setVersion(const QString& version); |
| 56 | 56 | void updateOnlineTime(); |
| | 57 | void statMessage(const QString& msg); |
| | 58 | void statReply(); |
| 57 | 59 | private: |
| 58 | 60 | int id_; |
-
|
r377
|
r379
|
|
| 532 | 532 | nick->updateLastActivity(); |
| 533 | 533 | 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 | } |
| 534 | 548 | |
| 535 | 549 | checkMember(s, conf, nick); |