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
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Sun Apr 13, 2008 7:52 pm   

Help with dynamic roundtime tracker
 
So I'm trying to get a tracking script going that will keep the values of how long it takes to kill a mob for different forms that I can inhabit. I have a lot of different forms I can use so i'm trying to make this as dynamic as possible to make the code work for every form. I have an event, killrate that is set up like this at the moment:
Code:

#LOOP 1,%numitems( @killrate) {
  $index=%eval( %i/2.0)
  #if ($index != %int( $index)) {#if (%begins(%db(@{krate@{form}},%item(@killrate,%i)),"|") {#exec %remove("|",@{krate@{form}.%item(@killrate,%i)}
    #addkey %concat( krate, @form) %item(@killrate,%i) %concat(%db(@{krate@{form}},%item(@killrate,%i)),|,%item(@killrate,%eval(%i+1)))
    }
  }

the variable, killrate is setup like this:
Code:

Variable: + killrate            (Auto)        Beast|9|Monster|10|Monster|17|Monster|12|Beast|7|Beast|12|Beast|8|Monster|13|Ogre|9|Orc|7|Beast|17|...


so what my script does at the moment is it loops through all the values, and if %i is odd (where it is a mob's name) it executes the script. so that's what the $index, #if ($index = %int()... accomplished, it just loops it 1,3,5,ect. The #if (%begins is a code in progress to try and strip the | from the beginning of the record variables that occurs when there is no previous record of that kill. currently the output looks like this:

Code:

Variable: + kratedwarf         (Record)      Beast="|9|9|9|11|17"|Monster="|13|10|12|13|8|8|6|9"|Orc="|16|17|16|16|16|16|16"...


THis code right here,
Code:

#addkey %concat( krate, @form) %item(@killrate,%i) %concat(%db(@{krate@{form}},%item(@killrate,%i)),|,%item(@killrate,%eval(%i+1)))

is what makes the above variable, it adds a key to the current form.

So this is where I was thinking lua might be a good option to learn in doing this (from what I hear about its tables). What I want from this script is a list to compare my kill times to to see what kind of changes certain weapons/skills/stats are making on my character. So I want to have a display such as "killrates <form>" that will show a list of mobs I've killed, its average rounds to die and a stand. deviation, that stuff I can make on my own but I am having problems with manipulating my variables because of the need to concatenate my variables together from different variables. I tried using a local variable like $ratevariable=%concat(@,krate,@form) and using that to eliminate this possibility, but without luck. What I'm looking for is ideas on how to implement the information of my killrates variable into a form what I can calculate this information. And a setup that will not require individual code for each form.
Reply with quote
gamma_ray
Magician


Joined: 17 Apr 2005
Posts: 496

PostPosted: Mon Apr 14, 2008 12:54 am   
 
Yeah, this is a mess, but why don't you try using CMud's database function? (Not database variables, the.. er.. database database.) You'd need to set it up once using the gui, which should take about two seconds, but after that it's very scriptable.

Keeping your current form for the @killrate variable, you could then add stuff like this:
Code:
#loop %eval(%numitems(@killrate)/2) {#NEW krate {Form=@form|Mob=%pop(killrate)|Rate=%pop(killrate)}}


And you could get, say, the standard deviation (times 100) for all things killed while in {whatever} form using:
Code:
#query (&form=="%1") {} 1;#show %stdev(rate);#dbreset
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Mon Apr 14, 2008 1:59 am   
 
Hmm...i like the idea of making it into a database like format, but I'm horrified at the thought of using the database within zmud/cmud because of how slow it becomes as it grows. But I guess maybe setting up a com server with excel might be a solution. After what I saw with Fang's tutorial on lua i thought that perhaps Lua's tables could have the same layout of an excel spreadsheet but all be contained within zmud. I'm going to pursue both avenues I suppose, though I have never touched LUA. The first problem would be looping through a list and assigning a table based off this information, I can strip the variable to have only mob names w/o duplicates and loop that, but I'm going to need to get some lua help i'm sure of. Essentially the overall design I want would be a table named Form killrates, within that have a Form, say Dwarf, and within that have mob names with lists of the roundtimes per mob.
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Mon Apr 14, 2008 2:14 am   
 
At this point if I were going to do anything with a database I would try this nifty toy out.

http://forums.zuggsoft.com/forums/viewtopic.php?t=30282
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Mon Apr 14, 2008 8:16 pm   
 
Good idea Arminas Smile its definitely faster than using zMUD/CMUD current builtin database.
Chris if you do decide to give it a try and need some assistance I'd be pleased to help.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Tue Apr 15, 2008 1:17 am   
 
Well thanks for the offer, I really liked that database component but some things that immediately come to my mind as problems is using variables within the execute calls, and the problem that the table would have to be expanded each time a new mob was added if I set it up so only one table was used. So I'm supposing the best setup now would to be one table per form, having the first field be mob # in record to keep it unique, 2nd value mob name, 3rd value round time, and just for the hell of it add the xp value in the 4th so I could use that later if i felt like it. First order would to be to find a way to get a record count from the database, the rest should really be easy. I've never played around with SQL databases so any help would be appreciated. I'll try this myself and hope someone beats me with a solution before I edit this post :)

So far I have this in my trigger that will essentially be a killing blow and have all the relevent information such as xp change, ect

Code:

#if @killrates.IsOpen() {} {#var killrates %comcreate("Sqlite.ZMUD.WSC");#call @killrates.Open("roundtimes")}
#show @killrates.AbsolutePath()
//#call @killrates.Execute("create table "@form" (entry,mob,rounds,xp)")
#var entryvar @killrates.Execute("SELECT * FROM "@form" WHERE entry>?","0")
#show @entryvar
#var entryvar %numitems(@entryvar)
#show @entryvar
#if (@entryvar) {#show tru;#call @killrates.Execute("insert into "@form" values(?,?,?,?)",""@entryvar"",""@mobkilled"",""@mobrounds"",""@xpchange"")} {#show false;#call @killrates.Execute("insert into "@form" values(?,?,?,?)","1",""@mobkilled"",""@mobrounds"",""@xpchange"")}


So the problem at this stage seems to be calculating an entry var, I tried using @killrates.Execute("SELECT COUNT(entry) FROM "@form"") without any luck. THe entry var is what I'm going to use as my index, and that isn't working well. Is there some sort of autoid value that can be set in the table? Also is there a way to check if that form already has a table created? I commented out that line until I can figure out how to do that.


Last edited by chris-74269 on Tue Apr 15, 2008 2:58 am; edited 2 times in total
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue Apr 15, 2008 2:37 am   
 
Getting a record count for records that match a particular query is easy, use the COUNT() function.
SELECT COUNT(*) FROM tablename would return the total number of records in a certain table.
You can also count specific things by using a clause.
SELECT COUNT(*) FROM tablename WHERE Form= 'Form1' to get the number of records where the Form column contains the string "Form1" or whatever it is you want to search.
I'm not sure what problem with variable in the execute calls would be.
a typical SQL statement with variable arguments would be called like this.
if the variable @conn contained the Database componented opened to whatever database you're using.
then

Code:
#var fval = "Someform"
#var kval = "12"
#var result {@conn.Execute("SELECT mobname,krate,level FROM mobtable WHERE Form=? AND krate > ?",@fval,@kval)}


Could return a stringlist of either stringlist or db variables(depending on how you configured @conn), with the mobname,krate and level, of each record where the Form contains a value of "Someform"
and the krate is greater than 12 or whatever.

In the Execute call above the two question marks are substituted with the value of @kval and @fval.
What the database engine would see is
Code:
"SELECT mobname,krate,level FROM mobtable WHERE Form='Someform' AND krate > 12"


Anyways if you gave me some sample data, and the operations you want to perform on it.
You know show me what you have, tell me what you're trying to do with it, then show me how it should look when you're done.
Given that info I'm certain we could get done what ya need.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Tue Apr 15, 2008 3:22 am   
 
C:\Program Files\CMUD\roundtimes
entry1mobAn Orc Herdrounds3322xp20183
entry1mobAn Ogrerounds3322xp20183


A problem that is arrising is vars are entering a lot more than they are being received as in entry var will be 4, then 4 again, but suddenly it will grow to 4, 8, 190, ect, almost like exponential growth. Also the entryvar itself is being listed as 1 in both of them, that doesn't seem to be adding up right. The output I would like is a table looking like:
Entry(some id #), Mob name, Rounds to kill, Xp
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Tue Apr 15, 2008 4:18 am   
 
If you kill a mob several times in a particular form do you want to record the XP , Rounds to Kill just once for each form/mob combo?
If not do you wish to say record the XP/Rounds each time meaning a new entry each time you kill a mob, or perhaps just a recent history say the last ten times? with older entries getting pushed out?
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Wed Apr 16, 2008 2:48 am   
 
I would like to record the roundtime per form for the last 25 times, and a timestamp I just thought would be good. This is to monitor subtle changes in my characters setup that may not be readily apparent. The xp value can be a one time thing, but the rounds should be each time. So a new entry each time with pushing old entries out of that same mob would be ideal to keep the database to a reasonable size where I can still get an average and a st. dev to compare results against. The relevant variables I use are:
@mobkilled for the mob's name
@mobrounds for rounds required to kill
@xpchange is the delta xp from that mob
@form is my current form

All these variables are already recorded. The layout of the database would best be 'Id, Mob name, Rounds, Xp garnered, time stamp'
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed Apr 16, 2008 7:02 pm   
 
I Hadn't noted that you had edited the post before my 2nd last post, no doubt you hit reply sometime before you actually submitted it.

chris-74269 wrote:
Is there some sort of autoid value that can be set in the table?

Yes there is CREATE TABLE IF NOT EXISTS tablename

Anyways looking at the code from that post I think you're missing some of the points in using a database.
You're dynamically creating new tables for each which I don't think is a very good idea.
I understand that you want to be able to clearly group the data by Forms, but this can be done with a query that filters by form.

I'm working on an implementation that requires only two tables.
One table FormMob is really just a lookup table that provides a uninue integer [FMID] for each Form/Mob combo.
The 2nd table Encounters Holds most of the info.
It's unique primary key is an autoincrement integer called EID
It has a reference to the FormMobs table FMID.
Since SQlite doesn't enforce foreign key references I have created Triggers for referential enforcement.
It also holds Rounds XP and Timestamp for each encounter.
an Encounter is simply a specific time when a MOB is killed by a particular form.
Anyways the SQL is below.


Code:
CREATE TABLE [Encounters] (
[EID] INTEGER  PRIMARY KEY AUTOINCREMENT NULL,
[FMID] INTEGER  NOT NULL,
[Rounds] INTEGER  NOT NULL,
[XP] INTEGER  NOT NULL,
[TStamp] TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL
);

CREATE TABLE [FormMob] (
    FMID INTEGER PRIMARY KEY AUTOINCREMENT,
    Form TEXT NOT NULL,
    Mob TEXT NOT NULL,
    UNIQUE(Form,Mob)
    );

CREATE INDEX [IDX_ENCOUNTERS_FMID] ON [Encounters](
[FMID]  DESC
);

CREATE UNIQUE INDEX [IDX_ENCOUNTERS_EID] ON [Encounters](
[EID]  DESC
);



CREATE TRIGGER [fki_Encounters_FMID_FormMob_FMID]
BEFORE INSERT ON [Encounters]
FOR EACH ROW
BEGIN

SELECT RAISE(ROLLBACK, 'insert on table "Encounters" violates foreign key constraint "FMID value is not present in FormMob"')
  WHERE (SELECT FMID FROM FormMob WHERE FMID = NEW.FMID) IS NULL;

END;

CREATE TRIGGER [fku_Encounters_FMID_FormMob_FMID]
BEFORE UPDATE ON [Encounters]
FOR EACH ROW
BEGIN

SELECT RAISE(ROLLBACK, 'update on table "Encounters" violates foreign key constraint "FMID value is not present in FormMob"')
      WHERE (SELECT FMID FROM FormMob WHERE FMID = NEW.FMID) IS NULL;

END;

CREATE TRIGGER fkdc_Encounters_FMID_FormMob_FMID
BEFORE DELETE ON FormMob
FOR EACH ROW BEGIN
    DELETE FROM Encounters WHERE Encounters.FMID = OLD.FMID;
END;

CREATE TRIGGER fkuc_Encounters_FMID_FormMob_FMID
AFTER UPDATE OF FMID ON FormMob
FOR EACH ROW BEGIN
    UPDATE  Encounters SET FMID = NEW.FMID WHERE Encounters.FMID = OLD.FMID;
END;




That SQL Is to setup the database it only gets called once you can use the ExecuteScript method of the Sqlite.ZMUD.WSC component.
What I do is use a tool like Sqlite Administrator, Sqlite Expert or the SQLite Manager plugin for Firefox, to set up the database.

Then this code below shows how you might use it.
It's bare bones no real error checking, but you can do that yourself.
Code:
<window name="untitled" host="0" usesession="false">
  <uid>{189D4896-7EAC-4B2B-A43D-3D30FD973F19}</uid>
  <packages>untitled</packages>
  <var name="killrates" id="1"></var>
  <func name="addentry" id="2">
    <value>;clean up form and mobkilled
$form = %lower(%trim($form))
$mobkilled = %lower(%trim($mobkilled))
;Inserts a new entry the FormMob table if this combo doesn't already exist
#CALL @killrates.Execute("INSERT OR IGNORE INTO FormMob VALUES(NULL,?,?);",$form,$mobkilled)
#CALL @killrates.Execute("INSERT INTO Encounters VALUES(NULL,(SELECT FMID FROM FormMob WHERE Form=? AND MOB = ? LIMIT 1),?,?,datetime('now');",$form,$mobkilled,$mobrounds,$xpchange)
#IF %null(@killrates.LastError) {#ECHO new entry added for $form and $mobkilled} {#echo error adding new entry for $form and $mobkilled : @killrates.LastError}

</value>
    <arglist>$form,$mobkilled,$mobrounds,$xpchange</arglist>
  </func>
  <func name="getFormEntries" id="3">
    <value>;$form = %lower(%trim($form))
#echo form $form
$result = @killrates.Execute("SELECT EID,Form,Mob,Rounds,XP,TStamp FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form=?",$form)
#IF (not %null(@killrates.LastError) ) {#echo Error in getFormEntries for $form: @killrates.LastError}
#return $result</value>
    <arglist>$form</arglist>
  </func>
  <func name="TrimFM" id="4">
    <value>#CALL @killrates.Execute("DELETE FROM Encounters WHERE EID IN (SELECT EID FROM Encounters WHERE FMID=(SELECT FMID FROM FormMob WHERE Form=? AND Mob=? LIMIT 1) ORDER BY EID DESC LIMIT  -1 OFFSET 25)",$form,$mob)


 </value>
    <arglist>$form,$mob,$limit</arglist>
  </func>
</window>


I actually have a more extensive version of the SQL posted above that uses VIEWS and TRIGGERS to allow you act as if there is only one table,Let me know if you want to see it.
I didn't want to scare you off by posting a huge SQL script, but really its no big deal since it only ever needs to be executes once, and its not necessary to do this in zmud.
Any of the tools I mentioned above could be used to enter the DDL (Data Definition Language) in seconds.

Anyways If I'm way off base lemme know I'll give it another go.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Thu Apr 17, 2008 12:02 am   
 
wow that firefox SQL manager is incredible. About your statement with using the multiple tables per form, I did this in thinking that there would be a speed benefit in queries. If each form would keep maybe 20 copies of round times per each unique mob, then that would get very large very fast. Having about 100 forms to use (in reality I use like 6 of them) But still with this, 6 forms * say 100 mobs * 20 entries per =12000 entries, and 100 mobs isn't a large amount of mobs. So that was my thinking in doing that. I'm going to play with your code and that sqlite firefox manager and will get back in a few hours about it. thanks
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Thu Apr 17, 2008 1:00 am   
 
Ok the only error in your script was a parenthesis missing on the addentry after datetime('now'). But your help with this is simply incredible and beyond anything I could have imagined. I guess I need to pay it back and write someone else scripts on the forum now :). Thanks a lot, I'm going to see how well your setup copes with a larger database in time and hope it does it well.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Apr 17, 2008 2:31 am   
 
A pleasure, it was fun and I learned new things doing it Very Happy
Currently MDL code above does not autolimit the values to 20 or anything.
The TrimFM function gives an idea how to write the SQL for it.
It could be made automatic by adding an update trigger.
I figured you could trim it manually using something like the TrimFM function if the database got too big.

Let me know if any problems arise or if after playing with it a while you wish to make improvements and need an assist.

P.S if you delete an entry from the FormMob all entries with that FMID listed in the Encounters table will automatically be deleted.
If you update the Form and/or Mob and or FMID in the FormMob table the corresponding entries in the Encounters table will automatically be updated.
thats what the fkuc_Encounters_FMID_FormMob_FMID and fkdc_Encounters_FMID_FormMob_FMID Triggers do cascade Update/Deletes.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Apr 17, 2008 3:47 am   
 
BTW ran some tests with an eye to your concerns regarding slow downs as the tables get bigger.
I used a Python script to populate the database randomly using 10 Forms and a possible 3200 or so different mobs, and 25 entries each combo.
That left 20765 entries in the MobForm table and 822500 entries in the Encounters table.Total FileSize of about 56MB
Then in CMUD using this script.

Code:
#var secs %secs;
#var res @killrates.Execute("SELECT EID,Form,Mob,Rounds,XP,TStamp FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form=? AND FormMob.Mob=?",@form,@mob)
#show (%secs-@secs)


The average time taken is 2 milliseconds on my machine.
So I think design will hold up.
If you do a lot of searches using the Rounds ,XP or TStamp fields in the WHERE clause, just create indexes for them as well.
Right now the FMID EID Form and Mob fields should be indexed already.

The only thing that will cause noticible slow downs is when you're returning a lot of records to CMUD it takes time to create that info wrap it into a format CMUD can understand return it to CMUD and then CMUD has to allocate memory if you save that data.
You can always use LIMIT and OFFSET to increment through a limited amout of a given data set, since the actual time required for the database to SELECT the data is so small compared to everything else.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Fri Apr 18, 2008 1:13 am   
 
Something I just tried to implement is for if I want to specify both a form and a mob, I used this:

Code:

$result = @killrates.Execute("SELECT * FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form=? AND FormMob.Mob LIKE ?", $form, $mob)


Now I know I need to have single quotes when using that, so after that initial query failed, i did this:
Code:

$mob = %concat(%',%lower( %trim(%-2)),'%)

This also failed, and I can't figure out how to get a LIKE operator working. This will only work if I use a FormMob.Mob=?, however that doesn't allow you too much leeway with your queries which I would like to do in case I don't remember verbatim the mob names. I played around with the firefox plugin to run some queries on the databse, and this will work:

Code:

SELECT * FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form='dwarf' AND FormMob.Mob LIKE '%bartender%';


However, my final pattern of:

Code:

$result = @killrates.Execute("SELECT * FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form=? AND FormMob.Mob LIKE ?",$form,$mob)


still gives nothing. The complete alias (killrate) is:

Code:

#if (%null = %2) {
  #if @killrates.IsOpen() {} {
    #var killrates %comcreate( "Sqlite.ZMUD.WSC")
    #call @killrates.Open("roundtimes")
    }
  $form=%lower( %trim( %1))
  $killrate=@getformentries( $form)
  #FOR $killrate {
    #ECHO *****
    #showdb {%i}
    }
  }
  {
  #if @killrates.IsOpen() {} {
    #var killrates %comcreate( "Sqlite.ZMUD.WSC")
    #call @killrates.Open("roundtimes")
    }
  $form = %lower( %trim( %1))
  $mob = %concat('%,%lower( %trim(%-2)),%')
  #show $form $mob
  $result = @killrates.Execute("SELECT * FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form=? AND FormMob.Mob LIKE ?",$form,$mob)
  #IF (not %null( @killrates.LastError) ) {#echo Error in getFormEntries for $form: @killrates.LastError} {
  #FOR $result {
    #ECHO *****
    #showdb {%i}
    }
  }
  }



Any idea why the LIKE won't work?
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Fri Apr 18, 2008 1:57 am   
 
You don't need to manually put the single quotes when using qmark substitution.
the enclosing single quotes are always automatically entered when the ? in your statement is substituted
Code:
$mob = %concat(%,%lower( %trim(%-2)),%)

should suffice.

Also don't worry about doubling single quotes or anything like that the qmark sub takes care of that too.
safer all around really :)
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Wed Apr 23, 2008 2:45 am   
 
So I'm wanting to do some math functions that aren't offered in the sqlite3, and I've been googling around for some ways to try and incorporate them without too much luck. I'm not very experienced in compiling/know where I would insert any of the functions found online. So I'm wondering if you could help me in getting a std. dev function in at this point. A nice website that has a library with a lot of functions is:
http://sqlite.org/contrib/download/extension-functions.c?get=22
from the website
http://lhealy.livejournal.com/tag/sqlite

any help you can do in getting this functionality is greatly appreciated, I really just at this point see a need to have a st dev included, I could probably get a rigged version to work in cmud by querying and just adding to a list, but I want think the speed would be better if it was more internal.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Wed Apr 23, 2008 7:47 am   
 
I'ts definitely possible to write these functions in Python and just add to the Sqlite.ZMUD.WSC component.
I had already added two such functions REGEXP and MATCH.
I could just add the Standard Dev function as well.
However, I'm thinking that I should find a way to keep these functions external to the main component because not everyone will need these extra functionality.
I'm thinking creating either a second auxilliary component or module to hold the functions( or classes necessary to implement the aggregate functions) and a manifest describing
which functions/classes to add and what params etc are needed.
I need to think about this, and if anyone has any feedback on how I should/might go about it then by all means sound off.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Wed Apr 23, 2008 1:42 pm   
 
It may not help you that much since you are using sqlite3, but CMUD already has a %stdev function in it. In the worst case you could copy sqlite column to a CMUD do and run the function against it.
_________________
Asati di tempari!
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Wed Apr 23, 2008 2:01 pm   
 
Yeah thats what I was implying on doing with my reference to rigging a setup within CMUD, off the top of my head
Code:

stdev = @killrates.Execute("SELECT rounds FROM Encounters,FormMob WHERE FormMob.FMID=Encounters.FMID AND FormMob.Form=? AND FormMob.Mob LIKE ?",$form,$mob)


Then I would probably just write my own function in cmud to deal with it. This route doesn't actually sound all that bad, but I have nothing to compare my speed against.
Reply with quote
chris-74269
Magician


Joined: 23 Nov 2004
Posts: 364

PostPosted: Thu Apr 24, 2008 3:15 am   
 
My St. Dev function:

Code:

<func name="stdev" id="230498">
  <value>$stdev=%replace($stdevinput,Rounds)
$stdev=%replace($stdev,%char(30))
stdevtotal=""
square=""
squaresum=""
#FORA $stdev {stdevtotal=%eval( @stdevtotal+%i)}
$stdevaverage=%eval( %concat( @stdevtotal, ".0")/%numitems( $stdev))
#FORA $stdev {
  square=%remove(-,%eval(%i-$stdevaverage))
  square=%eval(@square*@square)
  squaresum=%eval( @squaresum+@square)
  }
$stdev=%sqrt( %eval( @squaresum/%concat( %numitems( $stdev), ".0")))
stdevresult=$stdev</value>
  <arglist>$stdevinput</arglist>
</func>


Right now it's rigged up with a manual - sign removal due to the bug I just found with the %abs function stripping decimals with loops.
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Thu Apr 24, 2008 5:05 am   
 
In lieu of %concat try casting the values being passed to %eval using %float this will also help with your %abs problem.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
Reply with quote
Dharkael
Enchanter


Joined: 05 Mar 2003
Posts: 593
Location: Canada

PostPosted: Mon Apr 28, 2008 4:01 am   
 
chris-74269, I added a Standard Deviation extension Function STDDEV.
I based it on the explanation given here , I think it should be correct but you can always test it and let me know.
_________________
-Dharkael-
"No matter how subtle the wizard, a knife between the shoulder blades will seriously cramp his style."
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