Add a (useless?) test for features.communication.count_comms.

Formatting.
communication
junos 2021-04-06 17:12:36 +02:00
parent 414b30b7e1
commit b7b60294ba
3 changed files with 23 additions and 8 deletions

View File

@ -1,8 +1,17 @@
from datetime import datetime
from sqlalchemy import (TIMESTAMP, BigInteger, Boolean, Column, Float,
ForeignKey, Integer, SmallInteger, String,
UniqueConstraint)
from sqlalchemy import (
TIMESTAMP,
BigInteger,
Boolean,
Column,
Float,
ForeignKey,
Integer,
SmallInteger,
String,
UniqueConstraint,
)
from sqlalchemy.dialects.postgresql import ARRAY as PSQL_ARRAY
from sqlalchemy.dialects.postgresql import INTEGER as PSQL_INTEGER
from sqlalchemy.dialects.postgresql import JSONB as PSQL_JSONB

View File

@ -2,7 +2,7 @@ from typing import List
import pandas as pd
from config.models import Call, Participant, SMS
from config.models import SMS, Call, Participant
from setup import db_engine, session
call_types = {1: "incoming", 2: "outgoing", 3: "missed"}
@ -117,9 +117,11 @@ def count_comms(comm_df: pd.DataFrame) -> pd.DataFrame:
.add_prefix("duration_")
)
comm_features = comm_counts.join(comm_duration)
try: comm_features.drop(columns="duration_" + call_types[3], inplace=True)
try:
comm_features.drop(columns="duration_" + call_types[3], inplace=True)
# The missed calls are always of 0 duration.
except KeyError: pass
except KeyError:
pass
# If there were no missed calls, this exception is raised.
# But we are dropping the column anyway, so no need to deal with the exception.
elif "message_type" in comm_df:

View File

@ -5,7 +5,7 @@ import pandas as pd
from numpy.random import default_rng
from pandas.testing import assert_series_equal
from features.communication import enumerate_contacts, get_call_data
from features.communication import count_comms, enumerate_contacts, get_call_data
rng = default_rng()
@ -32,7 +32,7 @@ class CallsFeatures(unittest.TestCase):
rng.integers(1612169903000, 1614556703000, size=call_rows)
),
"device_id": "device1",
"call_type": rng.integers(1, 3, size=call_rows),
"call_type": rng.integers(1, 3, size=call_rows, endpoint=True),
"call_duration": rng.integers(0, 600, size=call_rows),
"trace": callers,
"participant_id": 29,
@ -65,3 +65,7 @@ class CallsFeatures(unittest.TestCase):
self.assertSeriesEqual(
self.calls["contact_id_manual"], self.calls["contact_id"], check_names=False
)
def test_count_comms(self):
self.features = count_comms(self.calls)
self.assertIsInstance(self.features, pd.DataFrame)