https://github.com/ValuingElectronicMusic/ifdb-analysis
Raw File
Tip revision: ff1cb86f687c4ca00fc9d35cb4b3d438a4855c78 authored by Anna Jordanous on 21 February 2014, 15:54:53 UTC
first commit ++
Tip revision: ff1cb86
process_ifdb_data.pyc
ó
`¸òRc@sÑddlmZdZd„Zddd„ƒYZddd„ƒYZddd	„ƒYZd
„Zd„Zd„Z	d
„Z
d„Zd„Zd„Z
d„Zd„Zd„Zd„Zd„Zd„ZdS(iÿÿÿÿ(tconnectsifdb_data.sqlitecCsIttƒ}|1|jƒ}|jdj|ƒƒ|jƒSWdQXdS(s>Returns contents of one entire table from the sqlite database.sSELECT * FROM {!s}N(Rtdb_pathtcursortexecutetformattfetchall(t	tableNametconntcurs((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyt	get_tables
tdata_holdercBseZdZd„ZRS(sDAn object to hold data from each of the four tables in the database.cCsXttdƒƒ|_ttdƒƒ|_ttdƒƒ|_ttdƒƒ|_dS(Nt
Receptionst
AuthoringstWorkstAgents(tsetR	t
receptionst
authoringstworkstagents(tself((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyt__init__s(t__name__t
__module__t__doc__R(((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyR
st
entity_holdercBseZdZdd„ZRS(sFAn object to hold data cheaply processed from those held in the above.ics d„|jDƒˆ_d„|jDƒˆ_d„|jDƒˆ_d„|jDƒˆ_d„|jDƒˆ_d„|jDƒˆ_d„|jDƒˆ_d„|jDƒˆ_	d	„|jDƒˆ_
‡fd
†|jDƒˆ_d„ˆjDƒˆ_‡fd†|jDƒˆ_
d
„ˆjDƒˆ_ˆjˆj@ˆ_ˆjˆj@ˆ_ˆjˆj
@ˆ_ˆjˆj@ˆ_ˆj
ˆj@ˆ_ˆjˆjBˆ_dS(NcSsh|]}|d’qS(i((t.0tx((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>#s	cSs0h|]&}t|dƒdkr|d’qS(ii
(tlen(RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>$s	cSs0h|]&}t|dƒdkr|d’qS(ii
(R(RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>%s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>&s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>'s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>(s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>)s	cSs*h|] }|ddkr|d’qS(ii((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>*s	cSs*h|] }|ddkr|d’qS(iii((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>+s	cs*h|] }|dˆkr|d ’qS(i((RR(trating_threshold(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>,s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>.s	cs-h|]#}|dˆjkr|d’qS(ii(t	highrated(RR(R(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>/s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>1s	(RtuserstnonusersRtauthorsRRt	receiverstreceivedtratedtraterstrecognitionsRt
recognisedtrecogniserstauthor_userstauthor_receiverst
author_raterstauthor_recogniserstrecognised_recogniserstactive_users(RtdataR((RRsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyR"s&(RRRR(((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyRstattribute_holdercBseZdZd„ZRS(sBAn object to hold ranges of categorical values for some variables.cCsFd„|jDƒ|_d„|jDƒ|_d„|jDƒ|_dS(NcSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>=s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>>s	cSsh|]}|d’qS(i((RR((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>?s	(Rtyearst	languagestdev_systems(RR/((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyR<s(RRRR(((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyR09sc
Csàg}g}g}g}g}g}g}g}xA|jD]6}	|	dsPq:nd|	dkrt|j|	dƒq:d|	dkr˜|j|	dƒq:d|	dkr¼|j|	dƒq:d|	dkrà|j|	dƒq:d|	dkr|j|	dƒq:d|	dkr(|j|	dƒq:d	|	dkrL|j|	dƒq:d
|	dkr:|j|	dƒq:q:Wit|ƒd6t|ƒd6t|ƒd
6t|ƒd6t|ƒd6t|ƒd6t|ƒd6t|ƒd6S(s[Returns a dictionary: keys are systems; values, works created therewith.

    Note that this doesn't bother with the full range of values in the
    data. Only the most common systems are returned, and different
    versions of a system are treated as the same system (e.g. 'Inform
    6' and 'Inform 7' games are grouped together under 'Inform').itADRIFTitInformtTADStZILtHugotQuilltEamontScotttadrifttinformttadstziltquillteamontscottthugo(RtappendR(
R/tADRIFT_listtInform_listt	TADS_listtZIL_listt
Quill_listt
Eamon_listt
Scott_listt	Hugo_listtwork((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytworks_by_systemAs>
cst‡fd†|DƒƒS(sÚReturns the human-readable name associated with an ID string.

    To get agent names, pass in the agents variable of a data_holder
    object; to get work names, pass in the works variable of a
    data_holder object.c3s)|]}|dˆkr|dVqdS(iiN((Rta(tid(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<genexpr>ps(tnext(RPtentity_data((RPsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytname_entityiscs!t‡fd†|jDƒƒdS(s0Returns the year a particular work was released.c3s%|]}|dˆkr|VqdS(iN((RRM(twork_ID(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<genexpr>usi(RQR(RTR/((RTsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytyear_ofrscs‡‡fd†|DƒS(s=Returns a dictionary of entities with a particular attribute.cs,i|]"‰‡‡fd†ˆDƒˆ“qS(cs*h|] }|ˆˆkr|d’qS(i((Rtmember(tattrt
attr_index(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>zs	((R(RXt
entity_set(RWsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys
<dictcomp>zs	((t	attributeRYRX((RXRYsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytattribute_entity_dictwscCsygt||ƒD]}|^q}t|ƒ}|dkr>dStg|D]}|d^qHƒt|ƒ}|tfSdS(sGReturns the number of ratings and the mean rating that a work received.iiN(ii(twork_ratingsRtsumtfloattmean_ratings(RMR/trtratingstnum_ratings((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytwork_number_and_mean_ratings~s"-cCs=tg|jD]}t||ƒ|f^q
ƒddd…S(sIReturns list of tuples in order of ranking of works by number of ratings.Niÿÿÿÿ(tsortedRRc(R/RM((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyt
most_ratedˆscs‡fd†|jDƒS(s@Returns set of agents credited with authorship of a single work.cs*h|] }|dˆkr|d’qS(ii((Rt	authoring(RM(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>‘s	(R(RMR/((RMsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyt
authors_ofŽscs‡fd†|jDƒS(s5Returns set of works for which an author is credited.cs*h|] }|dˆkr|d’qS(ii((RRf(tauthor(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>—s	(R(RhR/((Rhsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytworks_by”scs‡‡fd†|jDƒS(s“Returns set of agents who rated a given work highly.

    Note that ratings of works for which the rater is credited as an
    author are excluded.csGh|]=}|dˆkr|dt|dˆƒkr|d’qS(ii(Ri(Rtrec(R/RM(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp> s	(R&(RMtentitiesR/((R/RMsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytrecognisers_ofšscCs@tgƒ}x-t||ƒD]}|t|||ƒB}qW|S(s²Returns set of agents who rated a given author's works highly.

    Note that an agent's ratings of works that he or she co-authored
    with the author in question are excluded.(RRiRl(RhRkR/R(RM((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytrecognisers_of_author¤scs‡‡fd†|jDƒS(sFReturns all receptions of works with the given value for one variable.cs*h|] }|dˆˆkr|’qS(i((Rt	reception(tattr_entity_dictRZ(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys	<setcomp>²s	(R(RZRoR/((RoRZsm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyttotal_receptions_attribute¯scs‡‡fd†|DƒS(s8Returns a dictionary of receptions of works for one variable.

    Key is every value which that variable has in the data. I used
    this for comparing the number of ratings and reviews received by
    works in different languages, released in different years, or
    developed with different authoring systems.cs%i|]}t|ˆˆƒ|“qS((Rp(Rtatt(tatt_entity_dictR/(sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pys
<dictcomp>½s	((tatt_typeRrR/((RrR/sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyt$dict_total_receptions_attribute_typeµsc
Cs3tƒ}t|ƒ}t|ƒ}t|j|jdƒ}td||ƒ}djt|ƒƒGHt|j	|jdƒ}djt|dƒƒGHt
|j	||ƒ}djt|dƒƒGHt|j|jdƒ}t
|j||ƒ}d	GHd
GHx9|jD].}	dj|	t||	ƒt||	ƒƒGHqýWdS(
s%This is just to show how things work.isInform 6s!Receptions of Inform 6 works: {}
isWorks in Russian: {}sRussian (ru)s#Receptions of works in Russian: {}
isWorks and receptions by years$Year	Works	Receptions of those workss{}	{}	{}N(R
RR0R[R3RRpRRR2RtR1(
R/Rkt
attributest	sys_workstinf6_recepst
lang_workstlang_receptionst
year_workstyear_receptionsty((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pytdemonstrateÀs 	N((((tsqlite3RRR	R
RR0RNRSRUR[RcReRgRiRlRmRpRtR}(((sm/Users/annajordanous/Dropbox/KCL/projects/SoundCloudValue/git/cleaned_IFDB_code_and_data/process_ifdb_data.pyt<module>
s$			(					
				
			
back to top