Group Delimited Flat Data using Flex - actionscript-3

I've got some delimited data that I need to get into a Flex tree view (or some other kind of control that can display a hierarchy.) The data looks like this:
item1,groupA,mainGroup,root
item2,groupA,mainGroup,root
groupA,mainGroup,root
groupB,mainGroup,root
item3,groupB,mainGroup,root
item4,groupB,mainGroup,root
mainGroup,root
groupC,mainGroup,root
groupD,someOtherGroup,root
root
My flex app is connected to a jboss server that could potentially remove the root element (if necessary), but it really can't build the tree structure (for a variety of reasons unrelated to this question.)
At any rate, that needs to translates to a tree like this (the actual order doesn't matter, just the hierarchy.):
++ root
|-+ mainGroup
| |-+ groupA
| | - item1
| | - item2
| |-+ groupB
| | - item3
| | - item4
| |-+ groupC
|-+ someOtherGroup
| |-+ groupD
I know how to group flat data using a grouping collection, as is described here. But I haven't had any luck figuring out a way to get flex to actually read/interpret the delimited format (without preprocessing it and building the correct structure myself.)
Thanks in advance for any suggestions.

I think pre-processing it is going to be the only way. What I mean by that is having a method you write that creates the GroupingCollection appropriately based on an algorithm which is based on your initial data.
The split method:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/String.html#split()
GroupingCollection:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/GroupingCollection.html#grouping
Grouping:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/Grouping.html#fields
GroupingField:
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/collections/GroupingField.html
In looking through the docs they do have those groupingObjectFunction properties though for the life of me I can't understand what that's supposed to do.

Related

Problem with Kusto Query with nested JSON parameters Sentinel Log Analytics

I'm trying to extract some information from a nested JSON in log analytics.
It is nested several levels deep though. And I come unstuck at the 3rd tier.
The scenario is to query on what user ID has had permissions removed in Azure. the ifnormation is all there is raw format, but I want to extract it to be more readable.
The data layout is :
AzureActivity
Properties_d
responseBody
properties
principalId
It's the principalID I want (getting a UPN from AAD comes later ;)
My query works to a point. But the _propertieslevel3 comes up blank (no error).
_resonsebody is fine. It is a dynamic JSON that contains the responsebody field from Properties_d.
AzureActivity
| where (OperationNameValue contains "ROLEASSIGNMENTS/DELETE" and ActivityStatusValue contains "SUCCESS")
| extend _responsebody = parse_json(Properties_d.responseBody)
| extend _propertieslevel3 = parse_json(_responsebody.properties)
| extend ModifiedUser = parse_json(_propertieslevel3.principalId)
as _propertieslevel3 comes back blank, so does modified user. I can only guess that there is a problem trying to nest this deep.
Any ideas?
TIA.
data sample of Properties_d
{"eventCategory":"Administrative",
"eventDataId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"eventSubmissionTimestamp":"2022-03-09T16:53:26.4493278Z",
"resource":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"resourceProviderValue":"MICROSOFT.AUTHORIZATION",
"subscriptionId":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"activityStatusValue":"Success",
"entity":"/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.Authorization/roleAssignments/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"message":"Microsoft.Authorization/roleAssignments/delete",
"hierarchy":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"caller":"xxxxxx#xxxxxxx",
"httpRequest":"{\"clientIpAddress\":\"3.3.3.3\"}",
"statusCode":"OK",
"serviceRequestId":"",
"activitySubstatusValue":"OK",
"responseBody":"{\"properties\":{\"roleDefinitionId\":\"/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.Authorization/roleDefinitions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\",
\"principalId\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxx\",
\"principalType\":\"User\",
\"scope\":\"/subscriptions/xxxxxxxxxxxxxxxxxxxxxx\",
\"condition\":null,
\"conditionVersion\":null,
\"createdOn\":\"2022-03-09T11:28:48.4781104Z\",
\"updatedOn\":\"2022-03-09T11:28:48.4781104Z\",
\"createdBy\":\"xxxxxxxxxxxxxxxxxxxxxxxxx\",
\"updatedBy\":\"xxxxxxxxxxxxxxxxxxxxxxx\",
\"delegatedManagedIdentityResourceId\":null,
\"description\":null},
\"id\":\"/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.Authorization/roleAssignments/xxxxxxxxxxxxxxxxxxxxxx\",
\"type\":\"Microsoft.Authorization/roleAssignments\",
\"name\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\"}"}
Most likely, you need to apply parse_json() on the nested property bag too.
See: https://learn.microsoft.com/en-us/azure/data-explorer/kusto/query/parsejsonfunction
got it :)
Not sure why I needed to make _propertieslevel3 be just be the same as response body, rather than being able to extract .properties
but it works.
Thanks.
AzureActivity
| where (OperationNameValue contains "ROLEASSIGNMENTS/WRITE" and ActivityStatusValue contains "Start")
| extend _responsebody = parse_json(Properties_d.responseBody)
| extend _propertieslevel3 = parse_json(tostring(parse_json(_responsebody)))
| extend _level4 = parse_json(tostring(parse_json(_propertieslevel3.properties)))
| extend ModifiedUser = parse_json(tostring(parse_json(_level4.principalId)))

Reusing components

Can someone please help me to better understand components, queries, etc. I'm struggling with a seemingly trivial task, I need one component with parametrized query. Instances of that component need to be included in a parent component,
for example I want lists of different kinds of fruits that need to be distributed among group of kids and each row would show kid's name and a quantity of fruits of one kind:
(defui FruitsLedger
static om/IQuery
(query [this]
'[(:data/fruits) {:kind ?kind}])
Object (render [this]
(let [{:keys [data/fruits]} (om/props this)]
(dom/ul nil (apply #(dom/li nil (str "for " (% :kid) " " (% :qt))))))))
now I need to have let's say two instances of this component in another component
where :params
for the 1st instance would be: {:kind :apples}
for the 2nd instance would be: {:kind :oranges}
this should render 2 lists similar to this:
| apples | oranges |
|---------------+---------------|
| for Aaron 2 | for Katie 1 |
| for Dan 1 | for Rob 3 |
| for Charles 0 | for Charles 3 |
| | |
|---------------+---------------|
I'm sure that parameterized queries have their uses. But perhaps this problem and other similar ones can be solved without resort to them.
Have :app/fruit-query-kinds in your db (default db format). It will be a list of fruits. You already have the fruit component, but you will need another component that has this idea of being a list of fruit kinds for querying purposes. Give this component a query and an ident. It doesn't matter if it is going to be displayed or not. Most important thing is getting the data structure right. Its ident will just be something like: '[:fruit-query-kind/by-id 1100], and it might consist of '[:fruit/by-id 10] and '[:fruit/by-id 20]. As per your example 10 will be the id for apples and 20 for oranges. That will be the refs value (a vector of idents in default db storage) of the key :app/fruit-query-kinds. 1100 is just a unique number that won't be expected to change.
The data structure is the important thing, and everything can be modelled in it, even query parameters.
You will need mutations and some buttons (or other input) that call transact! somewhere that directly change the fruit query kinds in your db. If you don't need any re-rendering to happen call transact! with the app's reconciler rather than with a component.
The idea is that you can then have component/s that query on the choices previously made by the user. So your first list component there won't know that it is to be for apples - all it knows is that it is to display fruits of the first fruit query kind.
I've found that you can do as much to-ing and fro-ing between the view and the db as you like, having the db not just store data but the current state of the view. So far the only time I got into trouble with this was when I mistakenly transacted on the not of the boolean key in the component's query. That of course ended up in a forever flickery screen.
In my opinion the way to work simply with Om Next on the Client is for all your reads to look exactly the same, all using db->tree. Once you accept this approach the next step is to get rid of them all together, which you can do by switching to the Untangled framework.

Where to store dictionary data or function to be available in multiple Polymer elements?

I'm using Polymer to build an application that presents a data table. Every cell in the table contains a coded value.
I want that every time a user clicks on a cell, the value gets translated to a more descriptive tag.
Example:
| Page | Response |
|-------------------|----------|
| example.com/one | 200 |
| example.com/two | 200 |
| example.com/three | 500 |
| example.com/four | 301 |
Then I click on the 301:
| Page | Response |
|-------------------|----------|
| example.com/one | 200 |
| example.com/two | 200 |
| example.com/three | 500 |
| example.com/four | Redirect |
The table is a webpage-list element that contains a dom-repeat template of paper-items wrapped in a row element I've called like webpage-item.
I am creating a different element for any type of cell (in the example: one response-field element, then another could be content-type-field and so on).
Except, my table has several coded columns and the dictionaries are huge.
Where should I store the dictionary? I guess an app-scoped (global) dictionary object would be instantiated for every single cell, resulting in a massive resource leak.
Is there a way to provide a "translator" element to be called by reference by every cell? And... is this the right path to take?
Another path I am considering is letting the dictionary on the server, and then make REST calls every time I need a translation. But then, I would still need a translator element to handle the caching.
The iron-meta element was built for this purpose.
You can also build a custom more specialized element for this purpose.
Each instance of iron-meta just provides access to a shared (static) container.

Traverse a DAG (Directed Acyclic Graph) from specified node to create a tree view

I am putting together a parts database using the method below for directed acyclic graphs.
http://www.codeproject.com/Articles/22824/A-Model-to-Represent-Directed-Acyclic-Graphs-DAG-o
I am able to build my data set using the SQL queries from that page which I have converted to MySQL.
Previously I have used the nested sets model although we found that deletions became a problem.
I am unable to find any information on how to traverse the tree using this model. I simply need to be able to create a html tree to show the descendants from a selected parent node and identify leaf nodes (will be using jstree).
I can post the code from the nested sets model if that helps. I don't need any help with the html it is the SQL I am stuck with.
Does anyone have any idea where I can find information on the query I need.
EDIT:
Following on from the commments I'd like to adapt to something more closely linked to Bill Karwins closure model. http://www.slideshare.net/billkarwin/models-for-hierarchical-data
I notice however that on slides 49-50 which is where I want to select the descendants of a node that the output doesn't seem to provide enough to draw a simple tree. Previously with the nested sets model I was able to get a similar output that would traverse left to right, top to bottom. I'll try to explain.
Item | Depth
1 | 0
2 | 0
3 | 1
6 | 2
7 | 0
9 | 1
This allowed me to draw a tree as the SQL listed the order of descendants in a more manipulatable way. I believe it created "depth" by using a COUNT of subtrees and I will dig out the query if it would be useful here.
Thanks again for all your help.

Graphs - find common data

I've just started to read upon graph-teory and data structures.
I'm building an example application which should be able to find the xpath for the most common links. Imagine a Google serp, my application should be able to find the xpath for all links pointing to a result.
Imagine that theese xpaths were found:
/html/body/h2/a
/html/body/p/a
/html/body/p/strong/a
/html/body/p/strong/a
/html/body/p/strong/a
/html/body/div[#class=footer]/span[#id=copyright]/a
From these xpats, i've thought of a graph like this (i might be completely lost here):
html
|
body
h2 - p - div[#class=footer]
| | |
a (1) a - strong span[#id=copyright]
| |
a (3) a (1)
Is this the best approach to this problem?
What would be the best way (data structure) to store this in memory? The language does not mather. We can see that we have 3 links matching the path html -> body -> p -> strong -> a.
As I said, i'm totally new to this so please forgive me if I thought of this completely wrong.
EDIT: I may be looking for the trie data structure?
Don't worry about tries yet. Just construct a tree using standard graph representation (node = {value, count, parent} while immediately collapsing same branches and incrementing the counter. Then, sort all the leaves by count in descending order and traverse from each leaf upwards to get a path.