oTree Forum >

custom_export for multiple apps

#1 by gmauter

I'm trying to define a custom data export that gets data from multiple apps in a session. Initially, I've tried to do this by yielding all the variables as they are given in the standard data export. 


    def custom_export(players):
    
        for p in players:
            participant = p.participant
            session = p.session
       
            yield [participant.id_in_session, participant.code, prerating.participant.choice,             
            multiplayer_app.subsession.round_number, multiplayer_app.participant.payoff,
            multiplayer_app.participant.chosBandit, multiplayer_app.participant.fullConsensus, 
            multiplayer_app.group.fullConsensus, multiplayer_app.participant.rewardWin,
            multiplayer_app.participant.condition, multiplayer_app.group.reward_left, multiplayer_app.group.reward_right,
            multiplayer_app.group.images_left, multiplayer_app.group.images_right, postrating.participant.choice]
        
            * again, all these variable names are taken directly from the "all_apps_wide" csv output
            
The relevant apps include "prerating", "multiplayer_app", "postrating".       
For session variables, such as partipant.id_in_session, there are no problems in the custom export. However, when I reach 'prerating.participant.choice', I get the error: 

"2023-10-02T19:54:20.556070+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.9/site-packages/otree/export.py", line 455, in custom_export_app
2023-10-02T19:54:20.556070+00:00 app[web.1]:     for row in rows:
2023-10-02T19:54:20.556070+00:00 app[web.1]:   File "/app/multiplayer_app/__init__.py", line 735, in custom_export
2023-10-02T19:54:20.556073+00:00 app[web.1]:     yield [participant.id_in_session, participant.code, prerating.participant.choice, multiplayer_app.subsession.round_number, multiplayer_app.participant.payoff,
2023-10-02T19:54:20.556074+00:00 app[web.1]: NameError: name 'prerating' is not defined

This makes sense to me, as the apps "prerating" and "postrating" are in separate folders from this init.py file. My question is: is it possible to include data from these other apps in my custom_export definition? Or would I need to do a separate custom export for each app and then combine the data elsewhere? 

Thanks in advance!

#2 by gmauter

Update: I've separated the custom exports so that each app has its own. I'd still love to hear opinions on possible options for consolidating all apps into one data file, if anyone has that info.

However, now I'm receiving: "AttributeError: 'Participant' object has no attribute 'chosBandit' from the custom_export in "multiplayer_app/init.py". This is a player-level variable, and in the standard data file, it is designated as "multiplayer_app.player.chosBandit". Therefore, I figured that calling "player.chosBandit" from the multiplayer_app custom_export function would be able to access the variable. Any help on this is very much appreciated!

Write a reply

Set forum username