Displaying deeper levels programmatically in a Oracle APEX tree hierarchy - sql

I have a situation where I am going to have a fairly large dataset that I need to represent as a tree hierarchy within Oracle APEX v4.2.2. The dataset might be up to 6000 records with a depth of 5 levels.
Based on another thread, what I am looking at doing and this being the reason of this question, is initially within my tree query, I will only display up to 2 levels, i.e.:
WHERE level <= 2
My question is, while displaying my tree hierarchy of level <= 2, I want to then allow the user to click on a level 2 node, which would be fed somehow back into my tree hierarchy query and then basically display from a level 2 node down the tree to say the next 2 levels - now displaying from level 2 to level 4 and then continue in the same fashion.
Obviously I will also need a means of getting back to the top level of my tree from any lower levels being displayed at the time - say from level 4.
I am interested in how to best tackle this - I was also thinking whether I display a popup window of the next set of tree hierarchy data.

I think 6k records is still manageable by Javascript, so probably the easiest way would be to load the entire tree and collapse it onLoad with a Javascript/JQuery dynamic action.
Otherwise you can also try storing the desired level/key on a Hidden Page Item, build the tree hierarchy query using the value from this page item and just refresh the area with a dynamic action onClick.

Related

Count showing (visible) rows of a QTreeView

I found this question and this question.
I've also searched elsewhere.
The situation is that (starting with all root item children collapsed) my code iterates through the tree expanding the parents of those items whose data matches a certain criterion.
I just want to find the total number of showing rows displayed in the QTreeView at the end of that process. NB I use the word "showing" rather than "visible" as this is not a question about viewports: I want the total number showing assuming a viewport large enough not to have to create a vertical scrollbar.
Is there really no simple way to achieve this? Counting the total children displayed by, for example, counting all children of all parents which are expanded in this manner, as they get expanded, would be quite complex: sometimes, for example, two siblings meet the criterion, so the first expands its parent, but the second obviously doesn't. Not only that, but a node located deep in the tree expands not only its own parent, but (if necessary) its grandparent, great-grandparent, etc.
In view of the complexity of the foregoing, another possibility would be to iterate through the tree again, after expanding, in order to count the rows displayed. This seems a ludicrous effort just to get such a simple piece of information.
Please note that I'm talking about QTreeViews, not QTableViews. With the latter it appears that it possible to use table_view.verticalHeader().count(). But a QTreeView doesn't have the method verticalHeader.
QTreeView provides the indexAbove() and indexBelow() functions, and the latter:
Returns the model index of the item below index.
def count_showing_rows(self):
count = 0
index = self.model().index(0, 0)
while index.isValid():
count += 1
index = self.indexBelow(index)
return count

SSAS -How to select a particular attribute when we drag dimension into query editor

I have about 4 attributes in Race dimension as shown in blow
dimension name is Race
1)Race
2)RACE DESC
3)RACE KEY
4)RACE SHORT NAME
when go to cube browse and right click on Race dimension and select add query
as below
1)when i drag Race dimension to browser data panel it showing default Race Attribute data
2)i want show RACE DESC data only
3) at the same time i drag the RACE DIMENSION in Filter panel
4) i want show RACE DESC Attribute only
5) i don't want set attributehierarchyvisible =false
how do i achieve my above requirement
Thanks for the help
Create your own user's hierarchy and place it on the 1st place in dimension hierarchies part of screen. This will let SSAS to use it.
Here Report Date hierarchy is selected by default.
And Product Categories on the image below:
UPDATE
Here is detailed explanation:
Now you have 5 flat hierarchies and server takes first alphabetical one by default, like this (Count is measure here):
To fix this, you need to disable attributes hierarchy, which you want to be selected by default:
Than rename attribute, to be able to create user's hierarchy with the same name (so for users this will be identical as previous flat attribute hierarchy):
Finally, process this dimension again, and when you drag dimension, it will show your first user's hierarchy, which is State in our case.
Hope this helps.
UPDATE-2 (New example with races)
To achieve this, you need to do the same as described in UPDATE #1:
Rename RACE DESC to some other name (e.g. RACE DESC Attr) and disable it's hierarchy visibility by setting attributehierarchyvisible = false
Create user's hierarchy on this attribute with desirable name: RACE DESC
Process dimension.
That's all. Now default attribute will be RACE DESC. It's hierarchy is not disabled, just it's showing priority is changed to be the 1st one.

How can I summarize and reuse a complex dataset

How can I re-use a single complex dataset across a number of tables?
The dataset has a number of computed columns that needs to be reported both in detail and in summary. Here's a very simplified example dataset:
is_food sale_association food_type total_sold total_associations percent_total
1 Before Movie Popcorn 50 3 x BirtMath.safeDivide(...)
0 Before Movie Soda 10 2 x BirtMath.safeDivide(...)
1 During Movie Jujubee 10 1 x BirtMath.safeDivide(...)
0 After Movie Soda 15 2 x BirtMath.safeDivide(...)
From this one dataset, I'd want to create a detailed summary of all food types while rolling up non food (using the 'is_food' column), another summary of all food types, another detailed summary of food with rolled up non-food by sale_association, etc. etc.
The report would also contain a number of percentages (6 in the most complex table) that need to be calculated (some across a row, others across all rows in a given group), all of which can have a zero value for the denominator and so need to be guarded against with safeDivide (which is a PITA to do in the source SQL query which itself is doing aggregation -- checking for divide by zero when both the numerator and denominator are sums leads to hairy queries).
Obviously I can do this by focusing the() SQL query as appropriate, but it seems like a waste of time and effort to create 12 or 15 queries that are very similar when I've already managed to create the monster query for the most detailed table.
What doesn't seem straightforward is how to perform the rollups in a table. I managed to hack something together by hiding rows that would later be summed up (e.g. "is_food == 0" in the example) and then creating custom data bindings that are displayed in a footer row. Not only does it feel like a hack, it also interferes with the ability to naturally order rows. Again, going back to the example, if I was ordering by total_sold and summarizing rows with is_food == 0, the natural order should be Popcorn, Non-food, Jujubee.
There's nothing in the BIRT wiki about this, nor does "BIRT: A Field Guide, 3rd E." really delve into the topic.
This seems like a fairly open-ended question (although I agree that re-using a single dataset makes much more sense than having multiple queries retrieving the same data in slightly different ways). A few general suggestions:
Use the most detailed version of the data required as a common dataset for each BIRT report item (typically BIRT tables)
Where summary-only level reporting is required, add groups to the BIRT table at the desired level, add data items as required to the group headers/footers and delete the detail level row(s) from the BIRT table.
Where detail-level reporting is required in some cases (eg. for food items but not for non-food items), add groups to the BIRT table as above, and set the visibility of the detail row (in Property Editor - Properties - Visibility) to check Hide Element, then specify the appropriate expression to suppress the non-required rows (non-food items, in this example).
Aggregations (ie. summary expressions) can be added to tables by selecting the whole table, selecting the Binding tab within the Property Editor and clicking the Add Aggregation... button.

Dataset and Hierarchial Data How to Sort

This is probably a dumb question, but I've hit a wall with this one at this current time.
I have some data which is hierarchial in nature which is in an ADO.NEt dataset. The first field is the ID, the second is the Name, the third is the Parent ID.
ID NAME Parent ID
1 Air Handling NULL
2 Compressor 1
3 Motor 4
4 Compressor 1
5 Motor 2
6 Controller 4
7 Controller 2
So the tree would look like the following:
1- Air Handling
4- Compressor
6 - Controller
3 - Motor
2- Compressor
7- Controller
5 - Motor
What I'm trying to figure our is how to get the dataset in the same order that ths would be viewed in a treeview, which in this case is the levels at the appropriate levels for the nodes and then the children at the appropriate levels sorted by the name.
It would be like binding this to a treeview and then simply working your way down the nodes to get the right order.
Any links or direction would be greatly appreciated.
I would re-organize the data to be more normalized, however if you must work with what you have, do nested for statements (where the first one looks for the null in the parentID field. If you don't know how many layers deep the data goes, it will make your job more difficult, but it can be done.

How to only display a TreeView expand sign [+] if children exist

I've developed an application that populates a treeview from hierachical data in a database.
I've designed it to use lazy-loading so it only gets the child nodes when a node is expanded.
My problem is that obviously I don't know if a node has children unless I make a call to the database and look. Currently I have implemented a dummy child node, so that the [+] icon appears for all nodes, I then remove this dummy node and get the real child nodes in the BeforeExpand event.
This means I get a [+] icon for nodes that don't have child nodes, so the user clicks the expand icon and there's nothing show which looks a bit shoddy.
What is the preffrred method for handling child nodes in a lazy-load treeview? If I make a call to the database to see if there are child nodes then I might as well just load the child nodes and forget about lazy loading right?
One thought I had was to store a 'HasChildren' flag in the database, so I can selectively create my dummy child node only for the nodes that actually do have child nodes.
Sorry for rambling on, I'm very interested to see what other people think...
When you make a call, check for children along with the node data:
SELECT tp.*,
(
SELECT 1
FROM table tc
WHERE tc.parent = tp.id
LIMIT 1
) AS has_children
FROM table tp
You don't have to count, it may be long.
Just check that at least one child exists.
change your initial query to return all the same data, but also a count of children. when the children count is not zero show the [+]. post your schema and query for help getting the count
My preferred solution to this problem is to implement pre-ordered tree traversal on your set of hierarchical data. See http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/ for an example implementation.
The point is that if you maintain a left and right value for each node, then if the left value and right value differ by more than one, that node has children.
The only notable downside of this approach is that you have to actively maintain those left and right values when altering the structure of the nodes.