| Conditions | 20 |
| Total Lines | 167 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 AbstractGenerator._write_doc_aini2016() 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 -*- |
||
| 190 | def _write_doc_aini2016(self, doc, record): |
||
| 191 | print('"%s"' % record['Title']) |
||
| 192 | exreg4num = re.compile(r'\((\w+)\)') |
||
| 193 | |||
| 194 | font = doc.styles['Normal'].font |
||
| 195 | font.size = docx.shared.Pt(10) |
||
| 196 | font.name = 'Times New Roman' |
||
| 197 | |||
| 198 | # Program Number |
||
| 199 | # p = doc.add_paragraph() |
||
| 200 | # p.paragraph_format.line_spacing = docx.shared.Pt(12) |
||
| 201 | # p.paragraph_format.space_after = docx.shared.Pt(5) |
||
| 202 | # r = p.add_run(record['Program No.'].strip()) |
||
| 203 | |||
| 204 | # Title |
||
| 205 | p = doc.add_paragraph() |
||
| 206 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 207 | p.paragraph_format.space_before = docx.shared.Pt(25) |
||
| 208 | p.paragraph_format.space_after = docx.shared.Pt(14) |
||
| 209 | r = p.add_run(record['Title'].strip()) |
||
| 210 | r.font.size = docx.shared.Pt(12) |
||
| 211 | r.bold = True |
||
| 212 | r.italic = True |
||
| 213 | |||
| 214 | # Authors |
||
| 215 | p = doc.add_paragraph() |
||
| 216 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 217 | p.paragraph_format.line_spacing = docx.shared.Pt(12) |
||
| 218 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 219 | authors = self._to_array(record['Name'], '\n') |
||
| 220 | first = True |
||
| 221 | for author in authors: |
||
| 222 | m = self.exreg4author.match(author) |
||
| 223 | if not first: |
||
| 224 | p.add_run(', ').bold = True |
||
| 225 | name = m.group(1).strip().replace(' ', '\u00A0') |
||
| 226 | num = self._remove_parentheses(m.group(2).strip()) |
||
| 227 | p.add_run(name).bold = True |
||
| 228 | if num != '': |
||
| 229 | r = p.add_run('\u00A0' + num) |
||
| 230 | r.bold = True |
||
| 231 | r.font.superscript = True |
||
| 232 | first = False |
||
| 233 | p.add_run('\n') |
||
| 234 | |||
| 235 | # Affiliation |
||
| 236 | affiliations = self._to_array(record['Affiliation'], '\n') |
||
| 237 | first = True |
||
| 238 | for affiliation in affiliations: |
||
| 239 | m = self.exreg4affiliation.match(affiliation) |
||
| 240 | if not first: |
||
| 241 | p.add_run(', ') |
||
| 242 | num = self._remove_parentheses(m.group(1).strip()) |
||
| 243 | name = m.group(2).strip() |
||
| 244 | if num != '': |
||
| 245 | r = p.add_run(num + '\u00A0') |
||
| 246 | r.font.superscript = True |
||
| 247 | p.add_run(name) |
||
| 248 | first = False |
||
| 249 | p.add_run('\n' + record['e-mail']) |
||
| 250 | |||
| 251 | # DOI |
||
| 252 | p = doc.add_paragraph('DOI:' + record['DOI'].strip()) |
||
| 253 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 254 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 255 | |||
| 256 | # Abstract Body |
||
| 257 | items = self._to_array(record['Abstract'], '\n') |
||
| 258 | first = True |
||
| 259 | for item in items: |
||
| 260 | p = doc.add_paragraph(item) |
||
| 261 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 262 | p.paragraph_format.line_spacing = docx.shared.Pt(11) |
||
| 263 | p.paragraph_format.space_after = docx.shared.Pt(2) |
||
| 264 | if not first: |
||
| 265 | p.paragraph_format.first_line_indent = docx.shared.Pt(12) |
||
| 266 | first = False |
||
| 267 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 268 | |||
| 269 | # Figure |
||
| 270 | if not self._empty(record['Figure file Name']): |
||
| 271 | |||
| 272 | # Figure File Name |
||
| 273 | img_fpath = os.path.join(self.image_dir, record['Figure file Name']) |
||
| 274 | size = self._get_preferred_image_size(img_fpath) |
||
| 275 | doc.add_picture(img_fpath, width=size[0]) # , height=size[1]) |
||
| 276 | p = doc.paragraphs[-1] |
||
| 277 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 278 | |||
| 279 | # Figure Comment |
||
| 280 | items = self._to_array(record['Figure comment'], '\n') |
||
| 281 | first = True |
||
| 282 | for item in items: |
||
| 283 | p = doc.add_paragraph() |
||
| 284 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 285 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 286 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 287 | if first: |
||
| 288 | p.add_run('Figure: ').bold = True |
||
| 289 | first = False |
||
| 290 | p.add_run(item) |
||
| 291 | |||
| 292 | p.paragraph_format.space_after = docx.shared.Pt(14) |
||
| 293 | |||
| 294 | # References |
||
| 295 | items = self._to_array(record['References'], '\n') |
||
| 296 | first = True |
||
| 297 | for item in items: |
||
| 298 | if first: |
||
| 299 | p = doc.add_paragraph() |
||
| 300 | p.paragraph_format.line_spacing = docx.shared.Pt(11) |
||
| 301 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 302 | p.add_run('References:').bold = True |
||
| 303 | first = False |
||
| 304 | p = doc.add_paragraph() |
||
| 305 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 306 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 307 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 308 | p.add_run(item) |
||
| 309 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 310 | |||
| 311 | # Acknowledgement |
||
| 312 | items = self._to_array(record['Acknowledgement'], '\n') |
||
| 313 | first = True |
||
| 314 | for item in items: |
||
| 315 | p = doc.add_paragraph() |
||
| 316 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 317 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 318 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 319 | if first: |
||
| 320 | p.add_run('Ackknowledgement: ').bold = True |
||
| 321 | first = False |
||
| 322 | p.add_run(item) |
||
| 323 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 324 | |||
| 325 | # Funding |
||
| 326 | items = self._to_array(record['Funding'], '\n') |
||
| 327 | first = True |
||
| 328 | for item in items: |
||
| 329 | p = doc.add_paragraph() |
||
| 330 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 331 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 332 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 333 | if first: |
||
| 334 | p.add_run('Funding: ').bold = True |
||
| 335 | first = False |
||
| 336 | p.add_run(item) |
||
| 337 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 338 | |||
| 339 | # Citation |
||
| 340 | p = doc.add_paragraph() |
||
| 341 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 342 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 343 | p.add_run('Citation: ').bold = True |
||
| 344 | author_tmp = '' |
||
| 345 | first = True |
||
| 346 | for author in authors: |
||
| 347 | m = self.exreg4author.match(author) |
||
| 348 | if not first: |
||
| 349 | author_tmp += ', ' |
||
| 350 | author_tmp += m.group(1).strip() |
||
| 351 | first = False |
||
| 352 | p.add_run(author_tmp + ' (2016). ' + record['Title'].strip().replace('\n', ' ') + '. ') |
||
| 353 | p.add_run('Advances in Neuroinformatics IV. ').italic = True |
||
| 354 | p.add_run( |
||
| 355 | 'AINI 2016 and INCF Nodes Workshop Abstract: ' + record['Program No. Long'].strip() + '. DOI:' + record[ |
||
| 356 | 'DOI'].strip()) |
||
| 357 | |||
| 364 |