|
9 | 9 | from process_tracker.data_store import DataStore |
10 | 10 | from process_tracker.location_tracker import LocationTracker |
11 | 11 | from process_tracker.utilities.settings import SettingsManager |
| 12 | +from process_tracker.utilities import utilities |
12 | 13 | from process_tracker.models.extract import ( |
13 | 14 | Extract, |
14 | 15 | ExtractDependency, |
@@ -252,3 +253,75 @@ def retrieve_extract_process(self): |
252 | 253 | self.session.commit() |
253 | 254 |
|
254 | 255 | return extract_process |
| 256 | + |
| 257 | + def set_extract_low_high_dates(self, low_date, high_date, audit_type="load"): |
| 258 | + """ |
| 259 | + For the given extract, find the low and high date_times while writing or loading. |
| 260 | + :param low_date: The low date of the data set. |
| 261 | + :type low_date: Datetime/timestamp |
| 262 | + :param high_date: The high date of the data set. |
| 263 | + :type high_date: Datetime/timestamp. |
| 264 | + :param audit_type: The type of audit fields being populated. Valid types: write, load |
| 265 | + :type audittype: String |
| 266 | + :return: |
| 267 | + """ |
| 268 | + |
| 269 | + if audit_type == "write": |
| 270 | + |
| 271 | + previous_low_date_time = self.extract.extract_write_low_date_time |
| 272 | + previous_high_date_time = self.extract.extract_write_high_date_time |
| 273 | + |
| 274 | + if utilities.determine_low_high_date( |
| 275 | + date=low_date, previous_date=previous_low_date_time, date_type="low" |
| 276 | + ): |
| 277 | + self.extract.extract_write_low_date_time = low_date |
| 278 | + |
| 279 | + if utilities.determine_low_high_date( |
| 280 | + date=high_date, previous_date=previous_high_date_time, date_type="high" |
| 281 | + ): |
| 282 | + self.extract.extract_write_high_date_time = high_date |
| 283 | + |
| 284 | + elif audit_type == "load": |
| 285 | + |
| 286 | + previous_low_date_time = self.extract.extract_load_low_date_time |
| 287 | + previous_high_date_time = self.extract.extract_load_high_date_time |
| 288 | + |
| 289 | + if utilities.determine_low_high_date( |
| 290 | + date=low_date, previous_date=previous_low_date_time, date_type="low" |
| 291 | + ): |
| 292 | + self.extract.extract_load_low_date_time = low_date |
| 293 | + |
| 294 | + if utilities.determine_low_high_date( |
| 295 | + date=high_date, previous_date=previous_high_date_time, date_type="high" |
| 296 | + ): |
| 297 | + self.extract.extract_load_high_date_time = high_date |
| 298 | + |
| 299 | + else: |
| 300 | + self.logger.error("%s is not a valid audit_type." % audit_type) |
| 301 | + raise Exception("%s is not a valid audit_type." % audit_type) |
| 302 | + |
| 303 | + self.session.commit() |
| 304 | + |
| 305 | + def set_extract_record_count(self, num_records, audit_type="load"): |
| 306 | + """ |
| 307 | + For the given audit type, set the number of records for the given extract. |
| 308 | + :param num_records: Number of records tracked in extract |
| 309 | + :type num_records: int |
| 310 | + :param audit_type: The type of audit being populated. Valid types: write, load. |
| 311 | + :type audit_type: str |
| 312 | + :return: |
| 313 | + """ |
| 314 | + |
| 315 | + if audit_type == "write": |
| 316 | + |
| 317 | + self.extract.extract_write_record_count = num_records |
| 318 | + |
| 319 | + elif audit_type == "load": |
| 320 | + |
| 321 | + self.extract.extract_load_record_count = num_records |
| 322 | + |
| 323 | + else: |
| 324 | + self.logger.error("%s is not a valid audit_type." % audit_type) |
| 325 | + raise Exception("%s is not a valid audit_type." % audit_type) |
| 326 | + |
| 327 | + self.session.commit() |
0 commit comments