Exemplo n.º 1
0
def get_testset_item():
    raw_conf = get_raw_conf()
    db_conf = get_db_conf()

    print "start to connect the db.."
    try:
        conn = mysql.connector.connect(host=db_conf['host'],
                                       user=db_conf['user'],
                                       passwd=db_conf['passwd'])
    except Exception as err:
        logging.error(err)

    cur = conn.cursor()
    cur.execute('use %s' % (db_conf['db_name']))

    print 'start to search the users..'
    sql_str = 'select distinct user from user_train'
    cur.execute(sql_str)

    user_list = cur.fetchall()

    dates = datetime.date(2014, 12, 19)

    infile = open('../data/item_train.csv', 'rb')

    item_dict = {}

    print 'start to get the items.'

    for idx, row in enumerate(DictReader(infile)):
        if row['item_id'] not in item_dict:
            item_dict[row['item_id']] = row['item_category']
        else:
            print row['item_id']

    # TODO user_list 和 item_dict 可以存起来的

    print 'got the users items'

    for user in user_list:
        for item in item_dict:
            yield [user, item, item_dict[item]]
Exemplo n.º 2
0
feature抽取
'''
import mysql.connector
import sys
sys.path.append('..')
import logging, time

from util.db import mydb
from util.item import item
from util.get_item import get_item, get_raw_conf, get_db_conf
import datetime

import csv
import itertools

cf = get_db_conf()

raw_data = get_raw_conf()


def get_mydb():
    host = cf["host"]
    user = cf["user"]
    passwd = cf["passwd"]
    if passwd == "null":
        passwd = ""

    mdb = mydb(host=host, user=user, passwd=passwd, port=3306)
    return mdb

Exemplo n.º 3
0
# 将所有输出数据或者配置放到一个文件里还是一个不错的选择的
# 这样就不用在各个文件中添加read_conf了

import sys

sys.path.append('..')
import mysql.connector
import logging

from util.item import item
from util.get_item import get_db_conf, get_one_item, get_raw_conf

raw_conf = get_raw_conf()
data_path = raw_conf['u_tr_time']
dbconf = get_db_conf()

host = dbconf['host']
user = dbconf['user']
passwd = dbconf['passwd']

if passwd == 'null':
    passwd = ""

conn = mysql.connector.connect(host=host, user=user, passwd=passwd)


def create():

    cur = conn.cursor()