1

We have a state in our defects called "Need More Information". I would like to create a graph over time of how many defects are in that state at any particular period of time.

I think I can get the info to do that with the Lookback API with the following query:

my $find = {
    State                   => 'Need More Information',
    '_PreviousValues.State' =>  {'$ne' => 'Need More Information'},
    _TypeHierarchy          => -51006, # defect

    _ValidFrom  => {
        '$gte'  => '2012-09-01TZ',
        '$lt'   => '2012-10-23TZ',
    }

I thought that would give me back a list of all defect snapshots where the defect was transitioning into "Need More Information" state, but it does not (seems to list everything that was ever in "Need More Information" state.

Technically what I need is a query that lists snapshots of any defects transitioning either TO OR FROM the "Need More Information" state, but since this simpler one did not seem to work as I expected, I thought I would ask first why the query above did not work the way I expected.

The "Generated Query" in the header that comes back is:

    'fields' => 1,
    'skip' => 0,
    'limit' => 100,
    'find' => {
        '_TypeHierarchy' => -51006,
        '_ValidFrom' => {
            '$gte' => '2012-09-01T00:00:00.000Z',
            '$lt' => '2012-10-23T00:00:00.000Z'
        },
        '_PreviousValues.State' => {
            '$in' => [
                undef,
                5792599066,
                5792599067,
                5792599065,
                5792599070,
                5792599071,
                5792599068,
                5792599073,
                5792599072,
                5792599075,
                5792599077,
                5792599076,
                5792599078,
                3631859989,
                3631859988,
                3631859987,
                3631859986
            ]
        },
        'State' => {
            '$in' => [
                4384150044
            ]
        }
    }
};
johnr
  • 98
  • 6
kimon
  • 2,481
  • 2
  • 23
  • 33
  • When I look at it, I don't see anything obviously wrong. I'm not familiar with the syntax you are using, but I too think it should return snapshots which transitioned into "Need More Information". Can you post the generated query that comes back in the header of the response to help us run this down? – Larry Maccherone Oct 26 '12 at 17:40
  • I should have said, I'm not familiar with the language you are using. I tend to write in CoffeeScript or JavaScript. However, I'm very familiar with the LBAPI. – Larry Maccherone Oct 26 '12 at 17:51
  • Thanks Larry, I added the Generated Query. The language is Perl, but the output should be substantially similar to JSON that you are familiar with. – kimon Oct 26 '12 at 22:56
  • BTW, the reason I don't think its working correctly is because when I look at the "_PreviousValues" entry, most of the time I don't see the "State" field there. I would expect every snapshot to show "State" transitioning to "Need More Information" with this query. Is that assumption correct? – kimon Oct 26 '12 at 23:06
  • I think the problem is in that undefined. That will match anything even missing values. Try the approach using $nin that Curt suggests below. BTW, it's only supposed to show the _PreviousValues for the fields that change with that particular snapshot. This is useful when looking for specific transitions like you would when doing a throughput or velocity calculation. It's not ideal if you need to know the values at a particular moment in time. – Larry Maccherone Oct 27 '12 at 23:46
  • Unfortunately $nin returned the same results (and the same Generated Query). Is it perhaps a bug that undef is added to $in? State is a required field, and none of the valid entries is undef. – kimon Oct 29 '12 at 03:37

1 Answers1

3

I tried leveraging the $nin clause and had success with it. You might try adjusting your query to resemble something like this:

find: {
        _Type: 'Defect',
        State: 'Need More Information',
        '_PreviousValues.State': {
            $in: [
                'Submitted', 'Open', 'Fixed', 'Closed'
            ]
        },
    etc...
    }
kimon
  • 2,481
  • 2
  • 23
  • 33
Curt Tudor
  • 46
  • 1
  • Unfortunately adding $nin returns the exact same number of snapshots as $ne, including those that do not include phase transition for PreviousValues – kimon Oct 29 '12 at 03:35
  • I opened a defect last Friday concerning how 'null' is added to the list of $nin values by the LBAPI even when asked to exclude it, and that might be why you got unexpected results. We'll get that fixed soon. Meanwhile, perhaps you can try changing the $nin to $in, and then list all states other than 'Need More Information'. – Curt Tudor Oct 29 '12 at 14:29
  • Ok, $in with the inverse list works. Is it possible in one query to list all defects that transition to or from a particular state in a time period? (Specifically any defect that is either set to Needs More Information, or changed from Needs more information? – kimon Oct 30 '12 at 16:28