Commit c144c998 authored by OnellaNatalie's avatar OnellaNatalie

Merge remote-tracking branch 'origin/IT19041926'

# Conflicts:
#	backend/database.db
#	backend/models/attribute_model.py
#	backend/models/class_component_model.py
#	backend/routes/submission_routes.py
#	backend/services/class_model_detection_service.py
parent 3cad21a7
No preview for this file type
......@@ -3,9 +3,9 @@ from config.database import db
class Attribute(db.Model):
id = db.Column(db.Integer, primary_key=True)
data_type = db.Column(db.String(50), nullable=False)
data_type = db.Column(db.String(50))
name = db.Column(db.String(50), nullable=False)
access_spec = db.Column(db.String(50), nullable=False)
access_spec = db.Column(db.String(50))
class_id = db.Column(db.Integer)
def __repr__(self) -> str:
......
......@@ -5,7 +5,7 @@ from flask_jwt_extended import jwt_required, get_jwt_identity
from constants.http_status_codes_constant import HTTP_400_BAD_REQUEST, HTTP_200_OK
from services.class_model_detection_service import component_separation
from services.class_diagram_class_detection_service import component_separation
from models.actor_and_use_case import ActorANDUseCase
from services.submission_service import save_submission
from services.use_case_model_detection_service import model_object_detection
......
import operator
import os
import re
import cv2
import numpy as np
import pytesseract as ts
from PIL import Image
from models.attribute_model import Attribute
from object_detection.utils import label_map_util
import app
import tensorflow as tf
import spacy
from config.database import db
from models.component_model import Component
from models.method_model import Method
ts.pytesseract.tesseract_cmd = r'C:\Users\DELL\AppData\Local\Programs\Tesseract-OCR\tesseract.exe'
def component_separation(filename, class_comp_id):
mdl1_path = app.CLASS_SAVED_MODEL_PATH
lbl1_path = app.CLASS_SAVED_LABEL_PATH
img1_path = app.SUBMISSION_PATH_CLASS + '/' + filename
image_nparray = np.array(Image.open(img1_path))
# print(img1_path)
boxes, num_entities, accurate_indexes, num_entities, category_index, class_id = class_object_detection(mdl1_path,
lbl1_path,
image_nparray)
# Convert the class id in their name
if num_entities > 0:
for index in range(0, len(accurate_indexes)):
if category_index[class_id[index]]['name'] == 'class':
print(filename)
_image = crop_image_(image_nparray, boxes, index)
_image = cv2.resize(_image, None, fx=2, fy=2)
class_details_detection(_image, class_comp_id)
elif category_index[class_id[index]]['name'] == 'interface':
_image = crop_image_(image_nparray, boxes, index)
_image = cv2.resize(_image, None, fx=2, fy=2)
def class_object_detection(model_path, label_path, image_nparray):
detect_fn = tf.saved_model.load(model_path)
category_index = label_map_util.create_category_index_from_labelmap(label_path, use_display_name=True)
image_np = image_nparray
input_tensor = tf.convert_to_tensor(image_np)
input_tensor = input_tensor[tf.newaxis, ...]
detections = detect_fn(input_tensor)
num_detections = int(detections.pop('num_detections'))
detections = {key: value[0, :num_detections].numpy()
for key, value in detections.items()}
detections['num_detections'] = num_detections
detections['detection_classes'] = detections['detection_classes'].astype(np.int64)
accurate_indexes = [k for k, v in enumerate(detections['detection_scores']) if (v > 0.7)]
num_entities = len(accurate_indexes)
class_id = operator.itemgetter(*accurate_indexes)(detections['detection_classes'])
boxes = detections['detection_boxes']
return boxes, num_entities, accurate_indexes, num_entities, category_index, class_id
def class_details_detection(_image, class_comp_id):
attributes_methods = []
mdl2_path = app.CLASS_COMP_SAVED_MODEL_PATH
lbl2_path = app.CLASS_COMP_SAVED_LABEL_PATH
boxes_class, num_entities, accurate_indexes, num_entities, category_index, class_id = class_object_detection(
mdl2_path, lbl2_path, _image)
comp = class_name_detection(class_comp_id, _image, boxes_class, accurate_indexes)
if num_entities > 1:
for j in range(0, len(accurate_indexes)):
if category_index[class_id[j]]['name'] == 'class_attributes':
class_attributes = crop_image_(_image, boxes_class, j)
text = text_extraction(class_attributes)
attributes = save_attributes_methods(text, 'attribute')
alter_attributes_methods(attributes, comp.id)
elif category_index[class_id[j]]['name'] == 'class_methods':
class_methods = crop_image_(_image, boxes_class, j)
text = text_extraction(class_methods)
print(text)
methods = save_attributes_methods(text, 'method')
alter_attributes_methods(methods, comp.id)
print(text)
def crop_image_(image, boxes, index):
# image = cv2.imread(path)
height, width, c = image.shape
# crop box format: xmin, ymin, xmax, ymax
ymin = boxes[index][0] * height
xmin = boxes[index][1] * width
ymax = boxes[index][2] * height
xmax = boxes[index][3] * width
cropped_image = image[int(ymin):int(ymax), int(xmin):int(xmax)]
# image = cv2.cvtColor(cropped_image, cv2.COLOR_BGR2GRAY)
# image = cv2.resize(image, (800, 500))
return cropped_image
def text_extraction(image):
config = '-l eng --oem 1 --psm 4'
text = ts.image_to_string(image, config=config)
text = text.splitlines()
text = [x.strip(' ') for x in text]
text = list(filter(None, text))
return text
def save_attributes_methods(text, typ):
global saved_data
nlp = spacy.load('en_core_web_sm')
for element in text:
print(element)
# removable = str.maketrans('', '', '()')
nlp_ner = spacy.load('ner_models/model-best')
nlp_output = nlp_ner(element)
attr = Attribute()
method = Method()
for token in nlp_output.ents:
if typ == 'attribute':
if token.label_ == 'ATTRIBUTE_NAME':
attr.name = token.text
elif token.label_ == 'ACCESS_SP':
attr.access_spec = covert_to_access_specifier(token.text)
elif token.label_ == 'DATA_TYPE':
attr.data_type = token.text
elif typ == 'method':
if token.label_ == 'METHOD_NAME':
method.name = token.text
elif token.label_ == 'ACCESS_SP':
method.access_spec = covert_to_access_specifier(token.text)
elif token.label_ == 'DATA_TYPE':
method.return_type = token.text
if typ == 'attribute':
print(attr)
db.session.add(attr)
db.session.commit()
saved_data.append(attr)
else:
print(method)
db.session.add(method)
db.session.commit()
saved_data.append(method)
return saved_data
def alter_attributes_methods(element_list, class_id):
for element in element_list:
print(class_id)
print(element_list)
element.class_id = class_id
db.session.commit()
def covert_to_access_specifier(access):
if access == "-":
return "Private"
elif access == "#":
return "Protected"
if access == "+":
return "Public"
elif access == "~":
return "Package"
else:
return ''
def crop_and_hide(image, boxes, index):
height, width, c = image.shape
for i in range(0, len(index)):
ymin = boxes[i][0] * height
xmin = boxes[i][1] * width
ymax = boxes[i][2] * height
xmax = boxes[i][3] * width
cv2.rectangle(image, (int(xmin), int(ymin)), (int(xmax), int(ymax)), (255, 255, 255), -1)
return image
def class_name_detection(class_comp_id, image, boxes, index):
image = crop_and_hide(image, boxes, index)
class_name = text_extraction(image)
if ''.join(class_name) != '':
if "interface" in ''.join(class_name):
name = ''.join(class_name).replace("<<interface>>", "")
comp = Component(class_answer=class_comp_id, name=name, type="interface")
else:
name = ''.join(class_name)
comp = Component(class_answer=class_comp_id, name=name, type="class")
db.session.add(comp)
db.session.commit()
return comp
......@@ -11,15 +11,15 @@ def remove_unwanted_values(data):
return data
# removing duplicates
def remove_duplicates(data):
return list(set(data))
# # removing duplicates
# def remove_duplicates(data):
# return list(set(data))
# punctuation removal
# punctuation removing
def remove_punctuation(sentence):
text_no_punct = [token for token in sentence if not token.is_punct]
cleaned_sentence = ' '.join(token.text for token in text_no_punct)
text_without_punctuation = [token for token in sentence if not token.is_punct]
cleaned_sentence = ' '.join(token.text for token in text_without_punctuation)
return cleaned_sentence
......@@ -37,31 +37,32 @@ def main(scenario, assignment_type):
del sentences[-1]
# creating required lists
nc = []
nouns_pronouns = []
cleaned_extracted_actions = []
cleaned_sentences = []
splitted_actions_array = []
splitted_actions_and_actor_array = []
# looping through each sentence
for sentence in sentences:
# getting actors using nouns pronouns
res = get_nouns_pronouns(sentence)
nc.append(str(res))
nouns_pronouns.append(str(res))
cleaned_sentence = remove_punctuation(sentence)
cleaned_sentences.append(cleaned_sentence)
splitted_actions = split_actions(str(cleaned_sentence))
splitted_actions_array.append(splitted_actions)
splitted_actions_and_actor = split_actions(str(cleaned_sentence))
splitted_actions_and_actor_array.append(splitted_actions_and_actor)
extracted_actions = get_actions(splitted_actions)
extracted_actions = get_actions(splitted_actions_and_actor)
if extracted_actions is not None:
cleaned_extracted_actions.append(extracted_actions)
# remove duplicates of the actors
nc = list(dict.fromkeys(nc))
data = remove_unwanted_values(nc)
nouns_pronouns = list(dict.fromkeys(nouns_pronouns))
data = remove_unwanted_values(nouns_pronouns)
extracted_relationships = get_include_extend_relationships(splitted_actions_array)
extracted_relationships = get_include_extend_relationships(splitted_actions_and_actor_array)
actors_and_use_cases_array = identify_use_cases(cleaned_extracted_actions)
if assignment_type == 1:
......
......@@ -24,12 +24,14 @@ def get_nouns_pronouns(sentence):
return token
# removing punctuations
def remove_punctuation(sentence):
text_no_punct = [token for token in sentence if not token.is_punct]
cleaned_sentence = ' '.join(token.text for token in text_no_punct)
return cleaned_sentence
# get actions and actors
def split_actions(sentence):
split_string = "should be able to "
if split_string in sentence:
......@@ -37,16 +39,18 @@ def split_actions(sentence):
return extracted_string
def get_actions(splitted_action):
# get
def get_actions(splitted_action_and_actor):
temp_array = []
if splitted_action is not None and '|' in splitted_action[1]:
res = splitted_action[1].split(' | ')
# print('res',res)
temp_array.append(splitted_action[0])
if splitted_action_and_actor is not None and '|' in splitted_action_and_actor[1]:
res = splitted_action_and_actor[1].split(' | ')
temp_array.append(splitted_action_and_actor[0])
temp_array.append(res[0])
print(temp_array)
return temp_array
else:
return splitted_action
return splitted_action_and_actor
def get_sentences(text):
......
item {
id: 1
name: 'class'
name: 'association'
}
item {
id: 2
name: 'relationship'
name: 'class'
}
item {
id: 3
name: 'composition'
}
item {
id: 4
name: 'indirect association'
}
item {
id: 5
name: 'inheritance'
}
item {
id: 6
name: 'interface'
}
item {
id: 7
name: 'realization'
}
\ No newline at end of file
This diff is collapsed.
......@@ -18,29 +18,23 @@ import ProfilePicture from "../assets/images/admin-user-img.jpg";
import status from "../helpers/greeting";
const SupplierDashboard = () => {
const StudentDashboard = () => {
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(true);
const [orderDetails, setOrderDetails] = useState([]);
const [StudentSubjects, setStudentSubjects] = useState([]);
const [value, onChange] = useState(new Date());
const fields = [
"",
"Assignment",
"Subject",
"Subject Code",
];
const fields = ["", "Assignment", "Subject", "Subject Code"];
const subjects = [
{ ModuleCode: "IT20300", ModuleName: "CTSE", assign: "Assignment 01" },
{ ModuleCode: "IT30300", ModuleName: "DMS", assign: "Assignment 02" },
{ ModuleCode: "IT40300", ModuleName: "SPM", assign: "Assignment 03" }
]
{ ModuleCode: "IT40300", ModuleName: "SPM", assign: "Assignment 03" },
];
const renderOrderHead = (item, index) => <th key={index}>{item}</th>;
const renderOrderBody = (item, index) => (
<tr key={index}>
<td>{ }</td>
<td>{}</td>
<td>{item.assign}</td>
<td>{item.ModuleName}</td>
<td>{item.ModuleCode}</td>
......@@ -64,17 +58,17 @@ const SupplierDashboard = () => {
</tr>
);
const getAllOrders = async () => {
const getAllSubjects = async () => {
try {
const res = await axios.get("orders/supplier/my");
setOrderDetails(res.data.orders);
const res = await axios.get("/subjects");
setStudentSubjects(subjects);
setIsLoading(false);
} catch (err) {
console.log(err.response);
}
};
useEffect(() => getAllOrders(), []);
useEffect(() => getAllSubjects(), []);
return (
<div>
......@@ -91,16 +85,16 @@ const SupplierDashboard = () => {
<h3>
Today you have{" "}
{
orderDetails.filter(
(orderDetail) =>
orderDetail.DeliveryStatus === "pending"
StudentSubjects.filter(
(StudentSubject) =>
StudentSubject.stubjectstatus === "pending"
).length
}
{localStorage.setItem(
"notifications",
orderDetails.filter(
(orderDetail) =>
orderDetail.DeliveryStatus === "pending"
StudentSubjects.filter(
(StudentSubject) =>
StudentSubject.stubjectstatus === "pending"
).length
)}{" "}
Assignments to Complete
......@@ -140,18 +134,17 @@ const SupplierDashboard = () => {
<div className="card">
<div className="flex">
<h2 className="request-title">Assignments to complete</h2>
</div>
{/* {isLoading ? (
<Spinner />
) : orderDetails.length > 0 ? ( */}
<Table
limit="5"
headData={fields}
renderHead={(item, index) => renderOrderHead(item, index)}
bodyData={subjects}
renderBody={(item, index) => renderOrderBody(item, index)}
/>
<Table
limit="5"
headData={fields}
renderHead={(item, index) => renderOrderHead(item, index)}
bodyData={subjects}
renderBody={(item, index) => renderOrderBody(item, index)}
/>
{/* ) : (
<>
{setError("No Assignments found")}
......@@ -184,4 +177,4 @@ const SupplierDashboard = () => {
);
};
export default SupplierDashboard;
export default StudentDashboard;
......@@ -11,155 +11,44 @@ import Badge from "../components/badge/Badge";
import "../assets/css/Usercreate.css";
const ManageOrdersSupplier = () => {
const SubjectsStudent = () => {
const [error, setError] = useState("");
const [isLoading, setIsLoading] = useState(true);
const [orderDetails, setOrderDetails] = useState([]);
const fields = [
"",
"Module Code",
"Module Name",
"Year",
"",
"Actions",
];
const [SudentSubjects, setSudentSubjects] = useState([]);
const fields = ["", "Module Code", "Module Name", "Year", "", "Actions"];
const subjects = [
{ ModuleCode: "IT20300", ModuleName: "CTSE", Year: "4th Year" },
{ ModuleCode: "IT30300", ModuleName: "DMS", Year: "4th Year" },
{ ModuleCode: "IT40300", ModuleName: "SPM:", Year: "4th Year" }
]
{ ModuleCode: "IT40300", ModuleName: "SPM:", Year: "4th Year" },
];
const renderOrderHead = (item, index) => <th key={index}>{item}</th>;
const renderOrderBody = (item, index) => (
<tr key={index}>
<td>{ }</td>
<td>{}</td>
<td>{item.ModuleCode}</td>
<td>{item.ModuleName}</td>
<td>{item.Year}</td>
<td>{ }</td>
<td><Link to={`/auth/student/assignment`}>
<button className="view-btn">View</button>
</Link></td>
<td>{}</td>
<td>
<div className="row-user" style={{ paddingTop: "0" }}>
{item.DeliveryStatus === "pending" ? (
<div
style={{ cursor: "pointer" }}
onClick={() => {
if (
window.confirm(
"Are you sure to change order status as preparing?"
)
) {
changeDeliveryStatusAsPreparing(item._id);
}
}}
>
<Badge type="warning" content="Mark as preparing" />
</div>
) : item.DeliveryStatus === "preparing" ? (
<div
style={{ cursor: "pointer" }}
onClick={() => {
if (
window.confirm(
"Are you sure to change order status as delivering?"
)
) {
changeDeliveryStatusAsDelivering(item._id);
}
}}
>
<Badge type="primary" content="Mark as delivering" />
</div>
) : item.DeliveryStatus === "delivering" ? (
<div
style={{ cursor: "pointer" }}
onClick={() => {
if (
window.confirm(
"Are you sure to change order status as delivered?"
)
) {
changeDeliveryStatusAsDelivered(item._id);
}
}}
>
<Badge type="success" content="Mark as delivered" />
</div>
) : item.DeliveryStatus === "delivered" ? (
<div style={{ cursor: "pointer" }}>
<Link to={`/auth/supplier/deliveryreports/${item._id}`}>
<Badge type="normal" content="Send Delivery Report" />
</Link>
</div>
) : item.DeliveryStatus === "submitted" ? (
<div>
<Badge type="normal" content="Completed" />
</div>
) : (
""
)}
</div>
<Link to={`/auth/student/assignment`}>
<button className="view-btn">View</button>
</Link>
</td>
</tr>
);
const changeDeliveryStatusAsPreparing = async (id) => {
try {
const res = await axios.put(`orders/supplier/prepare/${id}`);
if (res.statusText === "OK") {
setIsLoading(true);
getAllOrders();
setError("");
window.alert("Delivery status changed as preparing");
window.location.reload();
setIsLoading(false);
}
} catch (err) {
console.log(err.response);
}
};
const changeDeliveryStatusAsDelivering = async (id) => {
try {
const res = await axios.put(`orders/supplier/deliver/${id}`);
if (res.statusText === "OK") {
getAllOrders();
setIsLoading(false);
window.alert("Delivery status changed as delivering");
window.location.reload();
}
} catch (err) {
console.log(err.response);
}
};
const changeDeliveryStatusAsDelivered = async (id) => {
try {
const res = await axios.put(`orders/supplier/delivered/${id}`);
if (res.statusText === "OK") {
getAllOrders();
window.alert("Delivery status changed as delivered");
setIsLoading(false);
window.location.reload();
}
} catch (err) {
console.log(err.response);
}
};
const getAllOrders = async () => {
const getAllSubjects = async () => {
try {
const res = await axios.get("orders/supplier");
setOrderDetails(res.data.orders);
const res = await axios.get("/subjects");
setSudentSubjects(res.data.orders);
setIsLoading(false);
} catch (err) {
console.log(err.response);
}
};
useEffect(() => getAllOrders(), []);
useEffect(() => getAllSubjects(), []);
return (
<div>
......@@ -193,4 +82,4 @@ const ManageOrdersSupplier = () => {
);
};
export default ManageOrdersSupplier;
export default SubjectsStudent;
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