<commit_before>package main

import (
	"koding/db/mongodb"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"time"
)

func init() {
	registerAnalytic(numberOfAccounts)
	registerAnalytic(numberOfUsersWhoLinkedOauth)
	registerAnalytic(numberOfEmailsImportedFromGoogle)
	registerAnalytic(numberOfInvitesSent)
	registerAnalytic(numberOfUsersWhoJoinedToday)
	registerAnalytic(numberOfUsersWhoDeletedTheirAccount)
}

func numberOfAccounts() (string, int) {
	var identifier string = "number_of_accounts"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfUsersWhoLinkedOauth() (string, int) {
	var identifier string = "number_of_users_who_linked_oauth"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"foreignAuth": bson.M{"$exists": true}}).Count()

		return err
	}

	mongodb.Run("jUsers", query)

	return identifier, count
}

func numberOfEmailsImportedFromGoogle() (string, int) {
	var identifier string = "number_of_emails_imported_from_google"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(nil).Count()

		return err
	}

	mongodb.Run("jReferrableEmails", query)

	return identifier, count
}

func numberOfInvitesSent() (string, int) {
	var identifier string = "number_of_invites_sent"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"invited": true}).Count()

		return err
	}

	mongodb.Run("jReferrableEmails", query)

	return identifier, count
}

func numberOfUsersWhoJoinedToday() (string, int) {
	var identifier string = "number_of_users_who_joined_today"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		year, month, day := time.Now().Date()
		var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)
		var filter = bson.M{"meta.createdAt": bson.M{"$gte": today}}

		count, err = c.Find(filter).Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfUsersWhoDeletedTheirAccount() (string, int) {
	var identifier string = "number_of_users_who_deleted_their_account"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"status": "deleted"}).Count()

		return err
	}

	mongodb.Run("jUsers", query)

	return identifier, count
}
<commit_msg>graphite: add guest, other user analytics<commit_after>package main

import (
	"koding/db/mongodb"
	"labix.org/v2/mgo"
	"labix.org/v2/mgo/bson"
	"time"
)

func init() {
	registerAnalytic(numberOfAccounts)
	registerAnalytic(numberOfUsersWhoLinkedOauth)
	registerAnalytic(numberOfEmailsImportedFromGoogle)
	registerAnalytic(numberOfInvitesSent)
	registerAnalytic(numberOfUsersWhoJoinedToday)
	registerAnalytic(numberOfGuestAccountsCreatedToday)
	registerAnalytic(numberOfUsersWhoDeletedTheirAccount)
	registerAnalytic(numberOfUsersWhoPostedContentToday)
	registerAnalytic(numberOfUsersWhoAreOnline)
	registerAnalytic(numberOfUsersWhoLoggedInToday)
}

func numberOfAccounts() (string, int) {
	var identifier string = "number_of_accounts"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfUsersWhoLinkedOauth() (string, int) {
	var identifier string = "number_of_users_who_linked_oauth"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"foreignAuth": bson.M{"$exists": true}}).Count()

		return err
	}

	mongodb.Run("jUsers", query)

	return identifier, count
}

func numberOfEmailsImportedFromGoogle() (string, int) {
	var identifier string = "number_of_emails_imported_from_google"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(nil).Count()

		return err
	}

	mongodb.Run("jReferrableEmails", query)

	return identifier, count
}

func numberOfInvitesSent() (string, int) {
	var identifier string = "number_of_invites_sent"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"invited": true}).Count()

		return err
	}

	mongodb.Run("jReferrableEmails", query)

	return identifier, count
}

func numberOfUsersWhoJoinedToday() (string, int) {
	var identifier string = "number_of_users_who_joined_today"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		year, month, day := time.Now().Date()
		var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)
		var filter = bson.M{"meta.createdAt": bson.M{"$gte": today}, "type": "registered"}

		count, err = c.Find(filter).Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfGuestAccountsCreatedToday() (string, int) {
	var identifier string = "number_of_guest_accounts_created_today"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		year, month, day := time.Now().Date()
		var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)
		var filter = bson.M{"meta.createdAt": bson.M{"$gte": today}, "type": "unregistered"}

		count, err = c.Find(filter).Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfUsersWhoDeletedTheirAccount() (string, int) {
	var identifier string = "number_of_users_who_deleted_their_account"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"status": "deleted"}).Count()

		return err
	}

	mongodb.Run("jUsers", query)

	return identifier, count
}

func numberOfUsersWhoPostedContentToday() (string, int) {
	var identifier string = "number_of_users_who_posted_content_today"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		year, month, day := time.Now().Date()
		var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)
		var filter = bson.M{"meta.modifiedAt": bson.M{"$gte": today}}

		count, err = c.Find(filter).Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfUsersWhoAreOnline() (string, int) {
	var identifier string = "number_of_users_who_are_online"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		count, err = c.Find(bson.M{"onlineStatus": "online"}).Count()

		return err
	}

	mongodb.Run("jAccounts", query)

	return identifier, count
}

func numberOfUsersWhoLoggedInToday() (string, int) {
	var identifier string = "number_of_users_who_logged_in_today"
	var count int
	var err error
	var query = func(c *mgo.Collection) error {
		year, month, day := time.Now().Date()
		var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)
		var filter = bson.M{"lastLoginDate": bson.M{"$gte": today}}

		count, err = c.Find(filter).Count()

		return err
	}

	mongodb.Run("jUsers", query)

	return identifier, count
}

{'fraction_non_alphanumeric': 0.1213245789323437, 'fraction_numerical': 0.0034256351698544107, 'mean_word_length': 4.973572037510657, 'pattern_counts': {'":': 21, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2485896', 'n_tokens_mistral': 2641, 'n_tokens_neox': 2456, 'n_words': 611}