Mangle
Mangle readings plate files to simulate poor formatting.
mangle(options)
Main driver for mangling readings plates.
- options.dbfile: path to SQLite database.
- options.outdir: output directory.
- options.tidy: directory containing tidy readings files.
Mangled files are written to the specified output directory. The files have the same name as the original (tidy) files.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options
|
Namespace
|
see above. |
required |
Source code in snailz/mangle.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
_consolidate(records)
Pick a single (plate, staff) pair for each plate.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
records
|
list
|
list of (plate, staff) pairs from database. |
required |
Returns:
Type | Description |
---|---|
list
|
One (plate, staff) pair for each plate. |
Source code in snailz/mangle.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
_mangle_file(options, record)
Mangle a single file.
- Read file as header and body sections.
- Apply randomly-chosen mangling functions to modify in place.
- Save result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options
|
Namespace
|
see above. |
required |
record
|
dict
|
dictionary of database query results for a single record. |
required |
Source code in snailz/mangle.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
_do_date(record, sections)
Mangle data in place by adding date in header.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record
|
dict
|
entire record data. |
required |
sections
|
dict
|
dictionary of header, body, and footer. |
required |
Source code in snailz/mangle.py
89 90 91 92 93 94 95 96 97 98 99 |
|
_do_footer(record, sections)
Mangle data in place by adding a footer.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record
|
dict
|
entire record data. |
required |
sections
|
dict
|
dictionary of header, body, and footer. |
required |
Source code in snailz/mangle.py
103 104 105 106 107 108 109 110 111 112 113 |
|
_do_indent(record, sections)
Mangle data in place by indenting all rows by one space
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record
|
dict
|
entire record data. |
required |
sections
|
dict
|
dictionary of header, body, and footer. |
required |
Source code in snailz/mangle.py
117 118 119 120 121 122 123 124 125 126 |
|
_do_staff_name(record, sections)
Mangle data in place by adding staff name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
record
|
dict
|
entire record data. |
required |
sections
|
dict
|
dictionary of header, body, and footer. |
required |
Source code in snailz/mangle.py
130 131 132 133 134 135 136 137 |
|
_read_sections(options, filename)
Read tidy readings file and split into sections.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options
|
Namespace
|
see above. |
required |
filename
|
str
|
file to read from. |
required |
Returns:
Type | Description |
---|---|
dict
|
Dictionary with header, head-to-body spacing, body, and footer (empty in tidy file). |
Source code in snailz/mangle.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
_write_sections(options, filename, sections)
Write sections of mangled file to file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
options
|
Namespace
|
see above. |
required |
filename
|
str
|
file to write to. |
required |
sections
|
dict
|
dictionary of header, head-to-body spacing, body, and footer. |
required |
Source code in snailz/mangle.py
161 162 163 164 165 166 167 168 169 170 171 172 |
|