예제 #1
0
파일: task.py 프로젝트: JelteF/bottor
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()
예제 #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()
예제 #3
0
파일: matrix.py 프로젝트: JelteF/bottor
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()
예제 #4
0
파일: matrix.py 프로젝트: JelteF/bottor
def create():
    """ Create new matrix """
    matrix_dict = request.json

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

    return jsonify(id=matrix.id)
예제 #5
0
파일: matrix.py 프로젝트: JelteF/bottor
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))
예제 #6
0
파일: matrix.py 프로젝트: JelteF/bottor
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))
예제 #7
0
파일: job.py 프로젝트: 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
예제 #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
예제 #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())
예제 #10
0
파일: views.py 프로젝트: JelteF/bottor
def multiply():
    return render_template('multiply.htm',
                           data={
                               'matrices': MatrixController.get_all_data(),
                           })
예제 #11
0
파일: views.py 프로젝트: JelteF/bottor
def matrix():
    return render_template('matrix.htm',
                           data={'matrixes': MatrixController.get_all()})
예제 #12
0
파일: job.py 프로젝트: 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())