MetricManagerAdvanced.cpp

A more advanced metric that updates the history of a metric. Usually this would be a metric from an external data source, e.g. e-mail or Facebook messages.

#include <libusermetricsinput/MetricManager.h>
#include <QtCore/QCoreApplication>
using namespace UserMetricsInput;
int main(int argc, char *argv[]) {
QCoreApplication application(argc, argv);
// We start with a manager object
MetricManagerPtr manager(MetricManager::getInstance());
// You can hold onto this shared pointer for as long as you want
MetricPtr metric(
manager->add(
MetricParameters("twitter").formatString(
"<b>%1</b> tweets received today").emptyDataString(
"No tweets today").textDomain(APP_ID)));
// The update is sent when the update object is destroyed
MetricUpdatePtr update(metric->update());
// Get our data from somewhere
TwitterService twitterService;
// The data is ordered starting from today, going backwards in time
for (const TwitterData &twitterData : twitterService.getTweetCounts()) {
update->addData(twitterData.toDouble());
}
return 0;
}
MetricManager.h
UserMetricsInput::MetricParameters
Definition MetricManager.h:41
UserMetricsInput
The user metrics input library namespace.
Definition Metric.h:29
UserMetricsInput::MetricManagerPtr
QScopedPointer< MetricManager > MetricManagerPtr
Shared pointer for the MetricManager.
Definition MetricManager.h:39
UserMetricsInput::MetricUpdatePtr
QScopedPointer< MetricUpdate > MetricUpdatePtr
Useful to store your instance of MetricUpdate in.
Definition MetricUpdate.h:36
UserMetricsInput::MetricPtr
QSharedPointer< Metric > MetricPtr
Definition Metric.h:36