|
|
from datetime import datetime,timedelta |
|
|
import pandas as pd |
|
|
import os |
|
|
import sys |
|
|
import git |
|
|
from pympler.tracker import SummaryTracker |
|
|
|
|
|
|
|
|
root = git.Repo('.', search_parent_directories = True).working_tree_dir |
|
|
sys.path.append(root) |
|
|
os.chdir(os.path.join(root)) |
|
|
|
|
|
from lib.data_helpers.pull_events import PullEvents |
|
|
from lib.utilities import serialize |
|
|
from data.source.build_master.pullers.pull_events_use import PullEventsUse |
|
|
from data.source.build_master.pullers.pull_events_alt import PullEventsAlt |
|
|
|
|
|
|
|
|
from lib.data_helpers.clean_events import CleanEvents |
|
|
from data.source.build_master.cleaners.clean_surveys import CleanSurveys |
|
|
from data.source.build_master.cleaners.clean_events_use import CleanEventsUse |
|
|
from data.source.build_master.cleaners.clean_events_status import CleanEventsStatus |
|
|
from data.source.build_master.cleaners.clean_events_budget import CleanEventsBudget |
|
|
from data.source.build_master.cleaners.clean_events_snooze_delays import CleanEventsSnoozeDelays |
|
|
from data.source.build_master.cleaners.clean_events_snooze import CleanEventsSnooze |
|
|
from data.source.build_master.cleaners.clean_events_alt import CleanEventsAlt |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from lib.data_helpers.gaming import Gaming |
|
|
from data.source.build_master.master_raw_user import MasterRawUser |
|
|
from data.source.build_master.master_raw_user_day_app import MasterRawUserDayApp |
|
|
|
|
|
from lib.experiment_specs import study_config |
|
|
|
|
|
""" |
|
|
|
|
|
""" |
|
|
class Builder(): |
|
|
|
|
|
@staticmethod |
|
|
def build_master(): |
|
|
tracker = SummaryTracker() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(f"\nCleaning Traditional Use Individual {datetime.now()}") |
|
|
Builder._build_pd_use_indiv() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_use(): |
|
|
pd_use_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="Use", |
|
|
scratch=False, |
|
|
test=False, |
|
|
time_cols=["Created", "Recorded"], |
|
|
raw_timezone="Local", |
|
|
appcode_col='Source', |
|
|
identifying_cols=["AppCode", "ForegroundApp", "ScreenActive", |
|
|
"CreatedDatetimeHour"], |
|
|
sort_cols= ["CreatedDatetimeHour","RecordedDatetimeHour"], |
|
|
drop_cols= ["PlayStoreCategory","UploadLag"], |
|
|
cat_cols = ["ForegroundApp"], |
|
|
compress_type="txt", |
|
|
processing_func=PullEventsUse.process_raw_use) |
|
|
|
|
|
raw_hour_use = pd_use_puller.update_data() |
|
|
|
|
|
use_cleaner = CleanEvents(source="PhoneDashboard", keyword="Use") |
|
|
use_phase, use_hour = use_cleaner.clean_events(raw_event_df=raw_hour_use, |
|
|
date_col="CreatedDate", |
|
|
cleaner=CleanEventsUse(use_type="Traditional")) |
|
|
|
|
|
CleanEventsUse.get_timezones(use_hour, "CreatedDatetimeHour", "CreatedEasternDatetimeHour") |
|
|
|
|
|
|
|
|
return use_phase, use_hour |
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_use_indiv(): |
|
|
pd_use_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="UseIndiv", |
|
|
scratch=True, |
|
|
test=False, |
|
|
time_cols=["Created", "Recorded"], |
|
|
raw_timezone="Local", |
|
|
appcode_col='Source', |
|
|
identifying_cols=["AppCode", "ForegroundApp", "StartTime", "UseMinutes"], |
|
|
sort_cols= ["StartTime"], |
|
|
drop_cols= ["PlayStoreCategory","UploadLag"], |
|
|
cat_cols = ["ForegroundApp"], |
|
|
compress_type="txt", |
|
|
processing_func=PullEventsUse.process_raw_use_indiv) |
|
|
|
|
|
raw_hour_use = pd_use_puller.update_data() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_status(raw_master: pd.DataFrame, alt_use_hour: pd.DataFrame): |
|
|
pd_use_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="Status", |
|
|
scratch=False, |
|
|
test=False, |
|
|
time_cols=["LastUpload"], |
|
|
raw_timezone="Local", |
|
|
appcode_col='Participant', |
|
|
identifying_cols=["AppCode", "Group", "Blocker", |
|
|
"LastUpload", "AppVersion","PlatformVersion","PhoneModel","OptedOut"], |
|
|
sort_cols = ["LastUpload"], |
|
|
drop_cols = ['PhaseUseBrowser(ms)', |
|
|
'PhaseUseFB(ms)', |
|
|
'PhaseUseIG(ms)', |
|
|
'PhaseUseOverall(ms)', |
|
|
'PhaseUseSnap(ms)', |
|
|
'PhaseUseYoutube(ms)',"AsOf"], |
|
|
cat_cols = [], |
|
|
compress_type="txt",) |
|
|
|
|
|
raw_status = pd_use_puller.update_data() |
|
|
raw_status["LastUploadDate"] = raw_status["LastUpload"].apply(lambda x: x.date()) |
|
|
use_cleaner = CleanEvents(source="PhoneDashboard", keyword="Status") |
|
|
clean_status = use_cleaner.clean_events(raw_event_df=raw_status, |
|
|
date_col="LastUploadDate", |
|
|
cleaner=CleanEventsStatus(), |
|
|
phase_data=False) |
|
|
|
|
|
pd_latest = CleanEventsStatus.get_latest_pd_health(clean_status, raw_master, alt_use_hour) |
|
|
return clean_status, pd_latest |
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_alt(clean_trad_use_hour): |
|
|
alt_json_reader = PullEventsAlt() |
|
|
pd_alt_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="Alternative", |
|
|
scratch=False, |
|
|
test=False, |
|
|
time_cols=["Created"], |
|
|
raw_timezone="Local", |
|
|
appcode_col='AppCode', |
|
|
identifying_cols=["AppCode", "ForegroundApp", "CreatedDatetimeHour"], |
|
|
sort_cols = ["Observed","CreatedDatetimeHour"], |
|
|
drop_cols = ["Com.AudaciousSoftware.PhoneDashboard.AppTimeBudget", "Timezone", |
|
|
"CreatedDatetime","CreatedEasternDatetime","Label", "CreatedDate", |
|
|
"PlayStoreCategory","DaysObserved","Index","ZipFolder","CreatedEasternMinusLocalHours"], |
|
|
cat_cols = ["ForegroundApp"], |
|
|
compress_type="folder", |
|
|
processing_func=alt_json_reader.process_raw_use, |
|
|
file_reader=alt_json_reader.read_alt) |
|
|
|
|
|
|
|
|
|
|
|
raw_alt_use_hour = pd_alt_puller.update_data() |
|
|
try: |
|
|
combined_raw_alt_use_hour = PullEventsAlt.combine_trad_alt(raw_alt_use_hour,clean_trad_use_hour) |
|
|
except: |
|
|
print("could not combine trad and alt") |
|
|
combined_raw_alt_use_hour = raw_alt_use_hour.copy() |
|
|
|
|
|
use_cleaner = CleanEvents(source="PhoneDashboard", keyword="Alternative") |
|
|
use_phase, use_hour = use_cleaner.clean_events(raw_event_df=combined_raw_alt_use_hour, |
|
|
date_col="CreatedDate", |
|
|
cleaner=CleanEventsUse(use_type="Alternative")) |
|
|
|
|
|
config_user_dict = serialize.open_yaml("config_user.yaml") |
|
|
if config_user_dict['local']['test']== False: |
|
|
try: |
|
|
print(f"\n Clean Alt Install data events {datetime.now()}") |
|
|
CleanEventsAlt.process_appcode_files( |
|
|
input_folder = os.path.join("data", "external", "input", "PhoneDashboard", "RawAltInstall"), |
|
|
output_file = os.path.join("data", "external", "intermediate", "PhoneDashboard", "AltInstall"), |
|
|
cleaning_function= CleanEventsAlt.clean_install |
|
|
) |
|
|
except: |
|
|
print("could not aggregate install data") |
|
|
return use_hour, use_phase |
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_budget(): |
|
|
"""processes the limit setting data""" |
|
|
pd_budget_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="Budget", |
|
|
scratch=False, |
|
|
test=False, |
|
|
time_cols=["Updated","EffectiveDate"], |
|
|
raw_timezone="Local", |
|
|
appcode_col="Source", |
|
|
identifying_cols=["AppCode", "App", "Updated", "EffectiveDate"], |
|
|
sort_cols=["Updated"], |
|
|
drop_cols = [], |
|
|
cat_cols = [], |
|
|
compress_type="txt") |
|
|
|
|
|
pd_budget = pd_budget_puller.update_data() |
|
|
|
|
|
budget_cleaner = CleanEvents(source="PhoneDashboard", keyword="Budget") |
|
|
clean_budget = budget_cleaner.clean_events(raw_event_df=pd_budget, |
|
|
date_col="EffectiveDate", |
|
|
cleaner=CleanEventsBudget(), |
|
|
phase_data = False) |
|
|
|
|
|
budget_sum = CleanEventsBudget.get_latest_budget_data(clean_budget) |
|
|
|
|
|
return budget_sum, clean_budget |
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_snooze_delay(): |
|
|
"""process the custom snooze data (post study functionality)""" |
|
|
pd_snooze_delay_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="Delays", |
|
|
scratch = False, |
|
|
test = False, |
|
|
time_cols=["UpdatedDatetime", "EffectiveDatetime"], |
|
|
raw_timezone = "Local", |
|
|
appcode_col="App Code", |
|
|
identifying_cols=["AppCode", "SnoozeDelay", "UpdatedDatetime"], |
|
|
sort_cols = ["UpdatedDatetime"], |
|
|
drop_cols= [], |
|
|
cat_cols = [], |
|
|
compress_type="txt") |
|
|
|
|
|
raw_delayed_snooze = pd_snooze_delay_puller.update_data() |
|
|
snooze_delay_cleaner = CleanEvents(source="PhoneDashboard", keyword="Delays") |
|
|
|
|
|
clean_delays = snooze_delay_cleaner.clean_events(raw_event_df=raw_delayed_snooze, |
|
|
date_col= "EffectiveDate", |
|
|
cleaner= CleanEventsSnoozeDelays(), |
|
|
phase_data=False) |
|
|
|
|
|
clean_delays.to_csv(os.path.join("data","external", "intermediate", "PhoneDashboard", "Delays.csv")) |
|
|
|
|
|
|
|
|
|
|
|
@staticmethod |
|
|
def _build_pd_snooze(): |
|
|
"""processes the snooze event data""" |
|
|
pd_snooze_puller = PullEvents(source="PhoneDashboard", |
|
|
keyword="Snooze", |
|
|
scratch = False, |
|
|
test = False, |
|
|
time_cols=["Recorded", "Created"], |
|
|
raw_timezone = "Local", |
|
|
appcode_col="Source", |
|
|
identifying_cols=["AppCode", "App", "Event", "Created"], |
|
|
sort_cols = ["Created"], |
|
|
drop_cols= [], |
|
|
cat_cols = [], |
|
|
compress_type="txt") |
|
|
|
|
|
raw_snooze = pd_snooze_puller.update_data() |
|
|
|
|
|
snooze_cleaner = CleanEvents(source="PhoneDashboard", keyword="Snooze") |
|
|
|
|
|
pd_snooze = snooze_cleaner.clean_events(raw_event_df=raw_snooze, |
|
|
date_col= "Date", |
|
|
cleaner= CleanEventsSnooze(), |
|
|
phase_data=False) |
|
|
|
|
|
CleanEventsSnooze.get_premature_blocks(pd_snooze) |
|
|
|
|
|
return pd_snooze |
|
|
|
|
|
if __name__ == "__main__": |
|
|
pd_snooze = Builder._build_pd_snooze_delay() |