From: Stéphane A. <ste...@gm...> - 2013-06-04 10:31:01
|
Hello, Decoding the mask would depend on what you really intend to do ... but basically you will need to perfom bitwise AND with the value you're searching and bitwise OR with the values you want to update. Some information can be found here : http://wiki.python.org/moin/BitwiseOperators The whole idea is to use number in binary format, using each bit to encode something. Below, you'll find representation of 1, 2, 4, 8 and 16 in binary format 1 : 00000001 2 : 00000010 4 : 00000100 8 : 00001000 16 : 00010000 The interesting part is that if you do bitwise OR between 2 and 4, you keep all the information : 2 | 4 = 00000110 Looking at that number in binary format (which is just 2+4 by the way), you can without a doubt know that it's been "constructed" with the 2 and the 4. FYI, that's the method used behind unix rights (0=no right, 1=read, 2=write, 4=access if i remember right, so that chmod 771 means give all rights to me and my group and only read access to other). Decoding it can be done with bitwise AND operator and comparison to the mask : What bitwise AND does : foreach bit of our byte, if both bits are 1, resulting bit is 1, else resulting bit is 0. Example : variable = 00000110 if (2&variable)==2 : 2 is "part of the variable" (true here) if (4&variable)==4 : 4 is "part of the variable" (true here) if (8&variable)==8 : 8 is "part of the variable" (false here) This mecanism was very much used when coding in C/C++ because it helped encoding important part of information in only 1 number and lets you perform comparison with number not strings (which is faster). Since I don't quite well remember where all that was left in the code, I'd describe two types of algorithms below. Let me know if what you're looking for is different. 1) If what you're looking for is "which tourney parts have been processed ?", you could loop through available masks (1, 2, 4, 8, 16) and do a bitwise AND between the variable value and the mask and compare it to the mask ( (variable & 2) == 2 ?). 2) If what you're looking for is to fill information about a tourney as summary files arrive, you'd have to 2.a) Identify in the summary file which tourney summary part it is 2.b) Check if that file has already been processed for that tourney (bitwise AND between what's already in DB and the bitwise mask associated with your tourney summary file : 1,2,4,8,16). 2.c) If yes, not sure what to do, probably nothing 2.d) If not, update what has to be updated (amount won, ...) and also update matrixIdProcessed to something like matrixIdProcessed | <bitwise mask associated with tourney summary file>. Hope all this helps. Let me know. Stéphane On Sun, Jun 2, 2013 at 4:07 PM, Chaz Littlejohn <ch...@po...> wrote: > fpdbers, > > Making a renewed attempt to update all things tournaments ahead of the > impending v0.40 release. One of the yet unresolved problems are with > Full Tilt's Matrix tournaments. Stéphane, looks like you've laid a > pretty good groundwork, that was never fully implemented. The one > question I had was what is the simplest algorithm we can use to > 'decode' the matrix mask? Never taken a CS class before, so this > method is rather new to me. > > I'm also kicking around an alternative solution to this problem that I > wanted to get people's input on. Trying to deal with Multi-Entry and > Re-Entry tournaments in this release as well, and i'm planning on > doing that by adding a field 'entryId' as part of the > 'TourneysPlayers' key. We could potentially use this for matrix > tournaments as well. The upside to this is you could back out which > match a particular hand is from if each player/match combo is tied to > a unique record in TourneysPlayers. > > Thoughts? Better late than never i suppose :) > > Chaz > > On Sun, Jun 2, 2013 at 9:33 AM, Chaz Littlejohn <ch...@po...> wrote: > > Hi Steffen, > > > > I created those attributes in the Tourney class, and I agree with your > > different suggestions, even though I'm currently not active in fpdb > > development. So I guess, if anybody else has anything to say about moving > > those attributes to TourneyTypes, it might be interesting to listen. > > > > Regarding matrixIdProcessed, you're right, it is supposed to handle the > > FTP's matrix SNG's. > > I'll try to remember how it was supposed to work (I'm not quite sure I > went > > through coding all the parts to handle those tourneys) : > > > > - First, the files : FTP produces : > > * 4 HH files : 1 for each "match", and > > * 5 summary files : 1 for each "match" and 1 for the overall ranking > (each > > player earns points according to his finishing position in each of the > > matches). > > > > So, when processing one file, the Tourney.matrixIdProcessed is supposed > to > > bet set to a value that reflects the file processed (0 for the positional > > summary, 1 through 4 for the other matches files). > > > > - Second, DB storage. > > Basically, the issue is that you have only one DB record for a matrix > sng, > > but you have to process multiple summary files in order to have accurate > > data for that tourney (each match file and the positional file include > parts > > of the winings). > > So, the idea (and that part is definitely not coded) was to use > > the matrixIdProcessed column of the Tourneys table to record what has > been > > processed, using a mask of powers of 2 (as said in the creation comment > : /* > > Mask use : 1=Positionnal Winnings|2=Match1|4=Match2|...|pow(2,n)=Matchn > > */). > > > > In case you're not familiar with that kind of stuff, here's how it works > : > > On creation that column's value is 0. > > Let's say you process (in that order) : Match 2, Match 1, positional, > Match > > 3, Match 4 > > Then, the value of that column will be : 4 , 6 (4+2), 7 (6+1), 15 > (7+8), 31 > > (15+16). > > > > When looking at that column's value you can also know if one particular > file > > has been processed (using bit for bit AND with the according mask). > > > > So what would have to be done for db storage, is something like : if no > > record found, insert with correct matrixIdProcessed column value, else, > > retrieve existing record, check if that summary file has already been > > processed in db : > > - If yes : do nothing > > - If not : update the values of money winings with those retrieved from > that > > particular file. > > > > > > I don't know if all that is very clear (might not even be in my head now > > ;-)). Anyway, feel free to ask fo further explanations if needed. > > > > Bye. > > > > Stephane > > > ------------------------------------------------------------------------------ > Get 100% visibility into Java/.NET code with AppDynamics Lite > It's a free troubleshooting tool designed for production > Get down to code-level detail for bottlenecks, with <2% overhead. > Download for free and get started troubleshooting in minutes. > http://p.sf.net/sfu/appdyn_d2d_ap2 > _______________________________________________ > Fpdb-main mailing list > Fpd...@li... > https://lists.sourceforge.net/lists/listinfo/fpdb-main > |