DBAssignments.py 2.57 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
# -*- coding: utf-8 -*-
"""
GEPARD - Gepard-Enabled PARticle Detection
Copyright (C) 2018  Lars Bittrich and Josef Brandt, Leibniz-Institut für 
Polymerforschung Dresden e. V. <bittrich-lars@ipfdd.de>    

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program, see COPYING.  
If not, see <https://www.gnu.org/licenses/>.
"""

import pickle

def loadAssigments(fname):
    with open(fname, "rb") as fp:
        assignment = pickle.load(fp)
    return assignment

def saveAssignments(assignment, fname):
    with open(fname, "wb") as fp:
        pickle.dump(assignment, fp, protocol=-1)


class DBAssignment(object):
    def __init__(self):
        self.filename = None
        self.assignments = []
    
    def setFileName(self, fname):
        self.filename = fname
    
    def save(self):
        saveAssignments(self, self.filename)
        
    def hasAssignment(self, polymerName):
        polymIsPresent = False
        for assignment in self.assignments:
            if assignment.polymerName == polymerName:
                polymIsPresent = True
                break
        return polymIsPresent
    
    def getAssignment(self, polymerName):
        for assignment in self.assignments:
            if assignment.polymerName == polymerName:
                return assignment
    
    def createNewAssignment(self, polymerName):
        self.assignments.append(Assignment(polymerName))
    
    def updateAssignment(self, polymerName, result, catRes, indic_paint):
        for assignment in self.assignments:
            if assignment.polymerName == polymerName:
                assignment.update(result, catRes, indic_paint)
                return


class Assignment(object):
    def __init__(self, polymerName):
        self.polymerName = polymerName
        self.result = None
        self.categorizedResult = None
        self.indication_paint = None
    
    def update(self, result, catRes, indic_paint):
        self.result = result
        self.categorizedResult = catRes
        self.indication_paint = indic_paint