Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Sorting-Tutorial
Berikut ini merupakan salah satu project yang menjadi bagian dari seleksi asisten IRK 2018

## Latar Belakang
Salah satu penerapan algoritma yang paling mudah adalah sorting. Saat ini sudah banyak algoritma untuk sorting yang telah dikembangkan di seluruh dunia. Untuk membantu orang - orang memahami berbagai algoritma sorting, tercetuslah ide untuk membuat sebuah website yang memberikan pemahaman mengenai algoritma sorting. Harapannya, website ini dapat dikembangkan lebih lanjut untuk pembelajaran strategi algoritma yang lain seperti Divide & Conquer, Dynamic Programming, dll

## Spesifikasi
Buatlah sebuah aplikasi web dengan spesifikasi sebagai berikut :
1. Pengguna dapat memilih jenis algoritma sorting yang digunakan. Pilihan yang tersedia ialah sebagai berikut :
Expand All @@ -13,12 +15,35 @@ Buatlah sebuah aplikasi web dengan spesifikasi sebagai berikut :
5. Teknologi dan bahasa pemrograman bebas untuk back-end, dan untuk front-end dibuat semenarik mungkin dengan menggunakan **React.js** atau **Vue.js**
6. Pastikan Readme ini diganti dengan Readme untuk project yang kalian buat (dibuat sejelas mungkin) !

**Keterangan** : Pilihan algoritma sewaktu - waktu dapat ditambahkan dan akan diumumkan
## Penilaian
Nilai maksimum adalah 1500. Berbagai aspek yang akan dinilai ialah
1. Kebenaran fungsionalitas program
2. UI
3. Clean Code (termasuk struktur repository)

## Bonus (500 poin)
Gunakan **Docker** dan **Deploy** website yang sudah selesai dibuat.
## Prerequisites to open program
1. Python 3.6/3.7/3.8 Download https://www.python.org/downloads/
2. Flask bisa diunduh melalui terminal dengan command pip install flask
3. Web Browser
4. Internet (untuk menjalankan dari server AWS)

### Built With
- Visual Studio Code
- Google Chrome

### Deploy With
- Docker
- AWS

### How to Run Locally
1. Buka terminal
2. Pergi ke direktori file backend
3. Selanjutnya, jalankan command: python -m flask run
4. Selanjutnya, pergi ke direktori file frontend
5. Jalankan command: npm start

### How to Run in AWS Server
Buka: http://ec2-52-220-86-67.ap-southeast-1.compute.amazonaws.com

### Demo Penggunaan
https://drive.google.com/drive/u/0/folders/1ESxnkqJjCAGnI0nVxohmmefGJCizXS9T

### Authors
- Fadhil Muhammad Rafi'

### Acknowledgement
- Muhammad Hendry Prasetya
1 change: 1 addition & 0 deletions Sorting-Tutorial
Submodule Sorting-Tutorial added at aa389b
27 changes: 27 additions & 0 deletions backend/Bubble.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import copy
def bubbleSort(array):
N = len(array)
steps = []
results=[]
actions=[]
for step in range(N):
for i in range(N-1):
if (array[i] > array[i+1]):
temp = array[i]
array[i] = array[i+1]
array[i+1] = temp
action = 'Swapping ' + str(array[i]) + ' and ' + str(array[i+1])
actions.append(action)
new_array = copy.deepcopy(array)
results.append(new_array)

for i in range(len(actions)):
steps.append(i+1)

for i in range(len(results)):
results[i] = str(results[i]) + ' '
res = []
res.append(steps)
res.append(actions)
res.append(results)
return res
10 changes: 10 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.6.10

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

COPY requirements.txt /usr/src/app
RUN pip install -r requirements.txt

ENTRYPOINT [ "flask" ]
CMD ["run", "--host=0.0.0.0", "--port=5000"]
92 changes: 92 additions & 0 deletions backend/Merge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
def printArray(arr):
N = len(arr)
if (N != 0):
for i in range(N):
print(arr[i])


def mergeSort(arr, res):
if len(arr) > 1:
temp = []


mid = len(arr)//2
L = arr[:mid]
R = arr[mid:]
step = 'Splitting ' + str(arr)
result = str(L) + ' and ' + str(R)
#print(step, 'to', result)
#steps.append(step)
#results.append(result)
temp.append(step)

temp.append(result)
for tem in temp:
res.append(tem)



mergeSort(L, res) # Sorting the first half
mergeSort(R, res) # Sorting the second half


i = j = k = 0

# Copy data to temp arrays L[] and R[]
while i < len(L) and j < len(R):
if L[i] < R[j]:
arr[k] = L[i]
i += 1
else:
arr[k] = R[j]
j += 1

k += 1


# Checking if any element was left
while i < len(L):
arr[k] = L[i]
i+= 1
k+= 1

while j < len(R):
arr[k] = R[j]
j+= 1
k+= 1
step = 'Combining ' + str(L) + ' and ' + str(R)
result = str(arr)
#print(step, 'to', result)

temp=[]
#steps.append(step)
#results.append(result)
temp.append(step)
temp.append(result)
for tem in temp:
res.append(tem)

return (res)


def parseResult(arr):
N = len(arr)
steps = []
actions = []
results = []
for i in range(N//2):
steps.append(i+1)

for i in range(N):
if i % 2 == 0:
actions.append(arr[i])
else:
results.append(arr[i])

res = []
res.append(steps)
res.append(actions)
res.append(results)

return res

54 changes: 54 additions & 0 deletions backend/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Merge
import Bubble
import re
from flask import Flask, Blueprint, render_template, request, jsonify
from flask_cors import CORS

app = Flask(__name__, static_folder='../build', static_url_path='/')
CORS(app)
api = Blueprint('api', __name__)

@app.route('/api')
def test():
return "Hello"

@app.route('/api/src/process', methods=['GET'])
def process():
string = request.args.get('input')
method = request.args.get('method')
res = Sort(string, method)

res = buildResponse(res)
sol = jsonify(res)
return sol

def Sort(string, method):
array = re.split(',', string)
new_array = []
if (len(array) <= 10):
for i in range(len(array)):
new_array.append(int(array[i]))

res = []
if (method == 'Merge'):
temp = Merge.mergeSort(new_array, res)
solution = Merge.parseResult(temp)
else:
solution = Bubble.bubbleSort(new_array)

return solution


def buildResponse(arr):
res = {

"actions" : arr[1],
"results" : arr[2],
"steps" : arr[0]
}
return res

app.register_blueprint(api, url_prefix='/api')

if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True, port=5050)
2 changes: 2 additions & 0 deletions backend/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
flask
flask-cors
24 changes: 24 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: "3"
services:
frontend:
container_name: frontend
build:
context: ./frontend
dockerfile: Dockerfile
ports:
- 80:80
volumes:
- /home/ubuntu/ssl:/etc/nginx/certs

backend:
restart: always
container_name: backend
build: ./backend
expose:
- 5000
volumes:
- ./backend:/usr/src/app
environment:
- FLASK_ENV=development
- FLASK_APP=app.py
- FLASK_DEBUG=1
23 changes: 23 additions & 0 deletions frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
3 changes: 3 additions & 0 deletions frontend/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "d:\\PADIL\\Akademik\\Tes Asisten IRK\\sorting-tutorial\\myprojectenv\\Scripts\\python.exe"
}
16 changes: 16 additions & 0 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:latest as build
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app

RUN npm install

COPY . /usr/src/app
RUN npm run build

FROM nginx:alpine
COPY --from=build /usr/src/app/build /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
68 changes: 68 additions & 0 deletions frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br />
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br />
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br />
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br />
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br />
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
Loading