From d50e2afaf5985a9d1faaf89370080ef587fc9b88 Mon Sep 17 00:00:00 2001 From: Marcin Masternak Date: Tue, 31 May 2016 16:19:44 +0200 Subject: [PATCH] [my-place][places_detector] Refactor getting place from Json. Change-Id: Ie67cf431797e68313348407fb03f9cd149d702de Signed-off-by: Marcin Masternak --- src/my-place/user_places/places_detector.cpp | 49 ++++++++++++-------- src/my-place/user_places/places_detector.h | 3 ++ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/my-place/user_places/places_detector.cpp b/src/my-place/user_places/places_detector.cpp index a85a557..11ddbb2 100644 --- a/src/my-place/user_places/places_detector.cpp +++ b/src/my-place/user_places/places_detector.cpp @@ -160,31 +160,40 @@ ctx::Visits ctx::PlacesDetector::__visitsFromJsons(std::vector& records) std::shared_ptr ctx::PlacesDetector::__placeFromJson(Json &row) { std::shared_ptr place = std::make_shared(); - { // category - int categId; - row.get(NULL, PLACE_COLUMN_CATEG_ID, &categId); - // This is due to the fact the JSON module API interface doesn't handle enum - place->categId = static_cast(categId); - } + __placeCategoryFromJson(row, *place); row.get(NULL, PLACE_COLUMN_NAME, &(place->name)); row.get(NULL, PLACE_COLUMN_WIFI_APS, &(place->wifiAps)); - { // location - int locationValidInt; - row.get(NULL, PLACE_COLUMN_LOCATION_VALID, &locationValidInt); - place->locationValid = (bool) locationValidInt; - row.get(NULL, PLACE_COLUMN_LOCATION_LATITUDE, &(place->location.latitude)); - row.get(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, &(place->location.longitude)); - } - { // createDate - int createDate; - row.get(NULL, PLACE_COLUMN_CREATE_DATE, &(createDate)); - // This is due to the fact the JSON module API interface doesn't handle time_t - place->createDate = static_cast(createDate); - } - _D("db_result: categId: %d; place: name: %s; wifiAps: %s; locationValid: %d; latitude: %lf, longitude: %lf, createDate: %d", place->categId, place->name.c_str(), place->wifiAps.c_str(), place->locationValid, place->location.latitude, place->location.longitude, place->createDate); + __placeLocationFromJson(row, *place); + __placeCreateDateFromJson(row, *place); + _D("db_result: categId: %d; place: name: %s; locationValid: %d; latitude: %lf, longitude: %lf, createDate: %d", place->categId, place->name.c_str(), place->locationValid, place->location.latitude, place->location.longitude, place->createDate); return place; } +void ctx::PlacesDetector::__placeCategoryFromJson(Json &row, ctx::Place &place) +{ + int categId; + row.get(NULL, PLACE_COLUMN_CATEG_ID, &categId); + // This is due to the fact the JSON module API interface doesn't handle enum + place.categId = static_cast(categId); +} + +void ctx::PlacesDetector::__placeLocationFromJson(Json &row, ctx::Place &place) +{ + int locationValidInt; + row.get(NULL, PLACE_COLUMN_LOCATION_VALID, &locationValidInt); + place.locationValid = (bool) locationValidInt; + row.get(NULL, PLACE_COLUMN_LOCATION_LATITUDE, &(place.location.latitude)); + row.get(NULL, PLACE_COLUMN_LOCATION_LONGITUDE, &(place.location.longitude)); +} + +void ctx::PlacesDetector::__placeCreateDateFromJson(Json &row, ctx::Place &place) +{ + int createDate; + row.get(NULL, PLACE_COLUMN_CREATE_DATE, &(createDate)); + // This is due to the fact the JSON module API interface doesn't handle time_t + place.createDate = static_cast(createDate); +} + std::vector> ctx::PlacesDetector::__placesFromJsons(std::vector& records) { std::vector> places; diff --git a/src/my-place/user_places/places_detector.h b/src/my-place/user_places/places_detector.h index 0cf6885..492fb23 100644 --- a/src/my-place/user_places/places_detector.h +++ b/src/my-place/user_places/places_detector.h @@ -38,6 +38,9 @@ namespace ctx { Visit __visitFromJson(Json &row); Visits __visitsFromJsons(std::vector& records); std::shared_ptr __placeFromJson(Json &row); + void __placeCategoryFromJson(Json &row, ctx::Place &place); + void __placeLocationFromJson(Json &row, ctx::Place &place); + void __placeCreateDateFromJson(Json &row, ctx::Place &place); std::vector> __placesFromJsons(std::vector& records); std::shared_ptr __graphFromVisits(const std::vector &visits); -- 2.34.1