This repository has been archived by the owner on Apr 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4133cc9
commit aa6349b
Showing
10 changed files
with
2,207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npm run build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
npm run start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
|
||
<!-- Bootstrap CSS --> | ||
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
<!-- Bootstrap Optional JavaScript --> | ||
<!-- jQuery first, then Popper.js, then Bootstrap JS --> | ||
<script>let $ = require('jquery');</script> | ||
<script>require('popper.js');</script> | ||
<script>require('bootstrap');</script> | ||
<script> | ||
window.$ = JQuery = require('jquery'); | ||
require('bootstrap') | ||
</script> | ||
<style> | ||
.matrixContainer { | ||
border-radius: 10px/40px; | ||
border: 2px solid #555555; | ||
border-top-color: rgb(85, 85, 85); | ||
border-bottom-color: rgb(85, 85, 85); | ||
padding: 10px 5px; | ||
border-top-color: transparent; | ||
border-bottom-color: transparent; | ||
margin: 0em 0.1em; | ||
} | ||
.table { | ||
width: 100%; | ||
border: none; | ||
margin-bottom: 20px; | ||
} | ||
tbody, td, tfoot, th, thead, tr { | ||
border-color: inherit; | ||
border-style: solid; | ||
border-width: 1px; | ||
text-align: center; | ||
} | ||
.table thead th { | ||
font-weight: bold; | ||
text-align: left; | ||
border: none; | ||
padding: 10px 15px; | ||
background: #d8d8d8; | ||
font-size: 14px; | ||
border-left: 1px solid #ddd; | ||
border-right: 1px solid #ddd; | ||
|
||
} | ||
|
||
.table tbody td { | ||
text-align: left; | ||
border-left: 1px solid #ddd; | ||
border-right: 1px solid #ddd; | ||
padding: 10px 15px; | ||
font-size: 14px; | ||
vertical-align: top; | ||
} | ||
|
||
.table thead tr th:first-child, .table tbody tr td:first-child { | ||
border-left: none; | ||
} | ||
|
||
.table thead tr th:last-child, .table tbody tr td:last-child { | ||
border-right: none; | ||
} | ||
|
||
.table tbody tr:nth-child(even){ | ||
background: #f3f3f3; | ||
} | ||
</style> | ||
<title>Matrix calc</title> | ||
</head> | ||
<body class="user-select-none"> | ||
<h4 class="text-center mt-1">Калькулятор умножения матриц чисел</h1> | ||
<hr> | ||
<div class="container" id="matrixSize"> | ||
<div class="alert alert-warning alert-dismissible fade show" role="alert"> | ||
<strong>Внимание!</strong> Для ввода значений матрицы c большим кол-вом столбцов, может потребоватся развернуть программу на полный экран | ||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
</div> | ||
<div class="row"> | ||
<label class="form-label">Размер матрицы A:</label> | ||
|
||
<div class="input-group mb-3"> | ||
<input type="number" id="aW" value="1" step="1" class="form-control"> | ||
<span class="input-group-text">x</span> | ||
<input type="number" id="aH" value="1" step="1" class="form-control"> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<label class="form-label">Размер матрицы B:</label> | ||
|
||
<div class="input-group mb-3"> | ||
<input type="number" id="bW" min="0" value="1" step="1" class="form-control"> | ||
<span class="input-group-text">x</span> | ||
<input type="number" id="bH" min="0" value="1" step="1" class="form-control"> | ||
</div> | ||
</div> | ||
<button id="setMatrixSize" class="btn btn-dark">Применить</button> | ||
</div> | ||
|
||
<div class="container" style="display:none" id="matrixA"></div> | ||
<div class="container" style="display:none" id="matrixB"></div> | ||
<div class="container" style="display:none" id="result"></div> | ||
<!-- Option 2: Separate Popper and Bootstrap JS --> | ||
<!-- | ||
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js" integrity="sha384-KsvD1yqQ1/1+IA7gi3P0tyJcT3vR+NdBTt13hSJ2lnve8agRGXTTyNaBYmCR/Nwi" crossorigin="anonymous"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-nsg8ua9HAw1y0W1btsyWgBklPnCUAFLuTMS2G72MMONqmOymq585AcH49TLBQObG" crossorigin="anonymous"></script> | ||
--> | ||
<script src="./renderer.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
// Modules to control application life and create native browser window | ||
const {app, BrowserWindow, Menu, ipcMain, dialog} = require('electron') | ||
const path = require('path'); | ||
let fs = require('fs-extra'); | ||
var xl = require('excel4node'); | ||
let mainWindow; | ||
|
||
function MultiplyMatrix(A, B){ | ||
let rowsA = A.length, | ||
colsA = A[0].length, | ||
rowsB = B.length, | ||
colsB = B[0].length, | ||
C = []; | ||
if(colsA != rowsB) return false; | ||
for(let i = 0; i < rowsA; i++) C[i] = []; | ||
for(let k = 0; k < colsB; k++){ | ||
for(let i = 0; i < rowsA; i++){ | ||
let t = 0; | ||
for(let j = 0; j < rowsB; j++) t += A[i][j] * B[j][k]; | ||
C[i][k] = t; | ||
} | ||
} | ||
return C; | ||
} | ||
|
||
ipcMain.handle('export', async (event, {a, b, result}) => { | ||
let dir = dialog.showOpenDialogSync(mainWindow, { | ||
properties: ['openDirectory'] | ||
}); | ||
|
||
if(dir !== undefined) { | ||
await fs.stat(dir[0]).then(async () => { | ||
|
||
//Export A matrix | ||
const wbA = new xl.Workbook(); | ||
const wsA = wbA.addWorksheet('Sheet'); | ||
const styleCenterA = wbA.createStyle({ | ||
alignment: { // §18.8.1 | ||
horizontal: ['center'], | ||
}, | ||
}); | ||
let rowIndexA = 1; | ||
let colIndexA = 1; | ||
for(let row of a){ | ||
for(let col of row){ | ||
wsA.cell(rowIndexA, colIndexA) | ||
.number(Math.round((col + Number.EPSILON) * 1000) / 1000) | ||
.style(styleCenterA); | ||
colIndexA++; | ||
} | ||
colIndexA = 1; | ||
rowIndexA++; | ||
} | ||
|
||
wbA.write(path.join(dir[0], 'MatrixA.xlsx')); | ||
|
||
//Export B matrix | ||
const wbB = new xl.Workbook(); | ||
const wsB = wbB.addWorksheet('Sheet'); | ||
const styleCenterB = wbB.createStyle({ | ||
alignment: { // §18.8.1 | ||
horizontal: ['center'], | ||
}, | ||
}); | ||
let rowIndexB = 1; | ||
let colIndexB = 1; | ||
for(let row of b){ | ||
for(let col of row){ | ||
wsB.cell(rowIndexB, colIndexB) | ||
.number(Math.round((col + Number.EPSILON) * 1000) / 1000) | ||
.style(styleCenterB); | ||
colIndexB++; | ||
} | ||
colIndexB = 1; | ||
rowIndexB++; | ||
} | ||
|
||
wbB.write(path.join(dir[0], 'MatrixB.xlsx')); | ||
|
||
//Export result | ||
const wbResult = new xl.Workbook(); | ||
const wsResult = wbResult.addWorksheet('Sheet'); | ||
const styleCenterResult = wbResult.createStyle({ | ||
alignment: { // §18.8.1 | ||
horizontal: ['center'], | ||
}, | ||
}); | ||
|
||
let rowIndexResult = 1; | ||
let colIndexResult = 1; | ||
for(let row of result){ | ||
for(let col of row){ | ||
wsResult.cell(rowIndexResult, colIndexResult) | ||
.number(Math.round((col + Number.EPSILON) * 1000) / 1000) | ||
.style(styleCenterResult); | ||
colIndexResult++; | ||
} | ||
colIndexResult = 1; | ||
rowIndexResult++; | ||
} | ||
|
||
wbResult.write(path.join(dir[0], 'MatrixResult.xlsx')); | ||
|
||
await new Promise((resolve) => { | ||
setTimeout(() => { | ||
dialog.showMessageBoxSync(mainWindow, { | ||
title: 'Успех!', | ||
type: 'info', | ||
message: 'Данные успешно экспортированы' | ||
}); | ||
resolve(); | ||
}, 500) | ||
}) | ||
}).catch((error) => { | ||
dialog.showMessageBoxSync(mainWindow, { | ||
title: 'Ошибка!', | ||
type: 'error', | ||
message: 'Выбранная директория не существует, экспорт отменен', | ||
detail: 'Код ошибки: '+ error.code | ||
}); | ||
}); | ||
} else dialog.showMessageBoxSync(mainWindow, { | ||
title: 'Внимание!', | ||
type: 'warning', | ||
message: 'Экспорт отменен, папка небыла выбрана' | ||
}); | ||
}); | ||
|
||
ipcMain.handle('calc', async (event, {a, b}) => { | ||
return MultiplyMatrix(a, b) | ||
}); | ||
|
||
function createWindow () { | ||
// Create the browser window. | ||
mainWindow = new BrowserWindow({ | ||
width: 800, | ||
height: 600, | ||
webPreferences: { | ||
preload: path.join(__dirname, 'preload.js'), | ||
nodeIntegration: true, | ||
contextIsolation: false, | ||
enableRemoteModule: true | ||
} | ||
}) | ||
|
||
// and load the index.html of the app. | ||
mainWindow.loadFile('index.html') | ||
Menu.setApplicationMenu(null) | ||
// Open the DevTools | ||
// mainWindow.webContents.openDevTools() | ||
} | ||
|
||
// This method will be called when Electron has finished | ||
// initialization and is ready to create browser windows. | ||
// Some APIs can only be used after this event occurs. | ||
app.whenReady().then(() => { | ||
createWindow() | ||
|
||
app.on('activate', function () { | ||
// On macOS it's common to re-create a window in the app when the | ||
// dock icon is clicked and there are no other windows open. | ||
if (BrowserWindow.getAllWindows().length === 0) createWindow() | ||
}) | ||
}) | ||
|
||
// Quit when all windows are closed, except on macOS. There, it's common | ||
// for applications and their menu bar to stay active until the user quits | ||
// explicitly with Cmd + Q. | ||
app.on('window-all-closed', function () { | ||
if (process.platform !== 'darwin') app.quit() | ||
}) | ||
|
||
// In this file you can include the rest of your app's specific main process | ||
// code. You can also put them in separate files and require them here. |
Oops, something went wrong.