Merge lp:~boiko/telephony-service/metrics into lp:telephony-service

Proposed by Gustavo Pichorim Boiko
Status: Merged
Approved by: Bill Filler
Approved revision: 753
Merged at revision: 746
Proposed branch: lp:~boiko/telephony-service/metrics
Merge into: lp:telephony-service
Diff against target: 315 lines (+151/-7)
9 files modified
CMakeLists.txt (+1/-0)
debian/control (+2/-0)
indicator/CMakeLists.txt (+3/-0)
indicator/callchannelobserver.cpp (+12/-0)
indicator/main.cpp (+4/-0)
indicator/metrics.cpp (+60/-0)
indicator/metrics.h (+53/-0)
indicator/textchannelobserver.cpp (+15/-7)
indicator/textchannelobserver.h (+1/-0)
To merge this branch: bzr merge lp:~boiko/telephony-service/metrics
Reviewer Review Type Date Requested Status
Bill Filler (community) Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+187611@code.launchpad.net

Commit message

Add support for user metrics.

Description of the change

Add support for user metrics.

To post a comment you must log in.
lp:~boiko/telephony-service/metrics updated
751. By Gustavo Pichorim Boiko

Remove leftover return statement.

752. By Gustavo Pichorim Boiko

Add Ugo to the authors section, as he did most of the code.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~boiko/telephony-service/metrics updated
753. By Gustavo Pichorim Boiko

Make ir float point.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

approved

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2013-08-22 17:51:46 +0000
+++ CMakeLists.txt 2013-09-25 22:22:00 +0000
@@ -60,6 +60,7 @@
60pkg_check_modules(NOTIFY REQUIRED libnotify)60pkg_check_modules(NOTIFY REQUIRED libnotify)
61pkg_check_modules(MESSAGING_MENU REQUIRED messaging-menu)61pkg_check_modules(MESSAGING_MENU REQUIRED messaging-menu)
62pkg_check_modules(GSETTINGS REQUIRED gsettings-qt)62pkg_check_modules(GSETTINGS REQUIRED gsettings-qt)
63pkg_check_modules(UserMetrics REQUIRED libusermetricsinput-1)
6364
64# Check if the messaging menu has the message header65# Check if the messaging menu has the message header
65set(CMAKE_REQUIRED_INCLUDES ${MESSAGING_MENU_INCLUDE_DIRS})66set(CMAKE_REQUIRED_INCLUDES ${MESSAGING_MENU_INCLUDE_DIRS})
6667
=== modified file 'debian/control'
--- debian/control 2013-08-29 23:14:15 +0000
+++ debian/control 2013-09-25 22:22:00 +0000
@@ -23,6 +23,7 @@
23 qtdeclarative5-test-plugin (>= 5.0),23 qtdeclarative5-test-plugin (>= 5.0),
24 qtmultimedia5-dev (>= 5.0),24 qtmultimedia5-dev (>= 5.0),
25 qtpim5-dev (>= 5),25 qtpim5-dev (>= 5),
26 libusermetricsinput1-dev,
26Standards-Version: 3.9.427Standards-Version: 3.9.4
27Homepage: https://launchpad.net/telephony-service28Homepage: https://launchpad.net/telephony-service
28# If you aren't a member of ~phablet-team but need to upload packaging changes,29# If you aren't a member of ~phablet-team but need to upload packaging changes,
@@ -41,6 +42,7 @@
41 telepathy-mission-control-5,42 telepathy-mission-control-5,
42 telepathy-ofono,43 telepathy-ofono,
43 ubuntu-sounds,44 ubuntu-sounds,
45 libusermetricsinput1,
44 dconf-cli,46 dconf-cli,
45 ${misc:Depends},47 ${misc:Depends},
46 ${shlibs:Depends},48 ${shlibs:Depends},
4749
=== modified file 'indicator/CMakeLists.txt'
--- indicator/CMakeLists.txt 2013-08-22 17:51:46 +0000
+++ indicator/CMakeLists.txt 2013-09-25 22:22:00 +0000
@@ -2,6 +2,7 @@
2set(qt_SRCS2set(qt_SRCS
3 callchannelobserver.cpp3 callchannelobserver.cpp
4 messagingmenu.cpp4 messagingmenu.cpp
5 metrics.cpp
5 textchannelobserver.cpp6 textchannelobserver.cpp
6 voicemailindicator.cpp7 voicemailindicator.cpp
7 )8 )
@@ -15,6 +16,7 @@
15 ${GSETTINGS_INCLUDE_DIRS}16 ${GSETTINGS_INCLUDE_DIRS}
16 ${CMAKE_SOURCE_DIR}/libtelephonyservice17 ${CMAKE_SOURCE_DIR}/libtelephonyservice
17 ${CMAKE_CURRENT_BINARY_DIR}18 ${CMAKE_CURRENT_BINARY_DIR}
19 ${UserMetrics_INCLUDE_DIRS}
18 )20 )
1921
20link_directories(${MESSAGING_MENU_LIBRARY_DIRS})22link_directories(${MESSAGING_MENU_LIBRARY_DIRS})
@@ -27,6 +29,7 @@
27 ${NOTIFY_LIBRARIES}29 ${NOTIFY_LIBRARIES}
28 ${MESSAGING_MENU_LIBRARIES}30 ${MESSAGING_MENU_LIBRARIES}
29 ${GSETTINGS_LIBRARIES}31 ${GSETTINGS_LIBRARIES}
32 ${UserMetrics_LIBRARIES}
30 telephonyservice33 telephonyservice
31 )34 )
3235
3336
=== modified file 'indicator/callchannelobserver.cpp'
--- indicator/callchannelobserver.cpp 2013-08-22 17:51:46 +0000
+++ indicator/callchannelobserver.cpp 2013-09-25 22:22:00 +0000
@@ -21,6 +21,8 @@
2121
22#include "callchannelobserver.h"22#include "callchannelobserver.h"
23#include "messagingmenu.h"23#include "messagingmenu.h"
24#include "metrics.h"
25#include "telepathyhelper.h"
24#include <TelepathyQt/Contact>26#include <TelepathyQt/Contact>
2527
26CallChannelObserver::CallChannelObserver(QObject *parent) :28CallChannelObserver::CallChannelObserver(QObject *parent) :
@@ -51,6 +53,9 @@
51 return;53 return;
52 }54 }
5355
56 bool incoming = channel->initiatorContact() != TelepathyHelper::instance()->account()->connection()->selfContact();
57 QDateTime activeTimestamp = channel->property("activeTimestamp").toDateTime();
58
54 switch (state) {59 switch (state) {
55 case Tp::CallStateEnded:60 case Tp::CallStateEnded:
56 Q_EMIT callEnded(channel);61 Q_EMIT callEnded(channel);
@@ -58,6 +63,13 @@
58 // FIXME: handle conf call63 // FIXME: handle conf call
59 MessagingMenu::instance()->addCall(channel->targetContact()->id(), QDateTime::currentDateTime());64 MessagingMenu::instance()->addCall(channel->targetContact()->id(), QDateTime::currentDateTime());
60 mChannels.removeOne(channel);65 mChannels.removeOne(channel);
66
67 // update the metrics
68 Metrics::instance()->increment(incoming ? Metrics::IncomingCalls : Metrics::OutgoingCalls);
69 if (activeTimestamp.isValid()) {
70 double minutes = activeTimestamp.secsTo(QDateTime::currentDateTime()) / 60.;
71 Metrics::instance()->increment(Metrics::CallDurations, qRound(minutes * 100) / 100);
72 }
61 break;73 break;
62 case Tp::CallStateActive:74 case Tp::CallStateActive:
63 channel->setProperty("activeTimestamp", QDateTime::currentDateTime());75 channel->setProperty("activeTimestamp", QDateTime::currentDateTime());
6476
=== modified file 'indicator/main.cpp'
--- indicator/main.cpp 2013-08-22 21:51:42 +0000
+++ indicator/main.cpp 2013-09-25 22:22:00 +0000
@@ -24,6 +24,7 @@
2424
25#include "applicationutils.h"25#include "applicationutils.h"
26#include "callchannelobserver.h"26#include "callchannelobserver.h"
27#include "metrics.h"
27#include "telepathyhelper.h"28#include "telepathyhelper.h"
28#include "textchannelobserver.h"29#include "textchannelobserver.h"
29#include "voicemailindicator.h"30#include "voicemailindicator.h"
@@ -69,5 +70,8 @@
69 VoiceMailIndicator voiceMailIndicator;70 VoiceMailIndicator voiceMailIndicator;
70 Q_UNUSED(voiceMailIndicator);71 Q_UNUSED(voiceMailIndicator);
7172
73 // instanciate the metrics helper
74 Metrics::instance();
75
72 return app.exec();76 return app.exec();
73}77}
7478
=== added file 'indicator/metrics.cpp'
--- indicator/metrics.cpp 1970-01-01 00:00:00 +0000
+++ indicator/metrics.cpp 2013-09-25 22:22:00 +0000
@@ -0,0 +1,60 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
6 * Ugo Riboni <ugo.riboni@canonical.com>
7 *
8 * This file is part of telephony-service.
9 *
10 * telephony-service is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 3.
13 *
14 * telephony-service is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#include "metrics.h"
24#include <QDebug>
25
26const QString APP_ID = QString("telephony-service");
27const QString MESSAGES_RECEIVED_STATISTICS_ID = QString("text-messages-received");
28const QString MESSAGES_SENT_STATISTICS_ID = QString("text-messages-sent");
29const QString DIALER_INCOMING_STATISTICS_ID = QString("dialer-calls-incoming");
30const QString DIALER_OUTGOING_STATISTICS_ID = QString("dialer-calls-outgoing");
31const QString DIALER_CALL_DURATION_STATISTICS_ID = QString("dialer-calls-duration");
32
33using namespace UserMetricsInput;
34
35Metrics::Metrics(QObject *parent) :
36 QObject(parent),
37 mMetricManager(MetricManager::getInstance())
38{
39 mMetrics[SentMessages] = mMetricManager->add(MetricParameters(MESSAGES_SENT_STATISTICS_ID).formatString("<b>%1</b> text messages sent today")
40 .emptyDataString("No text messages sent today").textDomain(APP_ID).minimum(0.0));
41 mMetrics[ReceivedMessages] = mMetricManager->add(MetricParameters(MESSAGES_RECEIVED_STATISTICS_ID).formatString("<b>%1</b> text messages received today")
42 .emptyDataString("No text messages received today").textDomain(APP_ID).minimum(0.0));
43 mMetrics[IncomingCalls] = mMetricManager->add(MetricParameters(DIALER_INCOMING_STATISTICS_ID).formatString("<b>%1</b> calls received today")
44 .emptyDataString("No calls received today").textDomain(APP_ID).minimum(0.0));
45 mMetrics[OutgoingCalls] = mMetricManager->add(MetricParameters(DIALER_OUTGOING_STATISTICS_ID).formatString("<b>%1</b> calls made today")
46 .emptyDataString("No calls made today").textDomain(APP_ID).minimum(0.0));
47 mMetrics[CallDurations] = mMetricManager->add(MetricParameters(DIALER_CALL_DURATION_STATISTICS_ID).formatString("Spent <b>%1</b> minutes in calls today")
48 .emptyDataString("No calls made today").textDomain(APP_ID).minimum(0.0));
49}
50
51Metrics *Metrics::instance()
52{
53 static Metrics *self = new Metrics();
54 return self;
55}
56
57void Metrics::increment(Metrics::MetricType metric, double amount)
58{
59 mMetrics[metric]->increment(amount);
60}
061
=== added file 'indicator/metrics.h'
--- indicator/metrics.h 1970-01-01 00:00:00 +0000
+++ indicator/metrics.h 2013-09-25 22:22:00 +0000
@@ -0,0 +1,53 @@
1/*
2 * Copyright (C) 2013 Canonical, Ltd.
3 *
4 * Authors:
5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
6 * Ugo Riboni <ugo.riboni@canonical.com>
7 *
8 * This file is part of telephony-service.
9 *
10 * telephony-service is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 3.
13 *
14 * telephony-service is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23#ifndef METRICS_H
24#define METRICS_H
25
26#include <QObject>
27#include <QMap>
28#include <libusermetricsinput/MetricManager.h>
29
30using namespace UserMetricsInput;
31
32class Metrics : public QObject
33{
34 Q_OBJECT
35public:
36 enum MetricType {
37 SentMessages,
38 ReceivedMessages,
39 IncomingCalls,
40 OutgoingCalls,
41 CallDurations
42 };
43
44 static Metrics *instance();
45 void increment(MetricType metric, double amount = 1.0f);
46
47private:
48 explicit Metrics(QObject *parent = 0);
49 QMap<MetricType, UserMetricsInput::MetricPtr> mMetrics;
50 UserMetricsInput::MetricManagerPtr mMetricManager;
51};
52
53#endif // METRICS_H
054
=== modified file 'indicator/textchannelobserver.cpp'
--- indicator/textchannelobserver.cpp 2013-08-22 17:51:46 +0000
+++ indicator/textchannelobserver.cpp 2013-09-25 22:22:00 +0000
@@ -22,6 +22,7 @@
22#include <libnotify/notify.h>22#include <libnotify/notify.h>
23#include "textchannelobserver.h"23#include "textchannelobserver.h"
24#include "messagingmenu.h"24#include "messagingmenu.h"
25#include "metrics.h"
25#include "chatmanager.h"26#include "chatmanager.h"
26#include "config.h"27#include "config.h"
27#include "contactutils.h"28#include "contactutils.h"
@@ -53,11 +54,6 @@
5354
54void TextChannelObserver::showNotificationForMessage(const Tp::ReceivedMessage &message)55void TextChannelObserver::showNotificationForMessage(const Tp::ReceivedMessage &message)
55{56{
56 // do not place notification items for scrollback messages
57 if (message.isScrollback() || message.isDeliveryReport() || message.isRescued()) {
58 return;
59 }
60
61 Tp::ContactPtr contact = message.sender();57 Tp::ContactPtr contact = message.sender();
6258
63 // try to match the contact info59 // try to match the contact info
@@ -131,12 +127,15 @@
131 connect(textChannel.data(),127 connect(textChannel.data(),
132 SIGNAL(pendingMessageRemoved(const Tp::ReceivedMessage&)),128 SIGNAL(pendingMessageRemoved(const Tp::ReceivedMessage&)),
133 SLOT(onPendingMessageRemoved(const Tp::ReceivedMessage&)));129 SLOT(onPendingMessageRemoved(const Tp::ReceivedMessage&)));
130 connect(textChannel.data(),
131 SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
132 SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
134133
135 mChannels.append(textChannel);134 mChannels.append(textChannel);
136135
137 // notify all the messages from the channel136 // notify all the messages from the channel
138 Q_FOREACH(Tp::ReceivedMessage message, textChannel->messageQueue()) {137 Q_FOREACH(Tp::ReceivedMessage message, textChannel->messageQueue()) {
139 showNotificationForMessage(message);138 onMessageReceived(message);
140 }139 }
141}140}
142141
@@ -148,7 +147,11 @@
148147
149void TextChannelObserver::onMessageReceived(const Tp::ReceivedMessage &message)148void TextChannelObserver::onMessageReceived(const Tp::ReceivedMessage &message)
150{149{
151 showNotificationForMessage(message);150 // do not place notification items for scrollback messages
151 if (!message.isScrollback() && !message.isDeliveryReport() && !message.isRescued()) {
152 showNotificationForMessage(message);
153 Metrics::instance()->increment(Metrics::ReceivedMessages);
154 }
152}155}
153156
154void TextChannelObserver::onPendingMessageRemoved(const Tp::ReceivedMessage &message)157void TextChannelObserver::onPendingMessageRemoved(const Tp::ReceivedMessage &message)
@@ -166,3 +169,8 @@
166 QString messageId(QByteArray::fromHex(encodedMessageId.toUtf8()));169 QString messageId(QByteArray::fromHex(encodedMessageId.toUtf8()));
167 ChatManager::instance()->acknowledgeMessage(phoneNumber, messageId);170 ChatManager::instance()->acknowledgeMessage(phoneNumber, messageId);
168}171}
172
173void TextChannelObserver::onMessageSent(Tp::Message, Tp::MessageSendingFlags, QString)
174{
175 Metrics::instance()->increment(Metrics::SentMessages);
176}
169177
=== modified file 'indicator/textchannelobserver.h'
--- indicator/textchannelobserver.h 2013-08-22 17:51:46 +0000
+++ indicator/textchannelobserver.h 2013-09-25 22:22:00 +0000
@@ -45,6 +45,7 @@
45 void onPendingMessageRemoved(const Tp::ReceivedMessage &message);45 void onPendingMessageRemoved(const Tp::ReceivedMessage &message);
46 void onReplyReceived(const QString &phoneNumber, const QString &reply);46 void onReplyReceived(const QString &phoneNumber, const QString &reply);
47 void onMessageRead(const QString &phoneNumber, const QString &encodedMessageId);47 void onMessageRead(const QString &phoneNumber, const QString &encodedMessageId);
48 void onMessageSent(Tp::Message, Tp::MessageSendingFlags, QString);
4849
49private:50private:
50 QList<Tp::TextChannelPtr> mChannels;51 QList<Tp::TextChannelPtr> mChannels;

Subscribers

People subscribed via source and target branches