예제 #1
0
파일: tests.py 프로젝트: keokilee/makahiki
 def testCurrentRound(self):
   """Tests that the current round retrieval is correct."""
   saved_rounds = settings.COMPETITION_ROUNDS
   current_round = "Round 1"
   start = datetime.date.today() - datetime.timedelta(days=3)
   end = start + datetime.timedelta(days=7)
   
   settings.COMPETITION_ROUNDS = {
     "Round 1" : {
       "start": start.strftime("%Y-%m-%d"),
       "end": end.strftime("%Y-%m-%d"),
     },
   }
   
   current = get_current_round()
   self.assertEqual(current, current_round, "Test that the current round is returned.")
   
   start = datetime.date.today() - datetime.timedelta(days=14)
   end = start + datetime.timedelta(days=7)
   
   settings.COMPETITION_ROUNDS = {
     "Round 1" : {
       "start": start.strftime("%Y-%m-%d"),
       "end": end.strftime("%Y-%m-%d"),
     },
   }
   
   current_round = get_current_round()
   self.assertTrue(current_round is None, "Test that there is no current round.")
   
   # Restore settings.
   settings.COMPETITION_ROUNDS = saved_rounds
예제 #2
0
    def testCurrentRound(self):
        """Tests that the current round retrieval is correct."""
        saved_rounds = settings.COMPETITION_ROUNDS
        current_round = "Round 1"
        start = datetime.date.today() - datetime.timedelta(days=3)
        end = start + datetime.timedelta(days=7)

        settings.COMPETITION_ROUNDS = {
            "Round 1": {
                "start": start.strftime("%Y-%m-%d"),
                "end": end.strftime("%Y-%m-%d"),
            },
        }

        current = get_current_round()
        self.assertEqual(current, current_round,
                         "Test that the current round is returned.")

        start = datetime.date.today() - datetime.timedelta(days=14)
        end = start + datetime.timedelta(days=7)

        settings.COMPETITION_ROUNDS = {
            "Round 1": {
                "start": start.strftime("%Y-%m-%d"),
                "end": end.strftime("%Y-%m-%d"),
            },
        }

        current_round = get_current_round()
        self.assertTrue(current_round is None,
                        "Test that there is no current round.")

        # Restore settings.
        settings.COMPETITION_ROUNDS = saved_rounds
예제 #3
0
파일: views.py 프로젝트: ilwoof/makahiki
def scoreboard(request,page):
   
  page = string.lower(page)
  if( page == "index"):
    page = "overall_lounge"
  user = request.user
  events = get_available_events(user)
  floor = user.get_profile().floor
  
  current_round = get_current_round()
  round_name = current_round if current_round else None
  floor_standings = Floor.floor_points_leaders(num_results=10, round_name=round_name)
  profile_standings = Profile.points_leaders(num_results=10, round_name=round_name).select_related("scoreboardentry")
  user_floor_standings = floor.points_leaders(num_results=10, round_name=round_name).select_related("scoreboardentry")
  
  categories_list = __get_categories(user)

  return render_to_response("mobile/scoreboard/"+page+".html",{
    "page": page,
    "events": events,
    "profile":user.get_profile(),
    "floor": floor,
    "categories":categories_list,
    "current_round": round_name or "Overall",
    "floor_standings": floor_standings,
    "profile_standings": profile_standings,
    "user_floor_standings": user_floor_standings,
    "help":help,
  }, context_instance=RequestContext(request))
예제 #4
0
파일: models.py 프로젝트: keokilee/makahiki
 def current_round_points(self):
   """Returns the amount of points the user has in the current round."""
   current_round = get_current_round()
   if current_round:
     return ScoreboardEntry.objects.get(profile=self, round_name=current_round).points
     
   return self.points
예제 #5
0
파일: views.py 프로젝트: tmac408/makahiki
def index(request):
  user = request.user
  events = get_available_events(user)
  floor = user.get_profile().floor
  
  current_round = get_current_round()
  round_name = current_round if current_round else None
  floor_standings = Floor.floor_points_leaders(num_results=10, round_name=round_name)
  profile_standings = Profile.points_leaders(num_results=10, round_name=round_name).select_related("scoreboardentry")
  user_floor_standings = floor.points_leaders(num_results=10, round_name=round_name).select_related("scoreboardentry")
  
  categories_list = __get_categories(user)
  
  try:
    help = HelpTopic.objects.get(slug="smart-grid-game", category="widget")     
  except ObjectDoesNotExist:
    help = None

  return render_to_response("view_activities/index.html", {
    "events": events,
    "profile":user.get_profile(),
    "floor": floor,
    "categories":categories_list,
    "current_round": round_name or "Overall",
    "floor_standings": floor_standings,
    "profile_standings": profile_standings,
    "user_floor_standings": user_floor_standings,
    "help":help,
  }, context_instance=RequestContext(request))
예제 #6
0
파일: models.py 프로젝트: keokilee/makahiki
  def current_round_floor_rank(self):
    """Returns the rank of the user for the current round in their own floor."""
    current_round = get_current_round()
    if current_round:
      return self.floor_rank(round_name=current_round)

    return None
예제 #7
0
파일: models.py 프로젝트: keokilee/makahiki
  def current_round_points(self):
    """Returns the number of points for the current round."""
    current_round = get_current_round()
    if current_round:
      return self.points(round_name=current_round)

    return None
예제 #8
0
파일: models.py 프로젝트: ilwoof/makahiki
    def current_round_points(self):
        """Returns the number of points for the current round."""
        current_round = get_current_round()
        if current_round:
            return self.points(round_name=current_round)

        return None
예제 #9
0
파일: models.py 프로젝트: keokilee/makahiki
 def current_round_overall_rank(self):
   """Returns the overall rank of the user for the current round."""
   current_round = get_current_round()
   if current_round:
     return self.overall_rank(round_name=current_round)
     
   return None
예제 #10
0
파일: models.py 프로젝트: ilwoof/makahiki
    def current_round_points(self):
        """Returns the amount of points the user has in the current round."""
        current_round = get_current_round()
        if current_round:
            return ScoreboardEntry.objects.get(profile=self,
                                               round_name=current_round).points

        return self.points
예제 #11
0
파일: views.py 프로젝트: ilwoof/makahiki
def index(request):
    user = request.user

    events = cache.get('user_events-%s' % user.username)
    if not events:
        events = get_available_events(user)
        # Cache the user_event for a day
        cache.set('user_events-%s' % user.username, events, 60 * 60)

    floor = user.get_profile().floor
    user_floor_standings = None

    current_round = get_current_round()
    round_name = current_round if current_round else None
    floor_standings = Floor.floor_points_leaders(num_results=10,
                                                 round_name=round_name)
    profile_standings = Profile.points_leaders(num_results=10,
                                               round_name=round_name)
    if floor:
        user_floor_standings = floor.points_leaders(num_results=10,
                                                    round_name=round_name)

    categories_list = __get_categories(user)

    hide_about = False
    ##TODO Check for the about cookie.
    ##if request.COOKIES.has_key("grid-hide-about"):
    ##  hide_about = True

    form = EventCodeForm()

    # Calculate active participation.
    floor_participation = Floor.objects.filter(
        profile__points__gte=50).annotate(user_count=Count(
            'profile'), ).order_by('-user_count').select_related('dorm')[:10]

    for f in floor_participation:
        f.active_participation = (f.user_count * 100) / f.profile_set.count()

    return render_to_response("view_activities/index.html", {
        "events": events,
        "profile": user.get_profile(),
        "floor": floor,
        "categories": categories_list,
        "current_round": round_name or "Overall",
        "floor_standings": floor_standings,
        "profile_standings": profile_standings,
        "user_floor_standings": user_floor_standings,
        "floor_participation": floor_participation,
        "hide_about": hide_about,
        "event_form": form,
    },
                              context_instance=RequestContext(request))
예제 #12
0
def competition(request):
    """Provides access to standard competition constants within a template."""
    user = request.user

    # We may want to retrieve theme settings for insertion into CSS.
    theme_name, theme_dict = get_theme()

    # Get user-specific information.
    floor_count = Floor.objects.count()
    overall_member_count = Profile.objects.count()
    floor_member_count = None
    quests = None
    notifications = None

    if user.is_authenticated():
        quests = get_quests(user)
        notifications = get_unread_notifications(user, limit=3)
        if user.get_profile().floor:
            floor_member_count = user.get_profile().floor.profile_set.count()

    # Get current round info.
    current_round = get_current_round() or "Overall"

    # Get Facebook info.
    try:
        facebook_app_id = settings.FACEBOOK_APP_ID
    except AttributeError:
        facebook_app_id = None

    return {
        "STATIC_URL": settings.STATIC_URL,
        "COMPETITION_NAME": settings.COMPETITION_NAME,
        "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point",
        "THEME_NAME": theme_name,
        "THEME": theme_dict,
        "FLOOR_COUNT": floor_count,
        "FLOOR_MEMBER_COUNT": floor_member_count,
        "OVERALL_MEMBER_COUNT": overall_member_count,
        "ROUNDS": get_rounds_for_header(),
        "FLOOR_LABEL": get_floor_label(),
        "CURRENT_ROUND": current_round,
        "CURRENT_ROUND_INFO": get_current_round_info(),
        "FACEBOOK_APP_ID": facebook_app_id,
        "QUESTS": quests,
        "NOTIFICATIONS": notifications,
        "IN_COMPETITION": in_competition(),
        "SPREADSHEETS": {
            "THIRTY_DAYS": settings.ENERGY_THIRTY_DAYS_URL,
            "ENERGY_GOAL": settings.ENERGY_GOAL_URL,
            "POWER": settings.POWER_GAUGE_URL,
        }
    }
예제 #13
0
def competition(request):
  """Provides access to standard competition constants within a template."""
  user = request.user
  
  # We may want to retrieve theme settings for insertion into CSS.
  theme_name, theme_dict = get_theme()
  
  # Get user-specific information.
  floor_count = Floor.objects.count()
  overall_member_count = Profile.objects.count()
  floor_member_count = None
  quests = None
  notifications = None
    
  if user.is_authenticated():
    quests = get_quests(user)
    notifications = get_unread_notifications(user, limit=3)
    if user.get_profile().floor:
      floor_member_count = user.get_profile().floor.profile_set.count()
  
  # Get current round info.
  current_round = get_current_round() or "Overall"
  
  # Get Facebook info.
  try:
    facebook_app_id = settings.FACEBOOK_APP_ID
  except AttributeError:
    facebook_app_id = None
    
  return {
    "STATIC_URL": settings.STATIC_URL,
    "COMPETITION_NAME": settings.COMPETITION_NAME,
    "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point",
    "THEME_NAME": theme_name, 
    "THEME": theme_dict,
    "FLOOR_COUNT": floor_count,
    "FLOOR_MEMBER_COUNT": floor_member_count,
    "OVERALL_MEMBER_COUNT": overall_member_count,
    "ROUNDS": get_rounds_for_header(),
    "FLOOR_LABEL": get_floor_label(),
    "CURRENT_ROUND": current_round,
    "CURRENT_ROUND_INFO": get_current_round_info(),
    "FACEBOOK_APP_ID": facebook_app_id,
    "QUESTS": quests,
    "NOTIFICATIONS": notifications,
    "IN_COMPETITION": in_competition(),
    "SPREADSHEETS": {
      "THIRTY_DAYS": settings.ENERGY_THIRTY_DAYS_URL,
      "ENERGY_GOAL": settings.ENERGY_GOAL_URL,
      "POWER": settings.POWER_GAUGE_URL,
    }
  }
예제 #14
0
def competition(request):
    """Provides access to standard competition constants within a template."""
    user = request.user

    # We may want to retrieve theme settings for insertion into CSS.
    theme_name, theme_dict = get_theme()

    # Get user-specific information.
    floor_count = Floor.objects.count()
    overall_member_count = Profile.objects.count()
    floor_member_count = None
    quests = None
    quest_help = None
    notifications = None

    # Try to load quest_help from the database.
    try:
        quest_help = HelpTopic.objects.get(slug="quests", category="widget")
    except HelpTopic.DoesNotExist:
        pass

    if user.is_authenticated():
        quests = get_quests(user)
        notifications = get_unread_notifications(user, limit=3)
        if user.get_profile().floor:
            floor_member_count = user.get_profile().floor.profile_set.count()

    # Get current round info.
    current_round = get_current_round()

    # Get Facebook info.
    try:
        facebook_app_id = settings.FACEBOOK_APP_ID
    except AttributeError:
        facebook_app_id = None

    return {
        "COMPETITION_NAME": settings.COMPETITION_NAME,
        "COMPETITION_POINT_NAME": settings.COMPETITION_POINT_NAME or "point",
        "THEME_NAME": theme_name,
        "THEME": theme_dict,
        "FLOOR_COUNT": floor_count,
        "FLOOR_MEMBER_COUNT": floor_member_count,
        "OVERALL_MEMBER_COUNT": overall_member_count,
        "ROUNDS": get_rounds_for_header(),
        "FLOOR_LABEL": get_floor_label(),
        "CURRENT_ROUND": current_round,
        "FACEBOOK_APP_ID": facebook_app_id,
        "QUESTS": quests,
        "QUEST_HELP": quest_help,
        "NOTIFICATIONS": notifications,
    }
예제 #15
0
파일: views.py 프로젝트: keokilee/makahiki
def index(request):
  user = request.user

  events = cache.get('user_events-%s' % user.username)
  if not events:
    events = get_available_events(user)
    # Cache the user_event for a day
    cache.set('user_events-%s' % user.username,
      events, 60 * 60)

  floor = user.get_profile().floor
  user_floor_standings = None
  
  current_round = get_current_round()
  round_name = current_round if current_round else None
  floor_standings = Floor.floor_points_leaders(num_results=10, round_name=round_name)
  profile_standings = Profile.points_leaders(num_results=10, round_name=round_name)
  if floor:
    user_floor_standings = floor.points_leaders(num_results=10, round_name=round_name)
  
  categories_list = __get_categories(user)

  hide_about = False
  ##TODO Check for the about cookie.
  ##if request.COOKIES.has_key("grid-hide-about"):
  ##  hide_about = True
 
  form = EventCodeForm()
  
  # Calculate active participation.
  floor_participation = Floor.objects.filter(profile__points__gte=50).annotate(
      user_count=Count('profile'),
  ).order_by('-user_count').select_related('dorm')[:10]
  
  for f in floor_participation:
    f.active_participation = (f.user_count * 100) / f.profile_set.count()
    
  return render_to_response("view_activities/index.html", {
    "events": events,
    "profile":user.get_profile(),
    "floor": floor,
    "categories":categories_list,
    "current_round": round_name or "Overall",
    "floor_standings": floor_standings,
    "profile_standings": profile_standings,
    "user_floor_standings": user_floor_standings,
    "floor_participation": floor_participation,
    "hide_about": hide_about,
    "event_form": form,
  }, context_instance=RequestContext(request))
예제 #16
0
파일: __init__.py 프로젝트: ilwoof/makahiki
def get_mobile_standings(user):
  """
  Gets a mobile version of the standings. In the mobile version, we are only using information for the current round.
  """
  current_round = get_current_round()
  
  # Retrieve standings. Note that the get_standings_for_user method returns a JSON string.
  if current_round:
    floor_standings = json.loads(get_standings_for_user(user, "floor", current_round))
    overall_standings = json.loads(get_standings_for_user(user, "all", current_round))
  else:
    # Retrieve the overall standings.
    floor_standings = json.loads(get_standings_for_user(user, "floor", None))
    overall_standings = json.loads(get_standings_for_user(user, "all", None))
  
  # Generate strings for use in the mobile website.
  info = floor_standings["info"]
  index = floor_standings["myindex"]
  rank = info[index]["rank"]
  
  if current_round:
    floor_string = "You are #%d in points for %s for %s." % (rank, user.get_profile().floor, current_round)
  else:
    floor_string = "You are #%d in points for %s in the competition." % (rank, user.get_profile().floor)
  if index > 0:
    diff = info[index - 1]["points"] - info[index]["points"]
    if diff < 2:
      floor_string += " Get 1 more point to move to #%d." % (rank - 1,)
    else:
      floor_string += " Get %d more points to move to #%d." % (diff, rank - 1)
    
  info = overall_standings["info"]
  index = overall_standings["myindex"]
  rank = info[index]["rank"]

  if current_round:
    overall_string = "You are #%d in overall points for %s." % (rank, current_round)
  else:
    overall_string = "You are #%d in overall points in the competition." % rank
  if index > 0:
    diff = info[index - 1]["points"] - info[index]["points"]
    if diff < 2:
      overall_string += " Get 1 more point to move to #%d." % (rank - 1,)
    else:
      overall_string += " Get %d more points to move to #%d." % (diff, rank - 1)
    
  return {"floor": floor_string, "overall": overall_string}
    
예제 #17
0
파일: views.py 프로젝트: keokilee/makahiki
def _get_raffle_prizes(user):
  """
  Private method to process the raffle half of the prize page.
  Takes a user and returns a dictionary to be used in the template.
  """
  current_round = get_current_round() or 'Overall'
  today = datetime.datetime.today()
  
  # Get deadline.
  try:
    deadline = RaffleDeadline.objects.get(round_name=current_round)
  except RaffleDeadline.DoesNotExist:
    # TODO; Handle if there is no raffle for this round.
    return None
    
  # Get the user's tickets.
  profile = user.get_profile()
  available_tickets = profile.available_tickets()
  total_tickets = profile.points / POINTS_PER_TICKET
  allocated_tickets = total_tickets - available_tickets
  
  prizes = None
  if deadline.pub_date < today < deadline.end_date:
    # Get the prizes for the raffle.
    prizes = RafflePrize.objects.filter(deadline=deadline).order_by("-value")
  elif today > deadline.end_date:
    # Determine if there are more prizes.
    prizes = RafflePrize.objects.filter(deadline__pub_date__gt=today)
    
  return {
    "deadline": deadline,
    "today": today,
    "points_per_ticket": POINTS_PER_TICKET,
    "tickets": {
        "available": available_tickets,
        "total": total_tickets,
        "allocated": allocated_tickets,
    },
    "prizes": prizes,
  }
예제 #18
0
파일: views.py 프로젝트: tmac408/makahiki
def _get_raffle_prizes(user):
  """
  Private method to process the raffle half of the prize page.
  Takes a user and returns a dictionary to be used in the template.
  """
  current_round = get_current_round()
  today = datetime.datetime.today()
  
  # Get deadline.
  try:
    deadline = RaffleDeadline.objects.get(round_name=current_round)
  except RaffleDeadline.DoesNotExist:
    # TODO; Handle if there is no raffle for this round.
    return None
    
  if today < deadline.pub_date:
    # TODO: Find the pub date of the next round and maybe post something about that.
    deadline = None
    
  # Get the user's tickets.
  profile = user.get_profile()
  available_tickets = profile.available_tickets()
  total_tickets = profile.points / POINTS_PER_TICKET
  allocated_tickets = total_tickets - available_tickets
  
  # Get the prizes for the raffle.
  prizes = RafflePrize.objects.filter(deadline=deadline)
    
  return {
    "deadline": deadline,
    "points_per_ticket": POINTS_PER_TICKET,
    "tickets": {
        "available": available_tickets,
        "total": total_tickets,
        "allocated": allocated_tickets,
    },
    "prizes": prizes,
  }
예제 #19
0
파일: models.py 프로젝트: keokilee/makahiki
  def current_round_rank(self):
    current_round = get_current_round()
    if current_round:
      return self.rank(round_name=current_round)

    return None
예제 #20
0
파일: models.py 프로젝트: ilwoof/makahiki
    def current_round_rank(self):
        current_round = get_current_round()
        if current_round:
            return self.rank(round_name=current_round)

        return None