Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Wed Aug 06, 2008 7:50 pm   

Using %subregex to sort/format data.
 
Have given it quite a bit of thought during today and even though I read through usual %subregex help + advanced one, I can't seem to crack it on my own.

Code:

 <var name="RoomDB" type="Record" id="1795">12931=10|12934=11|12939=12|12826=1|12949=13|12832=2|12837=3|12920=5|12921=6|12926=7|12928=8|12848=4|12929=9
</var>


Until now (under ZMud) I've used #loopdb and %format to visually format the info above to my liking.

However, I started to wonder whether under CMud its nicer and ultimately faster to use Subregex instead.

I was thinking about using the %dbitems(var) within %subregex and then formatting it by removing pipes and adding line breaks.

But as I said, I seem to be unable to crack it (and not even sure it's possible directly via subregex in the first place).

To set things straight, thats the code I was using until now.

Code:

#show {%ansi( 8)Filter: %ansi( 15)%format( "&5.0f", %val) %ansi( 8)Virtual: %ansi( 15)%format( "&5.0f", %key) %ansi( 8)Zone: %ansi( 15)%zonename( %roomzone( %key)) %ansi( 8)Room: %ansi( 15)%roomname( %key)}


(Credit goes where's credit due - all this is part of a bigger script which original idea came from an user named Full Throttle I believe.
As time has gone by, the code bit above is pretty much only thing left from original code, though Wink)

Hopefully someone can help me out with this idea.

Thanks in advance.

Prog
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Wed Aug 06, 2008 11:28 pm   
 
Did you search the forums? There was a post by Vijilante recently on sorting using %subregex...
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Aug 07, 2008 8:52 pm   
 
There actually is a bug or 3 in %subregex currently. They will be all cleared up in the next beta. If you look at that other post I have the exactly right group of functions for the reverse sort, but one of the bugs causes it break.

For your particular application I would also suggest eliminating the usages of %roomzone and %roomname, by using a JOINed SQL query. I think my Toolbox package has at least one or 2 examples of such a query, and I did plan on adding more. The benefits of doing this is a considerable speed jump.

Basically I would say ask again when the next beta is available.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Aug 15, 2008 7:01 pm   
 
It definitely looks like 2.36 cleared up the few odd bugs in %subregex. If you give me enough details about how your record variable is generated and what you want the output to be I should be able to come up with something that produces it much faster then your current #LOOPDB.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Fri Aug 15, 2008 7:15 pm   
 
I wish I'd know %subregex quite a bit, too. Feels like a very powerful command, but I still haven't completely understood it, heh.

However, the record variable generation etc is fairly simple.

Code:

#loop %numrooms {#addkey RoomDB {%roomvnum( %i)} {%i}}


This makes a db variable with %roomvnum as key and loop number as value. Those values are used later for walking into a
given room after I've parsed the data visually so that I can choose which number to take.

So far, thats what I've used for visual output.

Code:

#loopdb @RoomDB {
      #show {}
      #show {%ansi( 8)Filter: %ansi( 15)%format( "&5.0f", %val) %ansi( 8)Virtual: %ansi( 15)%format( "&5.0f", %key) %ansi( 8)Zone: %ansi( 15)%zonename( %roomzone( %key)) %ansi( 8)Room: %ansi( 15)%roomname( %key)}
}


This formats the data like that:

Code:

Filter:     1 Virtual: 12899 Zone: xxx Room: xxx
Filter:     2 Virtual: 12938 Zone: xxx Room: xxx
Filter:     3 Virtual: 12956 Zone: xxx Room: xxx


I suppose for you it'd be a piece of cake. I just really want to understand stuff with %subregex eventually myself, too.
I guess I'll just look at your code in deepest detail and figure it out, maybe, eventually Confused

Thanks for your help.

Prog
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Fri Aug 15, 2008 7:47 pm   
 
I am guessing you are using %mapfilter to control the rooms that are matched in this loop.
Code:
#loop %numrooms {#addkey RoomDB {%roomvnum( %i)} {%i}}

As demonstrated in another topic, and by my own experience, creating a single query that returns all the data desired from the map is much faster then %mapquery. My experience and timing test show that adding a correlative roomname lookup to a query, directly into a query, is exponentially faster than a loop using %roomname. This is true of all mapper related zScript functions because each call to the %roomxxx function requires it ensure proper thread synchonization, whereas the query only has to synchronize once to complete retreival of all the data.

Zugg has mentioned that some of the structure of the map database will change in future versions. The direct query system that is published as part of my Toolbox package is obviously dependent on the MDAC/ADO implementation. I would prefer to write a query and formatting routine that uses my published package and requires only that my package be updated to work with a future version, instead of writing a half assed portion based on an unoptimized filter. Please provide some details about the filter you are using.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Progonoi
Magician


Joined: 28 Jan 2007
Posts: 430

PostPosted: Fri Aug 15, 2008 8:03 pm   
 
Yeah, you guessed correctly.

Below is one of the complete parts of the code I'm currently using.

Code:

#if ((%1!="") and (!%isnumber( %1))) {
  RoomSearch=%1
  #call %mapfilter(%concat("Name"," LIKE ","'%",%replace(@RoomSearch,"'","''"),"%'"," AND ","ZoneID"," = ",%zonenum))
  RoomDB=%null
  #call %vartype(RoomDB,5)
  #loop %numrooms {#addkey RoomDB {%roomvnum( %i)} {%i}}
  #call %mapfilter(%null)
  #if (%numkeys( @RoomDB)=1) {#loopdb @RoomDB {#walk %key}}
  #if (%numkeys( @RoomDB)>1) {
    #show {}
    #loopdb @RoomDB {#show {%ansi( 8)Filter: %ansi( 15)%format( "&5.0f", %val) %ansi( 8)Virtual: %ansi( 15)%format( "&5.0f", %key) %ansi( 8)Zone: %ansi( 15)%zonename( %roomzone( %key)) %ansi( 8)Room: %ansi( 15)%roomname( %key)}}
    }
  }


This particular part is used when parameter added to alias isn't an empty one nor a number.
Basically this part is activated when I, for example, enter "wal stables" into command line.
Its just one example. There are few others where data is returned by different set of rules.
Hope this helps.

Btw, in one other thread I was suggested to use %mapquery instead actually. All this stemmed from my idea of learning direct COM queries to use getting the data and then parsing it afterwards. I put that idea on hold, because ADO is being switched for SQL soon anyway and then all of that work would be for nothing.

Prog
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net