Esempio n. 1
0
def smarttop10(p1):
    "有意思的推荐"
    start=datetime.now()
    rows=top200(p1)
    original_productserialcode=getproductserialcode(p1)
    original_categories=getcategories(p1)
    original_productname=getproductname(p1)
    original_color=getproductcolor(p1)
    results=[]
    recommend_group=mystruct()
    for i in rows:
        sim=i[2]
        if i[0]<>p1:
            recommend_productcode=i[0]
        else:
            recommend_productcode=i[1]
        recommend_productserialcode=getproductserialcode(recommend_productcode)
        recommend_categories=getcategories(recommend_productcode)
        recommend_productname=getproductname(recommend_productcode)
        recommend_color=getproductcolor(recommend_productcode)

        if original_productserialcode<>recommend_productserialcode:
            v=(recommend_productcode,recommend_productname,recommend_categories,sim,recommend_color,recommend_productserialcode)
            if recommend_group.has_key(recommend_productserialcode):
                recommend_group.update(recommend_productserialcode,v)
            else:
                recommend_group.add(recommend_productserialcode,v)
            #results.append("%s,%s,%s,%s\r\n"%(recommend_productcode,recommend_productname,recommend_categories,sim))
        
    for elem in recommend_group.getvalues():
        results.append("%s,%s,%s,%s,%s,%s\r\n"%elem[0])
    filehelper.savefile("recommand.csv",results)
    end=datetime.now()
    print "cost time:%ss"%(end-start).seconds
#! usr/bin/env python
#encoding=utf8
"""
brief:
export caculate similarity from redis memory to csv
prepare next step for preparing import to sqlserver
"""
import redis
from lib import filehelper
from datetime import datetime
start=datetime.now()
r6=redis.Redis(host="10.3.11.178",db=6)
print "total have %s recoreds"%r6.dbsize()
keys=r6.keys()
lines=[]
for key in keys:
    p1,p2=key.split(":")
    result=r6.get(key)
    lines.append("%s,%s,%s\r\n"%(p1,p2,result))

filehelper.savefile("result.csv",lines)
end=datetime.now()
print "cost time:%ss"%(end-start).seconds
print "done!"
Esempio n. 3
0
#! usr/bin/env python
#encoding=utf8
"""
this script need write permission

"""
import redis
from lib import filehelper
r3=redis.Redis(host="192.168.1.7",db=2)
filehelper.savefile("username.txt","\n".join(r3.keys()))
print len(r3.keys())
print "done"