[my-place] Make PlacesDetector pure static. 18/94018/1
authorMarcin Masternak <m.masternak@samsung.com>
Wed, 26 Oct 2016 17:29:07 +0000 (19:29 +0200)
committerMarcin Masternak <m.masternak@samsung.com>
Wed, 26 Oct 2016 17:29:07 +0000 (19:29 +0200)
Change-Id: Iaaef19e42b8af8480acae24f1dd397ae7ac16ed6
Signed-off-by: Marcin Masternak <m.masternak@samsung.com>
src/my-place/place/PlacesDetector.cpp
src/my-place/place/PlacesDetector.h

index 298506d..5ecd6eb 100644 (file)
        PLACE_COLUMN_WIFI_APS " STRING, "\
        PLACE_COLUMN_CREATE_DATE " timestamp"
 
-bool ctx::PlacesDetector::onTimerExpired(int timerId) {
-       _D("");
-       detectPlaces();
-       return true;
-}
-
 void ctx::PlacesDetector::detectPlaces()
 {
        _D("");
+       __dbCreateTable();
        __dbDeletePlaces();
        __dbDeleteOldEntries();
        std::vector<Json> records = __dbGetVisits();
@@ -168,7 +163,7 @@ void ctx::PlacesDetector::__reduceOutliers(ctx::Visits &visits)
                _D("Visits number from %d to %d (to short and to long reduction)", size, newSize);
 }
 
-std::vector<std::shared_ptr<ctx::Place>> ctx::PlacesDetector::__processVisits(ctx::Visits &visits)
+std::vector<std::shared_ptr<ctx::Place>> ctx::PlacesDetector::__processVisits(ctx::Visits &visits, bool testMode)
 {
 #ifdef TIZEN_ENGINEER_MODE
        std::vector<Visits> placesVisits; // TODO: remove from final solution.
@@ -181,7 +176,7 @@ std::vector<std::shared_ptr<ctx::Place>> ctx::PlacesDetector::__processVisits(ct
 
        for (std::shared_ptr<graph::Component> component : *components) {
                // Small places outliers reduction
-               if (!__testMode && component->size() < PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE)
+               if (!testMode && component->size() < PLACES_DETECTOR_MIN_VISITS_PER_BIG_PLACE)
                        continue;
                std::shared_ptr<Visits> merged = std::make_shared<Visits>();
                for (graph::Node i : *component) {
@@ -191,7 +186,7 @@ std::vector<std::shared_ptr<ctx::Place>> ctx::PlacesDetector::__processVisits(ct
                if (place->categId == PLACE_CATEG_ID_NONE)
                        continue;
                newDetectedPlaces.push_back(place);
-               if (!__testMode)
+               if (!testMode)
                        __dbInsertPlace(*place);
 
 #ifdef TIZEN_ENGINEER_MODE
@@ -342,14 +337,6 @@ void ctx::PlacesDetector::__dbDeleteOlderWifiAPsThan(time_t threshold)
        _D("deleting Wifi APs older than: %d, result: %s", threshold, ret ? "SUCCESS" : "FAIL");
 }
 
-ctx::PlacesDetector::PlacesDetector(bool testMode):
-       __testMode(testMode)
-{
-       if (testMode)
-               return;
-       __dbCreateTable();
-}
-
 void ctx::PlacesDetector::__dbCreateTable()
 {
        DatabaseManager dbManager;
@@ -385,7 +372,5 @@ void ctx::PlacesDetector::__dbInsertPlace(const Place &place)
 
 extern "C" SO_EXPORT void detectPlaces()
 {
-       _D("");
-       ctx::PlacesDetector placesDetector;
-       placesDetector.detectPlaces();
+       ctx::PlacesDetector::detectPlaces();
 }
index 81c6a44..ad07355 100644 (file)
 
 #include <vector>
 #include <cstdint>
-#include <ITimerListener.h>
 #include <UserPlacesTypes.h>
 #include <MyPlaceTypes.h>
 #include "Graph.h"
 
 namespace ctx {
 
-       class PlacesDetector : public ITimerListener {
+       class PlacesDetector {
 
        private:
-               bool __testMode;
-
-               double __doubleValueFromJson(Json &row, const char* key);
-               Categs __visitCategsFromJson(Json &row);
-               void __visitLocationFromJson(Json &row, ctx::Visit &visit);
-               Visit __visitFromJson(Json &row);
-               Visits __visitsFromJsons(std::vector<Json>& records);
-
-               std::shared_ptr<graph::Graph> __graphFromVisits(const std::vector<Visit> &visits);
-
-               void __dbCreateTable();
-               void __dbDeletePlaces();
-               void __dbDeleteOldEntries();
-               void __dbDeleteOlderVisitsThan(time_t threshold);
-               void __dbDeleteOlderWifiAPsThan(time_t threshold);
-               std::vector<Json> __dbGetVisits();
-               void __dbInsertPlace(const Place &place);
-
-               std::shared_ptr<Place> __placeFromMergedVisits(Visits &mergedVisits);
-               std::vector<std::shared_ptr<ctx::Place>> __processVisits(Visits &visits);
+               static double __doubleValueFromJson(Json &row, const char* key);
+               static Categs __visitCategsFromJson(Json &row);
+               static void __visitLocationFromJson(Json &row, ctx::Visit &visit);
+               static Visit __visitFromJson(Json &row);
+               static Visits __visitsFromJsons(std::vector<Json>& records);
+
+               static std::shared_ptr<graph::Graph> __graphFromVisits(const std::vector<Visit> &visits);
+
+               static void __dbCreateTable();
+               static void __dbDeletePlaces();
+               static void __dbDeleteOldEntries();
+               static void __dbDeleteOlderVisitsThan(time_t threshold);
+               static void __dbDeleteOlderWifiAPsThan(time_t threshold);
+               static std::vector<Json> __dbGetVisits();
+               static void __dbInsertPlace(const Place &place);
+
+               static std::shared_ptr<Place> __placeFromMergedVisits(Visits &mergedVisits);
+               static std::vector<std::shared_ptr<ctx::Place>> __processVisits(Visits &visits, bool testMode = false);
                static void __mergeLocation(const Visits &mergedVisits, Place &place);
-               std::shared_ptr<graph::Components> __mergeVisits(const std::vector<Visit> &visits);
+               static std::shared_ptr<graph::Components> __mergeVisits(const std::vector<Visit> &visits);
                static void __reduceOutliers(Visits &visits);
                static void __reduceOutliers(std::shared_ptr<graph::Components> &cc);
 
-               bool onTimerExpired(int timerId);
+               PlacesDetector();
 
        public:
-               PlacesDetector(bool testMode = false);
-               void detectPlaces();
+               static void detectPlaces();
 
        };  /* class PlacesDetector */