Skip to content
Snippets Groups Projects

Make loadData uses factory pattern instead of instantiating data object directly

Merged Kien Le requested to merge refactor-load_data_use_factory_method into master
2 unresolved threads

Implement the factory pattern for data loading.

Currently, loadData instantiates either RT130 or MSeed to create the object that stores loaded data. Because the constructor for these two classes takes only *args and **kwargs as arguments, there is no way to use static analysis on them. As a workaround, we create a factory method that takes explicit arguments to handle the creation of the data object. Seeing as this method has named arguments, we can use type hints to do static analysis on it.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
34 34 dataObject = None
35 35 for d in listOfDir:
36 36 if dataObject is None:
37 if dataType == 'RT130':
38 dataObject = RT130(
39 tracking_box, d,
37 try:
38 dataObject = DataTypeModel.create_data_object(
39 dataType, tracking_box, d,
40 40 reqWFChans=reqWFChans, reqSOHChans=reqSOHChans,
  • 39 dataType, tracking_box, d,
    40 40 reqWFChans=reqWFChans, reqSOHChans=reqSOHChans,
    41 41 readStart=readStart, readEnd=readEnd)
    42 else:
    43 try:
    44 dataObject = MSeed(
    45 tracking_box, d, reqWFChans=reqWFChans,
    46 reqSOHChans=reqSOHChans,
    47 readStart=readStart, readEnd=readEnd)
    48 except Exception as e:
    49 msg = f"Dir {d} can't be read due to error: {str(e)}"
    50 displayTrackingInfo(tracking_box, msg, "Warning")
    51 pass
    42 except Exception as e:
    43 msg = f"Dir {d} can't be read due to error: {str(e)}"
    44 displayTrackingInfo(tracking_box, msg, "Warning")
  • Software Administrator approved this merge request

    approved this merge request

  • Kien Le added 14 commits

    added 14 commits

    Compare with previous version

  • Kien Le mentioned in commit 2c148722

    mentioned in commit 2c148722

  • merged

  • Please register or sign in to reply
    Loading