number of subitems

Help each other out

number of subitems

Postby badubo on Thu Aug 03, 2006 3:33 pm

Hello,
inside a category, is there a way to know the number of subitems an item has ? (through a variable "category>???")
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Postby P3rv3rt B3ar on Thu Aug 03, 2006 5:03 pm

I plan to implement it in next version of xPerT.
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby badubo on Thu Aug 03, 2006 5:18 pm

I plan to implement it in next version of xPerT.


Ok, but, I need it for writting a plugin :wink:
Do you have an idea how to implement it?
My idea was to go down and then make a count using Next item command but unfortunatly, I cannot find a way to go down in a category
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Postby P3rv3rt B3ar on Thu Aug 03, 2006 5:52 pm

badubo wrote:
I plan to implement it in next version of xPerT.


Ok, but, I need it for writting a plugin :wink:
Do you have an idea how to implement it?
My idea was to go down and then make a count using Next item command but unfortunatly, I cannot find a way to go down in a category


Yes, there are internally methods in expert already in place which do it. I needed it for weighted random (regular random is just special case of it with weight 1, and that does exactly what is needed.) I just forget to make these methods available externally.

Ive been trying to explain here on several post already how to go down to subcategories. Check my post on this thread, it works perfectly http://www.xlobby.com/forum/viewtopic.php?p=30526&highlight=#30526
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby badubo on Thu Aug 03, 2006 6:49 pm

thanks for the link,
But I'm not sure to fully understand
what are you calling subcategory et supercategory?
How are they related?
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Postby P3rv3rt B3ar on Thu Aug 03, 2006 6:53 pm

Well if we take for example music database... supercategory could be cat called "music", which contains albums, while subcat could be "musicdetails", which contains individual songs.

But thats just example, in general relation is supercat contains subcat and depth of subcat is one less than supercat.

Heres pseudo code for u:

count (catpath)
{
if (catpath is leaf) return 1
else
{
int lkm=0;
divide catpath to currentcat and restofcatpath
XpluginHelper.sendCommand("command:category:reset:"+currentcat);
while(!catwalk complete)
{
lkm+=count(restofcatpath)
walk to next item in currentcat;
}
return lkm
}
}


Definition of rest of terminology:

Catwalk: Moving in category using nextItem command. Catwalk is said to be complete when current cat has been walked trough.

CatPath: Expression to fully descripe a category. for example in above category structure example catpath to "musicdetails" cat would be "music>musicdetails".

Oh, and here leaf refers to ""-sentinel, or item actually, empty string in restofcatpath when theres no more subcategories left to enter.

That pseudo algorith is general. It can handle any depth (thanks to recursion) and any categories. Only limitation is that u have to have all categories mentioned on catpath, though these can be dummy categories, and u need a way to determinate when catwalk is complete, hence u need a keyfield, which has unique value. Both of these limitations exist in xPerT too cause this is how xPerTs catwalk algorithms are implemented.

Now if u want to count all your songs and your music database structure is as mentioned abowe u use count with catpath "music>musicdetails"

and if u want to count how many songs particular album has, u have to first catwalk to that particular album and then call count with catpath "musicdetails".
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby badubo on Thu Aug 03, 2006 10:29 pm

Thanks for your explanations

If I understand, you need to have in your skin as many categories as depth in the dba, right?
But how can you create categories that belong to a particular level?

musicdetails is a special case in xlobby, this category contains subitems of the selected item in music.

Lets take an example :
I have a database that contains all my TVseries, sorted by seasons then episodes : (the complete path is Serie>Season>episode)

Serie1+season1+ep1
+ep2
+.....
+season2+ep1
+ep2
+.....
serie2+season1+ep1

etc...
How do you proceed (in the skin and/or in the code) to create all subcategories

if the main cat is Serie : a cat called Seriedetails will show seasons, but how can I create a category for the episodes (so that show details of the season level)?
badubo
 
Posts: 505
Joined: Mon May 03, 2004 7:33 pm
Location: Belgium

Postby P3rv3rt B3ar on Thu Aug 03, 2006 10:41 pm

That is good question.

I hope some skinner can shed some light on this one.

I never experiment with categories over depth 2 (at depth 2, everything works fine). I just made my code to work on any depth cause i assumed that deeper (mapped) cats are possible, cause in DBs atleast depth can be higher than 2.
Last edited by P3rv3rt B3ar on Thu Aug 03, 2006 11:44 pm, edited 2 times in total.
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby P3rv3rt B3ar on Thu Aug 03, 2006 11:04 pm

Unless skinners provide us with solution... i guess we have to start to beg xxx(details)*n type of cats from steven... unless u take ugly direct route to database .xml files.

Im bit sad now... tried to make general depth algorith... only to find that XLobby limits depth 2. Skinners is this really true? or is there some hack for this?
P3rv3rt B3ar
 
Posts: 1364
Joined: Fri Apr 07, 2006 9:52 pm
Location: West Coast Funland

Postby stevenhanna6 on Fri Aug 04, 2006 4:56 am

You guys are making it to complicated, here is an easy way


%music>branches%
%music>total%

this is a the new one I think you want
%music>selectionsubitems%

If those arent engough I can add more. Of course "music" is just the name of a category, you can use it on any category.
stevenhanna6
 
Posts: 904
Joined: Tue Feb 18, 2003 10:39 am
Location: Ontario, Canada