Count the different variables in an array in my document - rethinkdb

I'm trying out rethinkDB and playing around with some query to see if it could fit by use case. So far, so good. However, I have a question regarding reQL.
For example in this case I store analytics events in rethinkDB such as:
[{
"userId": "abdf213",
"timestamp": "Sat Jan 17 2015 00:32:20 GMT+00:00",
"action": "Page"
},
{
"userId": "123abc",
"timestamp": "Sat Jan 17 2015 00:42:20 GMT+00:00",
"action": "Track"
},
{
"userId": "abdf213",
"timestamp": "Sat Jan 17 2015 00:45:20 GMT+00:00",
"action": "Track"
},
{
"userId": "123abc",
"timestamp": "Sat Jan 17 2015 00:44:20 GMT+00:00",
"action": "Page"
},
{
"userId": "123abc",
"timestamp": "Sat Jan 17 2015 00:48:20 GMT+00:00",
"action": "Page"
}]
I'd like the end result of my query to look like this:
{
"group": "123abc",
"reduction": {
"Page": 2,
"Track": 1
}
},
{
"group": "abdf213",
"reduction": {
"Page": 1,
"Track": 1
}
}
Bear in mind that the action name are not known in advance.
TBH, I'm not quite sure how to achieve this with ReQL.
Right now I have this query (using the data explorer):
r.db('test').table('events').group('userId').map(function(event) {
return event('action')
})
which return doc like this one:
{
"group": "-71omc5zdgdimpuveheqs6dvt5q6xlwenjg7m" ,
"reduction": [
"Identify" ,
"Page" ,
"Track"
]
}
Anyone can point me in the right direction here?
Cheers,
S

Try:
r.table('events').group('userId').map(function(event) {
return r.object(event('action'), 1);
}).reduce(function(a, b) {
return a.merge(b.keys().map(function(key) {
return [key, a(key).default(0).add(b(key))];}).coerceTo('object'));
})

Here's my solution:
r.table("events").group("userId", "action").count().ungroup()
.group(r.row("group")(0))
.map([r.row("group")(1), r.row("reduction")])
.coerceTo("object")
ReQL doesn't support nesting groups, but you can group by multiple fields at the same time and then performing further grouping on the output.

Related

Columns order of WebDataRocks pivot grid

Trying to build a grid with months as columns using webdatarocks, and the problem is that columns are sorted alphabetically (Apr 2020, Aug 2020, Dec 200, ...). Is there an option to order columns by date (Dec 200, Nov 2020, Oct 2020, ...)?
Example is available here
https://codesandbox.io/s/nifty-stonebraker-7mf56?file=/src/App.tsx
This is possible by adding an object to your data that will define data types. Here is an explanation.
In your case, this object would look this way:
{
"CONTRACT": {
"type": "string"
},
"value": {
"type": "number"
},
"date": {
"type": "date string"
},
"name": {
"type": "string"
}
}, {
type: "CONTRACT",
value: 217,
date: "Dec 2020",
name: "24"
}, {
type: "CONTRACT",
value: 725.84,
date: "Dec 2020",
name: "3 "
}, ...
After this, the columns should be ordered by dates. Note that input dates should be formatted properly (compliant with ISO 8601).
The way dates are shown inside WebDataRocks can be modified with the help of datePattern from options.

Microsoft Graph API: Why is creating a recurring event in the past returning a 400?

I am running into an issue creating recurring events in the past using Graph API. When I POST this data to /me/calendars/[calendarId]/events I get an ErrorPropertyValidationFailure error:
{
"isAllDay": true,
"start": {
"timeZone": "America/New_York",
"dateTime": "2000-09-02"
},
"end": {
"timeZone": "America/New_York",
"dateTime": "2000-09-03"
},
"subject": "Jimmy's birthday",
"body": { "contentType": "text", "content": "" },
"isCancelled": false,
"recurrence": {
"pattern": {
"type": "absoluteYearly",
"interval": 1,
"dayOfMonth": 2,
"month": 9
},
"range": { "startDate": "2000-09-02", "type": "noEnd" }
},
"showAs": "free",
"type": "seriesMaster"
}
All of the data seems valid to me, and indeed just changing the start and end dateTime values and the recurrence range's startDate to be in 2019 instead of 2000, and it seems to work.
But here's where it gets weird: keep those values in 2000, and change the dayOfMonth in the recurrence pattern to an incorrect value, like 5. Then when submitting to the API, it works! The recurrence will instead appear to begin on Sep 5 of 2000 and there is nothing on Sep 2 (also, the event seems to run "Tue 9/5/2000, 11:00 PM to Wed 9/6/2000, 11:00 PM" on the calendar, which is strange, since it also appears as an all-day event).
So my question is: is this a bug? Or what the heck's happening? It looks like correct data is getting a validation error, but incorrect data creates an event.
Updating to add the error body:
{
"error": {
"code": "ErrorPropertyValidationFailure",
"message": "At least one property failed validation.",
"innerError": {
"date": "2020-10-15T22:48:50",
"request-id": "c08b1d73-5b6d-46ac-8751-d1f17310f652",
"client-request-id": "c08b1d73-5b6d-46ac-8751-d1f17310f652"
}
}
}

RethinkDB Query: How to pluck bassed on a date range

Given a table called alerts and a database called database with an array
of objects with a date attribute called History how can I pluck based
on a date range on that date attribute?
with the following query,
r.db("database").table("alerts").pluck("history").limit(10000)
I get back something like the following
{
"history": [
{
"text": "text1" ,
"updateTime": Thu Jun 20 2019 01:29:47 GMT+00:00 ,
},
{
"text": "text2" ,
"updateTime": Thu Jun 20 2019 01:24:59 GMT+00:00 ,
},
]
}
{
"history": [
{
"text": "text3" ,
"updateTime": Thu Jun 20 2018 01:29:47 GMT+00:00 ,
},
{
"text": "text4" ,
"updateTime": Thu Jun 20 2018 01:24:59 GMT+00:00 ,
},
]
}
how can I pluck the sub object called history and only return histories that are in a specific range on the updateTime attribute.
for example between jan/2/2009 to jan/3/2009
You need to filter based on a time range and use pluck on a nested object. Here are some examples about how to do that from the official documentation
r.table("users").filter(function (user) {
return user("subscriptionDate").during(
r.time(2012, 1, 1, 'Z'), r.time(2013, 1, 1, 'Z'));
}).run(conn, callback);
Source: https://www.rethinkdb.com/api/javascript/filter/
r.table('marvel').pluck({'abilities' : {'damage' : true, 'mana_cost' : true}, 'weapons' : true}).run(conn, callback)
Source: https://www.rethinkdb.com/api/javascript/pluck/

Android fitness REST API missing data points

Here is what I am doing:
I installed Google Fit app on my phone and collected some fitness data:
Then I wen to OAuth 2.0 Playground and tried to read that data with a REST request:
Method: POST
URI: https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate
BODY:
{
"aggregateBy": [{
"dataTypeName": "com.google.calories",
"dataSourceId": "derived:com.google.calories.bmr:com.google.android.gms:merged"
}],
"bucketByTime": { "durationMillis": 86400000 },
"startTimeMillis": 1547232519000,
"endTimeMillis": 1547837319000
}
What I expected to get:
7 datasets for 7 following days with one datapoint in each. Expected values are as follows:
12th January: 0
13th January: 0
14th January: 1688
15th January: 1934
16th January: 844
17th January: 0
18th January: 857
What I actually get is:
All days but 14th (with different start and end time of course):
{
"startTimeMillis": "1547578119000",
"endTimeMillis": "1547664519000",
"dataset": [
{
"dataSourceId":"derived:com.google.calories.bmr.summary:com.google.android.gms:aggregated",
"point": []
}
]
},
14th January:
{
"startTimeMillis": "1547491719000",
"endTimeMillis": "1547578119000",
"dataset": [
{
"dataSourceId": "derived:com.google.calories.bmr.summary:com.google.android.gms:aggregated",
"point": [
{
"startTimeNanos": "1547500395267000000",
"originDataSourceId": "derived:com.google.calories.bmr:com.google.android.gms:from_height&weight",
"endTimeNanos": "1547500402445000000",
"value": [
{
"mapVal": [],
"fpVal": 1688.25
},
{
"mapVal": [],
"fpVal": 1688.25
},
{
"mapVal": [],
"fpVal": 1688.25
}
],
"dataTypeName": "com.google.calories.bmr.summary"
}
]
}
]
},
Does anyone know why I don't get any value for most of the brackets while I do get value for one of them? And why is the value for 14th listed 3 times?
(Also I can't force these code blocks to format properly, apologies for that)
PUT THE CURRENT DATE AND TIME
1 Nov 2019: 1572586200 so the "startTimeMillis": "1572586200000"
8 Nov 2019: 1573191000 so the "endTimeMillis": "1573191000000"
put these 2 in the request body and it should work.

Problem with the interpretation of "Now" as #Sys.Time in Dialogflow

Currently i am creating a chatbot for skype using Dialogflow the main problem is when i use the command "Now" in a skype message it uses my current time +1 hour, but when i ask for the time "Now" from the IOS Application it use the current correct TimeZone, someone knows from "where" exactly dialogflow takes the current time zone for the word "Now" because from my app-IOS because from the IOS_Application it gets one value (Correct timezone value) and from skype it gets a another(timezone + 1 hour value)
Raw Interaction Log(Dialogflow - Skype):
{
"queryText": "what time is now?",
"parameters": {
"time": "StiDate [Thu Oct 18 12:38:16 CDT 2018]"
},
"fulfillmentText": "the time is 12:38:16",
"fulfillmentMessages": [
{
"text": {
"text": [
"[{\"type\":0,\"speech\":\"the time is 12:38:16\"}]"
]
}
}
],
"intent": {
"id": "37524c80-a15a-4c04-aa9b-38986ff38993",
"displayName": "A_Test_EventTime"
},
"languageCode": "en",
"sentimentAnalysisResult": {},
"id": "93ce9408-4b73-4f18-9ae0-b947a906afc8",
"sessionId": "6b69769b-1ce7-4359-9018-c88d017485bf",
"timestamp": "2018-10-18T17:38:16.164Z",
"source": "agent"
}
Raw Interaction Log(Dialogflow - AppIOS):
{
"queryText": "What time is now?",
"parameters": {
"time": "StiDate [Thu Oct 18 11:38:00 CST 2018]"
},
"fulfillmentText": "the time is 11:38:00",
"fulfillmentMessages": [
{
"text": {
"text": [
"[{\"type\":0,\"speech\":\"the time is 11:38:00\"}]"
]
}
}
],
"outputContexts": [
{
"name": "fa75fc39-7c68-47ac-bea5-12394f425855",
"lifespanCount": 4,
"parameters": {
"time.original": "now?",
"time": "StiDate [Thu Oct 18 11:38:00 CST 2018]"
}
}
],
"intent": {
"id": "37524c80-a15a-4c04-aa9b-38986ff38993",
"displayName": "A_Test_EventTime"
},
"languageCode": "en",
"sentimentAnalysisResult": {},
"id": "58ade82b-c842-44b6-b0a2-d6cced4d6648",
"sessionId": "dfe0efda53d11aa3d8d43e92a726f9e4",
"timestamp": "2018-10-18T17:38:00.695Z",
"source": "agent"
}
Dialogflow agents have a default time zone. You can change this time zone in your Dialogflow's agents settings in the console: https://dialogflow.com/docs/agents/create-manage#general

Resources