@@ -29,9 +29,10 @@ class Record:
2929
3030 BAD_SYMBOLS = [EMPTY_SLOT_SYMBOL , NOT_FOUND_SLOT_SYMBOL ]
3131
32- def __init__ (self , plate_type , barcodes , image_path , geometry , timestamp = 0.0 , id = 0 ):
32+ def __init__ (self , plate_type , holder_barcode , barcodes , image_path , geometry , timestamp = 0.0 , id = 0 ):
3333 """
3434 :param plate_type: the type of the sample holder plate (string)
35+ :param holder_barcode: the barcode of the holder plate
3536 :param barcodes: ordered array of strings giving the barcodes in each slot
3637 of the plate in order. Empty slots should be denoted by empty strings.
3738 :param image_path: the absolute path of the image.
@@ -43,8 +44,10 @@ def __init__(self, plate_type, barcodes, image_path, geometry, timestamp=0.0, id
4344 self .timestamp = float (timestamp )
4445 except ValueError :
4546 self .timestamp = 0.0
47+
4648 self .image_path = image_path
4749 self .plate_type = plate_type
50+ self .holder_barcode = holder_barcode
4851 self .barcodes = barcodes
4952 self .geometry = geometry
5053 self .id = str (id )
@@ -57,27 +60,25 @@ def __init__(self, plate_type, barcodes, image_path, geometry, timestamp=0.0, id
5760 # Generate timestamp and uid if none are supplied
5861 if timestamp == 0 :
5962 self .timestamp = time .time ()
63+
6064 if id == 0 :
6165 self .id = str (uuid .uuid4 ())
6266
63- # Separate Data and Time
67+ # Separate Date and Time
6468 dt = self ._formatted_date ().split (" " )
6569 self .date = dt [0 ]
6670 self .time = dt [1 ]
6771
6872 # Counts of numbers slots and barcodes
69- self .num_slots = len (barcodes )
70- self .num_empty_slots = len ([b for b in barcodes if b == EMPTY_SLOT_SYMBOL ])
71- self .num_unread_slots = len ([b for b in barcodes if b == NOT_FOUND_SLOT_SYMBOL ])
73+ self .num_slots = len (self . barcodes )
74+ self .num_empty_slots = len ([b for b in self . barcodes if b == EMPTY_SLOT_SYMBOL ])
75+ self .num_unread_slots = len ([b for b in self . barcodes if b == NOT_FOUND_SLOT_SYMBOL ])
7276 self .num_valid_barcodes = self .num_slots - self .num_unread_slots - self .num_empty_slots
7377
7478 @staticmethod
75- def from_plate (plate , second_plate , image_path ):
76- plate_type = second_plate .type
77- geometry = second_plate .geometry ()
78- barcodes = plate .barcodes () + second_plate .barcodes ()
79-
80- return Record (plate_type = plate_type , barcodes = barcodes , image_path = image_path , geometry = geometry )
79+ def from_plate (holder_barcode , plate , image_path ):
80+ return Record (plate_type = plate .type , holder_barcode = holder_barcode , barcodes = plate .barcodes (),
81+ image_path = image_path , geometry = plate .geometry ())
8182
8283 @staticmethod
8384 def from_string (string ):
@@ -89,21 +90,24 @@ def from_string(string):
8990 timestamp = items [Record .IND_TIMESTAMP ] #used to convert into float twice
9091 image = items [Record .IND_IMAGE ]
9192 plate_type = items [Record .IND_PLATE ]
92- barcodes = items [Record .IND_BARCODES ].split (Record .BC_SEPARATOR )
93+ all_barcodes = items [Record .IND_BARCODES ].split (Record .BC_SEPARATOR )
94+ holder_barcode = all_barcodes [0 ]
95+ pin_barcodes = all_barcodes [1 :]
9396
9497 geo_class = Geometry .get_class (plate_type )
9598 geometry = geo_class .deserialize (items [Record .IND_GEOMETRY ])
9699
97- return Record (plate_type = plate_type , barcodes = barcodes , timestamp = timestamp ,
100+ return Record (plate_type = plate_type , holder_barcode = holder_barcode , barcodes = pin_barcodes , timestamp = timestamp ,
98101 image_path = image , id = id , geometry = geometry )
99102
100103 def to_csv_string (self ):
101104 """ Converts a scan record object into a string that can be stored in a csv file.
102105 """
103- items = [0 ] * 3
104- items [0 ] = str (self .id )
105- items [1 ] = str (self ._formatted_date ())
106- items [2 ] = Record .BC_SEPARATOR .join (self .barcodes )
106+ items = list ()
107+ items .append (str (self .id ))
108+ items .append (str (self ._formatted_date ()))
109+ items .append (self .holder_barcode )
110+ items .append (Record .BC_SEPARATOR .join (self .barcodes ))
107111 return Record .BC_SEPARATOR .join (items )
108112
109113 def to_string (self ):
@@ -115,32 +119,20 @@ def to_string(self):
115119 items [Record .IND_TIMESTAMP ] = str (self .timestamp )
116120 items [Record .IND_IMAGE ] = self .image_path
117121 items [Record .IND_PLATE ] = self .plate_type
118- items [Record .IND_BARCODES ] = Record .BC_SEPARATOR .join (self .barcodes )
122+ items [Record .IND_BARCODES ] = Record .BC_SEPARATOR .join (self ._all_barcodes () )
119123 items [Record .IND_GEOMETRY ] = self .geometry .serialize ()
120124 return Record .ITEM_SEPARATOR .join (items )
121125
122- def any_barcode_matches (self , barcodes ):
123- """ Returns true if the record contains any barcode which is also
124- contained in the specified list
125- """
126- barcodes = [bc for bc in barcodes if bc not in Record .BAD_SYMBOLS ]
127- for bc in barcodes :
128- if bc in self .barcodes :
129- return True
130-
131- return False
126+ def _all_barcodes (self ):
127+ return [self .holder_barcode ] + self .barcodes
132128
133- #TODO: modify when two images merged
134- # only the image of the top for the time being
135- def image (self ):
129+ def _image (self ):
136130 image = Image .from_file (self .image_path )
137131 return image
138132
139- #TODO: modify when two images merged
140- # only the image of the top for the time being
141133 def marked_image (self , options ):
142134 geo = self .geometry
143- image = self .image ()
135+ image = self ._image ()
144136
145137 if options .image_puck .value ():
146138 geo .draw_plate (image , Color .Blue ())
@@ -155,9 +147,7 @@ def marked_image(self, options):
155147
156148 # marking the top image
157149 def _draw_pins (self , image , geometry , options ):
158- top_barcodes = list (self .barcodes ) #copy of the list
159- top_barcodes .pop (0 )# remove the first element (side barcode)
160- for i , bc in enumerate (top_barcodes ):
150+ for i , bc in enumerate (self .barcodes ):
161151 if bc == NOT_FOUND_SLOT_SYMBOL :
162152 color = options .col_bad ()
163153 elif bc == EMPTY_SLOT_SYMBOL :
0 commit comments