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>

    usingnamespaceUserMetricsInput;

    intmain(intargc,char*argv[]){
    QCoreApplicationapplication(argc,argv);

    //Westartwithamanagerobject
    MetricManagerPtrmanager(MetricManager::getInstance());

    //Youcanholdontothissharedpointerforaslongasyouwant
    MetricPtrmetric(
    manager->add(
    MetricParameters("twitter").formatString(
    "<b>%1</b>tweetsreceivedtoday").emptyDataString(
    "Notweetstoday").textDomain(APP_ID)));

    //Theupdateissentwhentheupdateobjectisdestroyed
    MetricUpdatePtrupdate(metric->update());

    //Getourdatafromsomewhere
    TwitterServicetwitterService;

    //Thedataisorderedstartingfromtoday,goingbackwardsintime
    for(constTwitterData&twitterData:twitterService.getTweetCounts()){
    update->addData(twitterData.toDouble());
    }

    return0;
    }