通过Lookback API自定义周期/提前期数据

时间:2013-09-25 21:04:23

标签: rally appsdk2 lookbackapi

我正在尝试使用JavaScript中的REST API为表格和图表视图生成自定义(和高度精细)周期/提前期数据。

我的故事中有一个自定义(非必需)字段&缺陷,c_KanbanStatus具有以下可能值[null,“Kickoff”,“PO”,“Creative”,“Team Backlog”,“Coding”,“Acceptance Testing”,“Accepted”]。

我最近才添加了这个自定义字段,所以我的很多故事都没有那个字段(或者没有“天生”)。

我的想法如下:

  • 为每个看板状态转换执行回顾查询
  • 按ObjectID汇总
  • 对于每个ObjectID,对于每个状态,计算对象进入该状态与对象进入后续状态之间的时间差。

这是我的代码的摘录:

    var kanbanStates =
    [
        "Kickoff",
        "PO",
        "Creative",
        "Team Backlog",
        "Coding",
        "Acceptance Testing"
    ];

    var username = "**************";
    var password = "**************";

    var deferreds = [];
    for(var i = 0; i < kanbanStates.length; i++)
    {
        var find =
        {
            _ProjectHierarchy: ***************,
            "_PreviousValues.c_KanbanStatus": { $lt: kanbanStates[i] },
            c_KanbanStatus: kanbanStates[i]
        };

        var config =
        {
            url:"https://rally1.rallydev.com/analytics/v2.0/service/rally/workspace/********/artifact/snapshot/query.js?find=" + JSON.stringify(find) + "&fields=true&pagesize=999999",
            dataType: "jsonp",
            jsonp: "jsonp",
            contentType: "application/json",
            beforeSend: function(xhr)
            {
                xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
            }
        };

        deferreds.push($.ajax(config));
    }

    var aggregateResultsByObjectID = function(results)
    {
        var resultsByItemID = {};
        for(var i = 0; i < results.length; i++)
        {
            if(!results[i][0].Results.c_KanbanStatus === kanbanStates[i])
                throw "States don't match!";

            for(var j = 0; j < results[i][0].Results.length; j++)
            {
                var itemID = results[i][0].Results[j].ObjectID;

                if(!resultsByItemID.hasOwnProperty(itemID))
                {
                    resultsByItemID[itemID] =
                    {
                        creationDate: results[i][0].Results[j].CreationDate,
                        name: results[i][0].Results[j].Name,
                        states: [],
                        results: []
                    };
                } 

                resultsByItemID[itemID].results.push(results[i][0].Results[j]);
                resultsByItemID[itemID].states.push(results[i][0].Results[j].c_KanbanStatus);
            }
        }
        return resultsByItemID;
    };

    $.when.apply($, deferreds).done(function()
    {
        var resultsByItemID = aggregateResultsByObjectID(arguments);
        console.log(resultsByItemID);
    });

此查询的问题在于,我为每个状态的每个ObjectID返回多个结果,即使我指定我只希望那些具有不同c_KanbanStatus字段的快照。当我检查结果时,对于相同的ObjectID和相同的组合,如果c_KanbanStatus和_PreviousValues.c_KanbanStatus,我会收到很多快照,每个快照都有一些其他的字段编辑。

例如,对于相同的ObjectID,我得到以下两个结果:

_PreviousValues:
{
    _User: 10301773174
    c_KanbanStatus: null
},
c_KanbanStatus: "Coding"

_PreviousValues:
{
    ScheduleState: 10148772688
    _User: 10148977759
},
c_KanbanStatus: "Coding"

我期待第一个结果(从没有设置c_KanbanStatus字段到“编码”时的快照)。第二个结果似乎暗示它从没有c_KanbanStatus字段到“编码”,但为什么呢?

我有一种感觉,我在Lookback API中缺少一些东西。请帮我理解!

2 个答案:

答案 0 :(得分:1)

预计每个州都会获得多个结果。每次修改故事时都会创建快照。假设有四个c_Kanban州:backlogin-progressdonereleased。继续这个例子,我将一个故事移动到正在进行的列并设置故事的PlanEstimate,然后阻止该故事下的任务,解锁任务,将任务的状态设置为已完成,最后将故事移动到看板上的完成列板。所有这些更改都将在c_Kanban === 'in-progress'

时创建唯一的快照

我在这个github repo中有一个应用程序,用于构建一个网格,其中包含故事在每个c_Kanban状态下花费的时间。请注意一个快照中的Blocked: trueBlocked: false中的c_Kanban: "in-progress"中的{{1}}:

enter image description here

答案 1 :(得分:0)

我一直在搞乱我自己解决这个问题的方法,这就是我想出来的。它需要更多的调整来处理角落情况,但它接近我需要的。我将继续开发并为此创建一个GitHub仓库以防任何人使用它。

编辑:GitHub回购:https://github.com/bfanti/RallyCustomCycleTimeApp

<!DOCTYPE html>
<html>
<head>
    <title>My App</title>

    <!--App information-->
    <meta name="Name" content="App: Custom Cycle Time Table"/>
    <meta name="Version" content="1.0"/>
    <meta name="Vendor" content=""/>

    <!--Include SDK-->
    <script type="text/javascript" src="/apps/2.0rc1/sdk.js"></script>

    <!--App code-->
    <script type="text/javascript">
        var kanbanStatuses =
        [
            "New Feature",
            "Kickoff",
            "PO",
            "Creative",
            "Team Backlog",
            "Coding",
            "Acceptance Testing"
        ];

        var shirtSizeLUT =
        {
            3: "S",
            5: "M",
            8: "L"
        };

        Rally.onReady(function()
        {
            Ext.define("CustomApp",
            {
                extend: "Rally.app.App",
                componentCls: "app",

                launch: function()
                {
                    var self = this;

                    Ext.create("Rally.data.lookback.SnapshotStore",
                    {
                        fetch   : [ "_UnformattedID", "_TypeHierarchy", "Name", "PlanEstimate", "c_KanbanStatus", "ScheduleState" ],
                        hydrate : [ "c_KanbanStatus", "ScheduleState" ],
                        filters :
                        [
                            {
                                property : "_ProjectHierarchy",
                                value    : ***********
                            },
                            {
                                property: "_TypeHierarchy",
                                value: { $nin: [ -51009, -51012, -51031, -51078 ] }
                            },
                            {
                                property: "_ValidFrom",
                                value: { $gt: "2013-09-13" }
                            }
                        ],
                        sorters :
                        [
                            {
                                property  : "_ValidTo",
                                direction : "ASC"
                            }
                        ]
                    }).load(
                    {
                        params:
                        {
                            compress: false,
                            removeUnauthorizedSnapshots: true
                        },
                        callback : function(records, operation, success)
                        {
                            var aggregateCycleTimes = [];

                            var allObjectIDs = {};
                            Ext.Array.each(records, function(record) { allObjectIDs[record.get("ObjectID")] = record.get("ObjectID"); });

                            for(var storyIndex = 0; storyIndex < Object.keys(allObjectIDs).length; storyIndex++)
                            {
                                (function()
                                {
                                    var currentObjectID = parseInt(Object.keys(allObjectIDs)[storyIndex], 10);
                                    var recordsByStory = Ext.Array.filter(records, function(record) { return record.get("ObjectID") === currentObjectID; });

                                    var currentStateOfStory = "";
                                    var currentStateOfStorySnapshot = Ext.Array.filter(recordsByStory, function(record) { return record.get("_ValidTo").indexOf("9999") !== -1; })[0];
                                    if(currentStateOfStorySnapshot)
                                        currentStateOfStory = currentStateOfStorySnapshot.get("c_KanbanStatus");

                                    var formattedID = (Ext.Array.contains(recordsByStory[0].get("_TypeHierarchy"), -51006) ? "DE" : "US") + recordsByStory[0].get("_UnformattedID");
                                    var cycleTimes =
                                    {
                                        id: formattedID,
                                        name: recordsByStory[0].get("Name"),
                                        planEstimate: shirtSizeLUT[Rally.util.Array.last(recordsByStory).get("PlanEstimate")],
                                        currentStateOfStory: currentStateOfStory
                                    };

                                    var allStatusesAreNull = true;

                                    for(var i = 0; i < kanbanStatuses.length; i++)
                                    {
                                        var currentStatus = kanbanStatuses[i];

                                        var currentSnapshot = Ext.Array.filter(recordsByStory, function(record) { return record.get("c_KanbanStatus") === currentStatus; })[0];

                                        if(!currentSnapshot)
                                        {
                                            cycleTimes[currentStatus] = null;
                                            continue;
                                        }

                                        var firstDate = new Date(currentSnapshot.get("_ValidFrom"));

                                        var nextSnapshot = Rally.util.Array.last(Ext.Array.filter(recordsByStory, function(record) { return record.get("c_KanbanStatus") === currentStatus; }));
                                        var secondDate = new Date();

                                        if(nextSnapshot && (new Date(nextSnapshot.get("_ValidTo"))).getFullYear() !== 9998)
                                            secondDate = new Date(nextSnapshot.get("_ValidTo"));

                                        var cycleTime = Rally.util.DateTime.getDifference(secondDate, firstDate, "day");
                                        cycleTimes[currentStatus] = cycleTime;

                                        if(cycleTime !== null)
                                            allStatusesAreNull = false;
                                    }

                                    if(!allStatusesAreNull)
                                        aggregateCycleTimes.push(cycleTimes);
                                })();
                            }

                            var myStore = Ext.create("Rally.data.custom.Store",
                            {
                                data: aggregateCycleTimes,
                                pageSize: 100,
                            });

                            var columnConfig = 
                            [
                                {
                                    text: "ID",
                                    dataIndex: "id"
                                },
                                {
                                    text: "Name",
                                    dataIndex: "name",
                                    width: "280px"
                                },
                                {
                                    text: "Size",
                                    dataIndex: "planEstimate"
                                },
                                {
                                    text: "Current State",
                                    dataIndex: "currentStateOfStory"
                                }
                            ];

                            for (var i = 0; i < kanbanStatuses.length; i++)
                            {
                                var columnConfigElement = {}; 
                                columnConfigElement["text"] = kanbanStatuses[i];
                                columnConfigElement["dataIndex"] = kanbanStatuses[i];
                                columnConfig.push(columnConfigElement);
                            }

                            if (!self.grid)
                            {
                                self.grid = self.add(
                                {
                                    xtype: "rallygrid",
                                    itemId: "mygrid",
                                    store: myStore,
                                    columnCfgs: columnConfig
                                });
                            }
                        }
                    });
                }
            });

            Rally.launchApp("CustomApp", { name: "My Custom App" });
        });
    </script>
</head>
<body>
</body>
</html>