Пример #1
0
static void insert_cap_success(CapStatistics *stats) {
	PurpleAccount *account = purple_buddy_get_account(stats->buddy);
	const gchar *buddy_name = purple_buddy_get_name(stats->buddy);
	const gchar *protocol_id = purple_account_get_protocol_id(account);
	const gchar *account_id = purple_account_get_username(account);
	const gchar *status_id = (stats->last_message_status_id) ?
		stats->last_message_status_id :
		purple_status_get_id(get_status_for(stats->buddy));
	struct tm *current_time;
	int minute;

	if(stats->last_message == -1) {
		time_t now = time(NULL);
		current_time = localtime(&now);
	} else {
		current_time = localtime(&stats->last_message);
	}
	minute = current_time->tm_min + current_time->tm_hour * 60;

	insert_cap_msg_count_success(buddy_name, account_id, protocol_id, minute);

	insert_cap_status_count_success(buddy_name, account_id, protocol_id, status_id);

	stats->last_message = -1;
	stats->last_message_status_id = NULL;
}
Пример #2
0
static void insert_cap_failure(CapStatistics *stats) {
	gchar *buddy_name = stats->buddy->name;
	const gchar *protocol_id = purple_account_get_protocol_id(stats->buddy->account);
	const gchar *account_id = purple_account_get_username(stats->buddy->account);
	const gchar *status_id = (stats->last_message_status_id) ?
		stats->last_message_status_id :
		purple_status_get_id(get_status_for(stats->buddy));
	struct tm *current_time = localtime(&stats->last_message);
	int minute = current_time->tm_min + current_time->tm_hour * 60;

	insert_cap_msg_count_failed(buddy_name, account_id, protocol_id, minute);

	insert_cap_status_count_failed(buddy_name, account_id, protocol_id, status_id);

	stats->last_message = -1;
	stats->last_message_status_id = NULL;
}
Пример #3
0
/* sent-im-msg */
static void sent_im_msg(PurpleAccount *account, const char *receiver, const char *message) {
	PurpleBuddy *buddy;
	guint interval, words;
	CapStatistics *stats = NULL;

	buddy = purple_find_buddy(account, receiver);

	if (buddy == NULL)
		return;

	interval = purple_prefs_get_int("/plugins/gtk/cap/max_msg_difference") * 60;
	words = word_count(message);

	stats = get_stats_for(buddy);

	insert_word_count(purple_account_get_username(account), receiver, words);
	stats->last_message = time(NULL);
	stats->last_message_status_id = purple_status_get_id(get_status_for(buddy));
	if(stats->timeout_source_id != 0)
		purple_timeout_remove(stats->timeout_source_id);

	stats->timeout_source_id = purple_timeout_add_seconds(interval, max_message_difference_cb, stats);
}
Пример #4
0
static void insert_status_change(CapStatistics *statistics) {
	insert_status_change_from_purple_status(statistics, get_status_for(statistics->buddy));
}
Пример #5
0
static double generate_prediction_for(PurpleBuddy *buddy) {
	double prediction = 1.0f;
	gboolean generated = FALSE;
	PurpleAccount *account = purple_buddy_get_account(buddy);
	const gchar *buddy_name = purple_buddy_get_name(buddy);
	const gchar *protocol_id = purple_account_get_protocol_id(account);
	const gchar *account_id = purple_account_get_username(account);
	const gchar *status_id = purple_status_get_id(get_status_for(buddy));
	time_t t = time(NULL);
	struct tm *current_time = localtime(&t);
	int current_minute = current_time->tm_min + current_time->tm_hour * 60;
	int threshold = purple_prefs_get_int("/plugins/gtk/cap/threshold");
	int min_minute = (current_minute - threshold) % 1440;
	int max_minute = (current_minute + threshold) % 1440;
	gchar *sql;
	sqlite3_stmt *stmt = NULL;
	const char *tail = NULL;
	int rc;


	sql = sqlite3_mprintf("select sum(success_count) as successes, sum(failed_count) as failures "
		"from cap_msg_count where "
		"buddy=%Q and account=%Q and protocol=%Q and minute_val>=%d and minute_val<=%d;",
		buddy_name,	account_id,	protocol_id, min_minute, max_minute);
	rc = sqlite3_prepare(_db, sql, -1, &stmt, &tail);
	if(rc == SQLITE_OK) {
		int successes = 0;
		int failures = 0;
		if(stmt != NULL) {
			if(sqlite3_step(stmt) == SQLITE_ROW) {
				successes = sqlite3_column_int(stmt, 0);
				failures = sqlite3_column_int(stmt, 1);
				if(failures + successes > 0) {
					prediction *= ((double)successes/((double)(successes+failures)));
					generated = TRUE;
				}
			}
			sqlite3_finalize(stmt);
		}
	}
	sqlite3_free(sql);

	sql = sqlite3_mprintf("select sum(success_count) as successes, sum(failed_count) as failures "
		"from cap_status_count where "
		"buddy=%Q and account=%Q and protocol=%Q and status=%Q;",
		buddy_name,	account_id,	protocol_id, status_id);
	rc = sqlite3_prepare(_db, sql, -1, &stmt, &tail);
	if(rc == SQLITE_OK) {
		int successes = 0;
		int failures = 0;
		if(stmt != NULL) {
			if(sqlite3_step(stmt) == SQLITE_ROW) {
				successes = sqlite3_column_int(stmt, 0);
				failures = sqlite3_column_int(stmt, 1);
				if(failures + successes > 0) {
					prediction *= ((double)successes/((double)(successes+failures)));
					generated = TRUE;
				}
			}
			sqlite3_finalize(stmt);
		}
	}
	sqlite3_free(sql);

	if(generated)
		return prediction;
	else
		return -1;
}