3
$\begingroup$

I usually process data such as follows:

Module[
 {vars},
 ...
 Map[
  Composition[
   h,
   g,
   f]
  ]@lst
 ...
]

For some lists which can take quite a long time to process I want to show a progress indicator.

Dynamic[ProgressIndicator[$progress/$total]]

where

$progress = listitem currently being processed;
$total = length of list

both

$progress, $total 

are global variables.

The issue is about how to implement progress indicators with as minimal change to the current programs as possible.

I was thinking of implementing the following 'standard'function for progress update:

p[]:=$progress++

this function can then be composed as last function of the current function compositions.

In each module initialize

$progress = 1
$total = Length[lst]

Finally, add p[] to the composition.

Rapping up:

Dynamic[ProgressIndicator[$progress/$total]]
Module[
 {$progress=1,$total=Length[lst]},
 ...
 Map[
  Composition[
   p,
   h,
   g,
   f]
  ]@lst
 ...
]

This method works but is not ideal. I haven't succeeded in getting this to work in a Manipulate Panel. I usually select lists and other parameters in a Manipulate program and start a processing module with an action Button, ideally I would like to see the progress in the Manipulate panel.

Questions: how can I implement a progress indicator construct which would work on a Manipulate panel?

Note that both the module and the Manipulate functions are members of a package, i.e.:

processRows[]

shows a Manipulate in the Notebook of the package user with several controls to select data and buttons to start the processing. I don't want to change this. The only additional requirement is the additional display of a progress indicator of some kind.

$\endgroup$
  • $\begingroup$ Like that or more specific? 78014 $\endgroup$ – Kuba Mar 6 '17 at 18:06
  • $\begingroup$ Nice Q&A!! Thanks. Ideally I would like to show the number of items processed and info from the item being processed. - I'll go in detail through that page and I am sure it will give me new ideas. $\endgroup$ – nilo de roock Mar 6 '17 at 18:16
  • $\begingroup$ For your composition to work should not p be defined p[x_] := ($progress++; x) instead? $\endgroup$ – Mr.Wizard Mar 7 '17 at 8:59
  • $\begingroup$ Correct! This did not work, I solved it in a different, less elegant, manner ( I'll update, self-answer later ). I'll try your suggestion, thank you. $\endgroup$ – nilo de roock Mar 7 '17 at 9:26
0
$\begingroup$

Although the Manipulate program is still in development, it does contain a working progress indicator. This is the code ( as is, per now ):

guidsBkmkCompEvents[] := Manipulate[
  a = (Select[
       MemberQ[bkmk, #bookmaker] && MemberQ[comp, #compName] &]@
      dsBkmkComp) // no;
  If[Length[a] > 0, $total = Length[a]];

  Column[{
    If[Length[a] > 
      0, (Select[
         MemberQ[bkmk, #bookmaker] && MemberQ[comp, #compName] &]@
        dsBkmkComp)[All, {"url"}]],
    If[Length[a] > 0, a],
    If[Length[a] > 0, Dynamic[ProgressIndicator[$progress/$total]]],
    If[bShow,
     While[$progress < $total, 
      res = dsBCE[a][All, {"id", "bookmaker", "compName", "url"}]]
     ],
    If[bShow, res]
    }],

  {bkmk, ListPicker[#1, 
     DeleteDuplicates[dsBkmkComp[All, "bookmaker"] // no]] &},
  {comp, ListPicker[#1, 
     DeleteDuplicates[dsBkmkComp[All, "compName"] // no]] &},

  Button["Release swarm",
   $progress = 0;
   bShow = True],

  Button["Clear",
   $progress = 0;
   $total = 1;
   bkmk = {};
   comp = {};
   bShow = False],

  Initialization :> {
    bShow = False,
    $progress = 0,
    $total = 1,
    res = {<||> // ta} // ds
    }
  ]

Contrary to what I thought earlier,

Dynamic[ProgressIndicator[$progress/$total]]

does work on a Manipulate panel. Key to getting it grow to 100%, while the program dsBCE is working, is to enclose it in Dynamic and maintaining the

$progress, $total 

variables in the program dsBCE.

$\endgroup$
  • $\begingroup$ This does not appear to be a self-contained example. Before I can vote for this I would like to see it work, and I shouldn't have to go to extra effort to construct an example before I can do that. $\endgroup$ – Mr.Wizard Mar 12 '17 at 6:39
  • $\begingroup$ I have abandoned that code. Hurts my eyes, after only 2.5 years. :-( $\endgroup$ – nilo de roock Nov 19 at 8:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.