[WIP] Add tests for ESM.
parent
8bf21ab272
commit
77c2ba87d5
|
@ -1,11 +1,9 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import pandas as pd
|
|
||||||
from numpy.random import default_rng
|
|
||||||
from pandas.testing import assert_series_equal
|
from pandas.testing import assert_series_equal
|
||||||
|
|
||||||
from features.esm import preprocess_esm
|
from features.esm import *
|
||||||
|
from features.esm_JCQ import *
|
||||||
|
|
||||||
|
|
||||||
class EsmFeatures(unittest.TestCase):
|
class EsmFeatures(unittest.TestCase):
|
||||||
|
@ -13,7 +11,31 @@ class EsmFeatures(unittest.TestCase):
|
||||||
def setUpClass(cls) -> None:
|
def setUpClass(cls) -> None:
|
||||||
cls.esm = pd.read_csv("../data/example_esm.csv", sep=";")
|
cls.esm = pd.read_csv("../data/example_esm.csv", sep=";")
|
||||||
cls.esm["esm_json"] = cls.esm["esm_json"].apply(eval)
|
cls.esm["esm_json"] = cls.esm["esm_json"].apply(eval)
|
||||||
|
cls.esm_processed = preprocess_esm(cls.esm)
|
||||||
|
cls.esm_clean = clean_up_esm(cls.esm_processed)
|
||||||
|
|
||||||
def test_preprocess_esm(self):
|
def test_preprocess_esm(self):
|
||||||
self.esm_processed = preprocess_esm(self.esm)
|
self.esm_processed = preprocess_esm(self.esm)
|
||||||
self.assertIn("question_id", self.esm_processed)
|
self.assertIn("question_id", self.esm_processed)
|
||||||
|
|
||||||
|
def test_classify_sessions_by_completion(self):
|
||||||
|
self.esm_classified_sessions = classify_sessions_by_completion(self.esm_processed)
|
||||||
|
self.assertFalse(self.esm_classified_sessions["session_response"].isna().any())
|
||||||
|
# Test that all sessions were indeed classified.
|
||||||
|
|
||||||
|
def test_classify_sessions_by_completion_time(self):
|
||||||
|
self.esm_classified = classify_sessions_by_completion_time(self.esm_processed)
|
||||||
|
session_of_interest = self.esm_classified.query("(device_id == '049df3f8-8541-4cf5-af2b-83f6b3f0cf4b') & (esm_session == 1)")
|
||||||
|
print(session_of_interest)
|
||||||
|
self.assertEqual(session_of_interest["time"], "daytime")
|
||||||
|
# Check that the first (morning) session is reclassified as a daytime session.
|
||||||
|
|
||||||
|
def test_clean_up_esm(self):
|
||||||
|
self.assertNotIn("esm_user_answer_numeric", self.esm_processed)
|
||||||
|
self.assertIn("esm_user_answer_numeric", self.esm_clean)
|
||||||
|
|
||||||
|
def test_reverse_jcq_demand_control_scoring(self):
|
||||||
|
esm_reversed = reverse_jcq_demand_control_scoring(self.esm_clean)
|
||||||
|
print(esm_reversed.loc[esm_reversed["question_id"] == 73, "esm_user_score"])
|
||||||
|
#self.assertIn(1.0, esm_reversed.loc[esm_reversed["question_id"] == 73, "esm_user_score"])
|
||||||
|
#self.assertNotIn(0, esm_reversed.loc[esm_reversed["question_id"] == 73, "esm_user_score"])
|
Loading…
Reference in New Issue