Professional Documents
Culture Documents
A PROJECT REPORT
Submitted by
ANIL NEERUKONDA INSTITUTE OF TECHNOLOGY
AND SCIENCES
(AUTONOMOUS)
SANGIVALASA, VISAKHAPATNAM - 531 162
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
Mrs.Lokeswari Mrs.Amaravathi
Asst.Professor &FACULTY
Asst.Professor&FACULTY
CSE,ANITS CSE,ANITS
DECLARATION
ACKNOWLEDGEMENT
An endeavor over a long period can be successful with the advice and
support of many well-wishers. We take this opportunity to express our
gratitude and appreciation to all of them.
We owe our tributes to Mrs.Lokeswari (Asst. Professor),
Department of Computer Science & Engineering for her valuable
support and guidance during the period of project implementation.
We wish to express our sincere thanks and gratitude to our project
guides Mrs.Amaravathi (Asst. Professor), Department of Computer
Science & Engineering for the stimulating discussions, in analyzing
problems associated with our project work and for guiding us throughout
the project. Project meetings were highly informative. We express our
warm and sincere thanks for the encouragement, untiring guidance and
the confidence they had shown in us. We are immensely indebted for
their valuable guidance throughout our project.
We also thank all the staff members of CSE department for
their valuable advices.
We also thank Principal and supporting staff for providing
resources as and when required.
Chapter 1 5
INTRODUCTION 5
Chapter 2 7
RELATED WORK 7
Login Module: 7
Scoreboard Module: 7
Accept Challenge Module: 7
Run Tests Module: 7
Errors and Warnings Module: 8
2. 1 Product Functions 8
Server 8
Client 9
Chapter 3 10
SYSTEM ANALYSIS 10
3.1. Software Requirement Specifications 10
3.2 Operating Environment 10
Server Hardware Requirements: 10
Client Hardware Requirements: 11
3.3 Design and Implementation Constraints 11
Server 11
client 11
External Interface Requirements 11
3.4User Interfaces 11
3.5 Hardware Interfaces 12
3.6 Software Interfaces 12
3.7 Communication Interfaces 12
3.8 Other Non Functional Requirements 12
3.8.1 Performance Requirements 12
3.8.2 Safety Requirements 12
3.8.3 Security Requirements 13
3.8.4 Software Quality Attributes 13
3.8.5 Business Rules 13
Chapter 4 13
SYSTEM DESIGN 14
4.1.System Architecture 14
4.1.1 Modules 15
Module Description 15
4.2. UML Design 16
4.2.1. Use Case Diagram 17
4.2.2. Class Diagram 19
4.2.3. Interaction Diagrams 21
4.2.4. Activity Diagram 22
Chapter 5 23
Implementation 24
5.1 Overview of the Softwares Used 24
Python 24
MySQL 25
HTML 25
PHP 26
PyCharm 27
Visual Studio Code 27
5. 2 Algorithm Explanation 28
Chapter 6 29
TESTING 30
6.1 Types of testing 30
6.1.1 Unit Testing 31
6.1.2 Integrating Testing 32
6.1.3 System Testing 32
6.1.4 Acceptance Testing 32
6.1.5 Security Testing: 33
6.2 Test Cases 33
Test Case 6.2.1 34
The Objective: Incorrect Login 34
Test Case 6.2.2 35
The Objective: Incorrect file extensions 35
Test Case 6.2.3 36
The Objective: Incorrect test cases 36
Chapter 7 38
RESULT ANALYSIS 38
Chapter 8 38
Chapter 1
INTRODUCTION
The objective of this project, CodeDuel is to provide a platform for coding competitions
and Hackathon events where the competition is done between two coders. Each contestant can
bring their own set of problems to challenge the other contestant. The challenge thrown by one
contestant should be solved by the other within a given time limit and the code should be pushed
to the server where it will be run against the test cases. The purpose of this SRS is to specify the
requirements of this project, CodeDuel and is intended to be the online judge for Cursors 2019
event “Code Avadhan”.
CodeDuel is a platform for code battles or similar competitions. It has an online judge
along with the capability to host code battles for many contestants. Given the rules of the event
“Code Avadhan”, there exists no platform to host it except to manually run the program files and
verify the outputs. This project will provide a solution by being the platform for the event.
The only purpose of building this application is to use it as a platform for the event “Code
Avadhan”. In this event, there exists contestants who challenge each other with coding problems.
The opponents solve the problem and push it to the server where the code will be tested against
the test cases provided. The contestants should register prior to the event and should submit their
question, solution and test cases as .txt, .c/.cpp/.java/.py and .txt file respectively. These files are
put into the server’s file system which is uniquely designed for this platform. Initially the scores
will be zero for all. When the event starts, the contestant will enter the problem key to pull it
from the server to a client machine. The contestant is then free to use any external IDE’s or text
editors to write code and test it. Once, he has solved it, he will upload it using the client side
software. This file is first validated against given set of valid file types. Then the program is
compiled and run against the test cases. Depending on the test cases passed or not the score is
updated in the database. This score is shown on the scoreboard of the client side software.
The contestant should have the knowledge to this competition. The UI is simple and clean such
that a well informed contestant will be able to use it with ease. No specific user training is
required. However, a demo might be necessary to all the contestants. There are two types of
users in this application.
1. Admin
2. Contestant
The administrator is the person conducting the event. He/She will have access to the database
and the file system on the server. He has the privileges to add or remove contestants, add or
remove problems, add or remove test cases and also to insert all the data into the database. The
spec files consists of the problem statement or specification. The permissions to upload these
files or remove them are only assigned to the admin. The admin does not user the client software
instead has a web application which he uses to login and perform the necessary tasks. Text files
are the test cases where each file consists either of the input or expected output. Each file is
entered into the database with a unique path and consists of a predefined no of marks. The admin
reserves the right to upload these files to the server and update the database as well. The admin
unlike the contestants will be able to view the scores of all the contestants. He will have a
scoreboard and a UI on the web application that is unlike the scoreboard on the client side. The
scoreboard will sort the leaders according the points earned and timestamp of their submissions.
The contestant will be able to perform the following operations. he/she will be able to view his
score and his opponent’s score only. He will have a refresh button which will update the
scoreboard based on the last entry in the database at the server side. The contestant will be able
to pull the spec file from the server to the client system.
Chapter 2
RELATED WORK
Login Module:
The login module will help the contestant to log into their accounts. They cannot register by
themselves since this is a closed event and requires a great deal of preprocessing. Hence, only the
contestants having access to their id and password can log in.
Scoreboard Module:
Each contestant is allowed to see two contestants score. One is themselves and the other is their
opponent’s score. The scope of the scoreboard is only limited to two contestants. Without this
platform, there would be no means to know the score except by manually asking. The scoreboard
also has a refresh button to update the scores.
Since this is a duel event, the questions can only be seen after accepting a challenge thrown by
the opponent. Here the opponent will just mention the key of his problem and the contestant will
enter into this module to view the challenge.
After solving a problem, the contestant can push his code to the server. Once this is done, the
corresponding test cases and their scores will be fetched and the tests are run. The database is
updated according to whether the test case has passed or not.
Errors and Warnings Module:
Since this is a coding event, the files pushed to the server might have compilation or runtime
errors, these errors have to be reported back to the client, else he will not know what is cause of
the failed test cases. This module will collect all errors and warnings and send it to the client.
The client side software is responsible for displaying it to the contestant.
2. 1 Product Functions
The proposed application software is designed for Code Avadhan. This application can be
classified into two parts.
1. Server
2. Client
Server
1. Server
2. Runtime
3. Database
The server will have all the socket programming related code. It also has a dedicated format to
receive the messages from the client system. Only the inputs in this format received by the server
are accepted else it will be discarded.
The received words tell the server to perform either of the following tasks:
1. Authenticate login.
2. Run tests for the file uploaded.
3. Fetch scores
for the contestant and his opponent. The runtime module is responsible for running the submitted
program and catching either the output, compilation errors or runtime errors. It opens a
subprocess and runs the program so that any harmful code executed via the subprocess is kept
safe from the application. The runtime module will also update the scores in the database
depending on the test cases passed. The database module is a separate class which acts like a
connector to the database. This will have a set of functions which can be called to perform a
certain task. This can be used as an API for the CodeDuel application. This method of clean
implementation means that the process will only be connected to the database and the connection
is passed as argument. New connections are only spawned for new threads. Other than that no
unnecessary connections are made.
Client
1. Client
2. ClientUI
The client will have all the code related to the socket connections. It also has a CLI that the
contestant can use to communicate with the client. The module will create a metadata.json file
with the contestant id and password and will store it on the client’s current working directory. It
sends messages in the format set earlier to the server. The clientUI module will have all the
tkinter components to build the GUI for the contestant. The UI consists of scoreboard, accept
challenge section, question section and push the code section with a background image. This
module will import the client module and make necessary calls to communicate with the server .
Chapter 3
SYSTEM ANALYSIS
System analysis is the description of a system into its component pieces to study how the
component pieces are study and work.
RAM: 8 GB or higher
HDD: 5 GB or higher
Network: LAN
Client Hardware Requirements:
RAM: 2 GB or higher
HDD: 5 GB or higher
Network: LAN
Server
Software Requirements:
client
Software Requirements:
3.4User Interfaces
The Graphical User Interface is clean and simple. Contestants with very less knowledge of the
system will be able to use the client software. Since, the users are contestants who write code,
they are also well versed with using the command line. The command “clash help” will let the
contestants know the commands on how to use it via CLI.
The connection between the client and server are done using socket connections. The port
number for sending requests is 32757 and for sending files is 6000.
The server and the client are connected over sockets and the communication protocol is unique
to the application.
3.8.3 Security Requirements
It is possible that the data can be modified for any reason. To overcome this factor we are using a
secure database. The file system by default is protected by the operating system. Additionally we
will change the permissions to the directories specific to the server side application.
Chapter 4
SYSTEM DESIGN
The purpose of software design is to specify how the output to be produced and in what
format samples of output is produced.It describes about the quality of the system.
Maintainability through simplified mapping to the problem domain, which provides for less
analysis effort, less complexity in system design, easier verification by the user.
4.1.System Architecture
System Architecture describes “the overall structure of the system and the ways in which
the structure provides conceptual integrity”. It describes how the system works when contestant
login into the system and what are the basic operations performed by the contestant and when the
contestant logout from the system.
Fig. 4.1. Architecture
4.1.1 Modules
1. Login.
2. View Scores.
3. Pull File.
4. Push File.
5. Logout.
Module Description
Login The Login module allows the contestant or user to enter the login credentials required to
enter into the system.If the credentials of the user are valid then the contestant is allowed to view
the other modules else the user will not be able to view the system.
View Scores
The view scores module allows the contestants to view the scores of his and the opponent with
whom he compete if the login credentials are valid.It doesn’t allow the contestant to view the
scores of all contestants participated in the competition.Only the admin has the access or right to
view all contestants scores and update them.
Push File
The push file module allows the contestant to upload a file on to the database which contains the
question that challenges the opponent and the conditions required to solve the particular
problem,a file that contains the test cases to be passed to award the scores based on no.of test
cases passed.It allows the opponent to upload the file that contains the solution to the problem
statement given by the contestant.
Pull File
The pull file module allows the contestant to download the problem statement file from the
database.The contestant is allowed to view the problem statement file only when he accepted the
challenge key given by the opponent.
Logout
The logout module is allowed the contestant to exit from the competition if the login credentials
are invalid or he performed the required operations.
4.2. UML Design
UML stands for Unified Modeling Language. Taking SRS document of analysis as input
to the design phase drawn UML diagrams. The UML is only language so is just one part of the
software development method. The UML is process independent, although optimally it should be
used in a process that should be driven, architecture-centric, iterative, and incremental. The UML
is language for visualizing, specifying, constructing, documenting the articles in a
software-intensive system.
A modeling language is a language whose vocabulary and rules focus on the conceptual
and physical representations of the system. A modeling language such as the UML is thus a
standard language for software blueprints.
Use Case during requirement elicitation and analysis to represent the functionality of the
system. Use Case describes a function provided by the system that yields a visible result for an
actor.
The identification of actors and use cases result in the definition of the boundary of the
system i.e., differentiating the tasks accomplished by the system and the tasks accomplished by
its environment. The actors are outside the boundary of the system, whereas the Use cases are
inside the boundary of the system. Use Cases describe the behavior of the system as seen from
the actor’s point of view. It describes the function provided by the system as a set of events that
yield a visible result for the actor.
Fig. 4.2.1. Use Case Diagram
1. Contestant.
2. Admin.
Contestant
Contestant is responsible for login into the system,peform the required operations like
push file,pull file,view scores and logout from the system.
Admin
Admin is responsible for add or delete contestants from the competition,add or delete test
cases and view the scores of all contestants in leaderboard.
The relationships used in CodeDuel are
1. Association.
2. Realisation.
The relationship between actor and usecase function must be a association.An actor can
be associated with multiple use cases and multiple actors can be associated with the single
usecase.
Realisation is used with the stereotype “<<includes>>” .It is used if one use case initiates
the task then other usecase must completes or controls the task.
Class diagrams model class structure and contents using design elements such as classes,
packages and objects. Class diagram describe three different perspectives when designing a
system- conceptual, specification and implementation. Classes are composed of three things:
name, attributes, and operations. Class diagrams also display relationships such as containment,
inheritance, associations etc. The association relationship is most common relationship in a class
diagram. The association shows the relationship between instances of classes.
1. Server side.
2. Client side.
Fig. 4.2.2. Class Diagram
CodeDuel_Database is responsible for login,get the opponent ,push or pull files ,get or update
opponent scores based on no.of test cases passed,update the test cases and view the scores.
Run_Tests is responsible for compiling and executing the test cases .The error will be handled by
this class if any runtime or compile time error occur .
Command is responsible for connection to the server,validation and configure and view the
duel_scores.
4.2.3. Interaction Diagrams
Sequence diagram displays the time sequence of the objects participating in the
interaction. This consists of the vertical dimension (time) and horizontal dimension (different
objects).
Object: can be viewed as an entity at a particular point in time with a specific value and as a
holder of identity that has different values over time.
Message: A message is sending of a signal from one sender object to other receiver object(s)
● There are two types of messages: synchronous and asynchronous messages .
● Synchronous messages will have a reply while asynchronous doesn’t has .
An activity diagram shows the flow from activity to activity. An activity is a going
non-atomic execution within a state machine. An activity results in some action, results in a
change of state or return of a value.
There are two states in Activity diagram : initial and final state .
Swim Lanes: Group work flow is called swim lanes. All groups are portioned by vertical solid
lines. Each swim lane specifies locus of activities and has a unique name. Each swim lane is
implemented by one or more classes. Transition may occur between objects across swim lanes.
Fig. 4.2.4. Activity Diagram
Chapter 5
Implementation
The implementation stage is where the coding part takes place and the project starting
taking form. Without this phase, there would be no working model or prototype to view the
project. Also, this is the phase will output code that will be worked on till the end and even
during maintenance.
The following programming languages were used in the development of this project.
1. Python 3.6.2
2. MySQL 8.0
3. HTML5
4. PHP
These languages were used in the following Integrated Development Environments and editors
to build the project.
1. PyCharm
2. Visual Studio Code
Python
Python is an interpreted, high-level, general-purpose programming language. Created by
Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes
code readability, notably using significant whitespace. It provides constructs that enable clear
programming on both small and large scales. Van Rossum led the language community until
stepping down as leader in July 2018.
Python features a dynamic type system and automatic memory management. It supports multiple
programming paradigms, including object-oriented, imperative, functional and procedural. It also
has a comprehensive standard library.
Python interpreters are available for many operating systems. CPython, the reference
implementation of Python, is open source software and has a community-based development
model, as do nearly all of Python's other implementations. Python and CPython are managed by
the non-profit Python Software Foundation.
MySQL
MySQL is an open-source relational database management system (RDBMS). Its name is
a combination of "My", the name of co-founder Michael Widenius's daughter, and "SQL", the
abbreviation for Structured Query Language.
MySQL is free and open-source software under the terms of the GNU General Public License,
and is also available under a variety of proprietary licenses. MySQL was owned and sponsored
by the Swedish company MySQL AB, which was bought by Sun Microsystems (now Oracle
Corporation).[8] In 2010, when Oracle acquired Sun, Widenius forked the open-source MySQL
project to create MariaDB.
MySQL is a component of the LAMP web application software stack (and others), which is an
acronym for Linux, Apache, MySQL, Perl/PHP/Python. MySQL is used by many
database-driven web applications, including Drupal, Joomla, phpBB, and WordPress. MySQL is
also used by many popular websites, including Facebook, Twitter, Flickr, and YouTube.
HTML
Hypertext Markup Language (HTML) is the standard markup language for creating web
pages and web applications. With Cascading Style Sheets(CSS) and JavaScript, it forms a triad of
cornerstone technologies for the World Wide Web.
Web browsers receive HTML documents from a web server or from local storage and render the
documents into multimedia web pages. HTML describes the structure of a web page semantically
and originally included cues for the appearance of the document.
HTML elements are the building blocks of HTML pages. With HTML constructs, images and other
objects such as interactive forms may be embedded into the rendered page. HTML provides a
means to create structured documents by denoting structural semantics for text such as headings,
paragraphs, lists, links, quotes and other items. HTML elements are delineated by tags, written using
angle brackets. Tags such as <img /> and <input /> directly introduce content into the page.
Other tags such as <p> surround and provide information about document text and may include
other tags as sub-elements. Browsers do not display the HTML tags, but use them to interpret the
content of the page.
HTML can embed programs written in a scripting language such as JavaScript, which affects the
behavior and content of web pages. Inclusion of CSS defines the look and layout of content. The
World Wide Web Consortium (W3C), maintainer of both the HTML and the CSS standards, has
encouraged the use of CSS over explicit presentational HTML since 1997.
PHP
PHP: Hypertext Preprocessor (or simply PHP) is a general-purpose programming
language originally designed for web development. It was originally created by Rasmus Lerdorf
in 1994; the PHP reference implementation is now produced by The PHP Group. PHP originally
stood for Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext
Preprocessor.
PHP code may be executed with a command line interface (CLI), embedded into HTML code, or
it can be used in combination with various web template systems, web content management
systems, and web frameworks. PHP code is usually processed by a PHP interpreter implemented
as a module in a web server or as a Common Gateway Interface (CGI) executable. The web
server combines the results of the interpreted and executed PHP code, which may be any type of
data, including images, with the generated web page. PHP can be used for many programming
tasks outside of the web context, such as standalone graphical applications and robotic drone
control.
The standard PHP interpreter, powered by the Zend Engine, is free software released under the
PHP License. PHP has been widely ported and can be deployed on most web servers on almost
every operating system and platform, free of charge.
The PHP language evolved without a written formal specification or standard until 2014, with
the original implementation acting as the de facto standard which other implementations aimed
to follow. Since 2014, work has gone on to create a formal PHP specification.
PyCharm
PyCharm is an integrated development environment (IDE) used in computer
programming, specifically for the Python language. It is developed by the Czech company
JetBrains. It provides code analysis, a graphical debugger, an integrated unit tester, integration
with version control systems (VCSes), and supports web development with Django.
PyCharm is cross-platform, with Windows, macOS and Linux versions. The Community Edition
is released under the Apache License, and there is also Professional Edition with extra features,
released under a proprietary license.
source and released under the permissive MIT License. The compiled binaries are freeware and
free for private or commercial use.
Visual Studio Code is based on Electron, a framework which is used to deploy Node.js
applications for the desktop running on the Blink layout engine. Although it uses the Electron
framework, the software does not use Atom and instead employs the same editor component
(codenamed "Monaco") used in Azure DevOps (formerly called Visual Studio Online and Visual
Studio Team Services).
In the Stack Overflow 2019 Developer Survey, Visual Studio Code was ranked the most popular
developer environment tool, with 50.7% of 87,317 respondents claiming to use it.
5. 2 Algorithm Explanation
The approach followed to build this application is the fork() system call. This system call
is available in C but the language we’ve used to construct this is Python. However, Python
interpreter is written using C and has many underlying C libraries that it can support. The
subprocess module that comes inbuilt with the python standard library acts as a wrapper to fork()
system call. It allows us to use PIPE to connect between the parent process and the forked
sub-process.
If we run the contestant’s program using the main process, there is a chance that the user
program might contain a runtime error which will crash during runtime bringing our server down
with it. To avoid this, we run the user-program using a subprocess which when crashed will be
limited to itself only.
Upon successful execution, the test cases are fetched from the database and passed as
input to the contestant’s program. The results are verified against the expected outputs. The
marks will be fetched from the database again and will be awarded accordingly.
If there exists a compile time, runtime error or any exception, it will be caught by the
server and sent back to the client for better understanding. The client application only focuses on
sending the files and receiving the status of it.
The entire process starts with the user logging in to the system. He will provide his user
id and password. The client sends these credentials to the server which will look up in the
database and returns the status. Upon success status, the client applications opens the next page.
Here the contestant enters the challenge key as told by his opponent. The key is sent to the
server, the appropriate spec file is fetched, sent back to the client and displayed on the UI. The
contestant is now free to use any external IDE’s or editors to solve the problem. Once solved he
will upload the file using the client application. Once a file is uploaded, it is verified with the
extension and then run on the server machine as described above. The status is returned to the
client as well. This process repeats till the server is killed or all the problems are solved.
Chapter 6
TESTING
The purpose of testing is to discover errors. Testing is the process of trying to discover
every conceivable fault or weakness in a work product. It provides a way to check the
functionality of components, sub assemblies, assemblies and/or a finished product. It is the
process of exercising software with the intent of ensuring that the software system meets its
requirements and user expectations and does not fail in an unacceptable manner.
Software testing is an important element of the software quality assurance and represents the
ultimate review of specification, design and coding. The increasing feasibility of software as a
system and the cost associated with the software failures are motivated forces for well planned
through testing.
Testing Objectives
These are several rules that can save as testing objectives they are:
● A good test case is one that has a high probability of finding an undiscovered error.
In order to make sure that the system does not have errors, the different levels of testing
strategies that are applied at differing phases of software development are:
6.1.1 Unit Testing
Unit Testing is done on individual modules as they are completed and become
executable. It is confined only to the designer's requirements. Unit testing is different from and
should be preceded by other techniques, including:
● Inform debugging
● Code inspections.
In this strategy some test cases are generated as input conditions that fully execute all
functional requirements for the program. This testing has been used to find error in the following
categories:
● Interface errors.
● Performance error.
In this the test cases are generated on the logic of each module by drawing flow graphs of
that module and logical decisions are tested on all the cases. It has been uses to generate the test
cases in the following cases:
● Execute all loops at their boundaries and within their operational bounds.
Integration testing ensures that software and subsystems work together a whole. It tests
the interface of all the modules to make sure that the modules behave properly when integrated
together. It is typically performed by developers, especially at the lower, module-to-module
level. Testers become involved at the higher levels.
Involves in - house testing of the entire system before delivery to the user. The aim is to
satisfy the user the system meets all requirements of the client's specifications. It is conducted by
the testing organization if a company has one. Test data may range from hand generated to
production.
● Inclusion of changes/fixes.
One common approach is graduated testing: as system testing progresses and (hopefully) fewer
and fewer defects are found, the code is frozen for testing for increasingly longer time periods.
It is a pre-delivery testing in which entire system is tested at client's site on real world
data to find errors.
“Beta testing”: Acceptance testing in the customer environment.
Requirements traceability:
Security testing is conducted to evaluate how secured the client-server system is while
authentication the request. Server should only send response to the request which is authentic
over the network.
In general a test case is a set of test data and test programs and their expected results. A test case
in software engineering normally consists of a unique identifier, requirement references from a
design specification, preconditions, events, a series of steps (also known as actions) to follow,
input, output and it validates one or more system requirements and generates a pass or fail.
Test Case 6.2.1
Test Case 6.2.2
1 Checking whether If the files uploaded Displays file type not Pass
the files uploaded do not have .c or supported
are of .c , .c++, .py , .c++ , .py , .java
.java or not extensions.
Test Case 6.2.3
Chapter 7
RESULT ANALYSIS
Since this is a one of a kind system that is designed for Code-Avadhan event exclusively,
we do not have an exactly similar existing system to compare our performance with. However,
we have taken necessary steps to make sure that the system’s performance is not compromised.
Everytime the server receives a request, it identifies the type of request and spawns a new
thread to service the requests. Necessary steps are taken to handle any runtime errors and
exceptions and close the connections when appropriate. Just like the regular coding platforms,
we have modified our subprocess calls to capture compile time and runtime errors and return it to
the client machine. However, infinite loops are a possible case hence, a time limit is also added
to run the code and if exceeded the process is terminated.
The server is designed so robust that it cannot be crashed by any sort of user inputs. The
user need not use it via the GUI but also through the command line arguments passing different
parameters while all the cases are well handled by displaying appropriate messages to the client
machine.
Since, the server is designed to run on one of the systems in the lab which is connected to
all the other user systems, the network requirement will only be a LAN connection. This means
that the requests are serviced very quick and the responses reach back in very short amount of
time. Also, the reason to spawn threads to service each request is that, when one thread creates a
forked process to run the contestant’s program and waits for it to return the output, other requests
can be serviced by running the threads independently. Spawning the threads not only introduces
parallelism but also allows the server to be in listening state for maximum amount of time
making it available all the time for the considered no of requests thereby not having to drop any
requests.
Chapter 8
Our project is developed to serve as a platform for Code Avadhan event. Since, this
platform is specifically tailored to suit the needs of the event, it can only be used for it. The
event, if not for the fest will be conducted under the CSI student branch of ANITS at various
times of an academic year by looking into the availability of the students. During all these times,
the platform will serve as an automated process reducing the manual effort to evaluate programs
and share the results among the duels of the contestants while the contest is going on.
Since, this is a closed event and only one event will be conducted at a time, there is no
need to improve the database or the server to handle multiple events. However, the client side
software can be modified to serve as a text editor and to go well with the command line interface
that is already designed for this application before the graphical user interface. This means that
the client software will be as good as this application, sublime text and git integration combined.
To make the competition much more fair, we can give the contestants a closed
environment that they will use to develop their software or write code to solve the problems. An
Integrated Development Environment (IDE) can be built into the client software. A better
approach to this would be to build a plugin with all the client software features and integrate this
into an existing IDE.
Chapter 9
REFERENCES
APPENDIX
//Client Functions
import sys
import socket
import os
import json
separator = '/'
class File_Transfer:
self.c_id = c_id
self.ftp = FTP('')
self.ftp.connect('10.0.67.232', 1026)
self.ftp.login()
#self.ftp.retrlines('LIST')
separator = '/'
dir_list = filepath.split(separator)
self.dir = separator.join(dir_list[:-1])
self.file = dir_list[-1]
self.separate_dir_file(filename)
try:
self.ftp.cwd('documents/codeduelcursors2019/src' +
separator + str(self.c_id) + separator + file)
except:
self.ftp.cwd('documents/codeduelcursors2019/src' +
separator + str(self.c_id))
def download_file(self, filename):
self.ftp.cwd('documents/codeduelcursors2019/spec' +
separator + file)
localfile.close()
def __del__(self):
self.ftp.quit()
class Command:
def __init__(self):
self.server = socket.socket()
self.server.connect((hostname, port))
try:
self.read_c_id('metadata.json')
except:
pass
metadata = json.load(metadata_file)
c_id = metadata['c_id']
self.c_id = c_id
self.server.send(message.encode())
response = self.server.recv(1024)
if response.decode() == 'success':
return True
return False
print('Login Failed. Check Credentails')
Return
self.c_id = c_id
metadata = dict()
metadata['c_id'] = c_id
metadata['password'] = password
json.dump(metadata, metadata_file)
print('Login Successful')
try:
self.read_c_id('metadata.json')
except:
try:
push_file = File_Transfer(self.c_id)
push_file.upload_file(program_file)
message = 'test,' + str(self.c_id) + ',' + program_file
self.server.send(message.encode())
test_run_status = self.server.recv(1024)
return test_run_status.decode()
except Exception as e:
print(e)
return '\n'
try:
pull_file = File_Transfer(-1)
pull_file.download_file(p_title)
except:
def get_duel_scores(self):
try:
self.read_c_id('metadata.json')
except:
try:
self.server.send(message.encode())
scores = self.server.recv(1024).decode()
return scores
except:
def print_help(self):
print(help)
def __del__(self):
self.server.close()
if __name__ == '__main__':
if len(sys.argv) == 1:
print("Wrong usage")
sys.exit(0)
cmd = Command()
argc = len(sys.argv)
test_run_status = cmd.push_file(sys.argv[i])
print(test_run_status)
cmd.accept_challenge(sys.argv[2])
elif sys.argv[1] == 'points' and argc == 2:
points = cmd.get_duel_scores()
print(points)
cmd.configure(int(sys.argv[2]), sys.argv[3])
cmd.print_help()
else:
cmd.print_help()
// Server Functions
import socket
with suppress(Exception):
with suppress(Exception):
import runtime
import database
import threading
class Server:
self.c_id = c_id
self.database = database
self.client_conn = client_conn
self.specs = specs
def ftp_service(self):
username = 'ajay'
port = 12345
authorizer = DummyAuthorizer()
authorizer.add_anonymous("/users/ajayraj/",
perm="elradfmw")
handler = FTPHandler
handler.authorizer = authorizer
ftp_server.serve_forever()
separator = '/'
dir_list = filepath.split(separator)
self.dir = separator.join(dir_list[:-1])
self.file = dir_list[-1]
def client_service(self):
print('TEST')
try:
self.separate_dir_file(self.specs)
src_path = self.database.get_directory_path('src')
test_path = self.database.get_directory_path('test')
p_id = self.database.get_pid(filename)
test_file_names =
self.database.get_test_filenames(p_id)
test_run_status = run.run_tests()
self.client_conn.send(test_run_status.encode())
duel_id = self.database.get_duel_id(self.c_id)
print('\n\n')
print('\n\n')
with suppress(Exception):
except Exception as e:
print(e)
with suppress(Exception):
def duel_scores(self):
print('SCORE', self.c_id)
try:
opponent_id = self.database.get_opponent_id(self.c_id)
contestant_name =
self.database.get_contestant_name(self.c_id)
opponent_name =
self.database.get_contestant_name(opponent_id)
contestant_score = 0 if self.database.get_score(self.c_id)
is None else self.database.get_score(self.c_id)
opponent_score = 0 if
self.database.get_score(opponent_id) is None else
self.database.get_score(opponent_id)
self.client_conn.send(message.encode())
except Exception as e:
print(e)
def validate_login(self):
print('LOGIN', self.c_id)
try:
if self.database.validate_login(self.c_id, specs):
message = 'success'
else:
message = 'fail'
self.client_conn.send(message.encode())
print(message)
except Exception as e:
print(e)
def __del__(self):
with suppress(Exception):
self.client_conn.close()
server = socket.socket()
server.bind((hostname, port))
server.listen(10)
ftp_service_thread =
threading.Thread(target=ftp_server.ftp_service)
ftp_service_thread.start()
while True:
received_message = conn.recv(port).decode()
try:
codeduel_db = database.CodeDuel_Database()
if action == 'score':
duel_scores_thread =
threading.Thread(target=server_interface.duel_scores)
duel_scores_thread.start()
client_service_thread =
threading.Thread(target=server_interface.client_service)
client_service_thread.start()
elif action == 'validate':
validate_thread =
threading.Thread(target=server_interface.validate_login)
validate_thread.start()
except:
conn.close()
//DataBase Validations
import socket
with suppress(Exception):
with suppress(Exception):
import runtime
import database
import threading
class Server:
self.c_id = c_id
self.database = database
self.client_conn = client_conn
self.specs = specs
def ftp_service(self):
username = 'ajay'
port = 12345
authorizer = DummyAuthorizer()
authorizer.add_anonymous("/users/ajayraj/",
perm="elradfmw")
handler = FTPHandler
handler.authorizer = authorizer
ftp_server.serve_forever()
separator = '/'
dir_list = filepath.split(separator)
self.dir = separator.join(dir_list[:-1])
self.file = dir_list[-1]
def client_service(self):
print('TEST')
try:
self.separate_dir_file(self.specs)
src_path = self.database.get_directory_path('src')
test_path = self.database.get_directory_path('test')
p_id = self.database.get_pid(filename)
test_file_names =
self.database.get_test_filenames(p_id)
test_run_status = run.run_tests()
self.client_conn.send(test_run_status.encode())
duel_id = self.database.get_duel_id(self.c_id)
print('\n\n')
print('\n\n')
with suppress(Exception):
except Exception as e:
print(e)
with suppress(Exception):
def duel_scores(self):
print('SCORE', self.c_id)
try:
opponent_id = self.database.get_opponent_id(self.c_id)
contestant_name =
self.database.get_contestant_name(self.c_id)
opponent_name =
self.database.get_contestant_name(opponent_id)
` contestant_score = 0 if self.database.get_score(self.c_id)
is None else self.database.get_score(self.c_id)
opponent_score = 0 if
self.database.get_score(opponent_id) is None else
self.database.get_score(opponent_id)
self.client_conn.send(message.encode())
except Exception as e:
print(e)
def validate_login(self):
print('LOGIN', self.c_id)
try:
if self.database.validate_login(self.c_id, specs):
message = 'success'
else:
message = 'fail'
self.client_conn.send(message.encode())
print(message)
except Exception as e:
print(e)
def __del__(self):
with suppress(Exception):
self.client_conn.close()
server = socket.socket()
server.bind((hostname, port))
server.listen(10)
ftp_service_thread =
threading.Thread(target=ftp_server.ftp_service)
ftp_service_thread.start()
while True:
received_message = conn.recv(port).decode()
try:
codeduel_db = database.CodeDuel_Database()
if action == 'score':
duel_scores_thread =
threading.Thread(target=server_interface.duel_scores)
duel_scores_thread.start()
client_service_thread =
threading.Thread(target=server_interface.client_service)
client_service_thread.start()
validate_thread =
threading.Thread(target=server_interface.validate_login)
validate_thread.start()
except:
conn.close()
A.2 Input/Outut Design
Login:
Accepting Challenge :
Uploading File :
View ScoreBoard :