| Total Complexity | 6 | 
| Total Lines | 26 | 
| Duplicated Lines | 0 % | 
| 1 | from niprov.format import Format | ||
| 4 | class NarratedFormat(Format): | ||
| 5 | """Generates human-readable text that describes provenance objects. | ||
| 6 | """ | ||
| 7 | |||
| 8 | def serializeSingle(self, img): | ||
| 9 | provenance = img.provenance | ||
| 10 | story = '' | ||
| 11 | if 'protocol' in provenance: | ||
| 12 |             story += 'This is a {0} image. '.format(provenance['protocol']) | ||
| 13 | if 'acquired' in provenance: | ||
| 14 |             datestr = provenance['acquired'].strftime('%B %d, %Y').replace(' 0',' ') | ||
| 15 |             story += 'It was recorded {0}. '.format(datestr) | ||
| 16 | if 'subject' in provenance: | ||
| 17 |             story += "The participant's name is {0}. ".format( | ||
| 18 | provenance['subject']) | ||
| 19 | if 'size' in provenance: | ||
| 20 | sizeInBytes = provenance['size'] | ||
| 21 | if sizeInBytes > (1000 * 1000): | ||
| 22 | unit = 'MB' | ||
| 23 | factor = 1000 * 1000 | ||
| 24 | else: | ||
| 25 | unit = 'KB' | ||
| 26 | factor = 1000 | ||
| 27 | size = int(provenance['size']/factor) | ||
| 28 |             story += "It is {0}{1} in size. ".format(size, unit) | ||
| 29 | return story | ||
| 30 |