Example #1
0
def	main(userid=None):
	data = KsdData()

	db = DbChamDemo.login()
	if userid==None:
		db.load(data)	
	else:
		db.load(data, WHERE="uid =%d" % (userid))	
	data.prn()
	
	for user,loglist in data.T.iteritems():
		print "====User %d: %d items" % (user, len(loglist))	
		vectors = getKsdVectors(loglist)
		updateConsistencyAndSharing(db, user, vectors)

		model = analyzeKsd(db, user, vectors)
		if model==None:
			continue

		updateScores(db, user, loglist, model)

		if model.trainset != None:
			print "  --- New Learning"
			db.updateCenter(user, model.center, model.radius, debug=1)
		else:
			print "  --- Old Learning"
			cleanvectors = getKsdVectors(loglist, maxscore=OUTLIER_SCORE)
			model = KsdModel()
			model.DoTraining(cleanvectors)
			db.updateCenter(user, model.center, model.radius, debug=1)
	def run(self):
		self.db = DbChamDemo.login()
		msg = self.cliSock.recv(1000)
		print msg
		self.cliSock.send("from Server : " + msg)
		cnt = 0
		while True:
			time.sleep(2)
			print "port=%d" % (self.cliPort)

		self.db.close()
Example #3
0
		id = file.split(".")[0]
		try:
			fname = "%s/%s" % (dirname, file)
			patterns = parseMcdFile(fname)
		except:
			print "ERROR in file", file
			continue

		uid = db.getUid("mobile_"+id)
		if uid==0:
			print "uid error for id '%s'" % (id)
			continue
		

		for i,vec in  enumerate(patterns):
			ksdvec = ' '.join(vec)
			ipaddr = random.choice(IPADDRS)
			logtime = len(patterns) - i + 1
			try:
				db.insertKsdlog(uid, ipaddr, logtime, ksdvec )
			except:
				print "ERROR in DB", file
			
		
if __name__ == "__main__":
	filelist =  getFileList("users", ".mcd")

	db = DbChamDemo.login()
	##insertUid(db, "users", filelist)
	insertKsdlog(db, "users", filelist)