示例#1
0
def generateEdmEmailingList(connection, site_id):
    logger = logging.getLogger("EDMCalculations")
    c_user_orders = getSiteDBCollection(connection, site_id, "user_orders")
    latest_order_datetime = getLatestUserOrderDatetime(connection, site_id)
    if latest_order_datetime is None:
        query = {}
    else:
        query = {"order_datetime": {"$gte": latest_order_datetime \
                                - datetime.timedelta(days=EMAILING_USER_ORDERS_MAX_DAY)}}
    db = getSiteDB(connection, site_id)
    result = db.command({"distinct": "user_orders", "key": "user_id", 
                "query": query})
    user_ids = result["values"]
    
    mongo_client = MongoClient(connection)
    c_edm_emailing_list = getSiteDBCollection(connection, site_id, "edm_emailing_list")
    c_edm_emailing_list.drop()
    c_edm_emailing_list = getSiteDBCollection(connection, site_id, "edm_emailing_list")
    count = 0
    t0 = time.time()
    for user_id in user_ids:
        count += 1
        if count % 100 == 0:
            logger.info("Count: %s, %s users/sec" % (count, count/(time.time() - t0)))
        recommendation_result, _ = mongo_client.recommend_for_edm(site_id, user_id, 
                                        max_amount=EXPECTED_RECOMMENDATION_ITEMS)
        if len(recommendation_result) == EXPECTED_RECOMMENDATION_ITEMS:
            c_edm_emailing_list.insert({"user_id": user_id, "recommendation_result": recommendation_result})
示例#2
0
文件: server.py 项目: jacobfan/poco
class HotIndexCalculation:
    def __init__(self, connection, site_id):
        self.connection = connection
        self.mongo_client = MongoClient(connection)
        self.site_id = site_id

    def run(self):
        self.mongo_client.updateHotViewList(self.site_id)
示例#3
0
def generateEdmEmailingList(connection, site_id):
    logger = logging.getLogger("EDMCalculations")
    c_user_orders = getSiteDBCollection(connection, site_id, "user_orders")
    latest_order_datetime = getLatestUserOrderDatetime(connection, site_id)
    if latest_order_datetime is None:
        query = {}
    else:
        query = {"order_datetime": {"$gte": latest_order_datetime \
                                - datetime.timedelta(days=EMAILING_USER_ORDERS_MAX_DAY)}}
    db = getSiteDB(connection, site_id)
    result = db.command({
        "distinct": "user_orders",
        "key": "user_id",
        "query": query
    })
    user_ids = result["values"]

    mongo_client = MongoClient(connection)
    c_edm_emailing_list = getSiteDBCollection(connection, site_id,
                                              "edm_emailing_list")
    c_edm_emailing_list.drop()
    c_edm_emailing_list = getSiteDBCollection(connection, site_id,
                                              "edm_emailing_list")
    count = 0
    t0 = time.time()
    for user_id in user_ids:
        count += 1
        if count % 100 == 0:
            logger.info("Count: %s, %s users/sec" % (count, count /
                                                     (time.time() - t0)))
        recommendation_result, _ = mongo_client.recommend_for_edm(
            site_id, user_id, max_amount=EXPECTED_RECOMMENDATION_ITEMS)
        if len(recommendation_result) == EXPECTED_RECOMMENDATION_ITEMS:
            c_edm_emailing_list.insert({
                "user_id":
                user_id,
                "recommendation_result":
                recommendation_result
            })
import sys
sys.path.insert(0, ".")
import datetime
import pymongo
from api import settings

from api.mongo_client import MongoClient
from common.utils import getSiteDBCollection

def getConnection():
    if(settings.replica_set):
        return pymongo.MongoReplicaSetClient(settings.mongodb_host, replicaSet=settings.replica_set)
    else:
        return pymongo.Connection(settings.mongodb_host)

mongo_client = MongoClient(getConnection())
mongo_client.reloadApiKey2SiteID()

if len(sys.argv) != 4:
    print "Usage: python calculate_traffic_metrics.py <site_id> <from_timestamp> <to_timestamp>"
    sys.exit(1)
else:
    site_id, from_timestamp_str, to_timestamp_str = sys.argv[1:]
    try:
        from_timestamp = datetime.datetime.strptime(from_timestamp_str, "%Y-%m-%d %H:%M:%S")
        to_timestamp = datetime.datetime.strptime(to_timestamp_str, "%Y-%m-%d %H:%M:%S")
    except ValueError:
        print "Please invalid <from_timestamp> or <to_timestamp>"
        sys.exit(1)

示例#5
0
文件: server.py 项目: jacobfan/poco
 def __init__(self, connection, site_id):
     self.connection = connection
     self.mongo_client = MongoClient(connection)
     self.site_id = site_id
示例#6
0
文件: views.py 项目: stipid/poco
from common.utils import getSiteDBCollection
from common.utils import convertTimedeltaAsDaysHoursMinutesSeconds

from api.mongo_client import MongoClient

from site_utils import generateApiKey
import settings


def getConnection():
    if settings.replica_set:
        return pymongo.MongoReplicaSetClient(settings.mongodb_host, replicaSet=settings.replica_set)
    else:
        return pymongo.Connection(settings.mongodb_host)

mongo_client = MongoClient(getConnection())


def fillSiteCheckingDaemonInfo(connection, sci):
    now = datetime.datetime.now()
    c_site_checking_daemon_logs = getSiteDBCollection(connection, sci["site_id"], "site_checking_daemon_logs")
    last_records = [row for row in c_site_checking_daemon_logs.find().sort("created_on", -1).limit(1)]
    
    sci["site_checking_status_msg"] = ""
    if last_records == []:
        sci["site_checking_status"] = "NEVER_CHECKED"
    else:
        last_record = last_records[0]
        sci["site_checking_last_id"] = last_record["checking_id"]
        if last_record["state"] in ("FAIL", "SUCC"):
            sci["site_checking_status"] = last_record["state"]