Commit d9f9de23 authored by Dexter Sapugay's avatar Dexter Sapugay

deez

parent 0ebd4e9b
drop database IPS;
create database IPS;
use IPS;
CREATE TABLE employee
(employee_id VARCHAR(10) NOT NULL,
employee_fname VARCHAR(255) NOT NULL,
employee_mname VARCHAR(255),
employee_lname VARCHAR(255) NOT NULL,
employee_sex CHAR(1) NOT NULL,
employee_bday DATE NOT NULL,
employee_email VARCHAR(255) NOT NULL,
employee_num CHAR(10),
employee_emergnum CHAR(10),
CONSTRAINT employee_pk PRIMARY KEY (employee_id));
CREATE TABLE joborder
(joborder_no VARCHAR(10) NOT NULL,
report_no VARCHAR(10) NOT NULL,
process VARCHAR(255) NOT NULL,
status VARCHAR(255) NOT NULL,
CONSTRAINT joborder_pk PRIMARY KEY (joborder_no, report_no));
CREATE TABLE productivity
(report_no VARCHAR(10) NOT NULL,
employee_id VARCHAR(10) NOT NULL,
prod_date DATE NOT NULL,
workinghours TIME,
remarks TEXT(2000),
prod_score FLOAT,
CONSTRAINT productivty_pk PRIMARY KEY (report_no),
CONSTRAINT productivity_fk FOREIGN KEY (employee_id) REFERENCES employee(employee_id));
CREATE TABLE history
(history_no VARCHAR(10) NOT NULL,
employee_id VARCHAR(10) NOT NULL,
position_id VARCHAR(10) NOT NULL,
employee_fname VARCHAR(255) NOT NULL,
employee_mname VARCHAR(255),
employee_lname VARCHAR(255) NOT NULL,
position_name VARCHAR(255) NOT NULL,
position_startdate DATE NOT NULL,
position_enddate DATE,
CONSTRAINT history_pk PRIMARY KEY (history_no),
CONSTRAINT history_fk1 FOREIGN KEY (employee_id) REFERENCES employee(employee_id));
CREATE TABLE position
(position_id VARCHAR(10) NOT NULL,
history_no VARCHAR(10) NOT NULL,
position_name VARCHAR(255) NOT NULL,
CONSTRAINT position_pk PRIMARY KEY (position_id),
CONSTRAINT position_fk FOREIGN KEY (history_no) REFERENCES history(history_no));
CREATE TABLE dashboard
(dashboard_id VARCHAR(10) NOT NULL,
employee_id VARCHAR(10) NOT NULL,
report_no VARCHAR(255) NOT NULL,
timespan TIME NOT NULL,
displaytype VARCHAR(255) NOT NULL,
total_workinghours TIME NOT NULL,
contribution VARCHAR(10) NOT NULL,
avgprodscore FLOAT(5,2) NOT NULL,
CONSTRAINT dashboard_pk PRIMARY KEY (dashboard_id),
CONSTRAINT dashboard_fk1 FOREIGN KEY (employee_id) REFERENCES employee(employee_id),
CONSTRAINT dashboard_fk2 FOREIGN KEY (report_no) REFERENCES productivity(report_no));
/* sample working hours
INSERT INTO my_table (id, duration) VALUES (1, INTERVAL '2:30' HOUR TO MINUTE);
sample date
INSERT INTO my_table (id, my_date) VALUES (1, '2023-02-13');
sample productivity_score
INSERT INTO my_table (id, productivity_score) VALUES (1, 7.5);
*/
<table>
<thead>
<tr>
<th>Report Number</th>
<th>Employee ID</th>
<th>Prod Date</th>
<th>Working Hours</th>
<th>Remarks</th>
<th>Prod Score</th>
<!-- add more headers for additional fields -->
</tr>
</thead>
<tbody>
{% for row in csv_data %}
<tr>
<td>{{ row.report_no }}</td>
<td>{{ row.employee_id }}</td>
<td>{{ row.prod_date }}</td>
<td>{{ row.workinghours }}</td>
<td>{{ row.remarks }}</td>
<td>{{ row.prod_score }}</td>
<!-- add more cells for additional fields -->
</tr>
{% endfor %}
</tbody>
</table>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<label for="csv_file">Upload a CSV file:</label>
<input type="file" name="csv_file" accept=".csv">
<input type="submit" value="Upload">
</form>
\ No newline at end of file
<!DOCTYPE html>
<html>
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Upload</button>
</form>
</html>
\ No newline at end of file
......@@ -5,6 +5,8 @@ from . import views
urlpatterns = [
path('admin/', admin.site.urls),
path('', views.home, name='home'),
path('upload_csv/', views.upload_csv, name = 'upload_csv'),
path('show_csv_data/', views.show_csv_data, name ='show_csv_data')
#path('', views.login_page, name='loginpage'),
]
\ No newline at end of file
import csv
from datetime import datetime
from django.shortcuts import render
from django.shortcuts import render, redirect
from .models import Productivity
from django.shortcuts import render
from django.contrib import messages
from django.utils.dateparse import parse_date, parse_duration
from dateutil.parser import parse as parse_date
def home(request):
return render(request, 'EmployeeProdDB/index.html')
def csv_import(request):
with open('C:\Users\dxsap\Downloads\IPS_dummy_data.csv') as f:
reader = csv.reader(f)
for row in reader:
my_model = Productivity(
field1=row[0],
field2=row[1],
field3=datetime.strptime(row[2], '%Y-%m-%d').date()
def upload_csv(request):
if request.method == 'POST':
csv_file = request.FILES['csv_file']
if not csv_file.name.endswith('.csv'):
messages.error(request, 'This is not a CSV file')
else:
# read the data from the uploaded file
csv_data = csv.reader(
(line.decode('utf-8') for line in csv_file),
delimiter=',',
quotechar='"'
)
my_model.save()
return render(request, 'csv_imported.html')
# create and save model instances for each row of data
for row in csv_data:
report_no = row[0]
employee_id = row[1]
prod_date_str = row[2]
#prod_date = row[2]
prod_date = None
if prod_date_str:
prod_date = parse_date(prod_date_str)
workinghours_str = row[3]
workinghours = None
if workinghours_str:
workinghours = parse_duration(workinghours_str)
remarks = row[4]
prod_score = row[5]
Productivity.objects.create(
report_no=report_no,
employee_id=employee_id,
prod_date=prod_date,
workinghours=workinghours,
remarks=remarks,
prod_score=prod_score,
# add more fields as needed
)
return redirect('show_csv_data')
return render(request, 'EmployeeProdDB/upload_csv.html')
def show_csv_data(request):
csv_data = Productivity.objects.all()
return render(request, 'EmployeeProdDB/show_csv_data.html', {'csv_data': csv_data})
#def handle_file_upload(request):
# if request.method == 'POST':
# file = request.FILES.get('file-input')
......
No preview for this file type
INSERT INTO employee
VALUES (1, 'Bernice', 'Atienza', 'Enrique', 'F', 2002-04-03, 'bernice.enrique@obf.ateneo.edu', 09493703771, 09193553990);
INSERT INTO employee
VALUES (2, 'Dexter', 'Quitalig', 'Sapugay', 'M', 2002-04-10, 'dexter.sapugay@obf.ateneo.edu', 09191234565, 09496758890);
INSERT INTO joborder
VALUES (1, 1, 'Binding', 'on-going');
INSERT INTO joborder
VALUES (2, 2, 'Binding', 'on-going');
INSERT INTO productivity
VALUES (1, 1, '2022-02-13', '01:30', 'This is dummy data', 97.1);
INSERT INTO productivity
VALUES (2, 1, '2022-02-14', '01:00', 'This is dummy data again', 96.2);
INSERT INTO productivity
VALUES (3, 2, '2022-02-13', '01:15', 'This is dummy data what is new', 98.3);
\ No newline at end of file
SELECT joborder.report_no, employee.employee_id, employee_fname, joborder_no, process
FROM employee, joborder,productivity
WHERE employee.employee_id = productivity.employee_id
AND joborder.report_no = productivity.report_no;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment