Rally: Date User Story is Defined - date

I am writing a program that needs to fetch user stories that are defined before day 3 of a release. Is there a way to find out what day a user story was set to the 'defined' state so that I could query that?
I looked through the Web Service API docs but I couldn't find anything that could help me, although I could have missed something.
This is the code I am using to get the 3rd day of a release:
var releaseStart = combobox.getRecord().get('ReleaseStartDate');
releaseStart.setDate(releaseStart.getDate()+3);
this._startDate = Rally.util.DateTime.toIsoString(releaseStart);
But I'm not sure how to relate this to the date a user story is defined.
If anyone could help it would be much appreciated!

You're right- this piece of data does not exist in the standard WSAPI. You can get it from LookbackAPI however. How about something like this to get started?
var releaseStart = combobox.getRecord().get('ReleaseStartDate');
var startDate = Rally.util.DateTime.add(releaseStart, 'day', 3);
var snapshotStore = Ext.create('Rally.data.lookback.SnapshotStore', {
context: {
workspace: this.getContext().getWorkspaceRef()
},
find: {
_ProjectHierarchy: this.getContext().getProject().ObjectID,
_TypeHierarchy: 'HierarchicalRequirement',
ScheduleState: {$gte: 'Defined'},
__At: startDate
},
sort: {
_UnformattedID: 1
},
fetch: ['FormattedID', 'Name', 'ScheduleState'],
limit: Infinity,
autoLoad: true,
listeners: {
load: function(store, records) {
//TODO: work with records here
}
}
});
More information on working with the Lookback API is here: https://help.rallydev.com/apps/2.1/doc/#!/guide/lookback_api

Related

Sails JS - Waterline ORM - Query Date only, not Time

Looking to query against the date only anyone encountered this?
Sample code:
////MODEL
module.exports = {
attributes: {
date: {
type: 'date',
required: true
}
}
};
////CONTROLLER
var today = moment().toISOString();
var queryObj = { date: today };
var newDay = { date: today };
Day.findOrCreate(queryObj, newDay).exec(function(err, day) {
console.log(day)
});
Obviously this creates a new record on each refresh, as the iso string will change with each passing second.
Thanks for the help!
Instead of querying for a single date, you can query for a date range that includes all of today. First, you'll need to actually create values for that range--I whipped this up using Moment, but there's probably a better way:
var begin = moment(moment().format("YYYY-MM-DD")).toISOString();
var end = moment(moment().format("YYYY-MM-DD")).add(1, 'days').toISOString();
Then you can use query operators to search the range:
var queryObj = {date: {'>=': begin, '<': end}};
Day.findOrCreate(queryObj, newDay).exec(function(err, day) {
console.log(day)
});
As always, be mindful of time zone issues!

Meteor template subscriptions and performance

I'm looking for advice on my approach here- I want to be sure I'm doing things in the "meteor way" and keeping the code fast.
Current situation:
We have a collection for Questions. Each question has a nested collection of Answers. Through a REST API, a device relays the answers that were selected by users.
Based on the answers that were selected, we show a chart for each question- simple number breakdowns and percentage bars. To improve performance, we've been tracking the number of responses each Answer has received on the Answer itself.
The publication looks (basically) like this:
Meteor.publish('questionsBySiteID', function(site_id){
return Questions.find({site_id: site_id});
});
And the route like this:
Router.route('/sites/:_id/questions', {
name: 'questionsList',
waitOn: function(){
return [
Meteor.subscribe('questionsBySiteID', this.params._id),
];
},
data: function(){
return {
publishedQuestions: Questions.find(
{ site_id : this.params._id, active: true, deleted: {$ne: true} },
{ sort : { order: 1} }
),
archivedQuestions : Questions.find(
{ site_id : this.params._id, active: false, deleted: {$ne: true} },
{ sort : { updated_at: -1 } }
),
deletedQuestions : Questions.find(
{ site_id : this.params._id, deleted: true },
{ sort : { updated_at: -1 } }
)
};
}
});
Change required:
Now we want responses to be date-filterable. This means the denormalized response counts we've tracked on Answers aren't very useful. We've been tracking another collection (Responses) with more a "raw" version of the data. A Response object tracks the module (questions in this case), question_id, answer_id, timestamp, id for the customer the question belongs to, etc.
Question:
Is this something that template subscriptions help with? Perhaps we need a publication that accepts a question_id and optional start/end dates for the filter. The stats template for each question would be subscribed to applicable Responses data in Template.question.create(). Based on the question_id, the publication would need to find Responses for related answers within the date filter. And maybe we use the publish-counts package to count the number of times each answer was selected and publish those counts.
The Responses collection will be quite large, so I'm trying to be careful about what I publish here. I don't want to waitOn all Responses to be published.

Rally Or Filter on Release Start Date sdk

I need help with the following code. The uncommented code works fine, but I need to get the commented code to work. See //value: releaseStartDateISO in my code below. Specifically, filter-2 doesn't work. I want to display defects that are active (ie, filter 1- not closed) or defects with a Closed Date greater than Release Start Date (filter 2). This will give me all active defects plus any that were closed during the current sprint. I tried converting Release Start Date to ISO, but this doesn't work. It seems like rally is not recognizing ReleaseStartDate and I don't know why. Note: This is the code from rally git. I added the "or filter" https://github.com/RallyApps/app-catalog/tree/master/src/apps/defectsummarymatrix
Thanks for your help!
_showComponentIfNeeded: function(component) {
if (component && component.isHidden()) {
component.show();
}
},
_initializeAllDefectStore: function(release) {
//var releaseStartDate = release.get('ReleaseStartDate');
//var releaseStartDateISO = Rally.util.DateTime.toIsoString(releaseStartDate,true);
var filter = Ext.create('Rally.data.QueryFilter', {
property: 'State',
operator: '!=',
value: 'Closed'
});
filter = filter.or({
property: 'ClosedDate',
operator: '>',
//value: releaseStartDateISO
value: '2014-09-10'
});
filter.toString();
if (this.releaseFilter && this.defectModel) {
this.allDefectStore = Ext.create('Rally.data.wsapi.Store', {
model: this.defectModel,
fetch: ['State','Priority'],
autoLoad: true,
limit: Infinity,
context: this.getContext().getDataContext(),
filters : [this.releaseFilter,filter],
listeners: {
load: this._onAllDefectStoreLoaded,
scope: this
}
});
}
},
_onAllDefectStoreLoaded: function(store, records, successful, eOpts) {
this._initializeMatrixTable();
this._populateMatrixTable(records);
this._createPriorityRecords(records);
this._updateMatrixGrid();
this.setLoading(false);
},
What is the value of release.get('ReleaseStartDate')? Is it possible the release record you have does not have that field populated?

Google Calendar API NodeJS - specify fields

Heyo, I'm using the google-api-nodejs-client package in my NodeJS project and I'm trying to build my query for calendar events. It's working, but I can't specify the "fields" field.
This returns five complete calendar events:
client.calendar.events.list({
calendarId: gcal_id,
maxResults: 5
})
.withAuthClient(authClient)
.execute(function(err, calendar) {
if (err)
console.log(err);
else
console.log(calendar);
});
But this returns nothing:
client.calendar.events.list({
calendarId: gcal_id,
maxResults: 5,
fields: {
items: ["end","start","status","summary"]
}
})
.withAuthClient(authClient)
.execute(function(err, calendar) {
if (err)
console.log(err);
else
console.log(calendar);
});
I've also tried:
fields: {
items: "end,start,status,summary"
}
Based on the Google Calendar V3 API, I should be able to make a query like this:
https://www.googleapis.com/calendar/v3/calendars/gcal_id.google.com/events?maxResults=5&fields=items(end%2Cstart%2Cstatus%2Csummary)&key={YOUR_API_KEY}
I'm not sure how to specify the "fields=items(end%2Cstart%2Cstatus%2Csummary)" portion of the URL, but I've tested it in Google's API Explorer and it works, so I know I'm doing something wrong in the JavaScript.
Any help would be much appreciated. For now I think I'll just clean up the response I get from the first code snippet.
Well, I figured it out. It should be one string.
fields: "items(end,start,status,summary)"

Auto increment in MongoDB to store sequence of Unique User ID

I am making a analytics system, the API call would provide a Unique User ID, but it's not in sequence and too sparse.
I need to give each Unique User ID an auto increment id to mark a analytics datapoint in a bitarray/bitset. So the first user encounters would corresponding to the first bit of the bitarray, second user would be the second bit in the bitarray, etc.
So is there a solid and fast way to generate incremental Unique User IDs in MongoDB?
As selected answer says you can use findAndModify to generate sequential IDs.
But I strongly disagree with opinion that you should not do that. It all depends on your business needs. Having 12-byte ID may be very resource consuming and cause significant scalability issues in future.
I have detailed answer here.
You can, but you should not
https://web.archive.org/web/20151009224806/http://docs.mongodb.org/manual/tutorial/create-an-auto-incrementing-field/
Each object in mongo already has an id, and they are sortable in insertion order. What is wrong with getting collection of user objects, iterating over it and use this as incremented ID? Er go for kind of map-reduce job entirely
I know this is an old question, but I shall post my answer for posterity...
It depends on the system that you are building and the particular business rules in place.
I am building a moderate to large scale CRM in MongoDb, C# (Backend API), and Angular (Frontend web app) and found ObjectId utterly terrible for use in Angular Routing for selecting particular entities. Same with API Controller routing.
The suggestion above worked perfectly for my project.
db.contacts.insert({
"id":db.contacts.find().Count()+1,
"name":"John Doe",
"emails":[
"john#doe.com",
"john.doe#business.com"
],
"phone":"555111322",
"status":"Active"
});
The reason it is perfect for my case, but not all cases is that as the above comment states, if you delete 3 records from the collection, you will get collisions.
My business rules state that due to our in house SLA's, we are not allowed to delete correspondence data or clients records for longer than the potential lifespan of the application I'm writing, and therefor, I simply mark records with an enum "Status" which is either "Active" or "Deleted". You can delete something from the UI, and it will say "Contact has been deleted" but all the application has done is change the status of the contact to "Deleted" and when the app calls the respository for a list of contacts, I filter out deleted records before pushing the data to the client app.
Therefore, db.collection.find().count() + 1 is a perfect solution for me...
It won't work for everyone, but if you will not be deleting data, it works fine.
Edit
latest versions of pymongo:
db.contacts.count() + 1
First Record should be add
"_id" = 1 in your db
$database = "demo";
$collections ="democollaction";
echo getnextid($database,$collections);
function getnextid($database,$collections){
$m = new MongoClient();
$db = $m->selectDB($database);
$cursor = $collection->find()->sort(array("_id" => -1))->limit(1);
$array = iterator_to_array($cursor);
foreach($array as $value){
return $value["_id"] + 1;
}
}
I had a similar issue, namely I was interested in generating unique numbers, which can be used as identifiers, but doesn't have to. I came up with the following solution. First to initialize the collection:
fun create(mongo: MongoTemplate) {
mongo.db.getCollection("sequence")
.insertOne(Document(mapOf("_id" to "globalCounter", "sequenceValue" to 0L)))
}
An then a service that return unique (and ascending) numbers:
#Service
class IdCounter(val mongoTemplate: MongoTemplate) {
companion object {
const val collection = "sequence"
}
private val idField = "_id"
private val idValue = "globalCounter"
private val sequence = "sequenceValue"
fun nextValue(): Long {
val filter = Document(mapOf(idField to idValue))
val update = Document("\$inc", Document(mapOf(sequence to 1)))
val updated: Document = mongoTemplate.db.getCollection(collection).findOneAndUpdate(filter, update)!!
return updated[sequence] as Long
}
}
I believe that id doesn't have the weaknesses related to concurrent environment that some of the other solutions may suffer from.
// await collection.insertOne({ autoIncrementId: 1 });
const { value: { autoIncrementId } } = await collection.findOneAndUpdate(
{ autoIncrementId: { $exists: true } },
{
$inc: { autoIncrementId: 1 },
},
);
return collection.insertOne({ id: autoIncrementId, ...data });
I used something like nested queries in MySQL to simulate auto increment, which worked for me. To get the latest id and increment one to it you can use:
lastContact = db.contacts.find().sort({$natural:-1}).limit(1)[0];
db.contacts.insert({
"id":lastContact ?lastContact ["id"] + 1 : 1,
"name":"John Doe",
"emails": ["john#doe.com", "john.doe#business.com"],
"phone":"555111322",
"status":"Active"
})
It solves the removal issue of Alex's answer. So no duplicate id will appear if any record is removed.
More explanation: I just get the id of the latest inserted document, add one to it, and then set it as the id of the new record. And ternary is for cases that we don't have any records yet or all of the records are removed.
this could be another approach
const mongoose = require("mongoose");
const contractSchema = mongoose.Schema(
{
account: {
type: mongoose.Schema.Types.ObjectId,
required: true,
},
idContract: {
type: Number,
default: 0,
},
},
{ timestamps: true }
);
contractSchema.pre("save", function (next) {
var docs = this;
mongoose
.model("contract", contractSchema)
.countDocuments({ account: docs.account }, function (error, counter) {
if (error) return next(error);
docs.idContract = counter + 1;
next();
});
});
module.exports = mongoose.model("contract", contractSchema);
// First check the table length
const data = await table.find()
if(data.length === 0){
const id = 1
// then post your query along with your id
}
else{
// find last item and then its id
const length = data.length
const lastItem = data[length-1]
const lastItemId = lastItem.id // or { id } = lastItem
const id = lastItemId + 1
// now apply new id to your new item
// even if you delete any item from middle also this work
}