| Conditions | 4 |
| Total Lines | 66 |
| Code Lines | 10 |
| 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:
| 1 | from datetime import datetime |
||
| 143 | def add_data(self) -> None: |
||
| 144 | with self.database.engine.begin() as connection: |
||
| 145 | queries = [ |
||
| 146 | """ |
||
| 147 | insert ignore into companies ( |
||
| 148 | code_uic, |
||
| 149 | short_name, |
||
| 150 | name, |
||
| 151 | country_code_iso, |
||
| 152 | allocation_date, |
||
| 153 | modified_date, |
||
| 154 | begin_of_validity, |
||
| 155 | end_of_validity, |
||
| 156 | freight, |
||
| 157 | passenger, |
||
| 158 | infrastructure, |
||
| 159 | holding, |
||
| 160 | integrated, |
||
| 161 | other, |
||
| 162 | url |
||
| 163 | ) |
||
| 164 | values ( |
||
| 165 | :code_uic, |
||
| 166 | :short_name, |
||
| 167 | :name, |
||
| 168 | :country_code_iso, |
||
| 169 | :allocation_date, |
||
| 170 | :modified_date, |
||
| 171 | :begin_of_validity, |
||
| 172 | :end_of_validity, |
||
| 173 | :freight, |
||
| 174 | :passenger, |
||
| 175 | :infrastructure, |
||
| 176 | :holding, |
||
| 177 | :integrated, |
||
| 178 | :other, |
||
| 179 | :url |
||
| 180 | ) |
||
| 181 | """, |
||
| 182 | """ |
||
| 183 | update companies |
||
| 184 | set |
||
| 185 | short_name = :short_name, |
||
| 186 | name = :name, |
||
| 187 | country_code_iso = :country_code_iso, |
||
| 188 | allocation_date = :allocation_date, |
||
| 189 | modified_date = :modified_date, |
||
| 190 | begin_of_validity = :begin_of_validity, |
||
| 191 | end_of_validity = :end_of_validity, |
||
| 192 | freight = :freight, |
||
| 193 | passenger = :passenger, |
||
| 194 | infrastructure = :infrastructure, |
||
| 195 | holding = :holding, |
||
| 196 | integrated = :integrated, |
||
| 197 | other = :other, |
||
| 198 | url = :url |
||
| 199 | where |
||
| 200 | code_uic = :code_uic |
||
| 201 | """, |
||
| 202 | ] |
||
| 203 | |||
| 204 | for index, row in self.data.iterrows(): |
||
| 205 | for query in queries: |
||
| 206 | connection.execute( |
||
| 207 | text(query), |
||
| 208 | row.to_dict(), |
||
| 209 | ) |
||
| 210 |