Beispiel #1
0
    def recover(self):

        # Forward to main page if already logged in
        if session.get("UserName"):
            redirect(url(controller="main", action="index"))

        # Attempt a recovery
        user_username = request.params.get("username")
        c.recover_error = ""

        # If we have no arguments; just post the regular form
        if not user_username:
            c.body_content = render("/form_recover.html")

        # Else, attempt to find the user
        else:

            # Attempt a recover
            c.recover_error = Users.UserReset(user_username)

            # If no error, we recovered correctly
            if len(c.recover_error) <= 0:
                c.body_content = render("/form_recovered.html")
            else:
                c.body_content = render("/form_recover.html")

        # Render page
        return render("/theme.html")
Beispiel #2
0
	def results_view(self):
		
		# Pull up this user's information
		UserName = request.path[request.path.find("results/") + 8 : len(request.path)]
		
		# Pull up this user's information
		ExistingUser = Users.UserQueryName(UserName)
		
		# Check for existance
		if not ExistingUser:
			abort(status_code = 404, detail = "User name \"" + UserName + "\" does not exist.")
		
		# Solution list
		c.solutions = []
		
		# Build a solutions list with connected data (i.e. challenge name, group name, etc..)
		solutions = Solutions.SolutionsUserID(ExistingUser.UserID)
		for solution in solutions:
		
			# Query the challenge to pull out the title and group name
			Challenge = Challenges.ChallengeQueryID(solution.ChallengeID)
			
			# Query the group
			ChallengeGroup = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False)
			
			# Post the challenge title and group name
			UserSolution = {"SolutionID": solution.SolutionID, "ChallengeID": solution.ChallengeID, "GroupName": ChallengeGroup.ChallengeGroupName, "GroupID": ChallengeGroup.ChallengeGroupID, "ChallengeTitle": Challenge.Title, "SubmissionDate": solution.SubmitDateTime, "MemoryUsage": solution.MemoryUsage, "RuntimeUsage": solution.RuntimeUsage, "ResultCode": solution.ResultCode}
			
			# Append to list
			c.solutions.append(UserSolution)
		
		# Render page
		c.body_content = render("/content_resultsview.html")
		return render("/theme.html")
Beispiel #3
0
	def recover(self):
		
		# Forward to main page if already logged in
		if session.get("UserName"):
			redirect(url(controller="main", action="index"))
		
		# Attempt a recovery
		user_username = request.params.get("username")
		c.recover_error = ""
		
		# If we have no arguments; just post the regular form
		if not user_username:
			c.body_content = render("/form_recover.html")
		
		# Else, attempt to find the user
		else:
			
			# Attempt a recover
			c.recover_error = Users.UserReset(user_username)
			
			# If no error, we recovered correctly
			if len(c.recover_error) <= 0:
				c.body_content = render("/form_recovered.html")
			else:
				c.body_content = render("/form_recover.html")
		
		# Render page
		return render("/theme.html")
Beispiel #4
0
	def challenges_view(self):
		
		# Query all of the challenges this user is bound to
		c.challengesview_challengegroup = Challenges.ChallengesQuery()
		
		# Render regular form
		c.body_content = render("/content_challengesview.html")
		return render("/theme.html")
Beispiel #5
0
    def challenges_view(self):

        # Query all of the challenges this user is bound to
        c.challengesview_challengegroup = Challenges.ChallengesQuery()

        # Render regular form
        c.body_content = render("/content_challengesview.html")
        return render("/theme.html")
Beispiel #6
0
	def result_view(self):
		
		# Is this a logged-in user? If not, forward them to log-in
		UserID = session.get("UserID")
		if not UserID:
			redirect(url(controller="users", action="login"))
		
		# Pull up this results's information
		ResultID = request.path[request.path.find("result/") + 7 : len(request.path)]
		
		# Query the results information
		Solution = Solver.QueryResultID(UserID, ResultID)
		
		# If no solution, post error
		if not Solution:
			abort(status_code = 404, detail = "Result ID \"" + ResultID + "\" does not exist.")
		
		# Query the challenge
		# Note to self: can I directly access via foriegn key?
		Challenge = Challenges.ChallengeQueryID(Solution.ChallengeID)
		if not Challenge:
			abort(status_code = 404, detail = "Challenge ID \"" + Solution.ChallengeID + "\" does not exist.")
		
		# Find all user solutions to this Challenge...
		Challenge.solutions = Solutions.SolutionsUserIDChallengeID(UserID, Solution.ChallengeID)
		Challenge.attempts = len(Challenge.solutions)
		Challenge.solved = False
		
		# Check if we have solved this challenge
		for solution in Challenge.solutions:
			if solution.ResultCode == 1:
				Challenge.solved = True
				break
		
		# Post the owner group of this challenge
		c.groupname = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False).ChallengeGroupName
		
		# Post the challenge view content
		c.challenge = Challenge
		
		# Post the parent group directory
		c.group_id = Challenge.ChallengeGroupID
		c.group_name = c.groupname
		
		# Post the user-level directory data
		c.challenge_id = Challenge.ChallengeID
		c.challenge_name = Challenge.Title
		
		# Convert the source code into html friendly code
		# NOTE: We are defaulting everything to just render in Python
		c.formated_code = h.code_to_html(Solution.SourceCode, "Python")
		c.formated_samplecode = h.code_to_html(Challenge.SampleCode, "Python")
		
		# Render the solution information
		c.challenge = Challenge
		c.result = Solution
		c.body_content = render("/content_resultview.html")
		return render("/theme.html")
Beispiel #7
0
    def admin(self):

        # Check for page permission
        if not self.IsAdmin():
            abort(status_code=403, detail="Forbidden: You are not an administrator.")

            # Render the admin page if the user has rights...
        c.body_content = render("/content_admin.html")
        return render("/theme.html")
Beispiel #8
0
    def admin(self):

        # Check for page permission
        if not self.IsAdmin():
            abort(status_code=403,
                  detail="Forbidden: You are not an administrator.")

        # Render the admin page if the user has rights...
        c.body_content = render("/content_admin.html")
        return render("/theme.html")
Beispiel #9
0
    def challenge_view(self):

        # Pull up this challenge's information
        ChallengeID = request.path[request.path.find("challenge/") + 10 : len(request.path)]

        # Is this a valid integer?
        if not ChallengeID.isdigit():
            abort(status_code=404, detail='Challenge ID "' + ChallengeID + '" does not exist.')

            # Query the challenge
        Challenge = Challenges.ChallengeQueryID(ChallengeID)
        if Challenge is None:
            abort(status_code=404, detail='Challenge ID "' + ChallengeID + '" failed to load.')
        if not Challenge.IsValid:
            abort(status_code=500, detail='Challenge ID "' + ChallengeID + '" failed to load: ' + Challenge.ErrorStr)

            # Find all user solutions to this Challenge...
        Challenge.solutions = Solutions.SolutionsUserIDChallengeID(session.get("UserID"), ChallengeID)
        Challenge.attempts = len(Challenge.solutions)
        Challenge.solved = False

        # Check if we have solved this challenge
        for solution in Challenge.solutions:
            if solution.ResultCode == 1:
                Challenge.solved = True
                break

                # Generate graphics / tables
        self.__generate_graphics(ChallengeID)

        # Post the owner group of this challenge
        c.groupname = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False).ChallengeGroupName

        # Convert the source code into html friendly code
        # NOTE: We are defaulting everything to just render in Python
        c.formated_code = h.code_to_html(Challenge.StarterCode, "Python")
        c.formated_samplecode = h.code_to_html(Challenge.SampleCode, "Python")

        # Post the challenge view content
        c.challenge = Challenge

        # Post the parent group directory
        c.group_id = Challenge.ChallengeGroupID
        c.group_name = c.groupname

        # Post the user-level directory data
        c.challenge_id = Challenge.ChallengeID
        c.challenge_name = Challenge.Title

        # Render regular form
        c.body_content = render("/content_challengeview.html")
        return render("/theme.html")
Beispiel #10
0
    def preferences(self):

        # Forward to main page if not logged in
        UserID = ""
        if not session.get("UserID"):
            redirect(url(controller="main", action="index"))
        else:
            UserID = session.get("UserID")

        # Reset post-back error strings
        c.change_error = ""
        c.icon_error = ""
        c.delete_error = ""

        # Are we resetting the password?
        if request.params.get("command") == "change":

            # Is the form empty, if so render out regular form
            OldPassword = request.params.get("change_oldpassword")
            NewPassword = request.params.get("change_newpassword")
            ConfirmPassword = request.params.get("change_confirmpassword")

            # Default error string to nothing...
            c.change_error = Users.SetUserPassword(session.get("UserName"),
                                                   OldPassword, NewPassword,
                                                   ConfirmPassword)

        # Else if, are we changing the user's icon?
        elif request.params.get("command") == "icon":

            # Set the user's icon ID and internally update as needed
            c.icon_error = Users.UserSetIconID(UserID,
                                               request.params.get("iconid"))
            self.BaseController_UpdateUserHeader()

        # Else if, are we deleting the account?
        elif request.params.get("command") == "delete":

            # Get the post-back
            Password = request.params.get("delete_password")
            ConfirmPassword = request.params.get("delete_confirmpassword")

            # Attempt to delete the account; if "deleted" string is returned that means success
            c.delete_error = Users.UserDelete(UserID, Password,
                                              ConfirmPassword)
            if c.delete_error == "deleted":
                redirect(url(controller="main", action="index"))

        # Post the preferences form
        c.body_content = render("/form_preferences.html")
        return render("/theme.html")
Beispiel #11
0
	def leaderboard(self):
		
		# Get list of total points
		c.top_scores = Users.GetUsersByScores()
		
		# Get list of most complete challenges
		c.top_challenges = Users.GetUsersByChallenges()
		
		# Get list of highest achievements
		c.top_achievements = Users.GetUsersByAchievements()
		
		# Post the preferences form
		c.body_content = render("/content_leaderboard.html")
		return render("/theme.html")
Beispiel #12
0
    def leaderboard(self):

        # Get list of total points
        c.top_scores = Users.GetUsersByScores()

        # Get list of most complete challenges
        c.top_challenges = Users.GetUsersByChallenges()

        # Get list of highest achievements
        c.top_achievements = Users.GetUsersByAchievements()

        # Post the preferences form
        c.body_content = render("/content_leaderboard.html")
        return render("/theme.html")
Beispiel #13
0
	def preferences(self):
		
		# Forward to main page if not logged in
		UserID = ""
		if not session.get("UserID"):
			redirect(url(controller="main", action="index"))
		else:
			UserID = session.get("UserID")
		
		# Reset post-back error strings
		c.change_error = ""
		c.icon_error = ""
		c.delete_error = ""
		
		# Are we resetting the password?
		if request.params.get("command") == "change":
			
			# Is the form empty, if so render out regular form
			OldPassword = request.params.get("change_oldpassword")
			NewPassword = request.params.get("change_newpassword")
			ConfirmPassword = request.params.get("change_confirmpassword")
			
			# Default error string to nothing...
			c.change_error = Users.SetUserPassword(session.get("UserName"), OldPassword, NewPassword, ConfirmPassword)
		
		# Else if, are we changing the user's icon?
		elif request.params.get("command") == "icon":
			
			# Set the user's icon ID and internally update as needed
			c.icon_error = Users.UserSetIconID(UserID, request.params.get("iconid"))
			self.BaseController_UpdateUserHeader()
		
		# Else if, are we deleting the account?
		elif request.params.get("command") == "delete":
			
			# Get the post-back
			Password = request.params.get("delete_password")
			ConfirmPassword = request.params.get("delete_confirmpassword")
			
			# Attempt to delete the account; if "deleted" string is returned that means success
			c.delete_error = Users.UserDelete(UserID, Password, ConfirmPassword)
			if c.delete_error == "deleted":
				redirect(url(controller="main", action="index"))
		
		# Post the preferences form
		c.body_content = render("/form_preferences.html")
		return render("/theme.html")
Beispiel #14
0
	def document(self):
		
		# Get some basic error information
		resp = request.environ.get('pylons.original_response')
		exception = request.environ.get('pylons.controller.exception')
		
		# If no exception, just post the original message
		if not exception:
			c.error_description = resp.status
		
		# Post error code and description (Just a combined string)
		else:
			c.error_description = str(resp.status_int) + " - " + str(exception.detail)
		
		# Load the about page content and then post it
		# back through the standard renderer
		c.body_content = render("/content_error.html")
		return render("/theme.html")
Beispiel #15
0
    def register(self):

        # Did we attempt to register?
        user_name = request.params.get("username")
        user_email = request.params.get("useremail")
        user_password = request.params.get("userpassword")
        user_passwordconfirm = request.params.get("userconpassword")

        # Attempt to register this user
        c.login_error = Users.UserRegister(user_name, user_email,
                                           user_password, user_passwordconfirm)

        # Redirect as needed if we are already logged-in
        if c.login_error == "redirect":
            redirect(url(controller="main", action="index"))

        # Reset the error message if nothing was posted (i.e. the user loaded this form the first time)
        elif len(request.params) == 0:
            c.login_error = ""
            c.body_content = render("/form_register.html")

        # Else, some sort of failure, just post back the error string
        elif len(c.login_error) > 0:
            c.body_content = render("/form_register.html")

        # Reset the error message if nothing was posted (i.e. post-back failure)
        elif len(request.params) != 4:
            c.login_error = "Post-back failure. Try to register again."
            c.body_content = render("/form_register.html")

        # All checks are applied; user is valid, so log-in for them
        else:

            # Force explicit log-in and refresh some of the
            Users.UserLogin(user_name, user_password, True)
            self.BaseController_UpdateUserHeader()

            # Post username and render the registered form
            c.user_name = user_name
            c.body_content = render("/form_registered.html")

        # Render regular form
        return render("/theme.html")
Beispiel #16
0
    def document(self):

        # Get some basic error information
        resp = request.environ.get('pylons.original_response')
        exception = request.environ.get('pylons.controller.exception')

        # If no exception, just post the original message
        if not exception:
            c.error_description = resp.status

        # Post error code and description (Just a combined string)
        else:
            c.error_description = str(resp.status_int) + " - " + str(
                exception.detail)

        # Load the about page content and then post it
        # back through the standard renderer
        c.body_content = render("/content_error.html")
        return render("/theme.html")
Beispiel #17
0
	def register(self):
		
		# Did we attempt to register?
		user_name = request.params.get("username")
		user_email = request.params.get("useremail")
		user_password = request.params.get("userpassword")
		user_passwordconfirm = request.params.get("userconpassword")
		
		# Attempt to register this user
		c.login_error = Users.UserRegister(user_name, user_email, user_password, user_passwordconfirm)
		
		# Redirect as needed if we are already logged-in
		if c.login_error == "redirect":
			redirect(url(controller="main", action="index"))
		
		# Reset the error message if nothing was posted (i.e. the user loaded this form the first time)
		elif len(request.params) == 0:
			c.login_error = ""
			c.body_content = render("/form_register.html")
		
		# Else, some sort of failure, just post back the error string
		elif len(c.login_error) > 0:
			c.body_content = render("/form_register.html")
		
		# Reset the error message if nothing was posted (i.e. post-back failure)
		elif len(request.params) != 4:
			c.login_error = "Post-back failure. Try to register again."
			c.body_content = render("/form_register.html")
		
		# All checks are applied; user is valid, so log-in for them
		else:
			
			# Force explicit log-in and refresh some of the
			Users.UserLogin(user_name, user_password, True)
			self.BaseController_UpdateUserHeader()
			
			# Post username and render the registered form
			c.user_name = user_name
			c.body_content = render("/form_registered.html")
		
		# Render regular form
		return render("/theme.html")
Beispiel #18
0
	def login(self):
		
		# Attempt a log-in
		user_username = request.params.get("username")
		user_password = request.params.get("password")
		c.login_error = Users.UserLogin(user_username, user_password)
		
		# Redirect as needed if we are already logged-in
		if c.login_error == "redirect":
			redirect(url(controller="main", action="index"))
		
		# Clear out error if the form is just empty
		if len(request.params) == 0:
			c.login_error = ""
		
		# Already logged-in, redirect forward to the main screen
		if len(request.params) == 2 and len(c.login_error) == 0:
			redirect(url(controller="main", action="index"))
		
		# Failed; post error
		else:
			c.body_content = render("/form_login.html")
			return render("/theme.html")
Beispiel #19
0
    def login(self):

        # Attempt a log-in
        user_username = request.params.get("username")
        user_password = request.params.get("password")
        c.login_error = Users.UserLogin(user_username, user_password)

        # Redirect as needed if we are already logged-in
        if c.login_error == "redirect":
            redirect(url(controller="main", action="index"))

        # Clear out error if the form is just empty
        if len(request.params) == 0:
            c.login_error = ""

        # Already logged-in, redirect forward to the main screen
        if len(request.params) == 2 and len(c.login_error) == 0:
            redirect(url(controller="main", action="index"))

        # Failed; post error
        else:
            c.body_content = render("/form_login.html")
            return render("/theme.html")
Beispiel #20
0
    def user_view(self):

        # Pull up this user's information
        UserName = request.path[request.path.find("users/") +
                                6:len(request.path)]

        # Pull up this user's information
        ExistingUser = Users.UserQueryName(UserName)

        # Check for existance
        if not ExistingUser:
            abort(status_code=404,
                  detail="User \"" + UserName + "\" does not exist.")

        # Basic user information
        c.user = ExistingUser
        c.user_points = Users.UpdateUserPoints(ExistingUser.UserID)

        # Post the achivements list
        c.achievements = Achievements.AchievementsQueryUserID(
            ExistingUser.UserID)

        # Find all unique solutions for each challenge, attempts, and succesfull attempts
        c.complete_challenges = []
        c.attempt_count = 0
        c.success_count = 0

        # Query all challenges and check each one if we have complete it...
        challenges = Challenges.QueryAllChallenges()
        for challenge in challenges:

            # Find all of the solutions for this challenge
            solutions = ChallengeSolutions = Solutions.SolutionsUserIDChallengeID(
                ExistingUser.UserID, challenge.ChallengeID)

            # Add to the number of attempts
            c.attempt_count += len(solutions)

            # Add the number of valid attempts
            for solution in solutions:
                if solution.ResultCode == 1:
                    c.success_count += 1

            # Save any and all solutions
            for solution in solutions:

                # Is this a valid solution though?
                if solution.ResultCode == 1:

                    # Query the challenge to pull out the title and group name
                    Challenge = Challenges.ChallengeQueryID(
                        challenge.ChallengeID)

                    # Query the group
                    ChallengeGroup = Challenges.ChallengesGroupQueryGroupID(
                        Challenge.ChallengeGroupID, False)

                    # Post the challenge title and group name
                    UserSolution = {
                        "ChallengeID": Challenge.ChallengeID,
                        "GroupID": Challenge.ChallengeGroupID,
                        "GroupName": ChallengeGroup.ChallengeGroupName,
                        "ChallengeTitle": Challenge.Title,
                        "ChallengePoints": Challenge.Points
                    }

                    # Put into the list and stop looking for solutions in this group
                    c.complete_challenges.append(UserSolution)
                    break

        # Post some statistical data / challenge data
        if c.attempt_count != 0:
            c.challenge_ratio = "%.2f%% (%d/%d)" % (
                float(float(c.success_count) / float(c.attempt_count)) * 100.0,
                c.success_count, c.attempt_count)
        else:
            c.challenge_ratio = "No challenges have been attempted"

        # Out of all the (valid) solutions, find the fastest (lowest) submission speed and lowest memory usage
        if len(c.complete_challenges) <= 0:
            c.fastest_speed = "No accepted solutions"
            c.smallest_memory = "No accepted solutions"
        else:
            c.fastest_speed = sys.maxint
            c.smallest_memory = sys.maxint

        # Find all the valid solutions and get the best run-time speeds and memory usage
        all_solutions = Solutions.SolutionsAcceptedUserID(ExistingUser.UserID)
        for solution in all_solutions:
            if solution.RuntimeUsage < c.fastest_speed:
                c.fastest_speed = solution.RuntimeUsage
            if solution.MemoryUsage < c.smallest_memory:
                c.smallest_memory = solution.MemoryUsage

        # Format string
        if len(c.complete_challenges) > 0:
            c.fastest_speed = str(c.fastest_speed) + " milliseconds"
            c.smallest_memory = str(c.smallest_memory) + " kB"

        # Render regular form
        c.body_content = render("/content_userview.html")
        return render("/theme.html")
Beispiel #21
0
	def challengegroup_view(self):
		
		# Pull up this challenge's information
		ChallengeGroupID = request.path[request.path.find("challenges/") + 11 : len(request.path)]
		
		# Find the challenge description
		ChallengesID = Challenges.ChallengesQueryGroupID(ChallengeGroupID)
		
		# If list is empty, just error out
		if len(ChallengesID) <= 0:
			abort(status_code = 404, detail = "No challenges in this challenge group.")
		
		# Start challenges meta-info list
		# Note that the second array is index the same and contains
		# a tuple representing the (Attempts / All Users) (Solved / All Attempts)
		ChallengesInfo = []
		ChallengePercentage = []
		
		# Query all the challenges associated with this challenge list
		for ChallengeID in ChallengesID:
			
			# PART 1: Get challenge meta data
			# Get the challenge information
			ChallengeInfo = Challenges.ChallengeQueryID(ChallengeID)
			
			# Query associated challenge solutions
			UserSolutions = Solutions.SolutionsUserIDChallengeID(session.get("UserID"), ChallengeID)
			ChallengeInfo.attempts = len(UserSolutions)
			ChallengeInfo.solved = False
			
			# Does the user's solutions contain at least one valid solution?
			for Attempt in UserSolutions:
				if Attempt.ResultCode == 1:
					ChallengeInfo.solved = True
					break
			
			# Put into challenge list
			ChallengesInfo.append(ChallengeInfo)
			
			# PART 2: Get the attempts / all users and solved / attempts percentage
			UserAttempts = Solutions.GetUserAttemptsCount(ChallengeID) # Number of attempts by users
			UserCount = Users.UserGetUserCount()
			
			TotalSuccess = Solutions.GetSolvedCount(ChallengeID, True) # Yes, count duplicate correct solutions
			AttemptCount = Solutions.GetAttemptsCount(ChallengeID)
			
			# Put into the percentage pair
			if UserCount != 0:
				AttemptsPercent = "%.2f" % (100.0 * float(UserAttempts) / float(UserCount))
			else:
				AttemptsPercent = "0.00"
			
			if AttemptCount != 0:
				SolvedPercent = "%.2f" % (100.0 * float(TotalSuccess) / float(AttemptCount))
			else:
				SolvedPercent = "0.00"
			
			# Put into percentage list
			ChallengePercentage.append([AttemptsPercent, SolvedPercent])
		
		# Post the challenges group info into the mako template context
		c.challengesview_challengesgroup = Challenges.ChallengesGroupQueryGroupID(ChallengeGroupID)
		
		# Post the challenges info into the mako template context
		c.challengesview_challengesmeta = ChallengesInfo
		c.chalenge_percentage = ChallengePercentage
		
		# Post top directory info
		c.group_name = c.challengesview_challengesgroup.ChallengeGroupName
		c.group_id = ChallengeGroupID
		
		# Render regular form
		c.body_content = render("/content_challengeslistview.html")
		return render("/theme.html")
Beispiel #22
0
	def about(self):
	
		# Load the about page content and then post it
		# back through the standard renderer
		c.body_content = render("/content_about.html")
		return render("/theme.html")
Beispiel #23
0
    def submit_view(self):
		
		# Is this a logged-in user? If not, forward them to log-in
		if not session.get("UserName"):
			redirect(url(controller="users", action="login"))
		
		# Get user ID
		UserID = session.get("UserID")
		
		# Pull up this challenge's information
		ChallengeID = request.path[request.path.find("submit/") + 7 : len(request.path)]
		
		# Is this a valid integer?
		if not ChallengeID.isdigit():
			abort(status_code = 404, detail = "Challenge ID \"" + ChallengeID + "\" does not exist.")
		
		# Default form error string
		c.submit_error = ""
		
		# Pull the given post-backs out
		SourceCode = request.params.get("code")
		SourceLanguage = request.params.get("language")
		
		# Query the challenge
		Challenge = Challenges.ChallengeQueryID(ChallengeID)
		if not Challenge:
			abort(status_code = 404, detail = "Challenge ID \"" + ChallengeID + "\" does not exist.")
		
		# Verify file is valid
		if not Challenge.IsValid:
			return Challenge.ErrorStr#abort(status_code = 404, detail = "Challenge ID \"" + ChallengeID + "\" failed to load.")
		
		# Query associated challenge solutions
		UserSolutions = Solutions.SolutionsUserIDChallengeID(session.get("UserID"), ChallengeID)
		Challenge.attempts = len(UserSolutions)
		Challenge.solved = False
		
		# Does the user's solutions contain at least one valid solution?
		for Attempt in UserSolutions:
			if Attempt.ResultCode == 1:
				Challenge.solved = True
				break
		
		# Post the owner group of this challenge
		c.groupname = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False).ChallengeGroupName
		
		# Post the challenge view content
		c.challenge = Challenge
		
		# Post the parent group directory
		c.group_id = Challenge.ChallengeGroupID
		c.group_name = c.groupname
		
		# Post the user-level directory data
		c.challenge_id = Challenge.ChallengeID
		c.challenge_name = Challenge.Title
		
		# Is this a fresh post-back?
		if not SourceCode or not SourceLanguage:
			
			# Render submission form...
			c.body_content = render("/form_submit.html")
			return render("/theme.html")
		
		# Else, we need to parse the given code!
		else:
			
			# Solve challenge...
			# Note to self: in the future, we will have to have an internal queue system that takes
			# in any number of calls to this function, but only posts back the results when they are ready...
			ResultID = Solver.SolveChallenge(UserID, ChallengeID, SourceCode, SourceLanguage)
			redirect(url(controller="result", action=str(ResultID)))
Beispiel #24
0
 def policy(self):
     c.body_content = render("/content_policy.html")
     return render("/theme.html")
Beispiel #25
0
 def contact(self):
     c.body_content = render("/content_contact.html")
     return render("/theme.html")
Beispiel #26
0
 def license(self):
     c.body_content = render("/content_license.html")
     return render("/theme.html")
Beispiel #27
0
    def about(self):

        # Load the about page content and then post it
        # back through the standard renderer
        c.body_content = render("/content_about.html")
        return render("/theme.html")
Beispiel #28
0
	def contact(self):
		c.body_content = render("/content_contact.html")
		return render("/theme.html")
Beispiel #29
0
    def index(self):

        # Render the main theme with the default main content
        c.body_content = render("/content_splash.html")
        return render("/theme.html")
Beispiel #30
0
	def user_view(self):
		
		# Pull up this user's information
		UserName = request.path[request.path.find("users/") + 6 : len(request.path)]
		
		# Pull up this user's information
		ExistingUser = Users.UserQueryName(UserName)
		
		# Check for existance
		if not ExistingUser:
			abort(status_code = 404, detail = "User \"" + UserName + "\" does not exist.")
		
		# Basic user information
		c.user = ExistingUser
		c.user_points = Users.UpdateUserPoints(ExistingUser.UserID)
		
		# Post the achivements list
		c.achievements = Achievements.AchievementsQueryUserID(ExistingUser.UserID)
		
		# Find all unique solutions for each challenge, attempts, and succesfull attempts
		c.complete_challenges = []
		c.attempt_count = 0
		c.success_count = 0
		
		# Query all challenges and check each one if we have complete it...
		challenges = Challenges.QueryAllChallenges()
		for challenge in challenges:
			
			# Find all of the solutions for this challenge
			solutions = ChallengeSolutions = Solutions.SolutionsUserIDChallengeID(ExistingUser.UserID, challenge.ChallengeID)
			
			# Add to the number of attempts
			c.attempt_count += len(solutions)
			
			# Add the number of valid attempts
			for solution in solutions:
				if solution.ResultCode == 1:
					c.success_count += 1
			
			# Save any and all solutions
			for solution in solutions:
				
				# Is this a valid solution though?
				if solution.ResultCode == 1:
				
					# Query the challenge to pull out the title and group name
					Challenge = Challenges.ChallengeQueryID(challenge.ChallengeID)
					
					# Query the group
					ChallengeGroup = Challenges.ChallengesGroupQueryGroupID(Challenge.ChallengeGroupID, False)
					
					# Post the challenge title and group name
					UserSolution = {"ChallengeID": Challenge.ChallengeID, "GroupID": Challenge.ChallengeGroupID, "GroupName": ChallengeGroup.ChallengeGroupName, "ChallengeTitle": Challenge.Title, "ChallengePoints": Challenge.Points}
					
					# Put into the list and stop looking for solutions in this group
					c.complete_challenges.append(UserSolution)
					break
					
		
		# Post some statistical data / challenge data
		if c.attempt_count != 0:
			c.challenge_ratio = "%.2f%% (%d/%d)" % (float(float(c.success_count) / float(c.attempt_count)) * 100.0, c.success_count, c.attempt_count)
		else:
			c.challenge_ratio = "No challenges have been attempted"
		
		# Out of all the (valid) solutions, find the fastest (lowest) submission speed and lowest memory usage
		if len(c.complete_challenges) <= 0:
			c.fastest_speed = "No accepted solutions"
			c.smallest_memory = "No accepted solutions"
		else:
			c.fastest_speed = sys.maxint
			c.smallest_memory = sys.maxint
		
		# Find all the valid solutions and get the best run-time speeds and memory usage
		all_solutions = Solutions.SolutionsAcceptedUserID(ExistingUser.UserID)
		for solution in all_solutions:
			if solution.RuntimeUsage < c.fastest_speed:
				c.fastest_speed = solution.RuntimeUsage
			if solution.MemoryUsage < c.smallest_memory:
				c.smallest_memory = solution.MemoryUsage
		
		# Format string
		if len(c.complete_challenges) > 0:
			c.fastest_speed = str(c.fastest_speed) + " milliseconds"
			c.smallest_memory = str(c.smallest_memory) + " kB"
		
		# Render regular form
		c.body_content = render("/content_userview.html")
		return render("/theme.html")
Beispiel #31
0
 def help(self):
     c.body_content = render("/content_help.html")
     return render("/theme.html")
Beispiel #32
0
    def challengegroup_view(self):

        # Pull up this challenge's information
        ChallengeGroupID = request.path[request.path.find("challenges/") + 11 : len(request.path)]

        # Find the challenge description
        ChallengesID = Challenges.ChallengesQueryGroupID(ChallengeGroupID)

        # If list is empty, just error out
        if len(ChallengesID) <= 0:
            abort(status_code=404, detail="No challenges in this challenge group.")

            # Start challenges meta-info list
            # Note that the second array is index the same and contains
            # a tuple representing the (Attempts / All Users) (Solved / All Attempts)
        ChallengesInfo = []
        ChallengePercentage = []

        # Query all the challenges associated with this challenge list
        for ChallengeID in ChallengesID:

            # PART 1: Get challenge meta data
            # Get the challenge information
            ChallengeInfo = Challenges.ChallengeQueryID(ChallengeID)

            # Query associated challenge solutions
            UserSolutions = Solutions.SolutionsUserIDChallengeID(session.get("UserID"), ChallengeID)
            ChallengeInfo.attempts = len(UserSolutions)
            ChallengeInfo.solved = False

            # Does the user's solutions contain at least one valid solution?
            for Attempt in UserSolutions:
                if Attempt.ResultCode == 1:
                    ChallengeInfo.solved = True
                    break

                    # Put into challenge list
            ChallengesInfo.append(ChallengeInfo)

            # PART 2: Get the attempts / all users and solved / attempts percentage
            UserAttempts = Solutions.GetUserAttemptsCount(ChallengeID)  # Number of attempts by users
            UserCount = Users.UserGetUserCount()

            TotalSuccess = Solutions.GetSolvedCount(ChallengeID, True)  # Yes, count duplicate correct solutions
            AttemptCount = Solutions.GetAttemptsCount(ChallengeID)

            # Put into the percentage pair
            if UserCount != 0:
                AttemptsPercent = "%.2f" % (100.0 * float(UserAttempts) / float(UserCount))
            else:
                AttemptsPercent = "0.00"

            if AttemptCount != 0:
                SolvedPercent = "%.2f" % (100.0 * float(TotalSuccess) / float(AttemptCount))
            else:
                SolvedPercent = "0.00"

                # Put into percentage list
            ChallengePercentage.append([AttemptsPercent, SolvedPercent])

            # Post the challenges group info into the mako template context
        c.challengesview_challengesgroup = Challenges.ChallengesGroupQueryGroupID(ChallengeGroupID)

        # Post the challenges info into the mako template context
        c.challengesview_challengesmeta = ChallengesInfo
        c.chalenge_percentage = ChallengePercentage

        # Post top directory info
        c.group_name = c.challengesview_challengesgroup.ChallengeGroupName
        c.group_id = ChallengeGroupID

        # Render regular form
        c.body_content = render("/content_challengeslistview.html")
        return render("/theme.html")
Beispiel #33
0
 def achievements(self):
     c.achievements = Achievements.AchievementsQueryAll()
     c.body_content = render("/content_achievements.html")
     return render("/theme.html")
Beispiel #34
0
	def policy(self):
		c.body_content = render("/content_policy.html")
		return render("/theme.html")
Beispiel #35
0
	def license(self):
		c.body_content = render("/content_license.html")
		return render("/theme.html")
Beispiel #36
0
    def challenge_view(self):

        # Pull up this challenge's information
        ChallengeID = request.path[request.path.find("challenge/") +
                                   10:len(request.path)]

        # Is this a valid integer?
        if not ChallengeID.isdigit():
            abort(status_code=404,
                  detail="Challenge ID \"" + ChallengeID +
                  "\" does not exist.")

        # Query the challenge
        Challenge = Challenges.ChallengeQueryID(ChallengeID)
        if Challenge is None:
            abort(status_code=404,
                  detail="Challenge ID \"" + ChallengeID +
                  "\" failed to load.")
        if not Challenge.IsValid:
            abort(status_code=500,
                  detail="Challenge ID \"" + ChallengeID +
                  "\" failed to load: " + Challenge.ErrorStr)

        # Find all user solutions to this Challenge...
        Challenge.solutions = Solutions.SolutionsUserIDChallengeID(
            session.get("UserID"), ChallengeID)
        Challenge.attempts = len(Challenge.solutions)
        Challenge.solved = False

        # Check if we have solved this challenge
        for solution in Challenge.solutions:
            if solution.ResultCode == 1:
                Challenge.solved = True
                break

        # Generate graphics / tables
        self.__generate_graphics(ChallengeID)

        # Post the owner group of this challenge
        c.groupname = Challenges.ChallengesGroupQueryGroupID(
            Challenge.ChallengeGroupID, False).ChallengeGroupName

        # Convert the source code into html friendly code
        # NOTE: We are defaulting everything to just render in Python
        c.formated_code = h.code_to_html(Challenge.StarterCode, "Python")
        c.formated_samplecode = h.code_to_html(Challenge.SampleCode, "Python")

        # Post the challenge view content
        c.challenge = Challenge

        # Post the parent group directory
        c.group_id = Challenge.ChallengeGroupID
        c.group_name = c.groupname

        # Post the user-level directory data
        c.challenge_id = Challenge.ChallengeID
        c.challenge_name = Challenge.Title

        # Render regular form
        c.body_content = render("/content_challengeview.html")
        return render("/theme.html")
Beispiel #37
0
	def help(self):
		c.body_content = render("/content_help.html")
		return render("/theme.html")
Beispiel #38
0
    def index(self):
        
        # Render the main theme with the default main content
        c.body_content = render("/content_splash.html")
        return render("/theme.html")
		
Beispiel #39
0
	def achievements(self):
		c.achievements = Achievements.AchievementsQueryAll()
		c.body_content = render("/content_achievements.html")
		return render("/theme.html")