Ejemplo n.º 1
0
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()
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
def create():
    """ Create new matrix """
    matrix_dict = request.json

    matrix = MatrixController.createFromFile(matrix_dict['filename'])

    return jsonify(id=matrix.id)
Ejemplo n.º 5
0
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))
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
Archivo: job.py Proyecto: JelteF/bottor
    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
Ejemplo n.º 8
0
    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
Ejemplo n.º 9
0
    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())
Ejemplo n.º 10
0
def multiply():
    return render_template('multiply.htm',
                           data={
                               'matrices': MatrixController.get_all_data(),
                           })
Ejemplo n.º 11
0
def matrix():
    return render_template('matrix.htm',
                           data={'matrixes': MatrixController.get_all()})
Ejemplo n.º 12
0
Archivo: job.py Proyecto: JelteF/bottor
    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())