From 8ac6ae346af9dd32c9400da85e1f27f22442320e Mon Sep 17 00:00:00 2001 From: mkhorin Date: Sat, 23 Dec 2023 09:35:32 +1000 Subject: [PATCH] Update 1.9.1 --- README.md | 2 +- dockerfile | 2 +- docs/js/common.js | 2 +- module/front/web/src/form/FormAttr.js | 4 ++-- module/front/web/src/misc/Drawing.js | 18 ++++++++---------- package.json | 5 +---- worker/convertImageSet.js | 2 +- 7 files changed, 15 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index fde0e70..19b92dc 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ docker-compose up -d server ## Typical installation #### Install environment -- [Node.js](https://nodejs.org) (version 16) +- [Node.js](https://nodejs.org) (version 20) - [MongoDB](https://www.mongodb.com/download-center/community) (version 5) #### Linux diff --git a/dockerfile b/dockerfile index bb2b9ea..c585735 100644 --- a/dockerfile +++ b/dockerfile @@ -1,4 +1,4 @@ -FROM node:16-alpine +FROM node:20-alpine WORKDIR /app diff --git a/docs/js/common.js b/docs/js/common.js index d914234..731cac5 100644 --- a/docs/js/common.js +++ b/docs/js/common.js @@ -48,7 +48,7 @@ jQuery('.navbar-target').append(`
label: 'Recognition digits', ru: 'Распознавание цифр' }]; - const lang = document.documentElement.lang; + const {lang} = document.documentElement; const result = []; for (const item of items) { if (item.header) { diff --git a/module/front/web/src/form/FormAttr.js b/module/front/web/src/form/FormAttr.js index 53bcd0f..02b6faf 100644 --- a/module/front/web/src/form/FormAttr.js +++ b/module/front/web/src/form/FormAttr.js @@ -72,8 +72,8 @@ Front.FormDate = class FormDate extends Front.FormAttr { } onChangeDate (event) { - const date = event.date; - const format = this.picker.options().format; + const {date} = event; + const {format} = this.picker.options(); const value = date ? moment(moment(date).format(format), format) : ''; this.$value.val(value ? Jam.DateHelper.stringify(value, this.utc) : ''); if (!date) { diff --git a/module/front/web/src/misc/Drawing.js b/module/front/web/src/misc/Drawing.js index c1fdcb5..2a1ca19 100644 --- a/module/front/web/src/misc/Drawing.js +++ b/module/front/web/src/misc/Drawing.js @@ -95,11 +95,12 @@ Front.Drawing = class Drawing extends Front.Element { exportData () { const rect = this.getCroppingRect(this.context, this.canvas.width, this.canvas.height); if (rect) { + const {height, width} = this.target; const sourceRect = this.convertToSquare(rect); const context = this.targetContext; - context.fillRect(0, 0, this.target.width, this.target.height); - context.drawImage(this.canvas, ...sourceRect, 2, 2, this.target.width - 4, this.target.height - 4); - const data = context.getImageData(0, 0, this.target.width, this.target.height); + context.fillRect(0, 0, width, height); + context.drawImage(this.canvas, ...sourceRect, 2, 2, width - 4, height - 4); + const data = context.getImageData(0, 0, width, height); this.invert(data); context.putImageData(data, 0, 0); return this.getGrayscale(data); @@ -107,9 +108,8 @@ Front.Drawing = class Drawing extends Front.Element { } getCroppingRect (context, width, height) { - let data = context.getImageData(0, 0, width, height).data; - let x1 = width, y1 = height; - let x2 = 0, y2 = 0, i = 0; + const {data} = context.getImageData(0, 0, width, height); + let x1 = width, y1 = height, x2 = 0, y2 = 0, i = 0; for (let y = 0; y < height; ++y) { for (let x = 0; x < width; ++x) { if (data[i] !== 255 || data[i] !== data[i + 1] || data[i] !== data[i + 2]) { @@ -144,8 +144,7 @@ Front.Drawing = class Drawing extends Front.Element { return [x, y, w, h]; } - invert (imageData) { - const data = imageData.data; + invert ({data}) { for (let i = 0; i < data.length; i += 4) { data[i] = 255 - data[i]; // red data[i + 1] = 255 - data[i + 1]; // green @@ -153,9 +152,8 @@ Front.Drawing = class Drawing extends Front.Element { } } - getGrayscale (imageData) { + getGrayscale ({data}) { const result = []; - const data = imageData.data; for (let i = 0; i < data.length; i += 4) { result.push(Math.round(data[i] * .299 + data[i + 1] * .587 + data[i + 2] * .114)); } diff --git a/package.json b/package.json index a60d01b..2aecdc3 100644 --- a/package.json +++ b/package.json @@ -1,15 +1,12 @@ { "name": "neural-net", - "version": "1.9.0", + "version": "1.9.1", "description": "Train, test and operate neural networks to recognize handwritten digits", "author": { "name": "Maxim Khorin", "email": "maksimovichu@gmail.com" }, "license": "MIT", - "engines": { - "node": ">=16.20.1" - }, "repository": { "type": "git", "url": "https://github.com/mkhorin/neural-net.git" diff --git a/worker/convertImageSet.js b/worker/convertImageSet.js index ba78ad5..940aec4 100644 --- a/worker/convertImageSet.js +++ b/worker/convertImageSet.js @@ -7,7 +7,7 @@ const {workerData, parentPort} = require('worker_threads'); const fs = require('fs'); const sharp = require('sharp'); const AdmZip = require('adm-zip'); -const file = workerData.file; +const {file} = workerData; console.log(`Unzipping archive: ${file}`);