require "sequel"
require "sqlite3"

class HopperNet
	def initialize
		@dba=Hash.new
	end

	def addcount(fobj='a',tobj='1')
		#fobj is the from variable and tobj is the to variable
		if (@dba.has_key?([fobj,tobj])==false)
			@dba[[fobj,tobj]]=1
		else
			@dba[[fobj,tobj]]+=1
		end
	end

	def getcount(fobj='a',tobj='1')
		puts @dba[[fobj,tobj]]
	end

	def outrelation(fobj='a')
		#this gets the relations (in and out) which contains object fobj

		choices = @dba.select { |key, value| key.to_s.match(fobj) } #selects regex from fobj which is hash key
		puts choices.values.inject(0){|x,y| x+y}
		#puts choices.values
		puts fobj

		#avalue.each {|key,value| total=total+value}
		#puts total
	end

	def getrelation(fobj='a',tobj='1')
		#this is a basic relation of one to one which r(x,y) = sx -> sy + sy -> sx
		puts @dba[[fobj,tobj]].to_i + @dba[[tobj,fobj]].to_i
	end

	def incrementrelation
		#need to set the hopper and get the number of links??
	end

	def getcores(fobj='a',tobj='1')
		#calculates cores based on the network values
	end

	def getall
		#prints all values
		puts @dba
	end
end	

objlist=Hash.new #this is the raw data that is obtained. it mixes a hash for reference

#DBmysql = Sequel.connect(:adapter => 'sqlite3', :host => 'localhost', :user => 'root', :password=>'x*****', :database => 'dobbs2')


# how to evaluate the accuracy of the match?
# frequent data / apps .. theres a curve?
# 1step influence. Probability of resource. P = score from t / outgoing from s.
# multistep core.
# How this can be proposed cloud architecture for data/app trace

# Hopper net test
aa=HopperNet.new
aa.addcount('a','b')
aa.addcount('a','b')
aa.addcount('a','b')
aa.addcount('a','c')
aa.addcount('a','c')
aa.addcount('a','d')
aa.addcount('ea','d')
aa.addcount('b','a')

#aa.getcount('a','b')
#aa.getall

#aa.getrelation('a','b')

aa.outrelation('"a"')
#This gets the window_id of the use


DBmysql = Sequel.connect(:adapter => 'mysql', :host => 'localhost', :user => 'test', :password=>'test', :database => 'dobbs2')
puts DBmysql.tables #lists the tables
puts DBmysql[:dobbsBrowseEvents].columns #lists the columns

DSmysql = DBmysql[:dobbsBrowseEvents].select(:domain, :time).where{user_id = '1997459307'}.limit(30)
DSmysql.each{|r| puts r[:domain].to_s}

