Пример #1
0
	def parseBSSIDs(self, network_info, timestamp):
		network_info_list = network_info
		
		if type(network_info) != list:
			network_info_list = []
			network_info_list.append(network_info)
		
		consolidated = DB(db="consolidated")
		found_bssids = []
			
		for network_info in network_info_list:
			inflate = consolidated.query(
				"_design/locations/_view/getByBSSID", 
				params={
					'bssid' : network_info['bssid']
				}
			)[0]
			
			if not inflate:
				# create a new entry
				inflate = {
					'bssid' : network_info['bssid']
				}
			
				bssid = BSSID(inflate=inflate)
			else:
				bssid = BSSID(_id=inflate['_id'])				
			
			if bssid.bssid not in found_bssids:
				found_bssids.append(bssid.bssid)
							
			parsed_location = self.parseLocationObject(bssid, timestamp)
			if parsed_location not in self.known_locations:
				self.known_locations.append(parsed_location)
		return found_bssids
Пример #2
0
class FTITemplate(Asset):
	def __init__(self, search_all=None, search_annos=None):
		self._id = "_design/textsearch"
		self.db = DB(db="derivatives")
		self.emit_omits = copy.deepcopy(emit_omits)
		
		asset = self.db.get(self._id)
		if asset is None:
			self._rev = self.db.post(self.emit())['_rev']
			
			self.fulltext = {}
			try:
				self.addSearchField('search_all', index=search_all)
			except:
				pass
				
			try:
				self.addSearchField('search_annos', index=search_annos)
			except:
				pass
		else:
			self.inflate(asset)
			
	def addSearchField(self, field, index=None):
		if index is None:
			index = wrapper % (inner % {'key' : field})
			field = "by_%s" % field
			
		self.fulltext[field] = {
			'index' : index.replace("\n","").replace("\t","")
		}
		
		self.save()
Пример #3
0
	def parseMACs(self, bt_info, timestamp):
		bt_info_list = bt_info
		
		if type(bt_info) != list:
			bt_info_list = []
			bt_info_list.append(bt_info)
			
		consolidated = DB(db="consolidated")
		found_macs = []
		
		for bt_info in bt_info_list:
			inflate = consolidated.query(
				"_design/locations/_view/getByMACAddress",
				params = {
					'MAC' : bt_info
				}
			)[0]
			
			if not inflate:
				inflate = {
					'MAC' : bt_info
				}
				mac = BTDevice(inflate=inflate)
			else:
				mac = BTDevice(_id=inflate['_id'])
			
			if mac.MAC not in found_macs:
				found_macs.append(mac.MAC)
							
			parsed_location = self.parseLocationObject(mac, timestamp)
			if parsed_location not in self.known_locations:
				self.known_locations.append(parsed_location)
		return found_macs
Пример #4
0
class SourceSearch():
	def __init__(self, params):
		self.params = None
		
		try:
			self.q = params['alias']
			del params['alias']
		except KeyError as e:
			print "no alias specified"
			
		if any(params):
			self.params = params
			print self.params
			
		if hasattr(self, 'q') or self.params is not None:
			self.perform()
			
	def perform(self):
		from couch import DB
		self.db = DB()
		self.sources = []
		
		if hasattr(self, 'q'):
			aliases = self.db.lucene_query("_design/sources/getSourceByAlias", q=self.q)
			if len(aliases) > 0 and aliases[0]:
				self.sources.extend(self.db.query("_design/sources/_view/getSources", params={'_ids':aliases}))
Пример #5
0
class DerivativeSearch():
	def __init__(self, params, remove=None):
		self.db = DB(db="derivatives")
		self.params = None
		
		try:
			self.q = params['keywords']
			del params['keywords']
		except KeyError as e:
			print "no keyworkds specified"
			
		try:
			self.geo = {
				'latitude' : params['latitude'],
				'longitude' : params['longitude']
			}
			
			del params['latitude']
			del params['longitude']
		except KeyError as e:
			print "no lat/lng specified"
			
		if hasattr(self, 'geo'):
			try:
				self.geo['radius'] = params['radius']
				del params['radius']
			except KeyError as e:
				print "no radius for geo query.  setting default as 5km"
				self.geo['radius'] = 5
				
		if any(params):
			self.params = params
			
		self.derivatives = [False]
		self.submissions = [False]
		
		if hasattr(self, 'geo') or hasattr(self, 'q') or self.params is not None:
			self.perform(remove=remove)
			
	def perform(self, remove=None):
		if hasattr(self, 'q'):
			self.derivatives = self.db.lucene_query("_design/textsearch/search_all",q=self.q, params=self.params)
		else:
			if self.params is not None:
				self.derivatives = self.db.multiparam_query(self.params)
				
		if hasattr(self, 'geo'):
			geos = self.db.geoquery(geo)
			if len(self.derivatives) > 0 and self.derivatives[0]:
				self.derivatives = list(set(self.derivatives).intersection(set(geos)))
			else:
				self.derivatives = geos
		
		if len(self.derivatives) > 0 and self.derivatives[0]:
			submission_ids = self.db.query("_design/static/_view/getDerivatives", params={'_ids':self.derivatives}, include_only=["submission_id"], include_only_as_list=True)
			
			db = DB()
			self.submissions = db.query("_design/submissions/_view/getSubmissions",params={'_ids':submission_ids}, remove=remove)
Пример #6
0
class SubmissionSearch():
	def __init__(self, submission, params):
		if not hasattr(submission, 'derivative'):
			return [False]
		
		self.submission = submission	
		self.params = None
		
		try:
			self.q = params['keywords']
			del params['keywords']
		except KeyError as e:
			print "no keywords specified"
			
		if any(params):
			self.params = params
			print self.params
			
		if hasattr(self, 'q') or self.params is not None:
			self.perform()
			
	def perform(self):
		from couch import DB
		self.db = DB("derivatives")
		
		if hasattr(self, 'q'):
			annotations = self.db.anno_query("_design/textsearch/search_annos", q=self.q, _id=self.submission._id)
			
			if annotations[0]:
				self.annotations = annotations
Пример #7
0
	def perform(self):
		from couch import DB
		self.db = DB("derivatives")
		
		if hasattr(self, 'q'):
			annotations = self.db.anno_query("_design/textsearch/search_annos", q=self.q, _id=self.submission._id)
			
			if annotations[0]:
				self.annotations = annotations
Пример #8
0
	def perform(self):
		from couch import DB
		self.db = DB()
		self.sources = []
		
		if hasattr(self, 'q'):
			aliases = self.db.lucene_query("_design/sources/getSourceByAlias", q=self.q)
			if len(aliases) > 0 and aliases[0]:
				self.sources.extend(self.db.query("_design/sources/_view/getSources", params={'_ids':aliases}))
Пример #9
0
	def perform(self, remove=None):
		if hasattr(self, 'q'):
			self.derivatives = self.db.lucene_query("_design/textsearch/search_all",q=self.q, params=self.params)
		else:
			if self.params is not None:
				self.derivatives = self.db.multiparam_query(self.params)
				
		if hasattr(self, 'geo'):
			geos = self.db.geoquery(geo)
			if len(self.derivatives) > 0 and self.derivatives[0]:
				self.derivatives = list(set(self.derivatives).intersection(set(geos)))
			else:
				self.derivatives = geos
		
		if len(self.derivatives) > 0 and self.derivatives[0]:
			submission_ids = self.db.query("_design/static/_view/getDerivatives", params={'_ids':self.derivatives}, include_only=["submission_id"], include_only_as_list=True)
			
			db = DB()
			self.submissions = db.query("_design/submissions/_view/getSubmissions",params={'_ids':submission_ids}, remove=remove)
Пример #10
0
	def parseCellIDs(self, cell_info, timestamp):
		cell_info_list = cell_info
		
		if type(cell_info) != list:
			cell_info_list = []
			cell_info_list.append(cell_info)
			
		consolidated = DB(db="consolidated")
		found_cell_ids = []
				
		for cell_info in cell_info_list:			
			if type(cell_info) != int:
				cell_info = int(cell_info)
				
			inflate = consolidated.query(
				"_design/locations/_view/getByCellID",
				params={
					'cellId' : AsTrueValue(cell_info)
				}
			)[0]
			
			if not inflate:
				inflate = {
					'cellId' : AsTrueValue(cell_info)
				}
				cell_id = CellID(inflate=inflate)
			else:
				cell_id = CellID(_id=inflate['_id'])
			
			if cell_id.cellId not in found_cell_ids:
				found_cell_ids.append(cell_id.cellId)
							
			parsed_location = self.parseLocationObject(cell_id, timestamp)
			if parsed_location not in self.known_locations:
				self.known_locations.append(parsed_location)
				
		return found_cell_ids
Пример #11
0
	def __init__(self, search_all=None, search_annos=None):
		self._id = "_design/textsearch"
		self.db = DB(db="derivatives")
		self.emit_omits = copy.deepcopy(emit_omits)
		
		asset = self.db.get(self._id)
		if asset is None:
			self._rev = self.db.post(self.emit())['_rev']
			
			self.fulltext = {}
			try:
				self.addSearchField('search_all', index=search_all)
			except:
				pass
				
			try:
				self.addSearchField('search_annos', index=search_annos)
			except:
				pass
		else:
			self.inflate(asset)
Пример #12
0
	def __init__(self, params, remove=None):
		self.db = DB(db="derivatives")
		self.params = None
		
		try:
			self.q = params['keywords']
			del params['keywords']
		except KeyError as e:
			print "no keyworkds specified"
			
		try:
			self.geo = {
				'latitude' : params['latitude'],
				'longitude' : params['longitude']
			}
			
			del params['latitude']
			del params['longitude']
		except KeyError as e:
			print "no lat/lng specified"
			
		if hasattr(self, 'geo'):
			try:
				self.geo['radius'] = params['radius']
				del params['radius']
			except KeyError as e:
				print "no radius for geo query.  setting default as 5km"
				self.geo['radius'] = 5
				
		if any(params):
			self.params = params
			
		self.derivatives = [False]
		self.submissions = [False]
		
		if hasattr(self, 'geo') or hasattr(self, 'q') or self.params is not None:
			self.perform(remove=remove)