<commit_before>import orca
from activitysim import defaults
from activitysim import tracing
import pandas as pd
import numpy as np
import os

from activitysim.tracing import print_elapsed_time

from activitysim import pipeline
import extensions


# comment out the line below to default base seed to 0 random seed so that run results are reproducible
# pipeline.get_rn_generator().set_base_seed(seed=None)


tracing.config_logger()

t0 = print_elapsed_time()

_MODELS = [
    'compute_accessibility',
    'school_location_simulate',
    'workplace_location_simulate',
    'auto_ownership_simulate',
    'cdap_simulate',
    'mandatory_tour_frequency',
    'mandatory_scheduling',
    'non_mandatory_tour_frequency',
    'destination_choice',
    'non_mandatory_scheduling',
    'tour_mode_choice_simulate',
    'trip_mode_choice_simulate'
]


resume_after = None
# resume_after = 'mandatory_tour_frequency'

pipeline.run(models=_MODELS, resume_after=resume_after)

print "\n#### run completed"

# retrieve the state of a checkpointed table after a specific model was run
df = pipeline.get_table(table_name="persons", checkpoint_name="school_location_simulate")
print "\npersons table columns after school_location_simulate:", df.columns.values

# get_table without checkpoint_name returns the latest version of the table
df = pipeline.get_table("tours")
print "\ntour_type value counts\n", df.tour_type.value_counts()

# get_table for a computed (non-checkpointed, internal, orca) table
# return the most recent value of a (non-checkpointed, internal) computed table
df = pipeline.get_table("persons_merged")
df = df[ ['household_id', 'age', 'auPkTotal', 'roundtrip_auto_time_to_work']]
print "\npersons_merged selected columns\n", df.head(20)

# write final versions of all checkpointed dataframes to CSV files to review results
for table_name in pipeline.checkpointed_tables():
    file_name = "final_%s_table.csv" % table_name
    file_path = os.path.join(orca.get_injectable("output_dir"), file_name)
    pipeline.get_table('households').to_csv(file_path)

# tables will no longer be available after pipeline is closed
pipeline.close()

t0 = print_elapsed_time("all models", t0)<commit_msg>updated example and fixed bug writing out tables #170<commit_after>import orca
from activitysim import defaults
from activitysim import tracing
import pandas as pd
import numpy as np
import os

from activitysim.tracing import print_elapsed_time

from activitysim import pipeline
import extensions


# comment out the line below to default base seed to 0 random seed
# so that run results are reproducible
# pipeline.get_rn_generator().set_base_seed(seed=None)


tracing.config_logger()

t0 = print_elapsed_time()

_MODELS = [
    'compute_accessibility',
    'school_location_simulate',
    'workplace_location_simulate',
    'auto_ownership_simulate',
    'cdap_simulate',
    'mandatory_tour_frequency',
    'mandatory_scheduling',
    'non_mandatory_tour_frequency',
    'destination_choice',
    'non_mandatory_scheduling',
    'tour_mode_choice_simulate',
    'create_simple_trips',
    'trip_mode_choice_simulate'
]


resume_after = None
# resume_after = 'mandatory_tour_frequency'

pipeline.run(models=_MODELS, resume_after=resume_after)

print "\n#### run completed"

# retrieve the state of a checkpointed table after a specific model was run
df = pipeline.get_table(table_name="persons", checkpoint_name="school_location_simulate")
print "\npersons table columns after school_location_simulate:", df.columns.values

# get_table without checkpoint_name returns the latest version of the table
df = pipeline.get_table("tours")
print "\ntour_type value counts\n", df.tour_type.value_counts()

# get_table for a computed (non-checkpointed, internal, orca) table
# return the most recent value of a (non-checkpointed, internal) computed table
df = pipeline.get_table("persons_merged")
df = df[['household_id', 'age', 'auPkTotal', 'roundtrip_auto_time_to_work']]
print "\npersons_merged selected columns\n", df.head(20)

# write final versions of all checkpointed dataframes to CSV files to review results
for table_name in pipeline.checkpointed_tables():
    file_name = "final_%s_table.csv" % table_name
    file_path = os.path.join(orca.get_injectable("output_dir"), file_name)
    pipeline.get_table(table_name).to_csv(file_path)

# tables will no longer be available after pipeline is closed
pipeline.close()

t0 = print_elapsed_time("all models", t0)
{'fraction_non_alphanumeric': 0.08643915581499775, 'fraction_numerical': 0.003367759317467445, 'mean_word_length': 5.896284829721362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6052673', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1363, 'n_words': 381}