Commit a6bd2b76 authored by Anton Akhmerov's avatar Anton Akhmerov

Merge branch 'react' into dualstack

parents 396f4491 2e4a8970
......@@ -8,7 +8,7 @@ import Dropzone from 'react-dropzone'
import * as api from '../api'
const StatusPDF = props => {
var iconClass = "fa fa-";
let iconClass = "fa fa-";
switch (props.pdf.status) {
case "processing":
iconClass += "refresh fa-spin";
......@@ -58,7 +58,7 @@ class Exams extends React.Component {
alert('Please upload a YAML..')
return
}
var data = new FormData()
const data = new FormData()
data.append('yaml', accepted[0])
api.post('exams', data)
.then(new_exam => {
......@@ -130,7 +130,7 @@ class Exams extends React.Component {
return
}
accepted.map(file => {
var data = new FormData()
const data = new FormData()
data.append('pdf', file)
api.post('pdfs/' + this.state.selected_exam.id, data)
.then(() => {
......@@ -156,8 +156,7 @@ class Exams extends React.Component {
.then(exams => {
this.setState({ exams: exams })
if (exams.length > 0) {
var first_exam = exams[0].id
this.selectExam(first_exam)
this.selectExam(exams[0].id)
}
})
.catch(err => {
......@@ -175,8 +174,8 @@ class Exams extends React.Component {
render() {
var isDisabled = this.state.exams.length == 0;
var textStyle = {
const isDisabled = this.state.exams.length == 0;
const textStyle = {
color: isDisabled ? 'grey' : 'black'
};
......
......@@ -110,7 +110,7 @@ class CheckStudents extends React.Component {
prev = () => {
var newIndex = this.state.submission.index - 1;
const newIndex = this.state.submission.index - 1;
if (newIndex >= 0 && newIndex < this.state.submission.list.length) {
this.setState({
......@@ -122,7 +122,7 @@ class CheckStudents extends React.Component {
}
}
next = () => {
var newIndex = this.state.submission.index + 1;
const newIndex = this.state.submission.index + 1;
if (newIndex >= 0 && newIndex < this.state.submission.list.length) {
this.setState({
......@@ -136,8 +136,8 @@ class CheckStudents extends React.Component {
}
prevUnchecked = () => {
var unchecked = this.state.submission.list.filter(sub => sub.validated === false).map(sub => sub.id);
var newInput = getClosest.lowerNumber(this.state.submission.id - 1, unchecked);
const unchecked = this.state.submission.list.filter(sub => sub.validated === false).map(sub => sub.id);
const newInput = getClosest.lowerNumber(this.state.submission.id - 1, unchecked);
if (typeof newInput !== 'undefined') {
this.setState({
......@@ -149,8 +149,8 @@ class CheckStudents extends React.Component {
}
}
nextUnchecked = () => {
var unchecked = this.state.submission.list.filter(sub => sub.validated === false).map(sub => sub.id);
var newInput = getClosest.greaterNumber(this.state.submission.id + 1, unchecked);
const unchecked = this.state.submission.list.filter(sub => sub.validated === false).map(sub => sub.id);
const newInput = getClosest.greaterNumber(this.state.submission.id + 1, unchecked);
if (typeof newInput !== 'undefined') {
this.setState({
......@@ -164,7 +164,7 @@ class CheckStudents extends React.Component {
search = (event) => {
var options = {
const options = {
shouldSort: true,
threshold: 0.6,
location: 0,
......@@ -177,8 +177,8 @@ class CheckStudents extends React.Component {
"lastName"
]
};
var fuse = new Fuse(this.students, options);
var result = fuse.search(event.target.value).slice(0, 10);
const fuse = new Fuse(this.students, options);
const result = fuse.search(event.target.value).slice(0, 10);
this.setState({
search: {
......@@ -191,9 +191,9 @@ class CheckStudents extends React.Component {
setSubmission = () => {
var input = parseInt(this.state.submission.input);
var i = this.state.submission.list.findIndex(sub => sub.id === input);
var sub = this.state.submission.list[i];
const input = parseInt(this.state.submission.input);
const i = this.state.submission.list.findIndex(sub => sub.id === input);
const sub = this.state.submission.list[i];
if (i >= 0) {
this.setState({
......@@ -218,7 +218,7 @@ class CheckStudents extends React.Component {
}
setSubInput = (event) => {
var patt = new RegExp(/^([1-9]\d*|0)?$/);
const patt = new RegExp(/^([1-9]\d*|0)?$/);
if (patt.test(event.target.value)) {
this.setState({
......@@ -288,7 +288,7 @@ class CheckStudents extends React.Component {
moveSelection = (event) => {
if (event.keyCode === 38 || event.keyCode === 40) {
event.preventDefault();
var sel = this.state.search.selected;
let sel = this.state.search.selected;
if (event.keyCode == 38 && sel > 0) sel--;
if (event.keyCode == 40 && sel < this.state.search.result.length - 1) sel++;
......@@ -307,7 +307,7 @@ class CheckStudents extends React.Component {
if (event.target.selected) {
this.matchStudent();
} else {
var index = this.state.search.result.findIndex(result => result.id == event.target.id);
const index = this.state.search.result.findIndex(result => result.id == event.target.id);
this.setState({
search: {
...this.state.search,
......@@ -352,9 +352,9 @@ class CheckStudents extends React.Component {
}
listMatchedStudent = () => {
var studIndex = this.students.findIndex(stud =>
const studIndex = this.students.findIndex(stud =>
stud.id === this.state.submission.studentID);
var stud = studIndex > -1 ? [this.students[studIndex]] : [];
const stud = studIndex > -1 ? [this.students[studIndex]] : [];
this.setState({
search: {
......@@ -370,11 +370,11 @@ class CheckStudents extends React.Component {
}
render() {
var inputStyle = {
const inputStyle = {
width: '5em'
};
var maxSubmission = Math.max(...this.state.submission.list.map(o => o.id));
const maxSubmission = Math.max(...this.state.submission.list.map(o => o.id));
return (
<div>
......
import React from 'react';
const ProgressBar = (props) => {
var total = props.submissions.length;
var checked = props.submissions.filter(sub => sub.validated).length;
var percentage = ((checked / total) * 100).toFixed(1);
const total = props.submissions.length;
const checked = props.submissions.filter(sub => sub.validated).length;
const percentage = ((checked / total) * 100).toFixed(1);
return (
<div className="level is-mobile">
......
......@@ -180,35 +180,35 @@ def make_temp_directory():
shutil.rmtree(temp_dir)
def extract_qr(image_path, yaml_version, scale_factor=4):
image = cv2.imread(image_path,
cv2.IMREAD_GRAYSCALE)[::scale_factor, ::scale_factor]
def extract_qr(image_path, yaml_version):
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
if image.shape[0] < image.shape[1]:
image = image.T
# Varied thresholds because zbar is picky about contrast.
for threshold in (200, 150, 220):
thresholded = 255 * (image > threshold)
# zbar also cares about orientation.
for direction in itertools.product([1, -1], [1, -1]):
flipped = thresholded[::direction[0], ::direction[1]]
scanner = zbar.Scanner()
results = scanner.scan(flipped.astype(np.uint8))
if results:
try:
version, name, page, copy = \
results[0].data.decode().split(';')
except ValueError:
return
if version != 'v{}'.format(yaml_version):
raise RuntimeError('Yaml format mismatch')
coords = np.array(results[0].position)
# zbar doesn't respect array ordering!
if not np.isfortran(flipped):
coords = coords[:, ::-1]
coords *= direction
coords %= image.shape
coords *= scale_factor
return ExtractedQR(name, int(page), int(copy), coords)
# Empirically we observed that the most important parameter
# for zbar to successfully read a qr code is the resolution
# controlled below by scaling the image by factor.
# zbar also seems to care about image orientation, hence
# the loop over dirx/diry.
for dirx, diry, factor in itertools.product([1, -1], [1, -1], [8, 5, 4, 3]):
flipped = image[::factor * dirx, ::factor * diry]
scanner = zbar.Scanner()
results = scanner.scan(flipped)
if results:
try:
version, name, page, copy = \
results[0].data.decode().split(';')
except ValueError:
return
if version != 'v{}'.format(yaml_version):
raise RuntimeError('Yaml format mismatch')
coords = np.array(results[0].position)
# zbar doesn't respect array ordering!
if not np.isfortran(flipped):
coords = coords[:, ::-1]
coords *= [factor * dirx, factor * diry]
coords %= image.shape
return ExtractedQR(name, int(page), int(copy), coords)
else:
return
......
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