Accessing Heroku database with django command ( oTree 3.x)

139 views
Skip to first unread message

flora...@gmail.com

unread,
Apr 27, 2021, 11:22:06 AM4/27/21
to oTree help & discussion
Dear All,

I wrote a django-admin command that accesses variables of all participants from one of my apps, selects some of them randomly (it is basically the payment randomization at the end of the experiment), and exports them to a csv. 

I can run it with python manage.py my-command-name and it works with the test sessions on the development server perfectly.

Is there a way to run this command similarly to access participant variables from the Heroku database? The closest I could get is to open a one-off dyno with heroku run bash -a my-app-name, and run the command there. It created the csv but I don't know how to download/save the csv to my local repository.

Thank you very much!
Best,
Luca


Chris @ oTree

unread,
Apr 27, 2021, 11:24:10 AM4/27/21
to oTree help & discussion
Yes, downloading files from Heroku can be a bit tricky. I suggest trying the custom_export feature first.

flora...@gmail.com

unread,
Apr 27, 2021, 11:31:50 AM4/27/21
to oTree help & discussion
Thank you Chris, I'll try that.

feb...@free.fr

unread,
Apr 28, 2021, 3:45:37 AM4/28/21
to oTree help & discussion
You can try using dataclips on the heroku database. A simple sql query to extract your data. Effective as long as the data is not stored in a dictionnary on oTree.
Otherwise, you will have to save your data to a specific variable.
You will get an access link from which you can directly donwload the CSV file from curl for example or any web browser.

Luca Flóra Drucker

unread,
Apr 28, 2021, 6:44:44 AM4/28/21
to oTree help & discussion
Thank you! 

Unfortunately my data is mostly stored in dictionaries... But custom_export seems to work.

Best,
Luca

--
You received this message because you are subscribed to a topic in the Google Groups "oTree help & discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/otree/b5bhRxOBz6k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/acbe0335-3869-4368-b754-b47a6fb80480n%40googlegroups.com.

flora...@gmail.com

unread,
Apr 30, 2021, 8:34:56 AM4/30/21
to oTree help & discussion
Dear Chris,

Is it possible for custom_export to export the data only once? So to not have as many rows per participant as rounds. 
I only want to export participant variables but I have many rounds, and the table will blow up quickly.

Thank you!
Luca

Luca Flóra Drucker

unread,
Apr 30, 2021, 9:45:56 AM4/30/21
to oTree help & discussion
Sorry for the stupid question. I realized that it is very easy to drop the duplicates later by participant code.

Chris @ oTree

unread,
Apr 30, 2021, 1:48:47 PM4/30/21
to Luca Flóra Drucker, oTree help & discussion
Yes or just filter player.round_number == 1. 

Sent from my phone

On Apr 30, 2021, at 9:46 PM, Luca Flóra Drucker <flora...@gmail.com> wrote:


You received this message because you are subscribed to the Google Groups "oTree help & discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to otree+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/otree/CAJCtKsnOsTnBdqX-wYC99jnUP5XZDdcrHC0PGrc4YzaMhC5r4w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages