NOTE: This section is out-of-date.
Getting campaigns, questions, responses, and custom fields. from Spoke.
First import the module:
import rlabsreporting
Instantiate the class:
# Requires a .env file with db credentials w/ the following keys:
# dbname, host port, user, password
#
# Also needs a list of campaign IDs (IDs should be ints)
pg_reporting = rlabsreporting.pg.PgReporting(campaign_ids)
Getting campaigns:
pg_reporting.get_campaigns()
==> creates a pg_reporting.campaigns
object, which is a
dictionary with campaign ID as keys and campaign titles as values
Getting survey responses:
pg_reporting.get_survey()
==> create a pg_reporting.survey
object, which is a dictionary with
campaign ID as keys, with dictionaries of question-keys
and response-values. (So, a nested ditionary of dictionaries -- not
sure how much I like nesting though, but that's the idea for now.)
Getting custom fields:
pg_reporting.get_custom_fields()
==> creates a pg_reporting.custom_fields
object, which is a dictionary
of campaign IDs and the names of their custom fields.
Parameters:
- Path to CSV w/ "flat" campaign export (file format might change, but CSV is ok for now)
- Excel sheet names (for each desired type of response), with the specific Spoke survey questions and associated reponses
- Desired custom fields
Example of #2:
{
"Know when they will vote": {
"Do they know when they will vote?": [
"Yes, they know when to vote",
"Yes"
],
"Do they know when to vote?": [
"Yes"
]
},
"Negative responses": {
"Do they know when they will vote?": [
"No",
"No they do not know when they will vote"
],
"Do they know when to vote?": [
"No"
]
}
}
Example of #3:
["DWID", "VAN_ID"]
- -1: Error
- 0: Requested (Default)
- 1: In progress
- 2: Completed
- 3: Cancelled
NOTE: Requires a .env file w/ Redshift credentials in current directory.
import rlabsreporting
rput = rlabsreporting.RedisPut()
rput.get_campaigns()
rput.get_custom_fields()
rput.get_survey()
rput.make_all_campaign_json()
rput.load_all_campaigns_into_redis()
New field: Priority (integer) Default: 0
New field: URL of object (will be stored on S3, but that's an unneeded detail in this context)
- Returns list of all report tasks
- Example:
{"reports": [{"id": 0, "c_ids": "6000,6001,6002", "name": "somename", "created_at": unixtime, "status" 0}]}
Probably should turn c_ids value into a JSON list.
- Accepts JSON object with four fields. Example:
{"name": somename, "surveys": [], "c_ids", [6000, 6001, 6002], "custom_fields": []}
Return 400 on bad request.
- Returns dict of JSON
One field: status Updates status of a report. (Cancelled, done, etc)
In future could allow arbitrary changing of fields.
[email protected]
needs its EnvironmentFile
value edited
to a environment with all Redshift credentials
Can also update Docker container and docker-dev.sh
to also have
credentials.
This looks clear. Would you consider returning lists of objects for get_campaigns(), get_survey(), and get_custom_fields() rather than a single object, where the campaign_id is stored as a value in each object? I've been finding that kind of interface much simpler for iterations, etc.