Files restructuring

This commit is contained in:
username 2021-01-29 20:08:23 +01:00
parent 7317b4130b
commit cc2d70bfdf
45 changed files with 538 additions and 369 deletions

110
.gitignore vendored
View File

@ -1,15 +1,119 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# TypeScript v1 declaration files
typings/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variables file
.env
.env.test
# parcel-bundler cache (https://parceljs.org/)
.cache
# Next.js build output
.next
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/sm_react/node_modules
/node_modules
/.pnp
.pnp.js
# testing
/sm_react/coverage
/coverage
# production
/sm_react/build
/build
# misc
.DS_Store

View File

@ -1,11 +1,70 @@
# Don't forget!
# Getting Started with Create React App
1. Change your React code
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
2. In the React directory run:
## Available Scripts
`npm run build`
In the project directory, you can run:
3. Then, in the project directory run:
### `npm start`
`python3 manage.py runserver`
Runs the app in the development mode.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
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.\
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.\
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 cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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](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](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](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](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](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](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

View File

View File

@ -1,22 +0,0 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sm_django.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View File

@ -1807,6 +1807,14 @@
"react-transition-group": "^4.4.0"
}
},
"@material-ui/icons": {
"version": "4.11.2",
"resolved": "https://registry.npmjs.org/@material-ui/icons/-/icons-4.11.2.tgz",
"integrity": "sha512-fQNsKX2TxBmqIGJCSi3tGTO/gZ+eJgWmMJkgDiOfyNaunNaxcklJQFaFogYcFl0qFuaEz1qaXYXboa/bUXVSOQ==",
"requires": {
"@babel/runtime": "^7.4.4"
}
},
"@material-ui/styles": {
"version": "4.11.3",
"resolved": "https://registry.npmjs.org/@material-ui/styles/-/styles-4.11.3.tgz",

View File

@ -4,6 +4,7 @@
"private": true,
"dependencies": {
"@material-ui/core": "^4.11.3",
"@material-ui/icons": "^4.11.2",
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",

View File

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

View File

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

View File

Before

Width:  |  Height:  |  Size: 9.4 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

View File

View File

@ -1,16 +0,0 @@
"""
ASGI config for sm_django project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sm_django.settings')
application = get_asgi_application()

View File

@ -1,127 +0,0 @@
"""
Django settings for sm_django project.
Generated by 'django-admin startproject' using Django 3.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '%o(h$_y53$1g+ygja(1p(1+27wyp5v@h!l&4c8h--9gl)ore1k'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'sm_django.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'sm_react/build'),
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'sm_django.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'sm_react/build/static'),
]

View File

@ -1,23 +0,0 @@
"""sm_django URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
urlpatterns = [
path('admin/', admin.site.urls),
path('', TemplateView.as_view(template_name='index.html')),
]

View File

@ -1,16 +0,0 @@
"""
WSGI config for sm_django project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sm_django.settings')
application = get_wsgi_application()

File diff suppressed because one or more lines are too long

View File

@ -1,70 +0,0 @@
# Getting Started with Create React App
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.\
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.
The page will reload if you make edits.\
You will also see any lint errors in the console.
### `npm test`
Launches the test runner in the interactive watch mode.\
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.\
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.\
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 cant go back!**
If you arent 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 youre on your own.
You dont have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldnt feel obligated to use this feature. However we understand that this tool wouldnt be useful if you couldnt 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](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](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](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](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](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](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)

View File

@ -1,6 +0,0 @@
.App {
font-family: "Nunito", sans-serif;
background: #253237;
color: white;
display: flex;
}

View File

@ -1,22 +0,0 @@
import React, { useState } from "react";
import Navbar from "./components/Navbar.js";
import MainSection from "./components/MainSection.js";
import "./App.css";
import "bootstrap/dist/css/bootstrap.min.css";
import bubbleSort from "./algorithms/bubbleSort";
import mergeSort from "./algorithms/mergeSort";
import quickSort from "./algorithms/quickSort";
export default function App() {
return (
<>
<div className="App">
<Navbar className="Navbar" />
<MainSection className="MainSection" />
</div>
</>
);
}

View File

@ -1,20 +0,0 @@
import { React, useState } from "react";
export default function Counter() {
const [array, setArray] = useState([]);
resetArray(() => {
const array = [];
for (let i = 0; i < 100; i++) {
array.push(Math.floor(Math.random() * 100));
}
setArray(array);
});
return (
<>
<div className="array-container">
<button onClick={resetArray()}>Generate New Array</button>
</div>
</>
);
}

View File

@ -1,36 +0,0 @@
import React from "react";
import {
FormControl,
FormControlLabel,
FormLabel,
Radio,
RadioGroup,
} from "@material-ui/core";
export default function Form({
formLabel,
values,
labels,
currentValue,
onChange,
}) {
return (
<div className="card container-small">
<FormControl>
<FormLabel>{formLabel}</FormLabel>
<RadioGroup value={currentValue} onChange={onChange}>
{values.map((value, index) => {
return (
<FormControlLabel
key={`${value}_${index}`}
value={values[index]}
control={<Radio />}
label={labels[index]}
/>
);
})}
</RadioGroup>
</FormControl>
</div>
);
}

38
src/App.css Normal file
View File

@ -0,0 +1,38 @@
.App {
font-family: "Nunito", sans-serif;
display: flex;
flex-direction: column;
align-items: center;
text-align: center;
background-color: #f2f2f2;
}
.container {
display: flex;
align-items: flex-end;
justify-content: center;
margin: 25px;
padding: 25px;
}
.container-small {
display: flex;
align-items: flex-end;
justify-content: center;
margin: 5px;
padding: 15px;
}
.bars {
height: 100px;
}
.card {
background: white;
border-radius: 15px;
box-shadow: 0px 5px 15px 0px #ddd;
}
.controls {
display: flex;
}

253
src/App.js Normal file
View File

@ -0,0 +1,253 @@
import React, { useState } from "react";
import { IconButton } from "@material-ui/core";
import {
PlayArrow,
Pause,
SkipPrevious,
SkipNext,
RotateLeft,
SettingsInputAntennaTwoTone,
} from "@material-ui/icons";
import Bar from "./components/Bar";
import Form from "./components/Form";
import "./App.css";
// algorithms
import bubbleSort from "./algorithms/bubbleSort";
import mergeSort from "./algorithms/mergeSort";
import quickSort from "./algorithms/quickSort";
class App extends React.Component {
state = {
array: [],
colorKey: [],
arraySteps: [],
colorSteps: [],
currentStep: 0,
timeouts: [],
algorithm: "Bubble Sort",
barCount: 10,
delay: 200,
};
ALGO_SET = {
"Bubble Sort": bubbleSort,
"Merge Sort": mergeSort,
"Quick Sort": quickSort,
};
componentDidMount() {
this.generateBars();
}
generateSteps = () => {
let array = this.state.array.slice();
let steps = this.state.arraySteps.slice();
let colorSteps = this.state.colorSteps.slice();
this.ALGO_SET[this.state.algorithm](array, 0, steps, colorSteps);
this.setState({
arraySteps: steps,
colorSteps: colorSteps,
});
};
setTimeouts() {
let steps = this.state.arraySteps;
let colorSteps = this.state.colorSteps;
this.clearTimeouts();
let timeouts = [];
let i = 0;
while (i < steps.length - this.state.currentStep) {
let timeout = setTimeout(() => {
let currentStep = this.state.currentStep;
this.setState({
array: steps[currentStep],
colorKey: colorSteps[currentStep],
currentStep: currentStep + 1,
});
}, this.state.delay * i);
timeouts.push(timeout);
i++;
}
this.setState({
timeouts: timeouts,
});
}
stepBack = () => {
if (this.state.currentStep === 0) return;
this.clearTimeouts();
let currentStep = this.state.currentStep - 1;
this.setState({
array: this.state.arraySteps[currentStep],
colorKey: this.state.colorSteps[currentStep],
currentStep: currentStep,
});
};
stepForward = () => {
if (this.state.currentStep >= this.state.arraySteps.length - 1) return;
this.clearTimeouts();
let currentStep = this.state.currentStep + 1;
this.setState({
array: this.state.arraySteps[currentStep],
colorKey: this.state.colorSteps[currentStep],
currentStep: currentStep,
});
};
changeAlgorithm = (event) => {
this.setState(
{
algorithm: event.target.value,
currentStep: 0,
arraySteps: [
this.state.arraySteps[
this.state.currentStep === 0 ? 0 : this.state.currentStep - 1
],
],
},
() => this.generateSteps()
);
this.clearTimeouts();
this.clearColorKey();
};
changeBarCount = (barCount) => {
this.setState({ barCount: barCount }, () => this.generateBars());
// setBarCount(barCount);
//() => generateBars();
};
changeDelay = (event) => {
this.clearTimeouts();
this.setState({
delay: parseInt(event.target.value),
});
};
clearTimeouts = () => {
this.state.timeouts.forEach((timeout) => clearTimeout(timeout));
this.setState({
timeouts: [],
});
};
clearColorKey = () => {
let blankKey = new Array(parseInt(this.state.barCount)).fill(0);
this.setState({
colorKey: blankKey,
colorSteps: [blankKey],
});
};
generateBars = () => {
this.clearTimeouts();
this.clearColorKey();
let barCount = parseInt(this.state.barCount);
let barsTemp = [];
for (let i = 0; i < barCount; i++) {
barsTemp.push(Math.floor(Math.random() * 90) + 10);
}
this.setState(
{
array: barsTemp,
arraySteps: [barsTemp],
barCount: barCount,
currentStep: 0,
},
() => this.generateSteps()
);
};
render() {
let barsDiv = this.state.array.map((value, index) => (
<Bar key={index} length={value} colorKey={this.state.colorKey[index]} />
));
let playButton;
// Set player controls
if (
this.state.timeouts.length !== 0 &&
this.state.currentStep !== this.state.arraySteps.length
) {
playButton = (
<IconButton onClick={() => this.clearTimeouts()}>
<Pause />
</IconButton>
);
} else if (this.state.currentStep === this.state.arraySteps.length) {
playButton = (
<IconButton color="secondary" onClick={() => this.generateBars()}>
<RotateLeft />
</IconButton>
);
} else {
playButton = (
<IconButton color="secondary" onClick={() => this.setTimeouts()}>
<PlayArrow />
</IconButton>
);
}
return (
<div className="App">
<section className="bars container card">{barsDiv}</section>
<section className="container-small">
<IconButton onClick={() => this.generateBars()}>
<RotateLeft />
</IconButton>
<IconButton onClick={this.stepBack}>
<SkipPrevious />
</IconButton>
{playButton}
<IconButton onClick={this.stepForward}>
<SkipNext />
</IconButton>
<IconButton />
</section>
<section className="controls container-small">
<Form
formLabel="Algorithm"
values={["Bubble Sort", "Merge Sort", "Quick Sort"]}
labels={["Bubble Sort", "Merge Sort", "Quick Sort"]}
currentValue={this.state.algorithm}
onChange={this.changeAlgorithm}
/>
<Form
formLabel="Array size"
values={[10, 25, 50]}
labels={["10 items", "25 items", "50 items"]}
currentValue={this.state.barCount}
onChange={(e) => this.changeBarCount(e.target.value)}
/>
<Form
formLabel="Speed"
values={[200, 100, 50]}
labels={["1x", "2x", "4x"]}
currentValue={this.state.delay}
onChange={this.changeDelay}
/>
</section>
</div>
);
}
}
export default App;

View File

@ -2,7 +2,7 @@ import React from "react";
import "./Bar.css";
export default function Bar({ length, colorKey }) {
const COLOR_SET = ["grey", "orange", "green"];
const COLOR_SET = ["lightgrey", "grey", "#F51057"];
let color = COLOR_SET[colorKey];

27
src/components/Counter.js Normal file
View File

@ -0,0 +1,27 @@
import React from "react";
export default class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {
array: [],
};
}
resetArray() {
const array = [];
for (let i = 0; i < 100; i++) {
array.push(Math.floor(Math.random() * 100));
}
this.setState(array);
}
render() {
const array = this.state;
return (
<div className="array-container">
<button onClick={() => this.resetArray()}>Generate New Array</button>
</div>
);
}
}

38
src/components/Form.js Normal file
View File

@ -0,0 +1,38 @@
import React from "react";
import {
FormControl,
FormControlLabel,
FormLabel,
Radio,
RadioGroup,
} from "@material-ui/core";
export default function Form({
formLabel,
values,
labels,
currentValue,
onChange,
}) {
return (
<>
<div className="card container-small">
<FormControl>
<FormLabel>{formLabel}</FormLabel>
<RadioGroup value={currentValue} onChange={onChange}>
{values.map((value, index) => {
return (
<FormControlLabel
key={`${value}_${index}`}
value={values[index]}
control={<Radio />}
label={labels[index]}
/>
);
})}
</RadioGroup>
</FormControl>
</div>
</>
);
}