Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submission Daffa -- 13519107 #9

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
13 changes: 13 additions & 0 deletions csv_inputs/airtravel.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
"Month, ""1958"", ""1959"", ""1960"""
JAN, 307, 360, 417
FEB, 318, 342, 391
MAR, 362, 406, 419
APR, 348, 396, 461
MAY, 363, 420, 472
JUN, 435, 472, 535
JUL, 491, 548, 622
AUG, 505, 559, 606
SEP, 404, 463, 508
OCT, 359, 407, 461
NOV, 310, 362, 390
DEC, 337, 405, 432
13 changes: 13 additions & 0 deletions csv_inputs/airtravel_cleaned.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Month,1958,1959,1960
JAN,307,360,417
FEB,318,342,391
MAR,362,406,419
APR,348,396,461
MAY,363,420,472
JUN,435,472,535
JUL,491,548,622
AUG,505,559,606
SEP,404,463,508
OCT,359,407,461
NOV,310,362,390
DEC,337,405,432
9 changes: 9 additions & 0 deletions csv_inputs/crash_catalonia.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"Day of Week", "Number of Crashes"
"Sunday", 13664
"Monday", 17279
"Tuesday", 17337
"Wednesday", 17394
"Thursday", 17954
"Friday", 19147
"Saturday", 15714

9 changes: 9 additions & 0 deletions csv_inputs/crash_catalonia_cleaned.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Day of Week,Number of Crashes
Sunday,13664
Monday,17279
Tuesday,17337
Wednesday,17394
Thursday,17954
Friday,19147
Saturday,15714

10 changes: 10 additions & 0 deletions csv_inputs/hurricanes.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"Month", "Average", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014", "2015"
"May", 0.1, 0, 0, 1, 1, 0, 0, 0, 2, 0, 0, 0
"Jun", 0.5, 2, 1, 1, 0, 0, 1, 1, 2, 2, 0, 1
"Jul", 0.7, 5, 1, 1, 2, 0, 1, 3, 0, 2, 2, 1
"Aug", 2.3, 6, 3, 2, 4, 4, 4, 7, 8, 2, 2, 3
"Sep", 3.5, 6, 4, 7, 4, 2, 8, 5, 2, 5, 2, 5
"Oct", 2.0, 8, 0, 1, 3, 2, 5, 1, 5, 2, 3, 0
"Nov", 0.5, 3, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1
"Dec", 0.0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1

10 changes: 10 additions & 0 deletions csv_inputs/hurricanes_cleaned.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Month,Average,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015
May,0.1,0,0,1,1,0,0,0,2,0,0,0
Jun,0.5,2,1,1,0,0,1,1,2,2,0,1
Jul,0.7,5,1,1,2,0,1,3,0,2,2,1
Aug,2.3,6,3,2,4,4,4,7,8,2,2,3
Sep,3.5,6,4,7,4,2,8,5,2,5,2,5
Oct,2.0,8,0,1,3,2,5,1,5,2,3,0
Nov,0.5,3,0,0,1,1,0,1,0,1,0,1
Dec,0.0,1,0,1,0,0,0,0,0,0,0,1

2 changes: 2 additions & 0 deletions src/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DB_PASSWORD='Gaussian021001'
SECRET_KEY='8wFz1OCrsQT170Z95dTre0ken12B5Dz3'
39 changes: 39 additions & 0 deletions src/csv_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import re
import pandas as pd
from collections import Counter

# Strip the csv file (Removing trailing spaces)
def clean_strip(filename):
cleaned_filename = re.search('(.*)\.csv', filename).group(1)
with open(filename, 'r', newline='') as inf, open(f'{cleaned_filename}_cleaned.csv', 'w') as of:
for line in inf:
trimmed = (field.strip().strip('"') for field in line.split(','))
of.write(','.join(trimmed)+'\n')

# Preprocess the data to delete inconsistent data
def data_preprocess(filename):
cleaned_filename = re.search('(.*)\.csv', filename).group(1)
df = pd.read_csv(f'{cleaned_filename}_cleaned.csv')
to_be_parsed = []
list_of_colname = df.columns.tolist()
to_be_parsed.append(list_of_colname)
for value in df.values.tolist():
to_be_parsed.append(value)
list_of_column = []
data_types = []
for row in to_be_parsed[1:]:
for i in range (len(row)):
list_of_column.append([row[i] for row in to_be_parsed[1:]])
data_types.append([type(row[i]) for row in to_be_parsed[1:]])
break
i = 0
result = []
for data_type in data_types:
c = Counter(data_type)
count_type = [(i, c[i] / len(data_types) * 100.0) for i in c.most_common()]
most_common_type = count_type[0]
result.append([col for col in list_of_column[i] if isinstance(col, most_common_type[0][0])])
i += 1
result.insert(0, list_of_colname)

return result
81 changes: 81 additions & 0 deletions src/database/sorts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
-- MariaDB dump 10.18 Distrib 10.5.8-MariaDB, for Win64 (AMD64)
--
-- Host: localhost Database: sorting_results
-- ------------------------------------------------------
-- Server version 10.5.8-MariaDB

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `sorts`
--

DROP TABLE IF EXISTS `sorts`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `sorts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tanggal_waktu` datetime DEFAULT NULL,
`algoritma` varchar(255) DEFAULT NULL,
`sorting_result` blob DEFAULT NULL,
`execution_time` float DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `sorts`
--

LOCK TABLES `sorts` WRITE;
/*!40000 ALTER TABLE `sorts` DISABLE KEYS */;
/*!40000 ALTER TABLE `sorts` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `user`
--

DROP TABLE IF EXISTS `user`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`public_id` varchar(50) DEFAULT NULL,
`name` varchar(255) DEFAULT NULL,
`username` varchar(50) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `public_id` (`public_id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user`
--

LOCK TABLES `user` WRITE;
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2021-06-10 1:27:14
108 changes: 108 additions & 0 deletions src/html_processing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# Function to make an html page for the specified algorithm
def sorting_page(algoritma, token):
return f"""
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>{algoritma} Sort</title>
</head>
<body>
<form action="/sort/{algoritma.lower()}?token={token}" method="post" enctype="multipart/form-data">
<label for="csv_file">Enter CSV File : </label>
<input type="file" accept=".csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" name="csv_file"/><br><br>
<label for="column_no">Enter Column No. : (Starts from 1)</label>
<input type="text" name="column_no"/><br><br>
<label for="orientation">Sorting Orientation : </label>
<input type="radio" id="asc" name="orientation" value="ascending"/>
<label for="asc">Ascending</label>
<input type="radio" id="desc" name="orientation" value="descending"/>
<label for="desc">Descending</label><br><br>
<input type="submit" value="Submit"/><br><br>
<a href='/mainpage?token={token}'>Back to Main Menu</a>
</form>
</body>
</html>
"""

# Login page in HTML
def log_page():
return """
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Login</title>
</head>
<body>
<form action="/login" method="post" enctype="multipart/form-data">
<label for="username">Username : </label>
<input type="text" name="username"/><br><br>
<label for="password">Password : </label>
<input type="text" name="password"/><br><br>
<input type="submit" value="Login"/><br><br>
<a href='/'>Back to Main Menu</a>
</form>
</body>
</html>
"""

# Signup page in HTML
def sign_page():
return """
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>Signup</title>
</head>
<body>
<form action="/signup" method="post" enctype="multipart/form-data">
<label for="username">Username : </label>
<input type="text" name="username"/><br><br>
<label for="password">Password : </label>
<input type="text" name="password"/><br><br>
<label for="name">Name : </label>
<input type="text" name="name"/><br><br>
<input type="submit" value="Signup"/><br><br>
<a href='/'>Back to Main Menu</a>
</form>
</body>
</html>
"""

# Function to turn a list into an html table (Should be list of row, not list column)
def list_to_table(l):
header = l[0]
body = l[1:]

table_script = f"""
<table class="dataframe" border="1">
<tbody>
<tr style="text-align: center">
"""
for colname in header:
table_script += f"""
<th>{colname}</th>
"""

table_script += """
</tr>
"""

for row in body:
table_script += """
<tr style="text-align: center">
"""
for col in row:
table_script += f"""
<td>{col}</td>
"""
table_script += """
</tr>
"""
table_script += """
</tbody>
</table>
"""
return table_script
Loading