Alloy UI Scheduler Multiple Day Event for selected Time Period - liferay

The problem being faced with Alloy UI Scheduler is that, I am unable to select multiple day event for a selected time period for example from 12-Aug2014 to 15 Aug 2014 with timing from 1:00 PM to 5:00 PM everyday from 12th to 15th Aug 2014. As of now current alloy ui scheduler is taking it as a allDay event which should not be the case as shown in image attached.
Please let me know how to achieve the above.

The best way that I could find to do this is to use a for loop. For your specific example of events from 1pm to 5pm from Aug 12th to the 15th, you could create a for loop similar to this one:
var events = [];
for (var i = 0; i < 4; i++) {
events.push({
content: 'Repeating Event',
endDate: new Date(2014, 7, 12 + i, 17),
startDate: new Date(2014, 7, 12 + i, 13)
});
}
new Y.Scheduler({
// ...
date: new Date(2014, 7, 11),
items: events,
render: true
// ...
});
Here's a full example with a runnable AlloyUI Scheduler (scroll down to see the events that start at 1pm):
YUI().use('aui-scheduler', function (Y) {
var events = [];
for (var i = 0; i < 4; i++) {
events.push({
content: 'Repeating Event',
endDate: new Date(2014, 7, 12 + i, 17),
startDate: new Date(2014, 7, 12 + i, 13)
});
}
new Y.Scheduler({
boundingBox: '#boundingBox',
date: new Date(2014, 7, 10),
items: events,
render: true,
views: [new Y.SchedulerWeekView()]
});
});
<script src="https://cdn.rawgit.com/stiemannkj1/701826667a70997013605edcd37e92a6/raw/469fe1ae297e72a5a80eb9015003b7b04eac735e/alloy-ui-3.0.1_aui_aui-min.js"></script>
<link href="https://cdn.rawgit.com/stiemannkj1/90be22de7f48c729b443af14796d91d3/raw/a9f35ceedfac7fc0559b121bed105eaf80f10bf2/aui-css_css_bootstrap.min.css" rel="stylesheet"></link>
<div id="boundingBox"></div>
If this solution is not good enough, you may want to check out the Scheduler API docs. SchedulerEvent has a repeated attribute that may be what you are looking for (Note: I could not get the repeated attribute to work in the way that I expected for your use case).

Related

node.js write data to influxdb timestamp is wrong

I'm writing data to my influxdb with node.js,but the time always wrong like,
I'm using Datetime in 'luxon'.
const from = DateTime.fromObject({ year: 2021, month: 12, day: 1, hour: 8});
const to = from.plus({ day: 1 });
let anchor = from;
whiel(anchor < to) {
notification.time = anchor.valueOf();
await write(notification);
anchor = anchor.plus({ minute: 5 });
}
the point should start from 2021/12/1 08:00:00 to 2021/12/3 15:55:00.
every 5 mins have a point,but see the picture in my influxdb
it seems like every 11 mins and 50 secs have one point, I don't understand.

Update DB when Google Calendar Event change

I have been implementing some functions of google calendar api. I have a custom calendar which have the capability to sync with google calendar. This means, you can create, and edit calendars and events from my dashboard to google calendar account. The main problem I am facing is, if I update the event directly from my google calendar. I have implemented push notifications and getting response like this:
{
"Google_channel_ID": "19835150 - 0057 - 11e6 - bc9c - 1735798 ca540",
"Google_channel_token": "calendar_id = 4e7 d5c20ht9lpfdtuukcsvgeq4 #group.calendar.google.com & user_id = 43e d7rxeqqce3fk09ahszc",
"Google_channel_expiration": "Tue,12 Apr 2016 12: 34: 36 GMT",
"Google_resource_id": "oLMEEhHAw5Xo3r2187CWykjAtm0",
"Google_resource_URI": "https: //www.googleapis.com/calendar/v3/calendars/4e7d5c20ht9lpfdtuukcsvgeq4#group.calendar.google.com/events?alt=json",
"Google_resource_state": "sync",
"Google_message_number": "1"
}
But this response is very general. For example, If I have 1000 events on this calendar, and update the complete 1000 events. I will receive always the same notification 1000. I would like to know, if it is possible to get which event id has change, so I can perform and update to my DB.
The way I init the watch is like this:
exports.watch = function(req, res){
var channel_id = uuid.v1();
var user_id = req.body.user_id;
var calendar_id = req.body.calendar_id;
authorize(user_id, function(oauth2Client){
var data = {
auth: oauth2Client,
calendarId: calendar_id,
resource: {
id: channel_id,
token: 'calendar_id='+ calendar_id + '&user_id=' + user_id,
address: 'https://api.medradr.com/google-watch',
type: 'web_hook',
params: {
ttl: '36000'
}
}
};
calendar.events.watch(data, function (err, response) {
if (err) {
console.error('The API returned an error: ' + err);
return;
}else{
res.send({ok: true, message: 'Listener created', result:response});
}
});
});
}
For people who are looking for a good way to get which events changed when the web hook triggers. When your web hook is triggered, you will get something like this:
X-Goog-Channel-ID: channel-ID-value
X-Goog-Channel-Token: channel-token-value
X-Goog-Channel-Expiration: expiration-date-and-time // In human-readable format; present only if channel expires.
X-Goog-Resource-ID: identifier-for-the-watched-resource
X-Goog-Resource-URI: version-specific-URI-of-the-watched-resource
X-Goog-Resource-State: sync
X-Goog-Message-Number: 1
On X-Goog-Resource-URI you will get something like this:
https://www.googleapis.com/calendar/v3/calendars/4e7d5c20ht9lpfdtuukcsvgeq4#group.calendar.google.com/events?alt=json
With you OAuth authentication, you can make a GET request to this URL to fetch all events that belongs to this calendar. Now the trick to know which resources have been changed is really simple. For each event you will get something like this:
{
event_id: 335,
user_id: '43ed7rxeqqce3fk09ahszc',
kind: 'calendar#event',
etag: '"2921213870180000"',
google_id: 'cpbcesg966skprb3rh1p1ud668',
status: 'confirmed',
htmlLink: 'https://www.google.com/calendar/event?eid=Y3BiY2VzZzk2NnNrcHJiM3JoMXAxdWQ2NjggNGU3ZDVjMjBodDlscGZkdHV1a2NzdmdlcTRAZw',
created: Thu Apr 14 2016 00:00:00 GMT-0500 (CDT),
updated: Thu Apr 14 2016 00:00:00 GMT-0500 (CDT),
summary: 'Testing google notifications',
description: '',
creator: 'guizarkrg#gmail.com',
organizer: '4e7d5c20ht9lpfdtuukcsvgeq4#group.calendar.google.com',
start: Sat Apr 09 2016 00:00:00 GMT-0500 (CDT),
end: Sun Apr 10 2016 00:00:00 GMT-0500 (CDT),
iCalUID: 'cpbcesg966skprb3rh1p1ud668#google.com',
event_type_id: 0,
calendar_id: 0,
timezone_id: 0,
sequence: 0,
calendar_color_id: ''
}
As you can see, the is a sequence: 0, this is incremental. This means, each time you apply some changes on your event (summary, description, start date, end date, etc). This number will be incremented +1. You can save this on your database, so each time web hook triggers, you update only events which sequence is > than saved sequence. So basically, you update the event and save the new value of sequence. Next time that web hook triggers, it will only update on your DB the events that are included in this condition.
Hope it helps, happy coding.

How to track iteration progress using Rally's Web Services API

I am writing a custom app to track iteration progress by day. Is there a builtin way in Rally to get the number of user stories that are in the "Accepted" state for a specific date, and the number of points (or do I have to get all user stories and parse their revision histories)?
There is IterationCumulativeFlowData object in WS API, which is populated at midnight of the Workspace Timezone when the Data Collection runs on workdays specified in the Workspace Setup screen.
Data is stored for each day of the Iteration and a corresponding state. There is CumulativeFlowData object for Day 1 of the Iteration for everything in a Defined state, Day 1 of Release for everything in an In-Progress state, etc.
The CumulativeFlowData object also stores CardEstimateTotal which is the sum of the estimates of cards in every state.
Here is a example of an app written with rally-node that returns iteration data for specific state (Accepted) as of the last day of the iteration.
In this examle the CreationDate of the last result is '2013-08-27T06:00:00.000Z, while the EndDate of the iteration in question was 2013-08-27 11:59:59 PM America/Denver (which is 2013-08-28T05:59:59.000Z), so I had to manipulate a date in order to make this query condition return the data for the last day of the iteration:
query = query.and('CreationDate', '>', endDateMinusOneDay);
Here is the full js file of the example:
var rally = require('rally'),
queryUtils = rally.util.query,
restApi = rally({
user: 'user#co.com',
pass: 'secret',
apiVersion: 'v2.0',
server: 'https://rally1.rallydev.com',
requestOptions: {
headers: {
'X-RallyIntegrationName': 'My cool node.js program',
'X-RallyIntegrationVendor': 'My company',
'X-RallyIntegrationVersion': '1.0'
},
}
});
function findIteration() {
return restApi.query({
type: 'Iteration',
start: 1,
pageSize: 2,
limit: 10,
fetch: ['ObjectID', 'EndDate'],
scope: {
project: '/project/12352608219',
up: false,
down: false
},
query: queryUtils.where('Name', '=', 'i777')
});
}
function queryIterationData(result) {
var endDate = result.Results[0].EndDate,
oid = result.Results[0].ObjectID;
console.log('endDate',endDate);
var date1 = new Date(endDate);
var ms = date1.getTime() - 86400000; //86400000 is the number of milliseconds in a day
var date2 = new Date(ms);
var endDateMinusOneDay = date2.toISOString();
console.log('date2 ISO', date2.toISOString());
var query = queryUtils.where('IterationObjectID', '=',oid );
query = query.and('CardState', '=', 'Accepted');
query = query.and('CreationDate', '>', endDateMinusOneDay);
return restApi.query({
type: 'IterationCumulativeFlowData',
fetch: ['CardCount', 'CardEstimateTotal', 'CardState', 'CardState', 'CreationDate'],
query: query,
});
}
function onSuccess(result) {
console.log('Success!', result);
}
function onError(errors) {
console.log('Failure!', errors);
}
findIteration()
.then(queryIterationData)
.then(onSuccess)
.fail(onError);
It returns:

MongoDB/Mongoose querying at a specific date?

Is it possible to query for a specific date ?
I found in the mongo Cookbook that we can do it for a range Querying for a Date Range
Like that :
db.posts.find({"created_on": {"$gte": start, "$lt": end}})
But is it possible for a specific date ?
This doesn't work :
db.posts.find({"created_on": new Date(2012, 7, 14) })
That should work if the dates you saved in the DB are without time (just year, month, day).
Chances are that the dates you saved were new Date(), which includes the time components. To query those times you need to create a date range that includes all moments in a day.
db.posts.find({ //query today up to tonight
created_on: {
$gte: new Date(2012, 7, 14),
$lt: new Date(2012, 7, 15)
}
})
...5+ years later, I strongly suggest using date-fns instead
import endOfDayfrom 'date-fns/endOfDay'
import startOfDay from 'date-fns/startOfDay'
MyModel.find({
createdAt: {
$gte: startOfDay(new Date()),
$lte: endOfDay(new Date())
}
})
For those of us using Moment.js
const moment = require('moment')
const today = moment().startOf('day')
MyModel.find({
createdAt: {
$gte: today.toDate(),
$lte: moment(today).endOf('day').toDate()
}
})
Important: all moments are mutable!
tomorrow = today.add(1, 'days') does not work since it also mutates today. Calling moment(today) solves that problem by implicitly cloning today.
Yeah, Date object complects date and time, so comparing it with just date value does not work.
You can simply use the $where operator to express more complex condition with Javascript boolean expression :)
db.posts.find({ '$where': 'this.created_on.toJSON().slice(0, 10) == "2012-07-14"' })
created_on is the datetime field and 2012-07-14 is the specified date.
Date should be exactly in YYYY-MM-DD format.
Note: Use $where sparingly, it has performance implications.
Have you tried:
db.posts.find({"created_on": {"$gte": new Date(2012, 7, 14), "$lt": new Date(2012, 7, 15)}})
The problem you're going to run into is that dates are stored as timestamps in Mongo. So, to match a date you're asking it to match a timestamp. In your case I think you're trying to match a day (ie. from 00:00 to 23:59 on a specific date). If your dates are stored without times then you should be okay. Otherwise, try specifying your date as a range of time on the same day (ie. start=00:00, end=23:59) if gte doesn't work.
similar question
You can use following approach for API method to get results from specific day:
# [HTTP GET]
getMeals: (req, res) ->
options = {}
# eg. api/v1/meals?date=Tue+Jan+13+2015+00%3A00%3A00+GMT%2B0100+(CET)
if req.query.date?
date = new Date req.query.date
date.setHours 0, 0, 0, 0
endDate = new Date date
endDate.setHours 23, 59, 59, 59
options.date =
$lt: endDate
$gte: date
Meal.find options, (err, meals) ->
if err or not meals
handleError err, meals, res
else
res.json createJSON meals, null, 'meals'
i do it in this method and works fine
public async getDatabaseorderbyDate(req: Request, res: Response) {
const { dateQuery }: any = req.query
const date = new Date(dateQuery)
console.log(date)
const today = date.toLocaleDateString(`fr-CA`).split('/').join('-')
console.log(today)
const creationDate = {
"creationDate": {
'$gte': `${today}T00:00:00.000Z`,
'$lt': `${today}T23:59:59.999Z`
}
};
`
``
Problem I came into was filtering date in backend, when setting date to 0 hour, 0 minute, 0 second, 0 milisecond in node server it does in ISO time so current date 0 hour, 0 minute, 0 second, 0 milisecond of client may vary i.e. as a result which may gives a day after or before due to conversion of ISO time to local timezone
I fixed those by sending local time from client to server
// If client is from Asia/Kathmandu timezone it will zero time in that zone.
// Note ISODate time with zero time is not equal to above mention
const timeFromClient = new Date(new Date().setHours(0,0,0,0)).getTime()
And used this time to filter the documents by using this query
const getDateQuery = (filterBy, time) => {
const today = new Date(time);
const tomorrow = new Date(today.getDate() + 1);
switch(filterBy) {
case 'past':
return {
$exists: true,
$lt: today,
};
case 'present':
return {
$exists: true,
$gte: today,
$lt: tomorrow
};
case 'future':
return {
$exists: true,
$gte: tomorrow
};
default:
return {
$exists: true
};
};
};
const users = await UserModel.find({
expiryDate: getDateQuery('past', timeFromClient)
})
This can be done in another approach using aggregate if we have timezoneId like Asia/Kathmandu
const getDateQuery = (filterBy) => {
const today = new Date();
const tomorrow = new Date(today.getDate() + 1);
switch(filterBy) {
case 'past':
return {
$exists: true,
$lt: today,
};
case 'present':
return {
$exists: true,
$gte: today,
$lt: tomorrow
};
case 'future':
return {
$exists: true,
$gte: tomorrow
};
default:
return {
$exists: true
};
};
};
await UserModel.aggregate([
{
$addFields: {
expiryDateClientDate: {
$dateToParts: {
date: '$expiryDate',
timezone: 'Asia/Kathmandu'
}
}
},
},
{
$addFields: {
expiryDateClientDate: {
$dateFromParts: {
year: '$expiryDateClientDate.year',
month: '$expiryDateClientDate.month',
day: '$expiryDateClientDate.day'
}
}
},
},
{
$match: {
expiryDateClientDate: getDateQuery('past')
}
}
])
We had an issue relating to duplicated data in our database, with a date field having multiple values where we were meant to have 1. I thought I'd add the way we resolved the issue for reference.
We have a collection called "data" with a numeric "value" field and a date "date" field. We had a process which we thought was idempotent, but ended up adding 2 x values per day on second run:
{ "_id" : "1", "type":"x", "value":1.23, date : ISODate("2013-05-21T08:00:00Z")}
{ "_id" : "2", "type":"x", "value":1.23, date : ISODate("2013-05-21T17:00:00Z")}
We only need 1 of the 2 records, so had to resort the javascript to clean up the db. Our initial approach was going to be to iterate through the results and remove any field with a time of between 6am and 11am (all duplicates were in the morning), but during implementation, made a change. Here's the script used to fix it:
var data = db.data.find({"type" : "x"})
var found = [];
while (data.hasNext()){
var datum = data.next();
var rdate = datum.date;
// instead of the next set of conditions, we could have just used rdate.getHour() and checked if it was in the morning, but this approach was slightly better...
if (typeof found[rdate.getDate()+"-"+rdate.getMonth() + "-" + rdate.getFullYear()] !== "undefined") {
if (datum.value != found[rdate.getDate()+"-"+rdate.getMonth() + "-" + rdate.getFullYear()]) {
print("DISCREPENCY!!!: " + datum._id + " for date " + datum.date);
}
else {
print("Removing " + datum._id);
db.data.remove({ "_id": datum._id});
}
}
else {
found[rdate.getDate()+"-"+rdate.getMonth() + "-" + rdate.getFullYear()] = datum.value;
}
}
and then ran it with mongo thedatabase fixer_script.js
Well a very simple solution to this is given below
const start = new Date(2020-04-01);
start.setHours(0, 0, 0, 0);
const end = new Date(2021-04-01);
end.setHours(23, 59, 59, 999);
queryFilter.created_at={
$gte:start,
$lte:end
}
YourModel.find(queryFilter)
So, the above code simply finds the records from the given start date to the given end date.
Seemed like none of the answers worked for me. Although someone mentioned a little hint, I managed to make it work with this code below.
let endDate = startingDate
endDate = endDate + 'T23:59:59';
Model.find({dateCreated: {$gte: startingDate, $lte: endDate}})
startingDate will be the specific date you want to query with.
I preferred this solution to avoid installing moment and just to pass the startingDate like "2021-04-01" in postman.

Creating a couchdb view that returns an array of unique values from a document set

I have a couchdb database filled with time-stamped documents so the format of a given document is something like this:
{ id: "uniqueid",
year: 2011,
month: 3,
day: 31,
foo: "whatever"
bar: "something else"
}
I would like to construct a set of views such that a given key will return an array of year, month or day values for which documents exist. For example given the view name Days, I would like the following view url
/db/_design/designdoc/_view/Days?key=[2011,3]
to return an array of all the days in March of 2011 for which documents exist. For example, if March 2011 had some number of documents falling on six days, it might look like:
[1, 2, 5, 15, 27, 31]
Similarly,
/db/_design/designdoc/_view/Months?key=2011
If 2011 had some number of documents falling on April, May, and September, it might look like:
[4, 5, 9]
And
/db/_design/designdoc/_view/Years
will return an array of years in the whole database. If the documents have this year and last, it might look like:
[2010, 2011]
I gather it is difficult to write a reduce function that returns an array because you end up running into reduce overflow errors as the document count increases. I know this because I wrote a reduce function that worked but then started throwing reduce overflow errors after I loaded it up with documents.
One solution I have examined is just creating a view without a reduce that creates an array key [year, month, day] and then using startkey and endkey parameters on the view to return documents. The problem with this approach is how it scales. Say my database has thousands of documents spread out over two years. Using this view, I need to iterate over the entire set of documents just to discover this.
I believe this question is trying to ask the same thing though I am not quite sure so I figured I'd add a new question. Also, the answers given on that question do not avoid reduce overflow errors for larger document sets, as far as I could tell with my limited view writing skills.
I think for this, ou need to construct your views not only with maps, but also with reduces.
Disregarding eventual scaling problems there are 2 solutions. I will take into account only Days since the answer for Months and Years is similar.
Solution 1:
view Days:
map:
function(doc) {
if (doc.year && doc. month && doc.day) {
emit([ year, month, day ], 1);
}
}
reduce:
function(keys, values) {
return sum(values);
}
list listDays:
function(head, req) {
start({
"headers": {
"Content-Type": "text/plain"
}
});
var row;
var days = new Array();
while(row = getRow()) {
days.push(row.key[2]);
}
var daysString = json.join(',');
send('[' + daysString + ']');
}
http call:
http://couch/db/_design/db/_list/listDays/Days?group=true&group_level=2&startkey=["2011","3"]&endkey=["2011","3Z"]
Solution 2:
view Days:
map:
function(doc) {
if (doc.year && doc. month && doc.day) {
emit([ year, month, day ], null);
}
}
list listDays:
function(head, req) {
start({
"headers": {
"Content-Type": "text/plain"
}
});
var row;
var days = new Array();
while(row = getRow()) {
if (days.indexOf(row.key[2] == -1) { days.push(row.key[2]); }
}
var daysString = json.join(',');
send('[' + daysString + ']');
}
http call:
http://couch/db/_design/db/_list/listDays/Days?startkey=["2011","3"]&endkey=["2011","3Z"]

Resources