Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to connect a progress bar to migration #136

Open
leendertvanwolfswinkel opened this issue Nov 13, 2024 · 3 comments
Open

Add option to connect a progress bar to migration #136

leendertvanwolfswinkel opened this issue Nov 13, 2024 · 3 comments
Assignees

Comments

@leendertvanwolfswinkel
Copy link

Now that the number of migrations is growing, it sometimes takes quite some time to migrate spatialites, esp. if they are really old. It would be great to show users the progress. I think the easiest implementation is to express the progress as number of migrations completed as percentage of the total number of migrations that needs to be done.

@margrietpalm
Copy link
Contributor

Progress (bar) display should be handled by FE or modeller interface; sepcific interfacing is needed.

Suggestion: add optional logging (can/should be made better to interface without direct printing)

def upgrade(
    config: Config,
    revision: str,
    sql: bool = False,
    tag: Optional[str] = None,
    output: Optional[TextIO] = sys.stderr  # Default to stderr if no output is provided
) -> None:

    # Function to be executed during migration
    def upgrade_with_progress(rev, context):
        progress = (current_step / n_steps) * 100
        output.write(f"Upgrade to revision {rev}")
        output.flush()  # Ensure the output is printed immediately        
        script._upgrade_revs(revision, rev)  # Perform the actual migration step

    with EnvironmentContext(
        config,
        script,
        fn=upgrade_with_progress,
        as_sql=sql,
        starting_rev=starting_rev,
        destination_rev=revision,
        tag=tag,
    ):
        script.run_env()

@leendertvanwolfswinkel
Copy link
Author

leendertvanwolfswinkel commented Nov 18, 2024

An example of how this has been implemented before is available in threedidepth. The function calculate_waterdepth() has an argument progress_func (see https://github.com/nens/threedidepth/blob/41c5b7366388f67bf7af23b3ceacb8821391b409/src/threedidepth/calculate.py#L685). It is called like this:

calculate_waterdepth(
      gridadmin_path=gridadmin_path,
      results_3di_path=results_3di_path,
      dem_path=dem_filename,
      waterdepth_path=waterdepth_output_file,
      calculation_steps=timesteps,
      mode=self.MODES[mode_index].name,
      progress_func=Progress(feedback),
      netcdf=as_netcdf,
)

In which feedback is a https://qgis.org/pyqgis/master/core/QgsProcessingFeedback.html object

@margrietpalm
Copy link
Contributor

Looks like progress function excepts a percentage (https://github.com/nens/threedidepth/blob/41c5b7366388f67bf7af23b3ceacb8821391b409/src/threedidepth/calculate.py#L624), se the example above could be easily adapted for this.

@margrietpalm margrietpalm self-assigned this Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants