def compute_fast_recommendations_phase2(user_id, send_notice): from recom_helper import RecomHelper from film20.core.models import Recommendation from film20.showtimes.showtimes_helper import get_films from film20.showtimes.models import Channel from film20.showtimes.utils import get_today from itertools import chain import pytz helper = RecomHelper() user = User.objects.get(pk=user_id) profile = user.get_profile() if profile.country in settings.COUNTRIES_WITH_SHOWTIMES: if profile.timezone_id: timezone = pytz.timezone(profile.timezone_id) else: timezone = pytz.utc logger.warning("user %r has no timezone, using utc", user) today = get_today(timezone) theaters = Channel.objects.selected_by(user, Channel.TYPE_CINEMA) tv_channels = Channel.objects.selected_by(user, Channel.TYPE_TV_CHANNEL) for i in range(3): date = today + timedelta(days=i) for channels in (theaters, tv_channels): for film in get_films(date, channels): count_guessed_rate(user, film) if send_notice: notification.send([user], "recommendations_fast_calculated", {})
def compute_fast_recommendations_phase2(user_id, send_notice): from recom_helper import RecomHelper from film20.core.models import Recommendation from film20.showtimes.showtimes_helper import get_films from film20.showtimes.models import Channel from film20.showtimes.utils import get_today from itertools import chain import pytz helper = RecomHelper() user = User.objects.get(pk=user_id) profile = user.get_profile() if profile.country in settings.COUNTRIES_WITH_SHOWTIMES: if profile.timezone_id: timezone = pytz.timezone(profile.timezone_id) else: timezone = pytz.utc logger.warning("user %r has no timezone, using utc", user) today = get_today(timezone) theaters = Channel.objects.selected_by(user, Channel.TYPE_CINEMA) tv_channels = Channel.objects.selected_by(user, Channel.TYPE_TV_CHANNEL) for i in range(3): date = today + timedelta(days=i) for channels in (theaters, tv_channels): for film in get_films(date, channels): count_guessed_rate(user, film) if send_notice: notification.send([user], 'recommendations_fast_calculated', {})
def pretty_weekday(context, date): from ..views import get_today timezone = context['request'].timezone days = (date - get_today(timezone)).days if days < 3: return TODAY_TOMORROW[days] return to_local_time(date, timezone).strftime("%A")
def top_personalized_recommendations(request): user = request.user has_location = user.is_authenticated() and user.get_profile().has_location( ) cinema_films = [] tv_films = [] today = get_today(request.timezone) a_day = datetime.timedelta(days=1) key = cache.Key("top_personalized_recommendations", today, request.user) films = cache.get(key) if films is None: cinemas = showtimes_helper.get_theaters(request) tvs = showtimes_helper.get_tv_channels(request) # How many days ahead we want to check PERSONALIZED_CINEMA_DAYS = settings.PERSONALIZED_CINEMA_DAYS PERSONALIZED_TV_DAYS = settings.PERSONALIZED_TV_DAYS # How many films we want to get PERS_CINEMA_NUMBER = settings.PERSONALIZED_CINEMA_FILMS_NUMBER PERS_TV_NUMBER = settings.PERSONALIZED_TV_FILMS_NUMBER # We get films sorted by personal taste of user if cinemas: cinema_films = showtimes_helper.collect_unique_films( today, cinemas, PERS_CINEMA_NUMBER, settings.PERSONALIZED_CINEMA_DAYS, user=user) if tvs: tv_films = showtimes_helper.collect_unique_films( today, tvs, PERS_TV_NUMBER, settings.PERSONALIZED_TV_DAYS, user=user) films = (cinema_films, tv_films) cache.set(key, films) (cinema_films, tv_films) = films display = (not has_location) | bool(tv_films) | bool(cinema_films) return { 'display': display, 'has_location': has_location, 'tv_films': tv_films, 'cinema_films': cinema_films, }
def top_personalized_recommendations(request): user = request.user has_location = user.is_authenticated() and user.get_profile().has_location() cinema_films = [] tv_films = [] today = get_today(request.timezone) a_day = datetime.timedelta(days=1) key = cache.Key("top_personalized_recommendations", today, request.user) films = cache.get(key) if films is None: cinemas = showtimes_helper.get_theaters(request) tvs = showtimes_helper.get_tv_channels(request) # How many days ahead we want to check PERSONALIZED_CINEMA_DAYS = settings.PERSONALIZED_CINEMA_DAYS PERSONALIZED_TV_DAYS = settings.PERSONALIZED_TV_DAYS # How many films we want to get PERS_CINEMA_NUMBER = settings.PERSONALIZED_CINEMA_FILMS_NUMBER PERS_TV_NUMBER = settings.PERSONALIZED_TV_FILMS_NUMBER # We get films sorted by personal taste of user if cinemas: cinema_films = showtimes_helper.collect_unique_films( today, cinemas, PERS_CINEMA_NUMBER, settings.PERSONALIZED_CINEMA_DAYS, user=user) if tvs: tv_films = showtimes_helper.collect_unique_films( today, tvs, PERS_TV_NUMBER, settings.PERSONALIZED_TV_DAYS, user=user) films = (cinema_films, tv_films) cache.set(key, films) (cinema_films, tv_films) = films display = (not has_location) | bool(tv_films) | bool(cinema_films) return { 'display': display, 'has_location': has_location, 'tv_films': tv_films, 'cinema_films': cinema_films, }