From 0a123e8367e3363581115a9a974d2ea5e1b00149 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Fri, 27 May 2016 19:31:29 +0200 Subject: [PATCH] [my-place] Move Place print2Stream to DebugUtils Change-Id: I940190b13719fe1bc5283232b5bba9bc75bc326d Signed-off-by: Marcin Masternak --- src/my-place/user_places/debug_utils.cpp | 18 ++++++++++++++++++ src/my-place/user_places/debug_utils.h | 3 +++ src/my-place/user_places/places_detector.cpp | 3 ++- src/my-place/user_places/user_places_params.h | 5 ----- src/my-place/user_places/user_places_types.cpp | 12 ------------ src/my-place/user_places/user_places_types.h | 2 -- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/my-place/user_places/debug_utils.cpp b/src/my-place/user_places/debug_utils.cpp index 48b9cd9..bb03751 100644 --- a/src/my-place/user_places/debug_utils.cpp +++ b/src/my-place/user_places/debug_utils.cpp @@ -16,6 +16,12 @@ #include "debug_utils.h" #include +#include + +/* + * Number of digits after decimal point used in geo coordinates. + */ +#define GEO_LOCATION_PRECISION 7 std::string ctx::DebugUtils::humanReadableDateTime(time_t timestamp, std::string format, size_t size, bool utc) { @@ -37,3 +43,15 @@ std::string ctx::DebugUtils::humanReadableDateTime(time_t timestamp, std::string } return std::string(buffer); } + +void ctx::DebugUtils::printPlace2Stream(const Place &place, std::ostream &out) +{ + out << "PLACE:" << std::endl; + out << "__CATEGORY: " << place.name << std::endl; + if (place.locationValid) { + out << "__LOCATION: lat=" << std::setprecision(GEO_LOCATION_PRECISION + 2) << place.location.latitude; + out << ", lon=" << place.location.longitude << std::setprecision(5) << std::endl; + } + out << "__WIFI:" << place.wifiAps << std::endl; + out << "__CREATE_DATE: " << humanReadableDateTime(place.createDate, "%F %T", 80) << std::endl; +} diff --git a/src/my-place/user_places/debug_utils.h b/src/my-place/user_places/debug_utils.h index 4651dfc..1e0965d 100644 --- a/src/my-place/user_places/debug_utils.h +++ b/src/my-place/user_places/debug_utils.h @@ -19,6 +19,8 @@ #include #include +#include +#include namespace ctx { @@ -26,6 +28,7 @@ namespace ctx { public: static std::string humanReadableDateTime(time_t timestamp, std::string format, size_t size, bool utc = false); + static void printPlace2Stream(const Place &place, std::ostream &out); }; /* class DebugUtils */ diff --git a/src/my-place/user_places/places_detector.cpp b/src/my-place/user_places/places_detector.cpp index a324984..95585d5 100644 --- a/src/my-place/user_places/places_detector.cpp +++ b/src/my-place/user_places/places_detector.cpp @@ -29,6 +29,7 @@ #include #include #include "user_places_params.h" +#include "debug_utils.h" #define __DELETE_PLACES_QUERY "DELETE FROM " PLACE_TABLE @@ -261,7 +262,7 @@ void ctx::PlacesDetector::__processVisits(ctx::Visits &visits) { // Print to file TODO: Only for debug -> remove in final solution std::ofstream out(__USER_PLACES_FILE); for (size_t i = 0; i < newDetectedPlaces.size(); i++) { - newDetectedPlaces[i]->print2Stream(out); + DebugUtils::printPlace2Stream(*newDetectedPlaces[i], out); Visits placeVisits = placesVisits[i]; for (Visit visit : placeVisits) { visit.printShort2Stream(out); diff --git a/src/my-place/user_places/user_places_params.h b/src/my-place/user_places/user_places_params.h index 262e7ed..e08f20c 100644 --- a/src/my-place/user_places/user_places_params.h +++ b/src/my-place/user_places/user_places_params.h @@ -67,11 +67,6 @@ #define PLACES_DETECTOR_RETENTION_DAYS 30 #define PLACES_DETECTOR_RETENTION_SECONDS 24 * 60 * 60 * PLACES_DETECTOR_RETENTION_DAYS -/* - * Number of digits after decimal point used in geo coordinates. - */ -#define GEO_LOCATION_PRECISION 7 - /* * Minimal duration of visit (in minutes) taking into account for place detection */ diff --git a/src/my-place/user_places/user_places_types.cpp b/src/my-place/user_places/user_places_types.cpp index f3faa37..7a9768d 100644 --- a/src/my-place/user_places/user_places_types.cpp +++ b/src/my-place/user_places/user_places_types.cpp @@ -248,15 +248,3 @@ ctx::Interval::Interval(time_t start_, time_t end_) : start(start_), end(end_) { _E("Negative interval, start=%d, end=%d", start_, end_); } } - -void ctx::Place::print2Stream(std::ostream &out) const -{ - out << "PLACE:" << std::endl; - out << "__CATEGORY: " << name << std::endl; - if (locationValid) { - out << "__LOCATION: lat=" << std::setprecision(GEO_LOCATION_PRECISION + 2) << location.latitude; - out << ", lon=" << location.longitude << std::setprecision(5) << std::endl; - } - out << "__WIFI:" << wifiAps << std::endl; - out << "__CREATE_DATE: " << DebugUtils::humanReadableDateTime(createDate, "%F %T", 80) << std::endl; -} diff --git a/src/my-place/user_places/user_places_types.h b/src/my-place/user_places/user_places_types.h index 508e889..7c20d97 100644 --- a/src/my-place/user_places/user_places_types.h +++ b/src/my-place/user_places/user_places_types.h @@ -215,8 +215,6 @@ namespace ctx { std::string wifiAps; // WiFi APs MAC addresses separated by "," time_t createDate; // The last update time of this place - void print2Stream(std::ostream &out) const; - }; /* class Place */ } /* namespace ctx */ -- 2.34.1