コード例 #1
0
	def get_events_by_date_region(self, date, region):
		events = []
		for country in REGIONS.get(region):
			cmd = 'select * from incidents_view where upper(country)="%s" and event_date >= date("%s") AND event_date <  date("%s", "+1 day");'%(country.upper(), self.format_date(date), self.format_date(date))
			output = self.db_access.execute(cmd)
			events.extend(self.get_events_from_output(output))
		return events
コード例 #2
0
 def retrieve_events_by_asset(self, request):
     print 'retrieve_assets_by_event'
     assets = [] 
     events = []
     country = request.POST.get('country')
     lat = request.POST.get('lat')
     lng = request.POST.get('lng')
     date = request.POST.get('date')
     distance_filter = request.POST.get('distance')
     if country and lat and lng and distance_filter:
         region = [key for key, value in REGIONS.iteritems() if country in value]
         if region:
             for asset in self.asset_mgr.get_assets_by_region(region[0]):
                 distance = get_distance(float(lat), float(lng), asset.lat, asset.lng)
                 if distance <= float(distance_filter):
                     assets.append({'asset': asset.__dict__,
                                   'distance': distance})
             for event in self.event_mgr.get_events_by_date_region(date, region[0]):
                 distance = get_distance(float(lat), float(lng), event.lat, event.lng)
                 if distance <= float(distance_filter):
                     events.append({'event': event.__dict__,
                                   'distance': distance})
     if events:
         events.sort(key=lambda x:x.get('distance'))
     return {'assets':assets, 'events': events, 'response': 'success'}