Первая страница
Наша команда
Контакты
О нас

    Головна сторінка



Розробка веб-додатку з імітаційного моделювання обчислювальних систем

Розробка веб-додатку з імітаційного моделювання обчислювальних систем




Сторінка16/16
Дата конвертації10.03.2017
Розмір0.82 Mb.
ТипПояснювальна записка
1   ...   8   9   10   11   12   13   14   15   16

ДОДАТОК Б
Лістинг програмної реалізації


Generator.js

function createCombinedGenerator(genParams) {
var generators = [];
var weights = [];
for (var i = 0; i < genParams.length; i ) {
if (genParams[i].rep) generators.push(new RepetitionGenerator(genParams[i].from, genParams[i].to));
else generators.push(new Generator(genParams[i].from, genParams[i].to));
weights.push(genParams[i].weight);
}
return new CombinedGenerator(generators, weights);
}

function CombinedGenerator(generators, weights) {
var overallWeight = weights.reduce(function (sum, weight){ return sum weight; });

this.next = function() {
var next = 0;
for (var i = 0; i < generators.length; i ) {
next = generators[i].next() * weights[i];
}
return next / overallWeight;
}
}

function RepetitionGenerator(minX, maxX) {
var x, y, step;

init();

function init() {
x = minX Math.floor(Math.random() * (maxX - minX));
y = Math.random();
step = 0;
}

this.next = function() {
step ;
if (step >= x) init();
return y;
};
}

function Generator(minX, maxX) {
var x, y, dy, step;
var ly = Math.random();

init();

function init() {
x = minX Math.floor(Math.random() * (maxX - minX));
y = Math.random();
dy = (y - ly) / x;
step = 0;
}

this.next = function() {
ly = dy;
step ;
if (step >= x) init();
return ly;
};
}

module.exports.createCombinedGenerator = createCombinedGenerator;
Chart.js

var CircularArray = require('./lib/CircularArray');

function Chart(containerElement, redThreshold, greenThreshold) {
this._chartOffsetX = 30;
this._chartOffsetY = 20;

this._redThreshold = redThreshold || 0.7;
this._greenThreshold = greenThreshold || 0.3;

this._wrap = document.createElement('div');
this._wrap.style.position = 'relative';
this._grid = document.createElement('canvas');
this._grid.style.position = 'absolute';
this._chart = document.createElement('canvas');
this._chart.style.position = 'absolute';


this._wrap.appendChild(this._grid);
this._wrap.appendChild(this._chart);
containerElement.appendChild(this._wrap);

var rect = containerElement.getBoundingClientRect();
this.setSize(rect.width, rect.height);

this._points = new CircularArray(rect.width);

this._ctx = this._chart.getContext('2d');
this._ctx.strokeStyle = 'black';

this._setGradientFill();
this._ctx.lineWidth = 2;

this._ctxGrid = this._grid.getContext('2d');
this._ctxGrid.strokeStyle = '#aaa';
this._ctxGrid.lineWidth = 1;

this._drawGrid();
}

Chart.prototype.setSize = function(width, height) {
this._wrap.width = width;
this._wrap.height = height;
this._grid.width = width;
this._grid.height = height;
this._chart.width = width - this._chartOffsetX;
this._chart.height = height - this._chartOffsetY;
};

Chart.prototype.setRedThreshold = function(threshold) {
this._redThreshold = threshold;
this._setGradientFill();
};

Chart.prototype.setGreenThreshold = function(threshold) {
this._greenThreshold = threshold;
this._setGradientFill();
};

Chart.prototype._setGradientFill = function () {
var greenColor = 'rgba(9, 237, 58, 0.8)';
var yellowColor = 'rgba(247, 247, 44, 0.8)';
var redColor = 'rgba(252, 33, 0, 0.8)';

var blur = 0.1;

var gradient = this._ctx.createLinearGradient(0, 0, 0, this._chart.height);

gradient.addColorStop(0, redColor);


gradient.addColorStop(Math.max(1 - this._redThreshold - blur / 2, 0), redColor);
gradient.addColorStop(Math.min(1 - this._redThreshold blur / 2, 1), yellowColor);

gradient.addColorStop(Math.max(1 - this._greenThreshold - blur / 2, 0), yellowColor);


gradient.addColorStop(Math.min(1 - this._greenThreshold blur / 2, 1), greenColor);
gradient.addColorStop(1, greenColor);

this._ctx.fillStyle = gradient;
};

Chart.prototype._drawGrid = function() {
var rowNum = 4;
var colNum = 7;
var rowHeight = this._chart.height / rowNum;
var colWidth = this._chart.width / colNum;

this._ctxGrid.textAlign = "left";
this._ctxGrid.textBaseline = "top";
for (var i = 0; i < rowNum 1; i ) {
this._ctxGrid.fillText(Math.round((1 - (i / rowNum)) * 100) '%', this._chart.width 1, i * rowHeight);
var startX = 0.5,
startY = Math.round(i * rowHeight) 0.5;
var endX = this._chart.width,
endY = startY;
this._ctxGrid.moveTo(startX, startY);
this._ctxGrid.lineTo(endX, endY);
}
for (i = 0; i < colNum 1; i ) {
startX = Math.round(i * colWidth) 0.5;
startY = 0.5;
endX = startX;
endY = this._chart.height 0.5;
this._ctxGrid.moveTo(startX, startY);
this._ctxGrid.lineTo(endX, endY);
}
this._ctxGrid.stroke();
};

Chart.prototype.draw = function() {
this._ctx.clearRect(0,0,this._chart.width,this._chart.height);
this._ctx.beginPath();
this._ctx.moveTo(this._chart.width - this._points.getLength(), this._chart.height);
for (var i = 0; i < this._points.getLength(); i ) {
this._ctx.lineTo(this._chart.width - this._points.getLength() i, this._chart.height - this._points.getAt(i));
}
this._ctx.lineTo(this._chart.width, this._chart.height);
this._ctx.closePath();
this._ctx.fill();
};

Chart.prototype.addRecord = function(record) {
this._points.push(record * this._chart.height);
};

Chart.prototype.clear = function () {
this._points.clear();
};

module.exports = Chart;

DerivativeChart.js



var CircularArray = require('./lib/CircularArray');

function DerivativeChart(containerElement, color) {
this._chartOffsetX = 30;
this._chartOffsetY = 20;

this._scale = 1;
this._wrap = document.createElement('div');
this._wrap.style.position = 'relative';
this._grid = document.createElement('canvas');
this._grid.style.position = 'absolute';
this._chart = document.createElement('canvas');
this._chart.style.position = 'absolute';


this._wrap.appendChild(this._grid);
this._wrap.appendChild(this._chart);
containerElement.appendChild(this._wrap);

var rect = containerElement.getBoundingClientRect();
this.setSize(rect.width, rect.height);

this._points = new CircularArray(rect.width);

this._ctx = this._chart.getContext('2d');
this._ctx.strokeStyle = color;

this._ctx.lineWidth = 1.5;

this._ctxGrid = this._grid.getContext('2d');
this._ctxGrid.strokeStyle = '#aaa';
this._ctxGrid.lineWidth = 1;

this._drawGrid();
}

DerivativeChart.prototype.setSize = function(width, height) {
this._wrap.width = width;
this._wrap.height = height;
this._grid.width = width;
this._grid.height = height;
this._chart.width = width - this._chartOffsetX;
this._chart.height = height - this._chartOffsetY;
};

DerivativeChart.prototype._drawGrid = function() {
this._ctxGrid.clearRect(0,0,this._grid.width,this._grid.height);
var rowNum = 4;
var colNum = 7;
var rowHeight = this._chart.height / rowNum;
var colWidth = this._chart.width / colNum;

this._ctxGrid.textAlign = "left";
this._ctxGrid.textBaseline = "top";
for (var i = 0; i < rowNum 1; i ) {
this._ctxGrid.fillText((((1 - (i / rowNum)) * 200 - 100) / this._scale).toFixed(1) '%', this._chart.width 1, i * rowHeight);
var startX = 0.5,
startY = Math.round(i * rowHeight) 0.5;
var endX = this._chart.width,
endY = startY;
this._ctxGrid.moveTo(startX, startY);
this._ctxGrid.lineTo(endX, endY);
}
for (i = 0; i < colNum 1; i ) {
startX = Math.round(i * colWidth) 0.5;
startY = 0.5;
endX = startX;
endY = this._chart.height 0.5;
this._ctxGrid.moveTo(startX, startY);
this._ctxGrid.lineTo(endX, endY);
}
this._ctxGrid.stroke();
};

DerivativeChart.prototype._calculateScale = function() {
var maxValue = 0;
for (var i = 1; i < this._points.getLength(); i){
var value = Math.abs(this._points.getAt(i) - this._points.getAt(i-1));
if (value > maxValue) maxValue = value;
}
this._scale = this._chart.height / 2 / maxValue;
};

DerivativeChart.prototype.draw = function() {
this._calculateScale();
this._drawGrid();
this._ctx.clearRect(0,0,this._chart.width,this._chart.height);
this._ctx.beginPath();
this._ctx.moveTo(this._chart.width - this._points.getLength(), this._chart.height/2 - (this._points.getAt(0) - this._points.getAt(1)) * this._scale);
for (var i = 1; i < this._points.getLength(); i ) {
this._ctx.lineTo(this._chart.width - this._points.getLength() i, this._chart.height/2 - (this._points.getAt(i) - this._points.getAt(i-1)) * this._scale);
}
this._ctx.stroke();
};

DerivativeChart.prototype.addRecord = function(record) {
this._points.push(record * this._chart.height/2);
};

DerivativeChart.prototype.clear = function () {
this._points.clear();
};

module.exports = DerivativeChart;
IntegralChart.js

var CircularArray = require('./lib/CircularArray');

function IntegralChart(containerElement, color) {
this._chartOffsetX = 50;
this._chartOffsetY = 20;

this._scale = 1;
this._wrap = document.createElement('div');
this._wrap.style.position = 'relative';
this._grid = document.createElement('canvas');
this._grid.style.position = 'absolute';
this._chart = document.createElement('canvas');
this._chart.style.position = 'absolute';

this._wrap.appendChild(this._grid);
this._wrap.appendChild(this._chart);
containerElement.appendChild(this._wrap);

var rect = containerElement.getBoundingClientRect();
this.setSize(rect.width, rect.height);

this._points = new CircularArray(rect.width);

this._ctx = this._chart.getContext('2d');
this._ctx.fillStyle = color;

this._ctx.lineWidth = 1.5;

this._ctxGrid = this._grid.getContext('2d');
this._ctxGrid.strokeStyle = '#aaa';
this._ctxGrid.lineWidth = 1;

this._drawGrid();
}

IntegralChart.prototype.setSize = function(width, height) {
this._wrap.width = width;
this._wrap.height = height;
this._grid.width = width;
this._grid.height = height;
this._chart.width = width - this._chartOffsetX;
this._chart.height = height - this._chartOffsetY;
};

IntegralChart.prototype._drawGrid = function() {
this._ctxGrid.clearRect(0,0,this._grid.width,this._grid.height);
var rowNum = 4;
var colNum = 7;
var rowHeight = this._chart.height / rowNum;
var colWidth = this._chart.width / colNum;

this._ctxGrid.textAlign = "left";
this._ctxGrid.textBaseline = "top";
for (var i = 0; i < rowNum 1; i ) {
this._ctxGrid.fillText(Math.round((1 - (i / rowNum)) * 100 / this._scale) '%', this._chart.width 1, i * rowHeight);
var startX = 0.5,
startY = Math.round(i * rowHeight) 0.5;
var endX = this._chart.width,
endY = startY;
this._ctxGrid.moveTo(startX, startY);
this._ctxGrid.lineTo(endX, endY);
}
for (i = 0; i < colNum 1; i ) {
startX = Math.round(i * colWidth) 0.5;
startY = 0.5;
endX = startX;
endY = this._chart.height 0.5;
this._ctxGrid.moveTo(startX, startY);
this._ctxGrid.lineTo(endX, endY);
}
this._ctxGrid.stroke();
};

IntegralChart.prototype._calculateScale = function() {
var sum = 0;
for (var i = 0; i < this._points.getLength(); i){
sum = Math.abs(this._points.getAt(i));
}
this._scale = this._chart.height / sum;
};

IntegralChart.prototype.draw = function() {
this._calculateScale();
this._drawGrid();
this._ctx.clearRect(0,0,this._chart.width,this._chart.height);
this._ctx.beginPath();

this._ctx.moveTo(this._chart.width - this._points.getLength(), this._chart.height - (this._points.getAt(0)) * this._scale);
this._ctx.moveTo(this._chart.width - this._points.getLength(), this._chart.height);

var sum = 0;

for (var i = 1; i < this._points.getLength(); i ) {
sum = this._points.getAt(i);
this._ctx.lineTo(this._chart.width - this._points.getLength() i, this._chart.height - sum * this._scale);
}
this._ctx.lineTo(this._chart.width, this._chart.height);
this._ctx.fill();
};

IntegralChart.prototype.addRecord = function(record) {
this._points.push(record * this._chart.height/2);
};

IntegralChart.prototype.clear = function () {
this._points.clear();
};

module.exports = IntegralChart;
ДОДАТОК В

Ілюстративний матеріал до захисту магістерської кваліфікаціної роботи


Завідувач кафедри ПЗ, д. т. н., професор ___________________ А. М. Пєтух
Науковий керівник, к. т. н., доцент кафедри ПЗ______________ О. М. Хошаба
Рецензент, зав. каф. МБІС, д.т.н., професор________________О. М. Роїк
Нормоконтроль, к. т. н., доцент кафедри ПЗ ________________ О. М. Хошаба
Виконавець, студент групи 1ПЗ-15мі____________________О. А. Коцюба














1   ...   8   9   10   11   12   13   14   15   16