Changeset 296

Show
Ignore:
Timestamp:
05/01/09 13:53:30 (3 years ago)
Author:
ocjhb
Message:

algorithm to get values for exchange

Location:
trunk/sandbox/jhb/oc2
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/sandbox/jhb/oc2/authorizer.py

    r280 r296  
    3838            mkc = self.getMKCById(keyid) 
    3939            amount += self.denominationToValue(mkc.denomination) 
    40         if amount > 10000: 
     40        if amount > 10000000: 
    4141            error = messages.Error() 
    4242            error.text = 'way too much' 
  • trunk/sandbox/jhb/oc2/coinsplitting.py

    r294 r296  
    2020    return tokens             
    2121 
     22def prepare_for_exchange(denominations,oldcoins,newcoins): 
     23    """returns ([value to keep,..],[value for paying,...],[value for blank,...]), 
     24     assumes that all newcoins are exchanged anyhow""" 
     25 
     26    oldcoins = list(oldcoins) 
     27    oldcoins.sort() 
     28    oldcoins.reverse() 
     29 
     30    newcoins = list(newcoins) 
     31    newcoins.sort() 
     32    newcoins.reverse() 
     33 
     34    amountold = sum([int(o) for o in oldcoins]) 
     35    amountnew = sum([int(n) for n in newcoins]) 
     36    amount = amountold + amountnew 
     37 
     38    targettokens = tokenizer(denominations,amount) 
     39    targettokens.sort() 
     40    targettokens.reverse() 
     41    keepold = [] 
     42    makenew = [] 
     43    for tt in targettokens: 
     44        try: 
     45            keepold.append(oldcoins.pop(oldcoins.index(tt))) 
     46        except ValueError: 
     47            makenew.append(tt) 
     48                 
     49    return (keepold,oldcoins,makenew)             
     50 
     51 
    2252def testspend(tokens,amount): 
    2353    picked = [] 
     
    3060    return picked          
    3161 
    32 if __name__ == '__main__': 
    33     dl = [[1,2,5,10,20,50,100],[1,3,9,27],[1,3,5,7,11,13,17,19,23],[1,17,33]] 
     62 
     63def test_tokenizer(): 
    3464    problems = 0 
    3565    for denominations in dl: 
     
    5484    amount = 137 
    5585    print tokenizer(dl[0],amount) 
     86 
     87def test_prepare_for_exchange(): 
     88    denominations = dl[0] 
     89    startvalue = max(denominations) 
     90    for i in range(1,startvalue * 2 +1): 
     91        print '#'*20,' i: %s ' % i, '#' * 20 
     92        start = tokenizer(denominations,i) 
     93        for j in range(1,i*3 +1): 
     94            print 'j: %s - ' % j, 
     95            newcoins = tokenizer(denominations,j) 
     96            keepold,paywith,makenew = prepare_for_exchange(denominations,start,newcoins) 
     97            sumkeep = sum(keepold) 
     98            sumnew = sum(makenew) 
     99            total = sumkeep + sumnew 
     100            print "keep: %s, tomake: %s, paywith: %s, %s, sum: %s" % (keepold,makenew,paywith,newcoins,total) 
     101 
     102if __name__ == '__main__': 
     103     
     104    dl = [[1,2,5,10,20,50,100],[1,3,9,27],[1,3,5,7,11,13,17,19,23],[1,17,33]] 
     105    #test_tokenizer() 
     106    #test_prepare_for_exchange()  
     107    print "keep: %s, paywith: %s, makenew: %s" %prepare_for_exchange(dl[0],[10],[5,2]) 
     108 
     109 
     110 
     111 
  • trunk/sandbox/jhb/oc2/testissuer.py

    r294 r296  
    2323 
    2424    print 'issuer: setup currency discription' 
    25     denominations=[1,2,5,10,20] 
     25    denominations=[1,2,5,10,20,50,100,200,500,1000,2000,5000,10000,20000,50000,100000,200000,500000] 
    2626    cdd = issuer.makeCDD('TestCent','tc',[str(d) for d in denominations],'http://192.168.2.101:%s/' % port,'') 
    2727    mint.setCDD(cdd)