21.01.2015 Views

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

color version - PET: Python Entre Todos - Python Argentina

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

If none of the evaluators were supplied to the agenda, it will try using the supplied<br />

interpolators.<br />

4. Create interpolators: The interpolators are used as second alternative to<br />

extraction of audience and impact, so each agenda receives 2 interpolators: an<br />

audience and an impact interpolator.<br />

Thus the impact interpolator will receive as value to interpolate “X” to the audience<br />

and will return a value “Y” for the impact.<br />

Now, if we wish to interpolate the value of the Audience the interpolator will receive as<br />

value “X” the Impact and will return a “Y” for the Audience.<br />

An example is shown below together.<br />

5. Create the agenda/s: When creating agendas they should be provided with<br />

different data:<br />

• What kind of information medium will measure.<br />

• A list of media to be measured (optional).<br />

• An audience data extractor (optional).<br />

• A impact data extractor (optional).<br />

• A audience interpolator (optional).<br />

• An impact interpolator (optional).<br />

An example is shown below together.<br />

6. Evaluate nodes: The agenda has methods to sort ISources by value, only to be<br />

iterated and thus generate a ranking of importance for each medium.<br />

By iterating on the Agenda it returns various ASNode which are data structures that<br />

encapsulate the media and add attributes corresponding to Audience, Impact and<br />

Value as well as date and time when the node was created.<br />

Full-featured example<br />

from infopython import session<br />

from infopython import agenda<br />

from infopython.util import interpolator<br />

from infopython.isources import webpages<br />

# Configure the session.<br />

# All these keys are for mock and for a real test any<br />

# user can register them on the website of each application.<br />

session.set(compete_key = "967b8490-e26a-11df-8cbe-0019662306b1",<br />

twitter_key = "967b8490-e26a-11df-8cbe-0019662306b1",<br />

twitter_secret = "967b8490-e26a-11df-8cbe-0019662306b1",<br />

twitter_user_key = "967b8490-e26a-11df-8cbe-0019662306b1",<br />

twitter_user_secret = "967b8490-e26a-11df-8cbe-0019662306b1",<br />

klout_api_key = "967b8490-e26a-11df-8cbe-0019662306b1")<br />

# Create two webpages<br />

google = webpages.WebPage("google.com")<br />

yahoo = webpages.WebPage("yahoo.com")<br />

# Extract measurements<br />

aud = lambda w: w.get_info("compete")["metrics"]["uv_count"] # audience<br />

imp = lambda w: w.get_info("pagerank")["pagerank"] # impact<br />

# an interpolator<br />

itp = interpolator.PieceWisePolynomial([0,0,1,1,2,45,64], [1,3,1,1,2,4,64])<br />

# Create the agenda<br />

# This agenda will try to extract the values of audience and impact with its<br />

# 'Valuators', in case of 'None' will try its interpolators.<br />

# If they return once again None, a value of 0.0 will be returned and medium<br />

# value will be calculated with them.<br />

ag = agenda.AgendaSetting(itype=webpages.WebPage,<br />

inf_sources=[google, yahoo],<br />

audience_valuator=aud,<br />

impact_valuator=imp,<br />

impact_interpolator=itp,<br />

audience_interpolator=itp)<br />

ag.rank() # sort the agenda by the value of each medium

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!