Just beginning with firebase... :-(
How do I set a property of an item?
This is my data structure:
myproject
|
- players
|
- -JPUAYuKUNeevXxaCMxM
|
- name: "John"
|
- skill
|
- mu: 25
|
- sigma: 8.333
- -JPUAYuRyJBH8sF93pNt
...
I can add a player with:
var ref = new Firebase(FIREBASE_URL + '/' + 'players');
ref.child(id).set(player);
The question is: how do I update only one property of an item (for example, 'skill') ?
I did try with:
var skill = {};
skill.mu = 27.0;
skill.sigma = 7.0;
ref.child(id).skill.update(skill);
I think I know what's going on here.
You expected ref.child(id) to have a property skill. However, you actually want the "skill" child; ref.child(id).child("skill").
Related
KQL beginner here - I have some CEF logs hitting one of my servers and I need to get into the data to get some meaningful reports from it.
Take this log - not json, just a string
CEF:0|vendor1|vendorproduct|1.0|Event1|Event2|1|source_ip=0.0.0.0 rt=2020-04-28T04:17:05.475Z data1=example1 group=example2 endpoint=55555555 user=444444
I want to access each field and store as a var for further query use. What is the best way to achieve this so I can have results such as the below? Regex? String functions?
| extend vendorname = // = vendor1
| extend source_ip = // = 0.0.0.0
| extend endpoint = // = 55555555
// etc
OK, I figured this one out - see below for KQL to achieve what I was looking for:
Syslog
| where SyslogMessage has "vendor-name"
| extend logs = split(SyslogMessage, "|")
| extend vendor = logs[1]
| extend app = logs[2]
| extend version = logs[3]
| extend event = logs[4]
| extend msg = logs[5]
| parse SyslogMessage with * "source_ip=" source_ip "rt=" rt " id=" id " data1=" data1 " group=" group " endpoint=" endpoint "user=" user
| project vendor, app, version, event, msg, rt, data1, source_ip, id, group, endpoint, user
I am trying to use the type ImageURISource which is here - https://github.com/facebook/react-native/blob/26684cf3adf4094eb6c405d345a75bf8c7c0bf88/Libraries/Image/ImageSource.js#L15
type ImageURISource = {
uri?: string,
bundle?: string,
method?: string,
headers?: Object,
body?: string,
cache?: 'default' | 'reload' | 'force-cache' | 'only-if-cached',
width?: number,
height?: number,
scale?: number,
};
export type ImageSource = ImageURISource | number | Array<ImageURISource>;
However we see that it is exported as a union along with 2 other things. Is it possible to pick from a union just one?
I was hoping to do:
$Pick<ImageSource, ImageURISource>
It's not very pretty, but you could use refinement to specifically refine the type that you want out of it by doing something like this:
var source: ImageSource = {}
if (typeof source === "number" || Array.isArray(source)) throw new Error();
var uriSource = source;
type ImageURISource = typeof uriSource;
The downside here is that if the add more types to the union, your code would start failing again.
It seems like you'd be best off making a PR to react-native to expose that type.
My goal is to use data from Google Spreadsheets as parameters for bulk creation of AdWords Remarketing Audiences from Google Analytics stats data.
My code is based on this article.
API connection seems to be working. Audiences are being created but I have an issue with specifying segment parameters that should include/exclude audience based on the ga:pagePath.
So my questions are:
What do I do wrong?
Can someone give a hint or an advice how to make it working?
Spreadsheet table
| Audience Name | URL include 1 | URL include 2 | URL include 3 | URL exclude 1 | URL exclude 2 | URL exclude 3 | Duration |
|---------------|---------------|---------------|---------------|---------------|---------------|---------------|----------|
| Test 1 | /test | /test2 | | | | | 540 |
|---------------|---------------|---------------|---------------|---------------|---------------|---------------|----------|
| Test 2 | /test3 | /test4 | | | | | 540 |
|---------------|---------------|---------------|---------------|---------------|---------------|---------------|----------|
Spreadsheet macro script
function main() {
var settings = {'linkedView':"XXXXXXXXX",
'linkedAccountId':"XXX-XXX-XXXX",
'accountId':'XXXXXXXX',
'propertyID':'UA-XXXXXXXX-X'};
var spreadsheet = SpreadsheetApp.openByUrl('XXXXXX');
var sheet = spreadsheet.getSheetByName('test');
var range = sheet.getRange(2, 1, sheet.getLastRow(), 8);
var values = range.getValues();
for(var i = 0; i < values.length; i++) {
var name = values[i][0];
var categoryUrl = values[i][1];
var duration = Math.floor(values[i][7]);
Logger.log(duration);
var inludeSegment = '';
var exludeSegment = '';
if(values[i][1]) {
inludeSegment += 'users::condition::ga:pagePath=#'+ values[i][1];
}
/*
if(values[i][2]) {
inludeSegment += ';ga:pagePath==' + values[i][2];
}
if(values[i][3]) {
inludeSegment += ';ga:pagePath==' + values[i][3];
}
if(values[i][4]) {
exludeSegment += 'sessions::condition::ga:pagePath==' + values[i][4];
}
if(values[i][5]) {
exludeSegment += ';ga:pagePath==' + values[i][5];
}
if(values[i][6]) {
exludeSegment += ';ga:pagePath==' + values[i][6];
}*/
var newAudience = Analytics.Management.RemarketingAudience.insert(
{
'name': name,
'linkedViews': [settings.linkedView],
'linkedAdAccounts': [{
'type': 'ADWORDS_LINKS',
'linkedAccountId': settings.linkedAccountId,
}],
'description' : 'test',
'audienceType': 'SIMPLE',
'audienceDefinition': {
'includeConditions': {
'daysToLookBack': 14,
'segment': inludeSegment,
'membershipDurationDays': duration,
'isSmartList': false
}
}
},
settings.accountId,
settings.propertyID
);
Logger.log(newAudience);
Logger.log(i + ' Audience ' + name + ' has been created');
};
}
I see you have issue with segments definition.
https://developers.google.com/analytics/devguides/reporting/core/v3/segments-feature-reference
This article helps you.
Because when you use ';' between pagePathes it means session must include both.
users::condition::ga:pagePath=#/category1;ga:pagePath=#/category2
This segment will collect all user who are visit 2 categories.
If we using ','
users::condition::ga:pagePath=#/category1**,**ga:pagePath=#/category2
This segment will collect all users from 1 and 2 categories, even user has visited only one.
you should use '!' To exclude something from segment
sessions::condition::**!**ga:exitPagePath==/
Hope it helps you!
My use case is that I have an <iron-form> with a single <paper-textarea> field that accepts a string list of email addresses which I parse into an array, then I want to:
Store the individual email addresses in my Firebase (for indexing and lookup purposes),
at multiple locations (per data fan out technique),
with a single write operation (because I don't want to make 100 API calls if the list is that long) and
without overwriting any existing data.
Specifically, I want to start with State A, as follows:
State A
my-app
|
- emails
| |
| - email1#example,com
| |- old: "data"
| - email2#example,com
| |- old: "data"
- users
|
- c0djhbQi6vc4YMB-fDgJ
And achieve State B as follows:
State B
my-app
|
- emails
| |
| - email1#example,com
| |- old: "data"
| - email2#example,com
| |- old: "data"
| - email3#example,com
| |- new: "data"
| - email4#example,com
| |- new: "data"
- users
|
- c0djhbQi6vc4YMB-fDgJ
|
- emails
|
- email3#example,com
|- new: "data"
- email4#example,com
|- new: "data"
Notice: The {old: "data"} is not overwritten.
Background
I seek to extend this SO question and answer.
There, we inserted a single node in a new location with three options:
using firebase-query
JS SDK
using firebase-document
Now, I need to do the same type of insertion (without deletion or replacing old data) for multiple nodes (with a user defined, not autogenerated, key; i.e., keys are specific email addresses). I also need to use the data fan out technique to update multiple paths with a single write operation.
Similar to what's shown here.
https://firebase.google.com/docs/database/web/read-and-write#update_specific_fields
function writeNewPost(uid, username, picture, title, body) {
// A post entry.
var postData = {
author: username,
uid: uid,
body: body,
title: title,
starCount: 0,
authorPic: picture
};
// Get a key for a new Post.
var newPostKey = firebase.database().ref().child('posts').push().key;
// * * * * * * * * * * * * * * * *
// THE ABOVE LINE NEEDS TO CHANGE TO SUPPORT USER-GENERATED KEYS SUCH AS EMAIL ADDRESSES
// * * * * * * * * * * * * * * * *
// Write the new post's data simultaneously in the posts list and the user's post list.
var updates = {};
updates['/posts/' + newPostKey] = postData;
updates['/user-posts/' + uid + '/' + newPostKey] = postData;
return firebase.database().ref().update(updates);
}
Also note, one of the comments mentions:
There's no reason newPostKey above couldn't be an email address...
The challenge is that I need to write multiple keys to multiple locations simultaneously in a single call.
The Firebase Realtime Database supports arbitrarily complex atomic deep updates (blog post). It works like so:
You can update any arbitrarily deep path with a single .update() call
The full path on the key side of your update map will be replaced, so you must address subkeys directly if you don't want to blow away the parent
Paths are relative to your current ref
So let's take your example:
var update = {};
update['emails/email3#example,com'] = {new: 'data'};
update['emails/email4#example,com'] = {new: 'data'};
update['users/c0djhbQi6vc4YMB-fDgJ/emails/email3#example,com'] = {new: 'data'};
update['users/c0djhbQi6vc4YMB-fDgJ/emails/email4#example,com'] = {new: 'data'};
firebase.database().ref().update(update);
This will update all of the locations simultaneously. To make it dynamic, simply use string interpolation when constructing the keys.
I have been given a dataset to work with that is layed out in the format of
Object | Type | Level | Comments | Parent | Child
So far I have been able to get the Object as the Parent Node and the Comments as a child node, however I need to get multiple children for this parent, and then children on them
An example of what I mean is like so
Object | Type | Level | Comments | Parent | Child
Dave | WH | 1 | comment | root | null
Simon | WH | 1 | comment | root | Fortnum
Simon | WH | 1 | comment | root | Mason
Tim | WH | 1 | comment | root | null
wallace| WH | 2 | comment | Simon | null
Mason | WH | 2 | comment | Simon | Mouse
Mouse | WH | 3 | comment | Mason | null
I need it to look like this
I have looked at the code from here Similar Stack Answer but its not working for me
I am pulling the sql data into a datatable and then looping through it to try and build the tree view.
This is the code that I am using that is only giving me the object as a parent node, and then the comment as a child node, but I need to be able to locate the actual children of the and then add them to the treeview.
For Each row As DataRow In dt.Rows
node = Searchnode(row.Item(4).ToString(), TreeView1)
If node IsNot Nothing Then
subNode = New TreeNode(row.Item(3).ToString())
node.ChildNodes.Add(subNode)
Else
node = New TreeNode(row.Item(0).ToString())
subNode = New TreeNode(row.Item(3).ToString())
node.ChildNodes.Add(subNode)
TreeView1.Nodes.Add(node)
End If
Next
then the function
Private Function Searchnode(ByVal nodetext As String, ByVal trv As TreeView) As TreeNode
For Each node As TreeNode In trv.Nodes
If node.Text = nodetext Then
Return node
End If
Next
End Function
Ive never really worked with treeviews before in ASP.Net but would be very grateful if anyone can help me.
Its not necessary to add child nodes when you add a new node. If the datatable is sorted the way your example shows the childnode will come up with a reference to its parent after the parent has already been added to the treeview.
so prior to this example edit the datatable and remove the duplicate objects
like remove one of the simons. the(child) column is not needed. also (optionally) going to add a reference to the parent when adding the child.
For Each row As DataRow In dt.Rows
node = Searchnode(row.Item(4).ToString(), TreeView1.Nodes)
If node IsNot Nothing Then
subNode = New TreeNode(row.Item(0).ToString()){ parent= node }
node.Nodes.Add(subNode)
Else 'root node
node = New TreeNode(row.Item(0).ToString())
TreeView1.Nodes.Add(node)
End If
Next
also searchnode needs to be recursive to check child nodes.
Private Function Searchnode(ByVal nodetext As String, ByVal tn As TreeNodeCollection) As TreeNode
TreeNode ret = nothing
For Each node As TreeNode In tn.Nodes
If node.Text = nodetext Then
ret = node
exit for
Else
ret = Searchnode(nodetext, node.Nodes)
End If
Next
Return ret
End Function