예제 #1
0
파일: stats.py 프로젝트: amirhhz/ug-proj
def save_user_counts():
    """This saves users and corresponding feature counts to a CSV file."""
    statfile = csv.writer(open(GENERAL_STATS, "w"))
    
    full_ones = user_coll.find(
        spec={"username": {"$exists": True} }, 
        fields=CONNS.values(),
        timeout=False)

    # Write CSV header
    statfile.writerow(["username"] + CONNS.values() )    
    for each in full_ones:
        row = []
        row.append(each["_id"])
        for field in CONNS:
            row.append(each[CONNS[field]])
        statfile.writerow(row)
예제 #2
0
파일: stats.py 프로젝트: amirhhz/ug-proj
def save_count_mismatch():
    """Finds and saves users for whom a feature's count does not match the 
    stored count value."""
    field_names = CONNS.keys() + CONNS.values()
    # Find users with complete documents
    cursor = user_coll.find(
                            spec={"username": {"$exists": True} }, 
                            fields=field_names,
                            timeout=False)

    statfile = csv.writer(open(MISMATCH_STATS, "w"))
    # CSV header
    statfile.writerow(["username", "connection", "real_count", "stored_count"])           
    for user in cursor:
        for conn in CONNS:
            if ( len(user[conn]) != user[CONNS[conn]] ):
                row = []
                row.append(user["_id"])
                row.append(conn)
                row.append(len(user[conn]))
                row.append(user[CONNS[conn]])

                statfile.writerow(row)