Skip to content

Commit eb19aa4

Browse files
committed
Move signal name constants to their own file, referenced from both run.py and process.py
1 parent 4d3bc3e commit eb19aa4

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
HOME_DWELL = 'median_home_dwell_time'
4+
COMPLETELY_HOME = 'completely_home_prop'
5+
FULL_TIME_WORK = 'full_time_work_prop'
6+
PART_TIME_WORK = 'part_time_work_prop'
7+
8+
SIGNALS = [
9+
HOME_DWELL,
10+
COMPLETELY_HOME,
11+
FULL_TIME_WORK,
12+
PART_TIME_WORK
13+
]
14+
15+
GEO_RESOLUTIONS = [
16+
'county',
17+
'state',
18+
]

safegraph/delphi_safegraph/process.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
import numpy as np
33
import pandas as pd
44

5+
from .constants import HOME_DWELL, COMPLETELY_HOME, FULL_TIME_WORK, PART_TIME_WORK
56
from .geo import FIPS_TO_STATE
67

78
# Magic number for modular arithmetic; CBG -> FIPS
89
MOD = 10000000
910

10-
1111
def add_prefix(signal_names, wip_signal, prefix: str):
1212
"""Adds prefix to signal if there is a WIP signal
1313
Parameters
@@ -90,10 +90,6 @@ def construct_signals(cbg_df, signal_names):
9090
Dataframe with columns: timestamp, county_fips, and
9191
{each signal described above}.
9292
"""
93-
prefix = 'wip_'
94-
COMPLETELY_HOME = 'completely_home_prop'
95-
FULL_TIME_WORK = 'full_time_work_prop'
96-
PART_TIME_WORK = 'part_time_work_prop'
9793

9894
# Preparation
9995
cbg_df['timestamp'] = cbg_df['date_range_start'].apply(
@@ -103,13 +99,13 @@ def construct_signals(cbg_df, signal_names):
10399

104100
# Transformation: create signal not available in raw data
105101
for signal in signal_names:
106-
if signal in (FULL_TIME_WORK, prefix + FULL_TIME_WORK):
102+
if signal.endswith(FULL_TIME_WORK):
107103
cbg_df[signal] = (cbg_df['full_time_work_behavior_devices']
108104
/ cbg_df['device_count'])
109-
elif signal in (COMPLETELY_HOME, prefix + COMPLETELY_HOME):
105+
elif signal.endswith(COMPLETELY_HOME):
110106
cbg_df[signal] = (cbg_df['completely_home_device_count']
111107
/ cbg_df['device_count'])
112-
elif signal in (PART_TIME_WORK, prefix + PART_TIME_WORK):
108+
elif signal.endswith(PART_TIME_WORK):
113109
cbg_df[signal] = (cbg_df['part_time_work_behavior_devices']
114110
/ cbg_df['device_count'])
115111

safegraph/delphi_safegraph/run.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,9 @@
99

1010
from delphi_utils import read_params
1111

12+
from .constants import SIGNALS, GEO_RESOLUTIONS
1213
from .process import process, add_prefix
1314

14-
SIGNALS = [
15-
'median_home_dwell_time',
16-
'completely_home_prop',
17-
'full_time_work_prop',
18-
'part_time_work_prop'
19-
]
20-
21-
GEO_RESOLUTIONS = [
22-
'county',
23-
'state',
24-
]
25-
26-
2715
def run_module():
2816

2917
params = read_params()

0 commit comments

Comments
 (0)