About planet and some Python lessons

I have some exciting plans for using the planet feed aggregator and have over the last couple of weeks using the “Venus” code line. I can now install on Ubuntu and the install passes all its tests. I want to be able to write a filter for the my plazes and also see how the foaf output might be used. I met up with my colleague, Dave Edmondson and we discussed the strengths and weaknesses of Python and planet.

The script planet.py runs two other python programs called spider and splice.

Spider gets the feeds defined in config.ini and creates a local cahce version, splice, reads the cache and generates the new formats from templates. The diagram below does not illustrate the template source files for the output formats and I shall probably need to dig further into the code in order to understand what needs to be done.

The diagram also indicates the location of Venus' plugin, where the plazes filter should be located.

We also discussed Python. I have been trying to write a game theory solver for a 2x2 formal game. I was representing the game as a dictionary so that I could retreive game scores using the strategy names. One problem is that two dimensional dictionaries get syntactically combersome. I had ended up with a list as the key. In theory it should make the programming easier, where game is a dictionary attached to class instance g.

i.e. score = g.game[('decoy', 'defend')]

makes great sense where decoy and defend are blue and red strategies, however, I have usually placed the evaluation of a score in an interation, and so coding the strategy names is rare e.g.

strategies=['heads', 'tails'];
for s in strategies:
   # some iterated code

It is probably simpler to represent the game as a 2x2 matrix held in a list and to use the classic technique of holding the names of the strategies in an ordered list so we can translate the matrix cell location such as n(1,1) into n(tails,tails) by looking co-ordinates up in one, or two name lists.

strategies=['heads','tails']
score=matrix(strategies.index('heads'), strategies.index('heads'))

This would also have the advantage that I could look for and use the matrix manipulation packages that exist to avoid writing a lot of code. The code would look a lot simpler, and not just because I have put a lot of it in an external package; this is usually a good clue that the answer is correct.

Lesson 1: Be careful when using dictionaries.

tags:

Comments:

Post a Comment:
Comments are closed for this entry.
About

DaveLevy

Search

Archives
« April 2014
MonTueWedThuFriSatSun
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    
       
Today