Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C# job progress calculation (progress bar)

This is more of a math question but also a design question. At the risk of sounding like an idiot, I figured I would post this questions here.

I have a long running process. Inside this process, there are stages. The amount of stages are dynamic (sometimes it maybe 4 stages, other times it might be 7 total stages). I am able to get a % complete from each stage.

My question is, how do I go about calculating the overall progress? This is going to drive a simple progress indicator on an application.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The process is an external service that posts this progress out to an .net API endpoint.

Each example below is a payload I receive during the execution phase.

In C# what would the function/math look like to report the accurate progress? Seems like it should be simple and it probably is…I am just stuck.

Thank you!


{
  "Message": "Running simulation for insulation type: DRY, departure time (UTC): 5/11/2023 2:32:08 AM",
  "Percentage": 0.741,
  "CurrentStage": 3,
  "NumStages": 4,
  "RequestId": "7520a59b-7dc4-4878-9e3e-104ce7da451b",
  "RunFailed": false,
  "Results": null
}
{
  "Message": "Running simulation for insulation type: DRY, departure time (UTC): 5/11/2023 2:47:08 AM",
  "Percentage": 0.852,
  "CurrentStage": 3,
  "NumStages": 4,
  "RequestId": "7520a59b-7dc4-4878-9e3e-104ce7da451b",
  "RunFailed": false,
  "Results": null
}
{
  "Message": "Running simulation for insulation type: DRY, departure time (UTC): 5/11/2023 3:02:08 AM",
  "Percentage": 0.963,
  "CurrentStage": 3,
  "NumStages": 4,
  "RequestId": "7520a59b-7dc4-4878-9e3e-104ce7da451b",
  "RunFailed": false,
  "Results": null
}

{
  "Message": "Running simulation for insulation type: DRY, departure time (UTC): 5/11/2023 2:32:08 AM",
  "Percentage": 0.741,
  "CurrentStage": 4,
  "NumStages": 4,
  "RequestId": "7520a59b-7dc4-4878-9e3e-104ce7da451b",
  "RunFailed": false,
  "Results": null
}
{
  "Message": "Running simulation for insulation type: DRY, departure time (UTC): 5/11/2023 2:47:08 AM",
  "Percentage": 0.852,
  "CurrentStage": 4,
  "NumStages": 4,
  "RequestId": "7520a59b-7dc4-4878-9e3e-104ce7da451b",
  "RunFailed": false,
  "Results": null
}
{
  "Message": "Running simulation for insulation type: DRY, departure time (UTC): 5/11/2023 3:02:08 AM",
  "Percentage": 0.963,
  "CurrentStage": 4,
  "NumStages": 4,
  "RequestId": "7520a59b-7dc4-4878-9e3e-104ce7da451b",
  "RunFailed": false,
  "Results": null
}

>Solution :

A simple solution would be to average to total progress. Since they seem to run sequentially and you have information about the stages it could look like:

( stages_complete + current_progress ) / total_stages

when stages_complete == total_stages, if current_progress is not 0 this equation will give a result above 1.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading