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
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2013-08-22 17:51:46 +0000
3+++ CMakeLists.txt 2013-09-25 22:22:00 +0000
4@@ -60,6 +60,7 @@
5 pkg_check_modules(NOTIFY REQUIRED libnotify)
6 pkg_check_modules(MESSAGING_MENU REQUIRED messaging-menu)
7 pkg_check_modules(GSETTINGS REQUIRED gsettings-qt)
8+pkg_check_modules(UserMetrics REQUIRED libusermetricsinput-1)
9
10 # Check if the messaging menu has the message header
11 set(CMAKE_REQUIRED_INCLUDES ${MESSAGING_MENU_INCLUDE_DIRS})
12
13=== modified file 'debian/control'
14--- debian/control 2013-08-29 23:14:15 +0000
15+++ debian/control 2013-09-25 22:22:00 +0000
16@@ -23,6 +23,7 @@
17 qtdeclarative5-test-plugin (>= 5.0),
18 qtmultimedia5-dev (>= 5.0),
19 qtpim5-dev (>= 5),
20+ libusermetricsinput1-dev,
21 Standards-Version: 3.9.4
22 Homepage: https://launchpad.net/telephony-service
23 # If you aren't a member of ~phablet-team but need to upload packaging changes,
24@@ -41,6 +42,7 @@
25 telepathy-mission-control-5,
26 telepathy-ofono,
27 ubuntu-sounds,
28+ libusermetricsinput1,
29 dconf-cli,
30 ${misc:Depends},
31 ${shlibs:Depends},
32
33=== modified file 'indicator/CMakeLists.txt'
34--- indicator/CMakeLists.txt 2013-08-22 17:51:46 +0000
35+++ indicator/CMakeLists.txt 2013-09-25 22:22:00 +0000
36@@ -2,6 +2,7 @@
37 set(qt_SRCS
38 callchannelobserver.cpp
39 messagingmenu.cpp
40+ metrics.cpp
41 textchannelobserver.cpp
42 voicemailindicator.cpp
43 )
44@@ -15,6 +16,7 @@
45 ${GSETTINGS_INCLUDE_DIRS}
46 ${CMAKE_SOURCE_DIR}/libtelephonyservice
47 ${CMAKE_CURRENT_BINARY_DIR}
48+ ${UserMetrics_INCLUDE_DIRS}
49 )
50
51 link_directories(${MESSAGING_MENU_LIBRARY_DIRS})
52@@ -27,6 +29,7 @@
53 ${NOTIFY_LIBRARIES}
54 ${MESSAGING_MENU_LIBRARIES}
55 ${GSETTINGS_LIBRARIES}
56+ ${UserMetrics_LIBRARIES}
57 telephonyservice
58 )
59
60
61=== modified file 'indicator/callchannelobserver.cpp'
62--- indicator/callchannelobserver.cpp 2013-08-22 17:51:46 +0000
63+++ indicator/callchannelobserver.cpp 2013-09-25 22:22:00 +0000
64@@ -21,6 +21,8 @@
65
66 #include "callchannelobserver.h"
67 #include "messagingmenu.h"
68+#include "metrics.h"
69+#include "telepathyhelper.h"
70 #include <TelepathyQt/Contact>
71
72 CallChannelObserver::CallChannelObserver(QObject *parent) :
73@@ -51,6 +53,9 @@
74 return;
75 }
76
77+ bool incoming = channel->initiatorContact() != TelepathyHelper::instance()->account()->connection()->selfContact();
78+ QDateTime activeTimestamp = channel->property("activeTimestamp").toDateTime();
79+
80 switch (state) {
81 case Tp::CallStateEnded:
82 Q_EMIT callEnded(channel);
83@@ -58,6 +63,13 @@
84 // FIXME: handle conf call
85 MessagingMenu::instance()->addCall(channel->targetContact()->id(), QDateTime::currentDateTime());
86 mChannels.removeOne(channel);
87+
88+ // update the metrics
89+ Metrics::instance()->increment(incoming ? Metrics::IncomingCalls : Metrics::OutgoingCalls);
90+ if (activeTimestamp.isValid()) {
91+ double minutes = activeTimestamp.secsTo(QDateTime::currentDateTime()) / 60.;
92+ Metrics::instance()->increment(Metrics::CallDurations, qRound(minutes * 100) / 100);
93+ }
94 break;
95 case Tp::CallStateActive:
96 channel->setProperty("activeTimestamp", QDateTime::currentDateTime());
97
98=== modified file 'indicator/main.cpp'
99--- indicator/main.cpp 2013-08-22 21:51:42 +0000
100+++ indicator/main.cpp 2013-09-25 22:22:00 +0000
101@@ -24,6 +24,7 @@
102
103 #include "applicationutils.h"
104 #include "callchannelobserver.h"
105+#include "metrics.h"
106 #include "telepathyhelper.h"
107 #include "textchannelobserver.h"
108 #include "voicemailindicator.h"
109@@ -69,5 +70,8 @@
110 VoiceMailIndicator voiceMailIndicator;
111 Q_UNUSED(voiceMailIndicator);
112
113+ // instanciate the metrics helper
114+ Metrics::instance();
115+
116 return app.exec();
117 }
118
119=== added file 'indicator/metrics.cpp'
120--- indicator/metrics.cpp 1970-01-01 00:00:00 +0000
121+++ indicator/metrics.cpp 2013-09-25 22:22:00 +0000
122@@ -0,0 +1,60 @@
123+/*
124+ * Copyright (C) 2013 Canonical, Ltd.
125+ *
126+ * Authors:
127+ * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
128+ * Ugo Riboni <ugo.riboni@canonical.com>
129+ *
130+ * This file is part of telephony-service.
131+ *
132+ * telephony-service is free software; you can redistribute it and/or modify
133+ * it under the terms of the GNU General Public License as published by
134+ * the Free Software Foundation; version 3.
135+ *
136+ * telephony-service is distributed in the hope that it will be useful,
137+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
138+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
139+ * GNU General Public License for more details.
140+ *
141+ * You should have received a copy of the GNU General Public License
142+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
143+ */
144+
145+#include "metrics.h"
146+#include <QDebug>
147+
148+const QString APP_ID = QString("telephony-service");
149+const QString MESSAGES_RECEIVED_STATISTICS_ID = QString("text-messages-received");
150+const QString MESSAGES_SENT_STATISTICS_ID = QString("text-messages-sent");
151+const QString DIALER_INCOMING_STATISTICS_ID = QString("dialer-calls-incoming");
152+const QString DIALER_OUTGOING_STATISTICS_ID = QString("dialer-calls-outgoing");
153+const QString DIALER_CALL_DURATION_STATISTICS_ID = QString("dialer-calls-duration");
154+
155+using namespace UserMetricsInput;
156+
157+Metrics::Metrics(QObject *parent) :
158+ QObject(parent),
159+ mMetricManager(MetricManager::getInstance())
160+{
161+ mMetrics[SentMessages] = mMetricManager->add(MetricParameters(MESSAGES_SENT_STATISTICS_ID).formatString("<b>%1</b> text messages sent today")
162+ .emptyDataString("No text messages sent today").textDomain(APP_ID).minimum(0.0));
163+ mMetrics[ReceivedMessages] = mMetricManager->add(MetricParameters(MESSAGES_RECEIVED_STATISTICS_ID).formatString("<b>%1</b> text messages received today")
164+ .emptyDataString("No text messages received today").textDomain(APP_ID).minimum(0.0));
165+ mMetrics[IncomingCalls] = mMetricManager->add(MetricParameters(DIALER_INCOMING_STATISTICS_ID).formatString("<b>%1</b> calls received today")
166+ .emptyDataString("No calls received today").textDomain(APP_ID).minimum(0.0));
167+ mMetrics[OutgoingCalls] = mMetricManager->add(MetricParameters(DIALER_OUTGOING_STATISTICS_ID).formatString("<b>%1</b> calls made today")
168+ .emptyDataString("No calls made today").textDomain(APP_ID).minimum(0.0));
169+ mMetrics[CallDurations] = mMetricManager->add(MetricParameters(DIALER_CALL_DURATION_STATISTICS_ID).formatString("Spent <b>%1</b> minutes in calls today")
170+ .emptyDataString("No calls made today").textDomain(APP_ID).minimum(0.0));
171+}
172+
173+Metrics *Metrics::instance()
174+{
175+ static Metrics *self = new Metrics();
176+ return self;
177+}
178+
179+void Metrics::increment(Metrics::MetricType metric, double amount)
180+{
181+ mMetrics[metric]->increment(amount);
182+}
183
184=== added file 'indicator/metrics.h'
185--- indicator/metrics.h 1970-01-01 00:00:00 +0000
186+++ indicator/metrics.h 2013-09-25 22:22:00 +0000
187@@ -0,0 +1,53 @@
188+/*
189+ * Copyright (C) 2013 Canonical, Ltd.
190+ *
191+ * Authors:
192+ * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
193+ * Ugo Riboni <ugo.riboni@canonical.com>
194+ *
195+ * This file is part of telephony-service.
196+ *
197+ * telephony-service is free software; you can redistribute it and/or modify
198+ * it under the terms of the GNU General Public License as published by
199+ * the Free Software Foundation; version 3.
200+ *
201+ * telephony-service is distributed in the hope that it will be useful,
202+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
203+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
204+ * GNU General Public License for more details.
205+ *
206+ * You should have received a copy of the GNU General Public License
207+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
208+ */
209+
210+#ifndef METRICS_H
211+#define METRICS_H
212+
213+#include <QObject>
214+#include <QMap>
215+#include <libusermetricsinput/MetricManager.h>
216+
217+using namespace UserMetricsInput;
218+
219+class Metrics : public QObject
220+{
221+ Q_OBJECT
222+public:
223+ enum MetricType {
224+ SentMessages,
225+ ReceivedMessages,
226+ IncomingCalls,
227+ OutgoingCalls,
228+ CallDurations
229+ };
230+
231+ static Metrics *instance();
232+ void increment(MetricType metric, double amount = 1.0f);
233+
234+private:
235+ explicit Metrics(QObject *parent = 0);
236+ QMap<MetricType, UserMetricsInput::MetricPtr> mMetrics;
237+ UserMetricsInput::MetricManagerPtr mMetricManager;
238+};
239+
240+#endif // METRICS_H
241
242=== modified file 'indicator/textchannelobserver.cpp'
243--- indicator/textchannelobserver.cpp 2013-08-22 17:51:46 +0000
244+++ indicator/textchannelobserver.cpp 2013-09-25 22:22:00 +0000
245@@ -22,6 +22,7 @@
246 #include <libnotify/notify.h>
247 #include "textchannelobserver.h"
248 #include "messagingmenu.h"
249+#include "metrics.h"
250 #include "chatmanager.h"
251 #include "config.h"
252 #include "contactutils.h"
253@@ -53,11 +54,6 @@
254
255 void TextChannelObserver::showNotificationForMessage(const Tp::ReceivedMessage &message)
256 {
257- // do not place notification items for scrollback messages
258- if (message.isScrollback() || message.isDeliveryReport() || message.isRescued()) {
259- return;
260- }
261-
262 Tp::ContactPtr contact = message.sender();
263
264 // try to match the contact info
265@@ -131,12 +127,15 @@
266 connect(textChannel.data(),
267 SIGNAL(pendingMessageRemoved(const Tp::ReceivedMessage&)),
268 SLOT(onPendingMessageRemoved(const Tp::ReceivedMessage&)));
269+ connect(textChannel.data(),
270+ SIGNAL(messageSent(Tp::Message,Tp::MessageSendingFlags,QString)),
271+ SLOT(onMessageSent(Tp::Message,Tp::MessageSendingFlags,QString)));
272
273 mChannels.append(textChannel);
274
275 // notify all the messages from the channel
276 Q_FOREACH(Tp::ReceivedMessage message, textChannel->messageQueue()) {
277- showNotificationForMessage(message);
278+ onMessageReceived(message);
279 }
280 }
281
282@@ -148,7 +147,11 @@
283
284 void TextChannelObserver::onMessageReceived(const Tp::ReceivedMessage &message)
285 {
286- showNotificationForMessage(message);
287+ // do not place notification items for scrollback messages
288+ if (!message.isScrollback() && !message.isDeliveryReport() && !message.isRescued()) {
289+ showNotificationForMessage(message);
290+ Metrics::instance()->increment(Metrics::ReceivedMessages);
291+ }
292 }
293
294 void TextChannelObserver::onPendingMessageRemoved(const Tp::ReceivedMessage &message)
295@@ -166,3 +169,8 @@
296 QString messageId(QByteArray::fromHex(encodedMessageId.toUtf8()));
297 ChatManager::instance()->acknowledgeMessage(phoneNumber, messageId);
298 }
299+
300+void TextChannelObserver::onMessageSent(Tp::Message, Tp::MessageSendingFlags, QString)
301+{
302+ Metrics::instance()->increment(Metrics::SentMessages);
303+}
304
305=== modified file 'indicator/textchannelobserver.h'
306--- indicator/textchannelobserver.h 2013-08-22 17:51:46 +0000
307+++ indicator/textchannelobserver.h 2013-09-25 22:22:00 +0000
308@@ -45,6 +45,7 @@
309 void onPendingMessageRemoved(const Tp::ReceivedMessage &message);
310 void onReplyReceived(const QString &phoneNumber, const QString &reply);
311 void onMessageRead(const QString &phoneNumber, const QString &encodedMessageId);
312+ void onMessageSent(Tp::Message, Tp::MessageSendingFlags, QString);
313
314 private:
315 QList<Tp::TextChannelPtr> mChannels;

Subscribers

People subscribed via source and target branches