Last active
January 11, 2019 13:01
-
-
Save MatthewWilkes/e8307152c545c1dee5f8d8eaabef5833 to your computer and use it in GitHub Desktop.
Utilities for examining cycle 2 experiments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import argparse | |
import json | |
import operator | |
import pprint | |
def sort_key(value): | |
player_id, payoff = value | |
return int(player_id) | |
def show_payoffs(experiment_id): | |
from dallinger.data import load | |
data = load(experiment_id) | |
info_df = data.infos.df | |
states = info_df[info_df.type=='state'] | |
latest_state = states.iloc[-1] | |
contents = json.loads(latest_state.contents) | |
payoffs = [(player['id'], player['payoff']) for player in contents['players']] | |
payoffs = sorted(payoffs, key=sort_key) | |
for player, payoff in payoffs: | |
print("{:>3}: {}".format(player, payoff)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('experiment_id') | |
args = parser.parse_args() | |
show_payoffs(args.experiment_id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import argparse | |
import json | |
import operator | |
import pprint | |
def sort_key(value): | |
row, data = value | |
return int(data.id) | |
def show_payments(experiment_id): | |
from dallinger.data import load | |
data = load(experiment_id) | |
participant_df = data.participants.df | |
participants = sorted(participant_df.iterrows(), key=sort_key) | |
for row, participant in participants: | |
print("{participant.id:>3}: " | |
"${participant.base_pay} + ${participant.bonus} " | |
"({participant.status} - {participant.recruiter_id})".format(participant=participant) | |
) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('experiment_id') | |
args = parser.parse_args() | |
show_payments(args.experiment_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment