def result(): # peer_id = 0 result = request.json task_id = result['id'] task = TaskController.get(task_id) task.completed += len(result['results']) job = task.job job.completed += len(result['results']) job.running -= len(result['results']) resultMatrix = Matrix.matrices[job.id]['result'] taskMatrix = Matrix.matrices[job.id]['task'] for res in result['results']: row = res['row'] col = res['col'] value = res['value'] resultMatrix[row][col] = value taskMatrix[row][col] = Constants.STATE_DONE print ("Job " + str(job.id) + ": " + str(job.completed) + "/" + str(job.toComplete) + " completed") if job.isFinished(): filename = "result_matrices/result_job_" + str(job.id) print ("Job " + str(job.id) + " completed. Writing result to file " + filename) MatrixController.writeToFile(Matrix.matrices[job.id]['result'], filename, True) job.end = datetime.now() # REMOVE JOB + MATRICES db.session.commit() return jsonify()
def result(): # peer_id = 0 result = request.json task_id = result['id'] task = TaskController.get(task_id) task.completed += len(result['results']) job = task.job job.completed += len(result['results']) job.running -= len(result['results']) resultMatrix = Matrix.matrices[job.id]['result'] taskMatrix = Matrix.matrices[job.id]['task'] for res in result['results']: row = res['row'] col = res['col'] value = res['value'] resultMatrix[row][col] = value taskMatrix[row][col] = Constants.STATE_DONE print("Job " + str(job.id) + ": " + str(job.completed) + "/" + str(job.toComplete) + " completed") if job.isFinished(): filename = "result_matrices/result_job_" + str(job.id) print("Job " + str(job.id) + " completed. Writing result to file " + filename) MatrixController.writeToFile(Matrix.matrices[job.id]['result'], filename, True) job.end = datetime.now() # REMOVE JOB + MATRICES db.session.commit() return jsonify()
def delete(matrix_id): """ Delete matrix """ matrix = MatrixController.get(matrix_id) if not matrix: return jsonify(error='Matrix not found'), 500 MatrixController.delete(matrix) return jsonify()
def create(): """ Create new matrix """ matrix_dict = request.json matrix = MatrixController.createFromFile(matrix_dict['filename']) return jsonify(id=matrix.id)
def get_all(): """ Get all data matrices """ matrices = MatrixController.get_all_data() if not matrices: return jsonify(error='No matrices were found'), 500 return jsonify(matrices=serialize_sqla(matrices))
def get(matrix_id): """ Get matrix """ matrix = MatrixController.get(matrix_id) if not matrix: return jsonify(error='Matrix not found'), 500 return jsonify(matrix=serialize_sqla(matrix))
def __init__(self, matrixA, matrixB): from app.controllers import MatrixController self.resultCols = matrixA.nRows self.resultRows = matrixB.nCols self.toComplete = self.resultCols * self.resultRows self.free = self.toComplete self.running = 0 self.completed = 0 self.matrixA = matrixA self.matrixB = matrixB self.matrixA_id = matrixA.id self.matrixB_id = matrixB.id resMatrix = MatrixController.createEmptyMatrix( self.resultRows, self.resultCols, "#", 'result') self.resultMatrix = resMatrix.id
def __init__(self, matrixA, matrixB): from app.controllers import MatrixController self.resultCols = matrixA.nRows self.resultRows = matrixB.nCols self.toComplete = self.resultCols * self.resultRows self.free = self.toComplete self.running = 0 self.completed = 0 self.matrixA = matrixA self.matrixB = matrixB self.matrixA_id = matrixA.id self.matrixB_id = matrixB.id resMatrix = MatrixController.createEmptyMatrix(self.resultRows, self.resultCols, "#", 'result') self.resultMatrix = resMatrix.id
def loadMatrices(self, matrixA, matrixB): from app.controllers import MatrixController print(self.id) Matrix.matrices[self.id] = {} MatrixController.loadInMemory( MatrixController.loadFromFile(matrixA.filename), self.id, 'dataA') bTransp = MatrixController.transpose( MatrixController.loadFromFile(matrixB.filename)) MatrixController.loadInMemory(bTransp, self.id, 'dataB') task = [[Constants.STATE_NONE for i in range(self.resultCols)] for j in range(self.resultRows)] MatrixController.loadInMemory(task, self.id, 'task') result = [['#' for i in range(self.resultCols)] for j in range(self.resultRows)] MatrixController.loadInMemory(result, self.id, 'result') print(Matrix.matrices[self.id].keys())
def multiply(): return render_template('multiply.htm', data={ 'matrices': MatrixController.get_all_data(), })
def matrix(): return render_template('matrix.htm', data={'matrixes': MatrixController.get_all()})
def loadMatrices(self, matrixA, matrixB): from app.controllers import MatrixController print(self.id) Matrix.matrices[self.id] = {} MatrixController.loadInMemory( MatrixController.loadFromFile(matrixA.filename), self.id, 'dataA') bTransp = MatrixController.transpose(MatrixController.loadFromFile( matrixB.filename)) MatrixController.loadInMemory(bTransp, self.id, 'dataB') task = [[Constants.STATE_NONE for i in range(self.resultCols)] for j in range(self.resultRows)] MatrixController.loadInMemory(task, self.id, 'task') result = [['#' for i in range(self.resultCols)] for j in range(self.resultRows)] MatrixController.loadInMemory(result, self.id, 'result') print(Matrix.matrices[self.id].keys())