Skip to content

Commit

Permalink
Merge pull request #1 from vkgo/ouguangye
Browse files Browse the repository at this point in the history
Ouguangye
  • Loading branch information
vkgo authored Mar 20, 2024
2 parents cc417f8 + 33066bf commit e6c1d71
Show file tree
Hide file tree
Showing 56 changed files with 449 additions and 116 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ migrations/
# testing
score_web/coverage

# production
score_web/build
score_server/index/migrations

# misc
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion CAN/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ train_label_path: 'datasets/CROHME/train_labels.txt'
eval_image_path: 'datasets/test_images/'
eval_label_path: 'datasets/test_labels.txt'

word_path: './scoreblocks/CAN/words_dict.txt'
word_path: '../scoreblocks/CAN/words_dict.txt'

# collate_fn
collate_fn: collate_fn
Expand Down
Binary file modified CAN/models/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified CAN/models/__pycache__/attention.cpython-38.pyc
Binary file not shown.
Binary file modified CAN/models/__pycache__/counting.cpython-38.pyc
Binary file not shown.
Binary file modified CAN/models/__pycache__/decoder.cpython-38.pyc
Binary file not shown.
Binary file modified CAN/models/__pycache__/densenet.cpython-38.pyc
Binary file not shown.
Binary file modified CAN/models/__pycache__/infer_model.cpython-38.pyc
Binary file not shown.
1 change: 0 additions & 1 deletion CAN/models/infer_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def __init__(self, params=None, draw_map=False):

"""经过cnn后 长宽与原始尺寸比缩小的比例"""
self.ratio = params['densenet']['ratio']

with open(params['word_path']) as f:
words = f.readlines()
print(f'共 {len(words)} 类符号。')
Expand Down
2 changes: 1 addition & 1 deletion score.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self):
# 模型
self.outer_segmentation = OuterSegmentation.OuterSegmentation()
self.blank_segmentation = BlankSegmentation.Model()
self.single_character_recognition = SingleCharacterRecognition.Model('./scoreblocks/CharacterRecognition/SpinalVGG_dict.pth', 'SpinalVGG')
self.single_character_recognition = SingleCharacterRecognition.Model('../scoreblocks/CharacterRecognition/SpinalVGG_dict.pth', 'SpinalVGG')
self.fill_blank_model = FillBlankModel.model()
self.candemo = CanDemo.model()
self.essay_score_model = EssayScoreModel.model()
Expand Down
Binary file modified score_server/db.sqlite3
Binary file not shown.
1 change: 1 addition & 0 deletions score_server/index/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Paper(models.Model):

class Problem(models.Model):
paper = models.ForeignKey(to=Paper, on_delete=models.CASCADE)
type = models.CharField(max_length=3)


class Answer(models.Model):
Expand Down
6 changes: 6 additions & 0 deletions score_server/index/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
path('student/papers', views.showPaperForStudent),
# 学生试卷图片获取
path('student/paper/detail', views.showPaperDetail),
# 学生作答试卷图片获取
path('student/paper/answer/detail', views.showPaperAnsDetail),
# 学生作答试卷图片删除
path('student/paper/answer/delete', views.deletePaperAnsPhoto),
# 获取分数
path('student/paper/score', views.getScore)
]
59 changes: 46 additions & 13 deletions score_server/index/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
from datetime import datetime
import PIL.Image
from django.conf import settings
Expand Down Expand Up @@ -85,9 +86,10 @@ def image_upload(file_obj, folder):
def paper_image_upload(request):
file_obj = request.FILES.get("upload_image")
name_obj = image_upload(file_obj, "paper")
print(name_obj)
paper_id = request.POST["paperId"]
paper = Paper.objects.get(id=paper_id)
PaperPhoto.objects.create(photoPath=name_obj["filename"], paper=paper)
PaperPhoto.objects.create(photoPath="/paper/" + name_obj["name"], paper=paper)
return JsonResponse({"msg": 'success', 'data': {
'url': request.build_absolute_uri("/media/paper/" + name_obj["name"]), 'name': name_obj["name"]}})

Expand All @@ -100,7 +102,7 @@ def student_image_upload(request):
username = request.POST["username"]
paper = Paper.objects.get(id=paper_id)
student = Student.objects.get(username=username)
StudentUploadAnswerPhoto.objects.create(photoPath=name_obj["filename"], paper=paper, student=student)
StudentUploadAnswerPhoto.objects.create(photoPath="/studentAns/" + name_obj["name"], paper=paper, student=student)
return JsonResponse({"msg": 'success', 'data': {
'url': request.build_absolute_uri("/media/studentAns/" + name_obj["name"]), 'name': name_obj["name"]}})

Expand All @@ -120,10 +122,13 @@ def ans_set(request):
Problem.objects.filter(paper=paper).delete()

# 新设置问题和答案
answer_list = body["list"]
for ans in answer_list:
problem = Problem.objects.create(paper=paper)
for a in ans:
answer_list = body["answerList"]
type_list = body["typeList"]

for ans_index in range(len(answer_list)):
problem_type = type_list[ans_index]
problem = Problem.objects.create(paper=paper, type=problem_type)
for a in answer_list[ans_index]:
Answer.objects.create(problem=problem, answer=a)

return JsonResponse({"msg": "success"})
Expand Down Expand Up @@ -166,33 +171,57 @@ def showPaperForStudent(request):
@require_http_methods(["GET"])
def showPaperDetail(request):
root_url = request.scheme + '://' + request.get_host()
print("url: ", root_url)
paper_id = request.GET["paperId"]
paper = Paper.objects.get(id=paper_id)
photos = PaperPhoto.objects.filter(paper=paper)
return JsonResponse({"msg": "success", "paperImages": [
{"imgUrl": root_url + settings.MEDIA_URL + "paper/" + photo.photoPath.split("/")[-1], "id": photo.id}
{"url": root_url + settings.MEDIA_URL + "paper/" + photo.photoPath.split("/")[-1], "uid": photo.id}
for photo in photos
]})


@require_http_methods(["GET"])
def showPaperAnsDetail(request):
pass
root_url = request.scheme + '://' + request.get_host()
paper_id = request.GET["paperId"]
username = request.GET["username"]
student = Student.objects.get(username=username)
paper = Paper.objects.get(id=paper_id)
photos = StudentUploadAnswerPhoto.objects.filter(paper=paper, student=student)
return JsonResponse({"msg": "success", "answerImages": [
{"url": root_url + settings.MEDIA_URL + "studentAns/" + photo.photoPath.split("/")[-1], "uid": photo.id}
for photo in photos
]})


@require_http_methods(["GET"])
def deletePaperAnsPhoto(request):
answer_id = request.GET["answerId"]
photo = StudentUploadAnswerPhoto.objects.get(id=answer_id)
if photo:
try:
os.remove(photo.photoPath)
photo.delete()
return JsonResponse({"msg": "success"})
except Exception as e:
return JsonResponse({"msg": str(e)})
else:
return JsonResponse({"msg": "fail"})


@require_http_methods(["GET"])
def getScore(request):
paper_id = request.GET["paperId"]
username = request.POST["username"]
username = request.GET["username"]
student = Student.objects.get(username=username)
paper = Paper.objects.get(id=paper_id)
photos = StudentUploadAnswerPhoto.objects.filter(paper=paper, student=student)
print(photos)
problems = Problem.objects.filter(paper=paper)
answers_list = []
for problem in problems:
answer_obj_list = Answer.objects.filter(problem=problem)
answers = {'section': 'tkt', 'value': []}
answers = {'section': problem.type, 'value': []}
for a in answer_obj_list:
answers['value'].append(a.answer)
answers_list.append(answers)
Expand All @@ -201,5 +230,9 @@ def getScore(request):
s.set_answer(answers_list)
scores = []
for photo in photos:
img = PIL.Image.open(photo.photoPath)
s.get_score(img)
img = PIL.Image.open(settings.MEDIA_ROOT + photo.photoPath)
total_result = s.get_score(img)
print(total_result)
scores.append(total_result)
return JsonResponse({"msg": "success", "score": scores})

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions score_server/score_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': ["../score_web/build"],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down Expand Up @@ -119,8 +119,11 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

# Media 路径
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, '../score_web/build/static')
]
4 changes: 3 additions & 1 deletion score_server/score_server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"""
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from django.urls import path, include, re_path
from django.views.static import serve
from django.views.generic import TemplateView

from score_server import settings

urlpatterns = [
path('admin/', admin.site.urls),
path("api/", include('index.urls')),
url(r'media/(?P<path>.*)', serve, {"document_root": settings.MEDIA_ROOT}),
re_path("^$", TemplateView.as_view(template_name="index.html"))
]
13 changes: 13 additions & 0 deletions score_web/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"files": {
"main.css": "/static/css/main.2904815d.css",
"main.js": "/static/js/main.c33a4185.js",
"index.html": "/index.html",
"main.2904815d.css.map": "/static/css/main.2904815d.css.map",
"main.c33a4185.js.map": "/static/js/main.c33a4185.js.map"
},
"entrypoints": [
"static/css/main.2904815d.css",
"static/js/main.c33a4185.js"
]
}
Binary file added score_web/build/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions score_web/build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><title>React App</title><script defer="defer" src="/static/js/main.c33a4185.js"></script><link href="/static/css/main.2904815d.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
2 changes: 2 additions & 0 deletions score_web/build/static/css/main.2904815d.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions score_web/build/static/css/main.2904815d.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions score_web/build/static/js/main.c33a4185.js

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions score_web/build/static/js/main.c33a4185.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-shim.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-shim/with-selector.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
1 change: 1 addition & 0 deletions score_web/build/static/js/main.c33a4185.js.map

Large diffs are not rendered by default.

17 changes: 10 additions & 7 deletions score_web/src/components/ImageUpload/ImageUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import type { UploadFile } from 'antd/es/upload/interface';

interface ImageUploadPropsInterface {
url: string,
data: {paperId: number, username?: string}
data: {paperId: number, username?: string},
showUploadButton?: boolean,
fileList: UploadFile[],
onFileChange: (files: UploadFile[]) => void
handleFileRemove ?: (files: UploadFile) => void
}

const ImageUpload:React.FC<ImageUploadPropsInterface> = (props) =>{
const [imagePreviewOpen, setImagePreviewOpen] = useState(false);
const [previewImage, setPreviewImage] = useState('');
const [fileList, setFileList] = useState<UploadFile[]>([]);

const handlePhotoPreview = (file) => {
console.log(file.url);
const handlePhotoPreview = (file:UploadFile) => {
setPreviewImage(file.url||file.thumbUrl)
setImagePreviewOpen(true)
}
Expand Down Expand Up @@ -48,7 +50,7 @@ const ImageUpload:React.FC<ImageUploadPropsInterface> = (props) =>{
message.error('上传图片失败')
}
}
setFileList(fileList)
props.onFileChange(fileList);
}

return (
Expand All @@ -59,11 +61,12 @@ const ImageUpload:React.FC<ImageUploadPropsInterface> = (props) =>{
action={props.url}
data = {props.data}
listType="picture-card"
fileList={fileList}
fileList={props.fileList}
onPreview={handlePhotoPreview}
onChange={handlePhotoChange}
onRemove={props.handleFileRemove}
>
{fileList.length >= 100 ? null : uploadButton}
{props.showUploadButton ? uploadButton : false}
</Upload>
<Modal open={imagePreviewOpen} footer={null} onCancel={handlePhotoModalCancel}>
<img alt="example" style={{ width: '100%' }} src={previewImage} />
Expand Down
Loading

0 comments on commit e6c1d71

Please sign in to comment.