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

Run optimize #275

Merged
merged 14 commits into from
Jun 8, 2018
Merged

Run optimize #275

merged 14 commits into from
Jun 8, 2018

Conversation

tech4GT
Copy link
Member

@tech4GT tech4GT commented Jun 1, 2018

fixes #269 @jywarren
I have leveraged the progressObj, since inside of node we only call the sequencer run once and we need the progress bar also
but in demo we don't need progressBar and we need run(index) so here index is passed in place of progressObj(We can rename this parameter to suit this new functionality)
Now this is perfectly optimized and only the current step is run, not the whole sequence

PS I Know this is based on an old fork, I'll rebase once you approve of this

tech4GT added 2 commits June 1, 2018 22:25
Signed-off-by: tech4GT <[email protected]>
Signed-off-by: tech4GT <[email protected]>
@ghost ghost assigned tech4GT Jun 1, 2018
@ghost ghost added the in-progress label Jun 1, 2018
Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start! I want to ensure this code is really readable and I'm also not sure about overloading the function unless we have very good documentation -- because the variable names in the function can be a little confusing then. Can you explain the different parameters that are now possible? Thanks!!

}

console.log(index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to remove this

if(arguments[0] != 'test'){
progressObj = spinnerObj
delete arguments['0']
delete arguments['0']
if(typeof progressObj == 'number') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is a bit hard to read - are you detecting if it's an index integer? If so can you explain a bit more in comments so it's more readable? Thanks!

@@ -47,7 +47,7 @@ function DefaultHtmlSequencerUi(_sequencer, options) {
var newStepName = $(addStepSel + " select").val();
_sequencer
.addSteps(newStepName, options)
.run(null);
.run(_sequencer.images.image1.steps.length - 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, how does this work? Can you leave a comment explaining?

Signed-off-by: tech4GT <[email protected]>
@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren I have added explanatory comments everywhere and changed the parameter name!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren It's not at all complicated, for a module writer nothing changes!! For us though, in Node.js first argument is the progressObject and in demo the first argument is the index from which we wish to run the sequencer!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

this first argument was being ignored in demo until now since we don't need the cli progress object in demo, so we are just using a part of the api that already existed but was not being used!!

@jywarren
Copy link
Member

jywarren commented Jun 2, 2018 via email

@jywarren
Copy link
Member

jywarren commented Jun 2, 2018

Think about this in terms of how you'd explain it to a newcomer looking to use this library. Would you say:

sequencer.run() -- this method accepts an optional parameter run(index) in the browser, but a different run(progressObject) parameter in Node.js

This is a little weird if we are telling people that the library works the same in different environments. What are our options?

  1. maybe use an options hash, so we'd submit .run({index: 1}) or .run({progressObject: ____}) so you never get mixed up?
  2. could we build in this functionality to the addStep/insertStep functions so it runs identically in both node and browser?

I think run() is a bit confusingly documented in general. I think we should think about how to really clearly present how it's supposed to be used between:

https://github.com/publiclab/image-sequencer#running-the-sequencer

and

https://github.com/publiclab/image-sequencer#running-a-sequencer-with-multiple-images

What do you think about all this? Do you have some ideas for how the run() function can be more clearly and completely explained?

Thanks Varun! This is great.

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren Actually sequencer already does not rerun in node since sequence is predefined

@jywarren
Copy link
Member

jywarren commented Jun 2, 2018

Maybe we start by listing out the different variants of run() usage. What are the current vs. new variants?

  • run(callback)

  • run(image, index, callback)

  • run(json) with { img_1: index, img_2: index }

  • we also had (though not documented): - run(spinnerObj, t_image, t_from) -- isn't that right?

New:

  • run(spinnerObj, t_image, t_from) ...

What else?

@@ -29,7 +29,7 @@ function DefaultHtmlSequencerUi(_sequencer, options) {

function removeStepUi() {
var index = $(removeStepSel).index(this) + 1;
sequencer.removeSteps(index).run();
sequencer.removeSteps(index).run(sequencer.images.image1.steps.length-1);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's where maybe we should think about whether run should auto-detect that nothing has changed in certain steps? Or do you think it makes sense to do this in the UI only?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren I think this only makes sense in the UI !!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that because when we are in Node, we aren't immediately running run() when we add steps? I almost think that would be a scenario where we'd want the sequencer to know that nothing has changed on prior steps, automatically, and not have to re-run the math for prior steps.

Like each step would potentially have a .changed property, and doing .insertStep() would switch that to true for any subsequent step. What do you think of this "switch-based" idea?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren I don't fully understand sorry, in node we run one predefined sequence right? So how would we be able to call insertStep in node?? I mean we can't modify the sequence during execution in node right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, i think we can set this aside for now based on my other comments. But just imagine --

var sequencer = require("../image-sequencer")();
...
sequencer.run();
sequencer.insertSteps('blur', 2);
sequencer.run(); // here, we wouldn't have to re-run steps 1 or 2, right?

Copy link
Member Author

@tech4GT tech4GT Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren Oh I got it!!! I was confusing node.js as CLI!! Obviously we need this functionality in node yeah!! let's do the thing where we pass in the values as keys in an object like {index: ,progressObj: }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK -- that sounds good. We can still do nice thorough docs as mentioned earlier, but just focusing on the different parameters rather than different types. 👍

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren Here is my view of run function:
sequencer.run(optionalParam) where optionalParam car represent an offset if it is a number or the progressObject if it is an object. We can do option 1 i guess but I think this is not that complicated
Simply sequencer.run() can be called in 2 ways sequencer.run(index) or sequencer.run(progressObj) everywhere, it's just that we won't be needing one of these in one of the environments

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren all this just adds 2 more usages to the existing list we already have documented, gives us the ability to pass either an index or a progressObject as the first argument

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

or maybe we can have these as keys inside an object as you suggested earlier in option 1, what do you suggest??

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren According to me we can handle the current api with comments and documentation

@jywarren
Copy link
Member

jywarren commented Jun 2, 2018 via email

@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren I'll write some now!!

@jywarren
Copy link
Member

jywarren commented Jun 2, 2018 via email

Signed-off-by: tech4GT <[email protected]>
@tech4GT
Copy link
Member Author

tech4GT commented Jun 2, 2018

@jywarren Have a look please!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 3, 2018

So lets merge the other pr and rebase and then I’ll do this to avoid merge conflicts

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I've been thinking about this. I agree with what you're saying that we can handle the current api with comments and documentation. I just needed to think through it a bit!

So, I really like your new documentation -- just a few comments/suggestions on it; take a look!

Thanks for thinking through this carefully with me! .run() is a central function to the library and it's super important that it be well thought through and stable.

README.md Outdated
@@ -204,13 +204,32 @@ modules.
sequencer.run();
```

Sequencer can be run with a custom progress object
Copy link
Member

@jywarren jywarren Jun 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just above here, where we introduce .run(), let's say:

## sequencer.run()

The `.run()` method starts the sequencer, running through each step to process the input image into a final output image. 

There are several different ways to use the `run()` function. You can pass in:

* `index` -- an `integer` - 
* `progressObj` -- an `object` used for a progress-tracking object that will be passed along the sequence (see Progress Tracking, below)
* `callback` -- a `function` to be run upon completion of the sequence

They can be used in different combinations:

`sequencer.run(index)` - run the sequencer from the given `index` starting step position

`sequencer.run(progressObj)` - 

...and so on, showing each usage separately (so not mixing `index/progressObj` in one example)

For examples of how `.run()` can be used, see [this test file demonstrating each use](...).

What do you think of this? Just really thorough, lots of examples, and link to the tests where we demonstrate it all working? The tests could be moved into a run.js test file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jywarren this is awesome, I can do this, this is really explanatory!! Let's first complete the urlSteps PR then rebase to avoid merge conflicts later since this is on an old fork!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 3, 2018

@jywarren So what I am doing on this now is refactoring run to accept the first parameter as an object which contains both index and progressObj, let's call it config and these are both optional and sequencer can be called without the config as well!!

@jywarren jywarren mentioned this pull request Jun 6, 2018
tech4GT added 3 commits June 7, 2018 19:17
Signed-off-by: tech4GT <[email protected]>
Signed-off-by: tech4GT <[email protected]>
Signed-off-by: tech4GT <[email protected]>
@tech4GT
Copy link
Member Author

tech4GT commented Jun 7, 2018

@jywarren I think we are done with this one!! Great!! Now should we complete our step api issue first or move to meta modules??

test('run() works with all possible argument combinations',function(t){
sequencer.run();
sequencer.run({index: 0});
sequencer.run({mode:test},function callback(out){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like test should be in quotes? Or do you pass in the test object?

Also, do you want to somehow try to confirm which steps are actually run? Maybe you could start by running only the last one, and assert that the earlier steps have no output. Then run() and see that all have outputs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, yeah I'll do that!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 7, 2018

@jywarren I am facing trouble finding which steps were run since that data is not available outside of run!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 7, 2018

I tried some techniques but it doesn't seem to work!!, should I try to output this as well that which steps have been run? That might need quite some change, should we open a separate issue for that?

Signed-off-by: tech4GT <[email protected]>
@jywarren
Copy link
Member

jywarren commented Jun 7, 2018

Hmm, what if you used invert twice, and then used a very small data-url image (as we've used in other tests) and compare it to see if it's the inverted version or not? You could visually compare the first time, then you'd be able to see if the inverted version matches. So you'd only be looking at whether invert ran once or twice, with .run(1) vs. just .run() -- you know?

@tech4GT
Copy link
Member Author

tech4GT commented Jun 7, 2018

@jywarren I didn't quite get this... are you suggesting comparing the image data to find whether the image was inverted, like parsing the data and checking?

@jywarren
Copy link
Member

jywarren commented Jun 7, 2018

Yes - check out this example!

test("Twice inverted image is identical to original image", function (t) {
var step1 = sequencer.images.image1.steps[0].output.src;
var step3 = sequencer.images.image1.steps[2].output.src;
step1 = DataURItoBuffer(step1);
step3 = DataURItoBuffer(step3);
looksSame(step1,step3,function(err,res){
if(err) console.log(err);
t.equal(res,true);
t.end();
});
});

@tech4GT
Copy link
Member Author

tech4GT commented Jun 7, 2018

@jywarren then I'll figure this out tomorrow maybe, it's pretty late, will that be ok?

@jywarren
Copy link
Member

jywarren commented Jun 7, 2018 via email

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

@jywarren Now working on this!!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

@jywarren even if we do it this way how can we still compare? I mean sequencer.run() will run both of the steps and sequencer.run(1) will just not run the previous invert but still it will give the same output. My point being how can we distinguish between the 2 by a test if the output is same on both. We can include a runcount passed to run's callback, what say?

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

@jywarren I have something in mind for this but I am at airport so I'll try to submit the pr as soon as possible, basically I am thinking of removing one invert step from the sequence and then running the sequencer from after that removed step to shoe that the output does not get affected, how does that sound??

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

@jywarren I have something in mind for this but I am at airport so I'll try to submit the pr as soon as possible, basically I am thinking of removing one invert step from the sequence and then running the sequencer from after that removed step to show that the output does not get affected, how does that sound??

@jywarren
Copy link
Member

jywarren commented Jun 8, 2018 via email

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

@jywarren i am fine with either way, it should not take much time anyway🙂

@jywarren
Copy link
Member

jywarren commented Jun 8, 2018 via email

Signed-off-by: tech4GT <[email protected]>
@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

@jywarren Done!! This is working nicely!!

@jywarren jywarren merged commit 10c6ad5 into publiclab:master Jun 8, 2018
@ghost ghost removed the in-progress label Jun 8, 2018
@jywarren
Copy link
Member

jywarren commented Jun 8, 2018

Fantastic work, Varun. This is a very readable, well tested self contained and very significant improvement!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

Thanks a lot @jywarren This has been so exciting!!! let's complete the stepAPI next and close that issue and then move to meta modules??

@jywarren
Copy link
Member

jywarren commented Jun 8, 2018

https://github.com/publiclab/image-sequencer/releases/tag/v2.0.0 :-) yes, that sounds good. Hopefully we don't have to break the API again on stepAPI so we won't need to so quickly bump another major version. But either way it'll be great!

@tech4GT
Copy link
Member Author

tech4GT commented Jun 8, 2018

haha, right!! I'll be more mindful about refactoring from now on!! Great!!😄

@jywarren
Copy link
Member

jywarren commented Jun 8, 2018

Hmm, i'm seeing some oddities in the demo now that I've merged v2 - can you try it out? Just adding and deleting steps. Are we using the new run indices?

@jywarren
Copy link
Member

jywarren commented Jun 8, 2018

oh no, it's not a problem to bump a major version number early in development. But as people begin to use our code, we'll want to aim for stability.

If there are some demo run/index changes we need to implement, maybe we can make them all consistent in #286 -- running addStep, deleteStep, and any settings update should update only the current step and ahead.

@jywarren
Copy link
Member

jywarren commented Jun 8, 2018

I can wait to publish to NPM until we get that all ironed out!

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

Successfully merging this pull request may close these issues.

2 participants