Merge lp:~schwann/camera-app/camera-update-today-user-metric into lp:camera-app
- camera-update-today-user-metric
- Merge into trunk
Status: | Rejected |
---|---|
Rejected by: | Florian Boucault |
Proposed branch: | lp:~schwann/camera-app/camera-update-today-user-metric |
Merge into: | lp:camera-app |
Diff against target: |
255 lines (+133/-10) 5 files modified
CMakeLists.txt (+5/-0) camera-app.qml (+9/-0) cameraapplication.cpp (+107/-10) cameraapplication.h (+11/-0) debian/control (+1/-0) |
To merge this branch: | bzr merge lp:~schwann/camera-app/camera-update-today-user-metric |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Florian Boucault (community) | Disapprove | ||
PS Jenkins bot | continuous-integration | Needs Fixing | |
Pete Woods (community) | Approve | ||
Review via email: mp+173135@code.launchpad.net |
Commit message
Update user metric for every captured photo/video
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
UNSTABLE: http://
SUCCESS: http://
deb: http://
UNSTABLE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Pete Woods (pete-woods) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:164
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Autolanding.
More details in the following jenkins job:
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Florian Boucault (fboucault) wrote : | # |
Already implemented in QML.
Unmerged revisions
Preview Diff
1 | === modified file 'CMakeLists.txt' |
2 | --- CMakeLists.txt 2013-06-27 00:31:29 +0000 |
3 | +++ CMakeLists.txt 2013-07-05 06:34:27 +0000 |
4 | @@ -12,6 +12,9 @@ |
5 | find_package(Qt5Quick) |
6 | find_package(Qt5Multimedia) |
7 | |
8 | +find_package(PkgConfig REQUIRED) |
9 | +pkg_check_modules(UserMetrics REQUIRED libusermetricsinput-1) |
10 | + |
11 | # Standard install paths |
12 | include(GNUInstallDirs) |
13 | |
14 | @@ -25,6 +28,7 @@ |
15 | ${Qt5Core_INCLUDE_DIRS} |
16 | ${Qt5Quick_INCLUDE_DIRS} |
17 | ${Qt5Multimedia_INCLUDE_DIRS} |
18 | + ${UserMetrics_INCLUDE_DIRS} |
19 | ) |
20 | |
21 | set(CAMERA_APP camera-app) |
22 | @@ -45,6 +49,7 @@ |
23 | ${Qt5Core_LIBRARIES} |
24 | ${Qt5Quick_LIBRARIES} |
25 | ${Qt5Multimedia_LIBRARIES} |
26 | + ${UserMetrics_LIBRARIES} |
27 | ) |
28 | |
29 | install(TARGETS ${CAMERA_APP} |
30 | |
31 | === modified file 'camera-app.qml' |
32 | --- camera-app.qml 2013-06-19 08:43:30 +0000 |
33 | +++ camera-app.qml 2013-07-05 06:34:27 +0000 |
34 | @@ -94,9 +94,18 @@ |
35 | snapshot.source = preview; |
36 | } |
37 | onImageSaved: { |
38 | + application.increaseTodaysPhotoMetrics(); |
39 | console.log("Picture saved as " + path) |
40 | } |
41 | } |
42 | + |
43 | + videoRecorder { |
44 | + onRecorderStateChanged: { |
45 | + if (videoRecorder.recorderState === CameraRecorder.StoppedState) |
46 | + application.increaseTodaysVideoMetrics() |
47 | + } |
48 | + |
49 | + } |
50 | } |
51 | |
52 | Connections { |
53 | |
54 | === modified file 'cameraapplication.cpp' |
55 | --- cameraapplication.cpp 2013-03-27 12:08:07 +0000 |
56 | +++ cameraapplication.cpp 2013-07-05 06:34:27 +0000 |
57 | @@ -24,15 +24,25 @@ |
58 | #include <QtCore/QDebug> |
59 | #include <QtCore/QStringList> |
60 | #include <QtCore/QLibrary> |
61 | +#include <QDate> |
62 | #include <QQmlContext> |
63 | #include <QQmlEngine> |
64 | -#include <QtQuick/QQuickItem> |
65 | -#include <QtDBus/QDBusInterface> |
66 | -#include <QtDBus/QDBusReply> |
67 | -#include <QtDBus/QDBusConnectionInterface> |
68 | #include <QScreen> |
69 | +#include <QSettings> |
70 | + |
71 | +#include <libusermetricsinput/MetricManager.h> |
72 | + |
73 | #include "config.h" |
74 | |
75 | +const QString APP_ID = QString("camera-app"); |
76 | +const int MAX_STATISTICS_DAYS = 10; |
77 | +const QString PHOTO_STATISTICS_ID = QString("camera-photos"); |
78 | +const QString VIDEO_STATISTICS_ID = QString("camera-videos"); |
79 | +const QString PHOTO_KEY_SUFFIX = QString("Photos"); |
80 | +const QString VIDEO_KEY_SUFFIX = QString("Videos"); |
81 | + |
82 | +using namespace UserMetricsInput; |
83 | + |
84 | static void printUsage(const QStringList& arguments) |
85 | { |
86 | qDebug() << "usage:" |
87 | @@ -41,7 +51,7 @@ |
88 | } |
89 | |
90 | CameraApplication::CameraApplication(int &argc, char **argv) |
91 | - : QGuiApplication(argc, argv), m_view(0) |
92 | + : QGuiApplication(argc, argv),m_view(0), m_settings(0) |
93 | { |
94 | |
95 | // The testability driver is only loaded by QApplication but not by QGuiApplication. |
96 | @@ -60,6 +70,17 @@ |
97 | qCritical("Library qttestability load failed!"); |
98 | } |
99 | } |
100 | + |
101 | + m_settings = new QSettings("ubuntu", APP_ID, this); |
102 | +} |
103 | + |
104 | +CameraApplication::~CameraApplication() |
105 | +{ |
106 | + clearOldStatictics(); |
107 | + |
108 | + if (m_view) { |
109 | + delete m_view; |
110 | + } |
111 | } |
112 | |
113 | bool CameraApplication::setup() |
114 | @@ -70,7 +91,6 @@ |
115 | Qt::InvertedLandscapeOrientation); |
116 | |
117 | m_view = new QQuickView(); |
118 | - QObject::connect(m_view, SIGNAL(statusChanged(QDeclarativeView::Status)), this, SLOT(onViewStatusChanged(QDeclarativeView::Status))); |
119 | m_view->setResizeMode(QQuickView::SizeRootObjectToView); |
120 | m_view->setTitle("Camera"); |
121 | m_view->rootContext()->setContextProperty("application", this); |
122 | @@ -83,9 +103,86 @@ |
123 | return true; |
124 | } |
125 | |
126 | -CameraApplication::~CameraApplication() |
127 | -{ |
128 | - if (m_view) { |
129 | - delete m_view; |
130 | +/*! |
131 | + * \brief CameraApplication::increaseTodaysPhotoMetrics increase the number of |
132 | + * Photos taken pictures today. Or reset it to 1 if it's a new day. |
133 | + * And update the data in the MetricManager |
134 | + */ |
135 | +void CameraApplication::increaseTodaysPhotoMetrics() |
136 | +{ |
137 | + MetricManagerPtr manager(MetricManager::getInstance()); |
138 | + MetricPtr metric(manager->add(PHOTO_STATISTICS_ID, "<b>%1</b> photos captured today", |
139 | + "No photo captured today", APP_ID)); |
140 | + MetricUpdatePtr update(metric->update()); |
141 | + |
142 | + QString todayPhotoKey = keyForToday(PHOTO_KEY_SUFFIX); |
143 | + int todaysPhotoNumber = m_settings->value(todayPhotoKey, 0).toInt(); |
144 | + ++todaysPhotoNumber; |
145 | + m_settings->setValue(todayPhotoKey, todaysPhotoNumber); |
146 | + |
147 | + update->addData(todaysPhotoNumber); |
148 | +} |
149 | + |
150 | +/*! |
151 | + * \brief CameraApplication::increaseTodaysVideoMetrics increase the number of |
152 | + * Videos taken pictures today. Or reset it to 1 if it's a new day. |
153 | + * And update the data in the MetricManager |
154 | + */ |
155 | +void CameraApplication::increaseTodaysVideoMetrics() |
156 | +{ |
157 | + MetricManagerPtr manager(MetricManager::getInstance()); |
158 | + MetricPtr metric(manager->add(VIDEO_STATISTICS_ID, "<b>%1</b> photos captured today", |
159 | + "No photo captured today", APP_ID)); |
160 | + MetricUpdatePtr update(metric->update()); |
161 | + |
162 | + QString todayVideoKey = keyForToday(VIDEO_KEY_SUFFIX); |
163 | + int todaysVideoNumber = m_settings->value(todayVideoKey, 0).toInt(); |
164 | + ++todaysVideoNumber; |
165 | + m_settings->setValue(todayVideoKey, todaysVideoNumber); |
166 | + |
167 | + update->addData(todaysVideoNumber); |
168 | +} |
169 | + |
170 | +/*! |
171 | + * \brief CameraApplication::clearOldStatictics removes all statistics that is |
172 | + * older then some days |
173 | + */ |
174 | +void CameraApplication::clearOldStatictics() |
175 | +{ |
176 | + QStringList allKeys = m_settings->allKeys(); |
177 | + foreach (const QString& key, allKeys) { |
178 | + if (key.endsWith(PHOTO_KEY_SUFFIX) || key.endsWith(VIDEO_KEY_SUFFIX)) { |
179 | + QDate date = dateOfKey(key); |
180 | + if (date.isValid() && date.daysTo(QDate::currentDate()) > MAX_STATISTICS_DAYS) { |
181 | + m_settings->remove(key); |
182 | + } |
183 | + } |
184 | } |
185 | } |
186 | + |
187 | +/*! |
188 | + * \brief CameraApplication::keyForToday generates the key for the statistics |
189 | + * for today, for given medium (use Photos or Videos) |
190 | + * \param medium |
191 | + * \return key conaining the current day and the medium (photo/video) |
192 | + */ |
193 | +QString CameraApplication::keyForToday(const QString &medium) |
194 | +{ |
195 | + if (medium != PHOTO_KEY_SUFFIX && medium != VIDEO_KEY_SUFFIX) |
196 | + return QString(); |
197 | + |
198 | + return QDate::currentDate().toString(Qt::ISODate) + medium; |
199 | +} |
200 | + |
201 | +/*! |
202 | + * \brief CameraApplication::dateOfKey returns the date of the key, used for |
203 | + * storing the number of photos/videos captured at one day |
204 | + * \param key |
205 | + * \return date of the key. Or an invalid date if the key is not a statistics key |
206 | + */ |
207 | +QDate CameraApplication::dateOfKey(const QString &key) const |
208 | +{ |
209 | + QString dateString = key; |
210 | + dateString.chop(6); |
211 | + return QDate::fromString(dateString, Qt::ISODate); |
212 | +} |
213 | |
214 | === modified file 'cameraapplication.h' |
215 | --- cameraapplication.h 2012-10-04 10:04:57 +0000 |
216 | +++ cameraapplication.h 2013-07-05 06:34:27 +0000 |
217 | @@ -23,6 +23,9 @@ |
218 | #include <QtQuick/QQuickView> |
219 | #include <QGuiApplication> |
220 | |
221 | +class QDate; |
222 | +class QSettings; |
223 | + |
224 | class CameraApplication : public QGuiApplication |
225 | { |
226 | Q_OBJECT |
227 | @@ -33,8 +36,16 @@ |
228 | |
229 | bool setup(); |
230 | |
231 | + Q_INVOKABLE void increaseTodaysPhotoMetrics(); |
232 | + Q_INVOKABLE void increaseTodaysVideoMetrics(); |
233 | + |
234 | private: |
235 | + void clearOldStatictics(); |
236 | + QDate dateOfKey(const QString& key) const; |
237 | + QString keyForToday(const QString& medium); |
238 | + |
239 | QQuickView *m_view; |
240 | + QSettings *m_settings; |
241 | }; |
242 | |
243 | #endif // CAMERAAPPLICATION_H |
244 | |
245 | === modified file 'debian/control' |
246 | --- debian/control 2013-06-13 22:36:48 +0000 |
247 | +++ debian/control 2013-07-05 06:34:27 +0000 |
248 | @@ -15,6 +15,7 @@ |
249 | qtdeclarative5-test-plugin, |
250 | qtdeclarative5-ubuntu-ui-toolkit-plugin, |
251 | qtmultimedia5-dev, |
252 | + libusermetricsinput1-dev, |
253 | gettext, |
254 | dh-translations, |
255 | Standards-Version: 3.9.4 |
PASSED: Continuous integration, rev:164 jenkins. qa.ubuntu. com/job/ camera- app-ci/ 67/ jenkins. qa.ubuntu. com/job/ camera- app-saucy- amd64-ci/ 20 jenkins. qa.ubuntu. com/job/ camera- app-saucy- armhf-ci/ 20 jenkins. qa.ubuntu. com/job/ camera- app-saucy- armhf-ci/ 20/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ camera- app-saucy- i386-ci/ 20 jenkins. qa.ubuntu. com/job/ generic- mediumtests- saucy/737 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- saucy/739 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- saucy/739/ artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ generic- mediumtests- runner- saucy/662
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins: 8080/job/ camera- app-ci/ 67/rebuild
http://