Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qualtrics integration preliminary #159

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ fastapi = "0.101"
typing-extensions = "4.5.0"
kaleido = "0.2.1"
lida = "^0.0.11"
qualtricsapi = "^0.6.1"

[tool.poetry.group.dev.dependencies]
bandit = "^1.7.1"
Expand Down
21 changes: 21 additions & 0 deletions tests/devices/qualtrics/test_qualtrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pytest
import pandas as pd
import wearipedia

@pytest.mark.parametrize("real", [True, False])
def test_qualtrics(real):

synthetic_survey = "your_survey_id_here"

device = wearipedia.get_device(
"qualtrics/qualtrics",
survey=synthetic_survey,
)

if real:
wearipedia._authenticate_device("qualtrics", device)

data = device.get_data('responses')

# Check that the data is a pandas DataFrame
assert isinstance(data, pd.DataFrame), f"Data is not a pandas DataFrame"
1 change: 1 addition & 0 deletions wearipedia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def get_all_device_names():
"polar/vantage",
"strava/strava",
"myfitnesspal/myfitnesspal",
"qualtrics/qualtrics",
]


Expand Down
1 change: 1 addition & 0 deletions wearipedia/devices/qualtrics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .qualtrics import *
50 changes: 50 additions & 0 deletions wearipedia/devices/qualtrics/qualtrics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from ...utils import seed_everything
from ..device import BaseDevice
from .qualtrics_fetch import *
from .qualtrics_gen import *

from QualtricsAPI.Setup import Credentials

class_name = "Qualtrics"

class Qualtrics(BaseDevice):
def __init__(self, seed=0, survey="SV_6FDXhJO8mupUnuC"):
cheejung marked this conversation as resolved.
Show resolved Hide resolved
params = {
"seed": seed,
"survey": str(survey),
}

self._initialize_device_params(
[
"responses",
],
params,
{
"seed": 0,
"synthetic_survey": "your_survey_id_here",
},
)

def _default_params(self):
return {
"survey": self.init_params["synthetic_survey"],
}

def _get_real(self, data_type, params):
return fetch_real_data(
params["survey"]
)

def _filter_synthetic(self, data, data_type, params):
return data

def _gen_synthetic(self):
seed_everything(self.init_params["seed"])
self.responses = create_syn_data(
self.init_params["synthetic_survey"],
)

def _authenticate(self, auth_creds):
token = auth_creds["token"]
data_center = auth_creds["data_center"]
Credentials().qualtrics_api_credentials(token=token, data_center=data_center)
6 changes: 6 additions & 0 deletions wearipedia/devices/qualtrics/qualtrics_fetch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from QualtricsAPI.Survey import Responses
from QualtricsAPI.Setup import Credentials

def fetch_real_data(survey):
cheejung marked this conversation as resolved.
Show resolved Hide resolved
responses = Responses().get_survey_responses(survey=survey, useLabels=True)
return responses
8 changes: 8 additions & 0 deletions wearipedia/devices/qualtrics/qualtrics_gen.py
cheejung marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import os
import pandas as pd

def create_syn_data(survey):
cheejung marked this conversation as resolved.
Show resolved Hide resolved
script_dir = os.path.dirname(__file__)
survey_file = os.path.join(script_dir, "sample_survey.csv")
df = pd.read_csv(survey_file)
return df
24 changes: 24 additions & 0 deletions wearipedia/devices/qualtrics/sample_survey.csv

Large diffs are not rendered by default.