示例#1
0
    def runTest(self):

        self.assertEqual(
            'New Taipei City, Taiwan',
            event_locations.LocationInfo(
                gen_event_with_location(u'捷運板橋站練舞')).final_city)
        self.assertEqual(
            (37.8693878, -122.2623099),
            event_locations.LocationInfo(
                gen_event_with_location(
                    u'   Haas Pavilion, Berkeley, CA 94720, United States')
            ).geocode.latlng())
示例#2
0
def _get_bounds_for_fb_event(fb_event,
                             fb_event_attending_maybe,
                             check_places=False):
    # We don't need google-maps latlong accuracy. Let's cheat and use the fb_event for convenience if possible...
    location = fb_event['info'].get('place', {}).get('location', {})
    if location and location.get('latitude') is not None:
        latlong = (location['latitude'], location['longitude'])
        # TODO: Someday we'd like to use locations of Taiwan or Germany to grab a bunch of stuff in those bounds
        # but for now, FB doesn't send us proper lat-long-boxes for them, and I don't want to look up everything
        # just in case there are bigger bounds...so we accept the latlong as-is.
        bounds = math.expand_bounds((latlong, latlong),
                                    cities_db.NEARBY_DISTANCE_KM)
    else:
        logging.info('Looking up event %s LocationInfo',
                     fb_event['info']['id'])
        # Places textsearch lookups turn out to be 10x-expensive against our quota
        # So we disable them here, and instead just rely on the 99% good address searches
        # It should fallback to places on un-geocodable addresses too...
        # But at least it won't try Places *in addition* to geocode lookups.
        location_info = event_locations.LocationInfo(
            fb_event,
            fb_event_attending_maybe=fb_event_attending_maybe,
            check_places=check_places)
        if location_info.geocode:
            bounds = math.expand_bounds(location_info.geocode.latlng_bounds(),
                                        cities_db.NEARBY_DISTANCE_KM)
        else:
            bounds = None
    return bounds
示例#3
0
    def runTest(self):
        fb_event = self.get_event('101')

        location_info = event_locations.LocationInfo(fb_event, debug=True)
        self.assertEqual(location_info.overridden_address, None)
        self.assertEqual(location_info.remapped_address, None)
        self.assertEqual(location_info.fb_address, None)
        self.assertEqual(location_info.final_city, None)
        self.assertEqual(location_info.latlong(), (None, None))
示例#4
0
    def runTest(self):
        db_event = eventdata.DBEvent(address='ungeocodeable mess of crap')
        fb_event = self.get_event('100')

        location_info = event_locations.LocationInfo(fb_event,
                                                     db_event=db_event,
                                                     debug=True)
        self.assertEqual(location_info.final_city, None)
        self.assertEqual(location_info.latlong(), (None, None))
示例#5
0
 def runTest(self):
     fb_event = self.get_event('100')
     location_info = event_locations.LocationInfo(fb_event, debug=True)
     self.assertEqual(location_info.overridden_address, None)
     self.assertEqual(location_info.remapped_address, None)
     self.assertEqual(location_info.fb_address, 'San Francisco')
     self.assertEqual(location_info.final_city,
                      'San Francisco, CA, United States')
     self.assertNearEqual(location_info.latlong(),
                          (37.774929499999999, -122.4194155))
示例#6
0
 def runTest(self):
     fb_event = self.get_event(EVENT_ID)
     location_info = event_locations.LocationInfo(fb_event, debug=True)
     self.assertEqual(location_info.overridden_address, None)
     self.assertEqual(location_info.remapped_address, None)
     self.assertEqual(location_info.fb_address,
                      'Hype Dance, 67 Earl Street, Sheffield')
     self.assertEqual(location_info.final_city, 'Sheffield, United Kingdom')
     self.assertNearEqual(location_info.latlong(),
                          (53.375206800000001, -1.4709795999999999))
示例#7
0
    def runTest(self):
        db_event = eventdata.DBEvent(address='San Francisco, CA')
        fb_event = self.get_event('100')

        try:
            event_locations.update_remapped_address(fb_event, 'TBD')

            location_info = event_locations.LocationInfo(fb_event,
                                                         db_event=db_event,
                                                         debug=True)
            self.assertEqual(location_info.overridden_address,
                             'San Francisco, CA')
            self.assertEqual(location_info.remapped_address, 'TBD')
            self.assertEqual(location_info.needs_override_address(), True)

            location_info = event_locations.LocationInfo(fb_event, debug=True)
            self.assertEqual(location_info.overridden_address, None)
            self.assertEqual(location_info.remapped_address, 'TBD')
            self.assertEqual(location_info.needs_override_address(), True)

        finally:
            event_locations.update_remapped_address(fb_event, '')
示例#8
0
    def runTest(self):
        db_event = eventdata.DBEvent(address='San Jose, CA')
        fb_event = self.get_event('100')

        location_info = event_locations.LocationInfo(fb_event,
                                                     db_event=db_event,
                                                     debug=True)
        self.assertEqual(location_info.overridden_address, 'San Jose, CA')
        self.assertEqual(location_info.remapped_address, None)
        self.assertEqual(location_info.fb_address, 'San Francisco')
        self.assertEqual(location_info.final_city,
                         'San Jose, CA, United States')
        self.assertNearEqual(location_info.latlong(),
                             (37.339385700000001, -121.89495549999999))
示例#9
0
    def runTest(self):
        fb_event = self.get_event('103')

        location_info = event_locations.LocationInfo(fb_event, debug=True)
        self.assertEqual(location_info.overridden_address, None)
        self.assertEqual(location_info.remapped_address, None)
        self.assertEqual(
            location_info.fb_address,
            u'Jingsta, \u795e\u5bae\u524d2-18-7\u5916\u82d1\u30d3\u30ebB1, Shibuya-ku, Tokyo, Japan'
        )
        self.assertEqual(location_info.final_city,
                         u'18, Shibuya-ku, T\u014dky\u014d-to, Japan')
        self.assertEqual(location_info.is_online_event(), False)
        self.assertEqual(location_info.actual_city(),
                         u'18, Shibuya-ku, T\u014dky\u014d-to, Japan')
        self.assertEqual(location_info.latlong(), (35.6724529, 139.7098159))
示例#10
0
    def runTest(self):
        db_event = eventdata.DBEvent(address=event_locations.ONLINE_ADDRESS)
        fb_event = self.get_event('100')

        location_info = event_locations.LocationInfo(fb_event,
                                                     db_event=db_event,
                                                     debug=True)
        self.assertEqual(location_info.overridden_address,
                         event_locations.ONLINE_ADDRESS)
        self.assertEqual(location_info.remapped_address, None)
        self.assertEqual(location_info.fb_address, 'San Francisco')
        self.assertEqual(location_info.final_city,
                         event_locations.ONLINE_ADDRESS)
        self.assertEqual(location_info.is_online_event(), True)
        self.assertEqual(location_info.actual_city(), None)
        self.assertEqual(location_info.latlong(), (None, None))
示例#11
0
    def runTest(self):
        fb_event = self.get_event('100')

        try:
            event_locations.update_remapped_address(fb_event, 'Oakland, CA')

            location_info = event_locations.LocationInfo(fb_event, debug=True)
            self.assertEqual(location_info.overridden_address, None)
            self.assertEqual(location_info.remapped_address, 'Oakland, CA')
            self.assertEqual(location_info.fb_address, 'San Francisco')
            self.assertEqual(location_info.final_city,
                             'Oakland, CA, United States')
            self.assertNearEqual(location_info.latlong(),
                                 (37.804363700000003, -122.2711137))

            event_locations.update_remapped_address(fb_event, '')
            super(TestNoVenueWithRemap,
                  self).runTest()  # should be the same as before
        finally:
            event_locations.update_remapped_address(fb_event, '')
示例#12
0
    def get(self):
        event_id = None
        if self.request.get('event_url'):
            event_id = urls.get_event_id_from_url(
                self.request.get('event_url'))
        elif self.request.get('event_id'):
            event_id = self.request.get('event_id')
        self.finish_preload()

        fb_event = get_fb_event(self.fbl, event_id)
        if not fb_event:
            logging.error('No fetched data for %s, showing error page',
                          event_id)
            return self.show_barebones_page(event_id, "No fetched data")

        e = eventdata.DBEvent.get_by_id(event_id)

        if not fb_events.is_public_ish(fb_event):
            if e:
                fb_event = e.fb_event
            else:
                self.add_error(
                    'Cannot add secret/closed events to dancedeets!')

        self.errors_are_fatal()

        owner_location = None
        if 'owner' in fb_event['info']:
            owner_id = fb_event['info']['owner']['id']
            location = self._get_location(owner_id, fb_api.LookupProfile,
                                          'profile') or self._get_location(
                                              owner_id, fb_api.LookupThingPage,
                                              'info')
            if location:
                owner_location = event_locations.city_for_fb_location(location)
        self.display['owner_location'] = owner_location

        display_event = search.DisplayEvent.get_by_id(event_id)
        # Don't insert object until we're ready to save it...
        if e and e.creating_fb_uid:
            #STR_ID_MIGRATE
            creating_user = self.fbl.get(fb_api.LookupProfile,
                                         str(e.creating_fb_uid))
            if creating_user.get('empty'):
                logging.warning(
                    'Have creating-user %s...but it is not publicly visible, so treating as None: %s',
                    e.creating_fb_uid, creating_user)
                creating_user = None
        else:
            creating_user = None

        potential_event = potential_events.make_potential_event_without_source(
            event_id)
        a = time.time()
        classified_event = event_classifier.get_classified_event(
            fb_event, potential_event.language)
        timelog.log_time_since('Running BasicText Classifier', a)
        self.display['classified_event'] = classified_event
        dance_words_str = ', '.join(list(classified_event.dance_matches()))
        if classified_event.is_dance_event():
            event_words_str = ', '.join(list(classified_event.event_matches()))
        else:
            event_words_str = 'NONE'
        self.display['classifier_dance_words'] = dance_words_str
        self.display['classifier_event_words'] = event_words_str
        self.display['creating_user'] = creating_user

        self.display['potential_event'] = potential_event
        self.display['display_event'] = display_event

        start = time.time()
        add_result = event_auto_classifier.is_auto_add_event(classified_event)
        notadd_result = event_auto_classifier.is_auto_notadd_event(
            classified_event, auto_add_result=add_result)
        timelog.log_time_since('Running Text Classifier', start)

        auto_classified = ''
        if add_result.is_good_event():
            auto_classified += 'add: %s.\n' % add_result
        if notadd_result[0]:
            auto_classified += 'notadd: %s.\n' % notadd_result[1]

        self.display['auto_classified_add'] = add_result
        self.display['auto_classified_notadd'] = notadd_result
        styles = categories.find_styles(fb_event)
        event_types = styles + categories.find_event_types(fb_event)
        self.display['auto_categorized_types'] = ', '.join(
            x.public_name for x in event_types)

        a = time.time()
        fb_event_attending_maybe = get_fb_event(
            self.fbl, event_id, lookup_type=fb_api.LookupEventAttendingMaybe)
        timelog.log_time_since('Loading FB Event Attending Data', a)
        a = time.time()

        location_info = event_locations.LocationInfo(
            fb_event,
            fb_event_attending_maybe=fb_event_attending_maybe,
            db_event=e,
            debug=True)
        self.display['location_info'] = location_info
        if location_info.fb_address:
            fb_geocode = gmaps_api.lookup_address(location_info.fb_address)
            self.display['fb_geocoded_address'] = formatting.format_geocode(
                fb_geocode)
        else:
            self.display['fb_geocoded_address'] = ''
        city_name = 'Unknown'
        if location_info.geocode:
            city = cities_db.get_nearby_city(
                location_info.geocode.latlng(),
                country=location_info.geocode.country())
            if city:
                city_name = city.display_name()
        self.display['ranking_city_name'] = city_name

        person_ids = fb_events.get_event_attendee_ids(fb_event_attending_maybe)
        if location_info.geocode:
            data = person_city.get_data_fields(person_ids,
                                               location_info.geocode.latlng())
            self.display['attendee_distance_info'] = data
        else:
            self.display['attendee_distance_info'] = 'Unknown'

        matcher = event_attendee_classifier.get_matcher(
            self.fbl,
            fb_event,
            fb_event_attending_maybe=fb_event_attending_maybe,
            classified_event=classified_event)
        timelog.log_time_since('Running Attendee Classifier', a)
        # print '\n'.join(matcher.results)
        sorted_matches = sorted(matcher.matches,
                                key=lambda x: -len(x.overlap_ids))
        matched_overlap_ids = sorted_matches[
            0].overlap_ids if matcher.matches else []
        self.display['auto_add_attendee_ids'] = sorted(matched_overlap_ids)
        self.display['overlap_results'] = [
            '%s %s: %s' % (x.top_n, x.name, x.reason) for x in sorted_matches
        ]

        self.display['overlap_attendee_ids'] = sorted(matcher.overlap_ids)

        if matcher.matches:
            attendee_ids_to_admin_hash_and_event_ids = sorted_matches[
                0].get_attendee_lookups()
            self.display[
                'attendee_ids_to_admin_hash_and_event_ids'] = attendee_ids_to_admin_hash_and_event_ids

        self.display['event'] = e
        self.display['event_id'] = event_id
        self.display['fb_event'] = fb_event

        self.jinja_env.filters[
            'highlight_keywords'] = event_classifier.highlight_keywords

        self.display['track_analytics'] = False
        self.render_template('admin_edit')
示例#13
0
    def post(self):
        if self.request.get('event_url'):
            event_id = urls.get_event_id_from_url(
                self.request.get('event_url'))
            if not event_id:
                self.add_error('Unrecognized Facebook event URL')
        else:
            self.add_error('Missing Facebook event URL')
        self.errors_are_fatal()

        event_errors = []
        event_warnings = []
        try:
            fb_event = self.fbl.get(fb_api.LookupEvent,
                                    event_id,
                                    allow_cache=False)
        except fb_api.NoFetchedDataException:
            event_errors.append(
                'Unable to fetch event. Please adjust your event privacy settings, or log in.'
            )
            return

        if 'cover_info' not in fb_event['info']:
            event_errors.append('The event needs a cover photo.')

        start_time = dates.parse_fb_start_time(fb_event)
        if start_time < datetime.datetime.now() - datetime.timedelta(days=1):
            event_errors.append(
                'Your event appears to be in the past. You should fix the date.'
            )

        if 'name' not in fb_event['info']:
            event_errors.append('The event needs a name.')

        if 'description' not in fb_event['info']:
            event_errors.append('The event needs a description.')

        if not fb_events.is_public(fb_event):
            event_errors.append(
                'The event privacy settings are too restricted.')

        classified_event = event_classifier.classified_event_from_fb_event(
            fb_event)
        classified_event.classify()
        auto_add_result = event_auto_classifier.is_auto_add_event(
            classified_event)
        if not auto_add_result.is_good_event():
            event_warnings.append(
                "The event wouldn't be automatically added. There weren't enough strong keywords for the system to identify it."
            )
        auto_notadd_result = event_auto_classifier.is_auto_notadd_event(
            classified_event, auto_add_result=auto_add_result)
        if auto_notadd_result[0]:
            event_warnings.append(
                'The event appears to be the "wrong" kind of dance event for DanceDeets. Are you sure it is a street dance event?'
            )

        # Intentionally don't pass the fb_event_attending_maybe, since we want the event to be tested standalone
        location_info = event_locations.LocationInfo(fb_event)
        if not location_info.geocode:
            event_errors.append(
                'Your event has no location. Please select a particular address, city, state, or country for this event.'
            )
        elif 'place' not in fb_event['info']:
            event_warnings.append(
                'For best results, your event should select a location from one of the venues Facebook suggests. DanceDeets believes your event is in %s'
                % location_info.final_city)

        self.display['event_warnings'] = event_warnings
        self.display['event_errors'] = event_errors
        self.display['event'] = fb_event

        # Add Event
        if self.request.get('force_add') or not event_errors:
            self.user.add_message('Your event "%s" has been added.' %
                                  fb_event['info']['name'])
            add_entities.add_update_fb_event(fb_event,
                                             self.fbl,
                                             creating_uid=self.user.fb_uid,
                                             creating_method=eventdata.CM_USER)
        self.render_page()