| Conditions | 20 |
| Total Lines | 165 |
| Lines | 0 |
| Ratio | 0 % |
| 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 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 -*- |
||
| 152 | def _write_doc_aini2016(self, doc, record): |
||
| 153 | print('"%s"' % record['Title'])
|
||
| 154 | exreg4num = re.compile(r'\((\w+)\)') |
||
| 155 | |||
| 156 | font = doc.styles['Normal'].font |
||
| 157 | font.size = docx.shared.Pt(10) |
||
| 158 | font.name = 'Times New Roman' |
||
| 159 | |||
| 160 | # Program Number |
||
| 161 | #p = doc.add_paragraph() |
||
| 162 | #p.paragraph_format.line_spacing = docx.shared.Pt(12) |
||
| 163 | #p.paragraph_format.space_after = docx.shared.Pt(5) |
||
| 164 | #r = p.add_run(record['Program No.'].strip()) |
||
| 165 | |||
| 166 | # Title |
||
| 167 | p = doc.add_paragraph() |
||
| 168 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 169 | p.paragraph_format.space_before = docx.shared.Pt(25) |
||
| 170 | p.paragraph_format.space_after = docx.shared.Pt(14) |
||
| 171 | r = p.add_run(record['Title'].strip()) |
||
| 172 | r.font.size = docx.shared.Pt(12) |
||
| 173 | r.bold = True |
||
| 174 | r.italic = True |
||
| 175 | |||
| 176 | # Authors |
||
| 177 | p = doc.add_paragraph() |
||
| 178 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 179 | p.paragraph_format.line_spacing = docx.shared.Pt(12) |
||
| 180 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 181 | authors = self._toArray(record['Name'], '\n') |
||
| 182 | first = True |
||
| 183 | for author in authors: |
||
| 184 | m = self.exreg4author.match(author) |
||
| 185 | if first == False: |
||
| 186 | p.add_run(', ').bold = True
|
||
| 187 | name = m.group(1).strip().replace(' ', '\u00A0')
|
||
| 188 | num = self._removeParentheses(m.group(2).strip()) |
||
| 189 | p.add_run(name).bold = True |
||
| 190 | if num != '': |
||
| 191 | r = p.add_run('\u00A0' + num)
|
||
| 192 | r.bold = True |
||
| 193 | r.font.superscript = True |
||
| 194 | first = False |
||
| 195 | p.add_run('\n')
|
||
| 196 | |||
| 197 | # Affiliation |
||
| 198 | affiliations = self._toArray(record['Affiliation'], '\n') |
||
| 199 | first = True |
||
| 200 | for affiliation in affiliations: |
||
| 201 | m = self.exreg4affiliation.match(affiliation) |
||
| 202 | if first == False: |
||
| 203 | p.add_run(', ')
|
||
| 204 | num = self._removeParentheses(m.group(1).strip()) |
||
| 205 | name = m.group(2).strip() |
||
| 206 | if num != '': |
||
| 207 | r = p.add_run(num + '\u00A0') |
||
| 208 | r.font.superscript = True |
||
| 209 | p.add_run(name) |
||
| 210 | first = False |
||
| 211 | p.add_run('\n' + record['e-mail'])
|
||
| 212 | |||
| 213 | # DOI |
||
| 214 | p = doc.add_paragraph('DOI:' + record['DOI'].strip())
|
||
| 215 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 216 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 217 | |||
| 218 | # Abstract Body |
||
| 219 | items = self._toArray(record['Abstract'], '\n') |
||
| 220 | first = True |
||
| 221 | for item in items: |
||
| 222 | p = doc.add_paragraph(item) |
||
| 223 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 224 | p.paragraph_format.line_spacing = docx.shared.Pt(11) |
||
| 225 | p.paragraph_format.space_after = docx.shared.Pt(2) |
||
| 226 | if first == False: |
||
| 227 | p.paragraph_format.first_line_indent = docx.shared.Pt(12) |
||
| 228 | first = False |
||
| 229 | p.paragraph_format.space_after = docx.shared.Pt(12) |
||
| 230 | |||
| 231 | # Figure |
||
| 232 | if self._empty(record['Figure file Name']) == False: |
||
| 233 | |||
| 234 | # Figure File Name |
||
| 235 | img_fpath = os.path.join(self.image_dir, record['Figure file Name']) |
||
| 236 | size = self._getPreferredImageSize(img_fpath) |
||
| 237 | doc.add_picture(img_fpath, width=size[0]) #, height=size[1]) |
||
| 238 | p = doc.paragraphs[-1] |
||
| 239 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.CENTER |
||
| 240 | |||
| 241 | # Figure Comment |
||
| 242 | items = self._toArray(record['Figure comment'], '\n') |
||
| 243 | first = True |
||
| 244 | for item in items: |
||
| 245 | p = doc.add_paragraph() |
||
| 246 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 247 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 248 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 249 | if first: |
||
| 250 | p.add_run('Figure: ').bold = True
|
||
| 251 | first = False |
||
| 252 | p.add_run(item) |
||
| 253 | |||
| 254 | p.paragraph_format.space_after = docx.shared.Pt(14) |
||
| 255 | |||
| 256 | # References |
||
| 257 | items = self._toArray(record['References'], '\n') |
||
| 258 | first = True |
||
| 259 | for item in items: |
||
| 260 | if first: |
||
| 261 | p = doc.add_paragraph() |
||
| 262 | p.paragraph_format.line_spacing = docx.shared.Pt(11) |
||
| 263 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 264 | p.add_run('References:').bold = True
|
||
| 265 | first = False |
||
| 266 | p = doc.add_paragraph() |
||
| 267 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 268 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 269 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 270 | p.add_run(item) |
||
| 271 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 272 | |||
| 273 | # Acknowledgement |
||
| 274 | items = self._toArray(record['Acknowledgement'], '\n') |
||
| 275 | first = True |
||
| 276 | for item in items: |
||
| 277 | p = doc.add_paragraph() |
||
| 278 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 279 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 280 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 281 | if first: |
||
| 282 | p.add_run('Ackknowledgement: ').bold = True
|
||
| 283 | first = False |
||
| 284 | p.add_run(item) |
||
| 285 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 286 | |||
| 287 | # Funding |
||
| 288 | items = self._toArray(record['Funding'], '\n') |
||
| 289 | first = True |
||
| 290 | for item in items: |
||
| 291 | p = doc.add_paragraph() |
||
| 292 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 293 | p.paragraph_format.space_after = docx.shared.Pt(0) |
||
| 294 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 295 | if first: |
||
| 296 | p.add_run('Funding: ').bold = True
|
||
| 297 | first = False |
||
| 298 | p.add_run(item) |
||
| 299 | p.paragraph_format.space_after = docx.shared.Pt(10) |
||
| 300 | |||
| 301 | # Citation |
||
| 302 | p = doc.add_paragraph() |
||
| 303 | p.paragraph_format.line_spacing = docx.shared.Pt(10) |
||
| 304 | p.alignment = docx.enum.text.WD_ALIGN_PARAGRAPH.JUSTIFY |
||
| 305 | p.add_run('Citation: ').bold = True
|
||
| 306 | author_tmp = '' |
||
| 307 | first = True |
||
| 308 | for author in authors: |
||
| 309 | m = self.exreg4author.match(author) |
||
| 310 | if first == False: |
||
| 311 | author_tmp += ', ' |
||
| 312 | author_tmp += m.group(1).strip() |
||
| 313 | first = False |
||
| 314 | p.add_run(author_tmp + ' (2016). ' + record['Title'].strip().replace('\n', ' ') + '. ')
|
||
| 315 | p.add_run('Advances in Neuroinformatics IV. ').italic = True
|
||
| 316 | p.add_run('AINI 2016 and INCF Nodes Workshop Abstract: ' + record['Program No. Long'].strip() + '. DOI:' + record['DOI'].strip())
|
||
| 317 | |||
| 324 |