| Conditions | 44 | 
| Total Lines | 216 | 
| Code Lines | 135 | 
| Lines | 131 | 
| Ratio | 60.65 % | 
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like build.bika.lims.exportimport.instruments.panalytical.omnia.AxiosXrfCSVParser.parse_headerline() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | # -*- coding: utf-8 -*-  | 
            ||
| 194 | def parse_headerline(self, line):  | 
            ||
| 195 | #Process incoming header line  | 
            ||
| 196 | """  | 
            ||
| 197 | 29/11/2013 10:15:44  | 
            ||
| 198 | PANalytical  | 
            ||
| 199 | "Quantification of sample ESFERA CINZA - 1g H3BO3 - 1:0,5 - NO PPC",  | 
            ||
| 200 | |||
| 201 | R.M.S.:,"0,035"  | 
            ||
| 202 | Result status:,  | 
            ||
| 203 | Sum before normalization:,"119,5 %"  | 
            ||
| 204 | Normalised to:,"100,0 %"  | 
            ||
| 205 | Sample type:,Pressed powder  | 
            ||
| 206 | Initial sample weight (g):,"2,000"  | 
            ||
| 207 | Weight after pressing (g):,"3,000"  | 
            ||
| 208 | Correction applied for medium:,No  | 
            ||
| 209 | Correction applied for film:,No  | 
            ||
| 210 | Used Compound list:,Oxides  | 
            ||
| 211 | Results database:,omnian 2013  | 
            ||
| 212 | Results database in:,c:\panalytical\superq\userdata  | 
            ||
| 213 | """  | 
            ||
| 214 | |||
| 215 |         if line.startswith('"Quantification of sample') or line.startswith('Quantification of sample'): | 
            ||
| 216 | line = to_unicode(line)  | 
            ||
| 217 | if len(self._header) == 0:  | 
            ||
| 218 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 219 | return -1  | 
            ||
| 220 | # Remove non important string and double comas to obtein  | 
            ||
| 221 | # the sample name free  | 
            ||
| 222 |             line = line.replace("Quantification of sample ", "") | 
            ||
| 223 |             line = line.replace('"', "") | 
            ||
| 224 |             splitted = line.split(' - ') | 
            ||
| 225 | |||
| 226 | if len(splitted) > 3:# Maybe we don't need this, i could be all the sample's identifier...  | 
            ||
| 227 |                 self._header['Sample'] = splitted[0].strip(' ') | 
            ||
| 228 | self._header['Quantity'] = splitted[1]  | 
            ||
| 229 | self._header['????'] = splitted[2]# At present we  | 
            ||
| 230 | # don't know what  | 
            ||
| 231 | # is that  | 
            ||
| 232 | self._header['PPC'] = splitted[3]  | 
            ||
| 233 | |||
| 234 | elif len(splitted) == 1:  | 
            ||
| 235 |                 self._header['Sample'] = splitted[0].replace('Quantification of sample','').strip(' ') | 
            ||
| 236 | |||
| 237 | else:  | 
            ||
| 238 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 239 | return 1  | 
            ||
| 240 | # Save each header field (that we know) and its own value in the dict  | 
            ||
| 241 | View Code Duplication |         if line.startswith('R.M.S.'): | 
            |
| 242 | |||
| 243 | if len(self._header) == 0:  | 
            ||
| 244 |                 self.err("No header found", numline=self._numline) | 
            ||
| 245 | return -1  | 
            ||
| 246 | |||
| 247 | splitted = self.splitLine(line)  | 
            ||
| 248 | if len(splitted) > 1:  | 
            ||
| 249 |                 self._header['R.M.S.'] = splitted[1].replace('"', '').strip() | 
            ||
| 250 | else:  | 
            ||
| 251 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 252 | return 0  | 
            ||
| 253 | |||
| 254 | View Code Duplication |         if line.startswith('Result status'): | 
            |
| 255 | if len(self._header) == 0:  | 
            ||
| 256 |                 self.err("No header found", numline=self._numline) | 
            ||
| 257 | |||
| 258 | splitted = self.splitLine(line)  | 
            ||
| 259 | if len(splitted) > 1:  | 
            ||
| 260 |                 self._header['Result status'] = splitted[1].replace('"', '').strip() | 
            ||
| 261 | else:  | 
            ||
| 262 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 263 | |||
| 264 | return 0  | 
            ||
| 265 | |||
| 266 | View Code Duplication |         if line.startswith('Sum before normalization'): | 
            |
| 267 | if len(self._header) == 0:  | 
            ||
| 268 |                 self.err("No header found", numline=self._numline) | 
            ||
| 269 | return -1  | 
            ||
| 270 | |||
| 271 | splitted = self.splitLine(line)  | 
            ||
| 272 | if len(splitted) > 1:  | 
            ||
| 273 |                 self._header['Sum'] = splitted[1].replace('"', '').strip() | 
            ||
| 274 | else:  | 
            ||
| 275 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 276 | |||
| 277 | return 0  | 
            ||
| 278 | |||
| 279 | View Code Duplication |         if line.startswith('Normalised to'): | 
            |
| 280 | if len(self._header) == 0:  | 
            ||
| 281 |                 self.err("No header found", numline=self._numline) | 
            ||
| 282 | return -1  | 
            ||
| 283 | |||
| 284 | splitted = self.splitLine(line)  | 
            ||
| 285 | if len(splitted) > 1:  | 
            ||
| 286 |                 self._header['Normalized'] = splitted[1].replace('"', '').strip() | 
            ||
| 287 | else:  | 
            ||
| 288 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 289 | |||
| 290 | return 0  | 
            ||
| 291 | |||
| 292 | View Code Duplication |         if line.startswith('Sample type'): | 
            |
| 293 | if len(self._header) == 0:  | 
            ||
| 294 |                 self.err("No header found", numline=self._numline) | 
            ||
| 295 | return -1  | 
            ||
| 296 | |||
| 297 | splitted = self.splitLine(line)  | 
            ||
| 298 | if len(splitted) > 1:  | 
            ||
| 299 | self._header['Sample type'] = splitted[1].strip()  | 
            ||
| 300 | else:  | 
            ||
| 301 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 302 | |||
| 303 | return 0  | 
            ||
| 304 | |||
| 305 | View Code Duplication |         if line.startswith('Initial sample weight (g)'): | 
            |
| 306 | if len(self._header) == 0:  | 
            ||
| 307 |                 self.err("No header found", numline=self._numline) | 
            ||
| 308 | return -1  | 
            ||
| 309 | |||
| 310 | splitted = self.splitLine(line)  | 
            ||
| 311 | if len(splitted) > 1:  | 
            ||
| 312 |                 self._header['Initial sample weight'] = splitted[1].replace('"', '').strip() | 
            ||
| 313 | else:  | 
            ||
| 314 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 315 | |||
| 316 | return 0  | 
            ||
| 317 | |||
| 318 | View Code Duplication |         if line.startswith('Weight after pressing (g)'): | 
            |
| 319 | if len(self._header) == 0:  | 
            ||
| 320 |                 self.err("No header found", numline=self._numline) | 
            ||
| 321 | return -1  | 
            ||
| 322 | |||
| 323 | splitted = self.splitLine(line)  | 
            ||
| 324 | if len(splitted) > 1:  | 
            ||
| 325 |                 self._header['Weight after pressing'] = splitted[1].replace('"', '').strip() | 
            ||
| 326 | else:  | 
            ||
| 327 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 328 | |||
| 329 | return 0  | 
            ||
| 330 | |||
| 331 | View Code Duplication |         if line.startswith('Correction applied for medium'): | 
            |
| 332 | if len(self._header) == 0:  | 
            ||
| 333 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 334 | return -1  | 
            ||
| 335 | |||
| 336 | splitted = self.splitLine(line)  | 
            ||
| 337 | if len(splitted) > 1:  | 
            ||
| 338 |                 self._header['Correction medium'] = splitted[1].replace('"', '').strip() | 
            ||
| 339 | else:  | 
            ||
| 340 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 341 | |||
| 342 | return 0  | 
            ||
| 343 | |||
| 344 | View Code Duplication |         if line.startswith('Correction applied for film'): | 
            |
| 345 | if len(self._header) == 0:  | 
            ||
| 346 |                 self.err("No header found", numline=self._numline) | 
            ||
| 347 | return -1  | 
            ||
| 348 | |||
| 349 | splitted = self.splitLine(line)  | 
            ||
| 350 | if len(splitted) > 1:  | 
            ||
| 351 |                 self._header['Correction film'] = splitted[1].replace('"', '').strip() | 
            ||
| 352 | else:  | 
            ||
| 353 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 354 | |||
| 355 | return 0  | 
            ||
| 356 | |||
| 357 | View Code Duplication |         if line.startswith('Used Compound list'): | 
            |
| 358 | if len(self._header) == 0:  | 
            ||
| 359 |                 self.err("No header found", numline=self._numline) | 
            ||
| 360 | return -1  | 
            ||
| 361 | |||
| 362 | splitted = self.splitLine(line)  | 
            ||
| 363 | if len(splitted) > 1:  | 
            ||
| 364 |                 self._header['Used compound'] = splitted[1].replace('"', '').strip() | 
            ||
| 365 | else:  | 
            ||
| 366 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 367 | |||
| 368 | return 0  | 
            ||
| 369 | View Code Duplication |         if line.startswith('Results database:'): | 
            |
| 370 | if len(self._header) == 0:  | 
            ||
| 371 |                 self.err("No header found", numline=self._numline) | 
            ||
| 372 | return -1  | 
            ||
| 373 | |||
| 374 | splitted = self.splitLine(line)  | 
            ||
| 375 | if len(splitted) > 1:  | 
            ||
| 376 |                 self._header['Result database'] = splitted[1].replace('"', '').strip() | 
            ||
| 377 | else:  | 
            ||
| 378 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 379 | |||
| 380 | return 0  | 
            ||
| 381 | |||
| 382 | |||
| 383 | if self.columns_name:  | 
            ||
| 384 | if len(self._header) == 0:  | 
            ||
| 385 |                 self.err("No header found", numline=self._numline) | 
            ||
| 386 | return -1  | 
            ||
| 387 | |||
| 388 | #Grab column names  | 
            ||
| 389 | self._end_header = True  | 
            ||
| 390 | self._columns = self.splitLine(line)  | 
            ||
| 391 | return 1  | 
            ||
| 392 | |||
| 393 |         if line.startswith('Results database in'): | 
            ||
| 394 | if len(self._header) == 0:  | 
            ||
| 395 |                 self.err("No header found", numline=self._numline) | 
            ||
| 396 | return -1  | 
            ||
| 397 | |||
| 398 | splitted = self.splitLine(line)  | 
            ||
| 399 | if len(splitted) > 1:  | 
            ||
| 400 | self._header['Database path'] = splitted[1]+splitted[2]  | 
            ||
| 401 | self.columns_name = True  | 
            ||
| 402 | else:  | 
            ||
| 403 |                 self.warn('Unexpected header format', numline=self._numline) | 
            ||
| 404 | |||
| 405 | return 1  | 
            ||
| 406 | |||
| 407 | else:  | 
            ||
| 408 | self._header['Date'] = line  | 
            ||
| 409 | return 1  | 
            ||
| 410 | |||
| 511 |