Name: statistics-context-provider
Summary: Statistics Context Provider
-Version: 0.5.3
+Version: 0.5.5
Release: 1
Group: System/Libraries
License: Apache-2.0
#include <sys/types.h>
#include <time.h>
-#include <sstream>
#include <Ecore_X.h>
#include <app_manager.h>
* We thus consider the apps being foregrounded at least 3 secs */
#define MIN_VALID_USE_TIME 2
+#define ONE_DAY_IN_SEC 86400
+
static Ecore_Event_Handler *window_property_event_handler = NULL;
ctx::app_use_monitor::app_use_monitor()
- : last_timestamp(0)
+ : last_cleanup_time(0)
+ , last_timestamp(0)
, last_pid(-1)
{
start_logging();
vals << duration;
std::stringstream query;
+ append_cleanup_query(query);
query << "INSERT INTO " << APP_TABLE_USAGE_LOG << " ("
<< cols.str() << ") VALUES (" << vals.str() << ")";
db_manager::execute(0, query.str().c_str(), NULL);
}
+
+void ctx::app_use_monitor::append_cleanup_query(std::stringstream &query)
+{
+ IF_FAIL_VOID(last_timestamp - last_cleanup_time >= ONE_DAY_IN_SEC);
+
+ last_cleanup_time = last_timestamp;
+
+ query << "DELETE FROM " APP_TABLE_USAGE_LOG " WHERE " \
+ STATS_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD << ";";
+}
#define __CONTEXT_APP_USE_MONITOR_H__
#include <string>
+#include <sstream>
#include <Ecore.h>
namespace ctx {
class app_use_monitor {
private:
+ int last_cleanup_time;
int last_timestamp;
int last_pid;
std::string last_app_id;
void verify_used_app(const char *app_id, int duration);
void insert_log(const char *app_id, int duration);
+ void append_cleanup_query(std::stringstream &query);
void on_active_window_changed(int pid);
static Eina_Bool on_window_property_changed(void* data, int type, void* event);
* limitations under the License.
*/
-#include <sstream>
+#include <time.h>
#include <types_internal.h>
#include <db_mgr.h>
#include <system_info.h>
#include "db_handle.h"
#include "media_content_monitor.h"
+#define PLAYCOUNT_RETENTION_PERIOD 259200 /* 1 month in secs */
+#define ONE_DAY_IN_SEC 86400
+
ctx::media_content_monitor::media_content_monitor()
: started(false)
+ , last_cleanup_time(0)
{
db_manager::create_table(0, MEDIA_TABLE_NAME, MEDIA_TABLE_COLUMNS, NULL, NULL);
db_manager::execute(0, MEDIA_PLAYCOUNT_TABLE_SCHEMA, NULL);
cnt);
}
+void ctx::media_content_monitor::append_cleanup_query(std::stringstream &query)
+{
+ int timestamp = static_cast<int>(time(NULL));
+ IF_FAIL_VOID(timestamp - last_cleanup_time >= ONE_DAY_IN_SEC);
+
+ last_cleanup_time = timestamp;
+
+ query <<
+ "DELETE FROM Log_MediaPlayCount WHERE UTC < strftime('%s', 'now') - " << PLAYCOUNT_RETENTION_PERIOD << ";" \
+ "DELETE FROM " MEDIA_TABLE_NAME " WHERE UTC < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD << ";";
+}
+
void ctx::media_content_monitor::update_play_count(const char *uuid, int type, int count)
{
std::stringstream query;
- query << "INSERT OR IGNORE INTO Log_MediaPlayCount" \
+ query <<
+ /* Inserting the media record to the play count table, if not exist */
+ "INSERT OR IGNORE INTO Log_MediaPlayCount" \
" (UUID, MediaType) VALUES ('" << uuid << "'," << type <<");" \
+ /* Updating the play count and getting the diff from the previous count */
"UPDATE Log_MediaPlayCount SET Diff = " << count << " - Count," \
- " Count = " << count << " WHERE UUID = '" << uuid << "';" \
+ " Count = " << count << ", UTC = strftime('%s', 'now')" \
+ " WHERE UUID = '" << uuid << "';";
+ append_cleanup_query(query);
+ query <<
+ /* Checking whether the play count changes */
"SELECT MediaType FROM Log_MediaPlayCount" \
" WHERE UUID = '" << uuid << "' AND Diff > 0;";
#ifndef __CONTEXT_MEDIA_CONTENT_MONITOR_H__
#define __CONTEXT_MEDIA_CONTENT_MONITOR_H__
+#include <sstream>
#include <media_content.h>
#include <db_listener_iface.h>
class media_content_monitor : public db_listener_iface {
private:
bool started;
+ int last_cleanup_time;
+
bool start_monitoring();
void stop_monitoring();
+ void append_cleanup_query(std::stringstream &query);
void update_play_count(const char *uuid, int type, int count);
void insert_log(int media_type);
#define MEDIA_PLAYCOUNT_TABLE_SCHEMA \
"CREATE TABLE IF NOT EXISTS Log_MediaPlayCount" \
" (UUID TEXT NOT NULL PRIMARY KEY, MediaType INTEGER NOT NULL," \
- " Count INTEGER DEFAULT 0, Diff INTEGER DEFAULT 0)"
+ " Count INTEGER DEFAULT 0, Diff INTEGER DEFAULT 0, " \
+ " UTC TIMESTAMP DEFAULT (strftime('%s', 'now')))"
#define CX_MEDIA_TYPE "MediaType"
#ifndef __CONTEXT_STATS_COMMON_TYPES_H__
#define __CONTEXT_STATS_COMMON_TYPES_H__
+#define LOG_RETENTION_PERIOD 7776000 /* 90 days in secs */
+
#define DEFAULT_TIMESPAN 30
#define DEFAULT_LIMIT 10
* limitations under the License.
*/
+#include <sstream>
#include <json.h>
#include <db_mgr.h>
#include <timer_mgr.h>
get_updated_contact_log_list(last_time, &list);
IF_FAIL_VOID(list);
+ remove_expired_log();
insert_contact_log_list(list);
destroy_contact_log_list(list);
}
} while(contacts_list_next(list) == CONTACTS_ERROR_NONE);
}
+
+void ctx::contact_log_aggregator::remove_expired_log()
+{
+ std::stringstream query;
+ query << "DELETE FROM " SOCIAL_TABLE_CONTACT_LOG " WHERE " \
+ STATS_UNIV_TIME " < strftime('%s', 'now') - " << LOG_RETENTION_PERIOD;
+ db_manager::execute(0, query.str().c_str(), NULL);
+}
void get_updated_contact_log_list(int last_time, contacts_list_h *list);
void insert_contact_log_list(contacts_list_h list);
void destroy_contact_log_list(contacts_list_h list);
+ void remove_expired_log();
public:
contact_log_aggregator();