import gzip, os, pandas as pd
import larch.numba as lx

"""
Explanation: 300: Itinerary Choice Data
End of explanation
"""


with gzip.open(lx.example_file("arc"), 'rt') as previewfile:
    print(*(next(previewfile) for x in range(70)))

"""
Explanation: The example itinerary choice described here is based on data derived from a ticketing database
provided by the Airlines Reporting Corporation. The data represent ten origin destination
pairs for travel in U.S. continental markets in May of 2013.   Itinerary characteristics
have been masked, e.g., carriers are labeled generically as "carrier X" and departure times
have been aggregated into categories. A fare is provided but is not completely accurate (a
random error has been added to each fare). These modifications were made to satisfy
nondisclosure agreements, so that the data can be published freely for teaching and
demostration purposes.  It is generally representative of real itinerary choice data used
in practice, and the results obtained from this data are intuitive from a behavioral
perspective, but it is not quite accurate and should not be used for behavioral studies.
In this example we will import the air itinerary choice example dataset, starting from a csv
text file in idca format.  Suppose that data file is gzipped, named "arc.csv.gz" and
is located in the current directory (use os.getcwd to see what is the
current directory).
End of explanation
"""


itin = pd.read_csv(lx.example_file("arc"), index_col=['id_case','id_alt'])
itin.info()

d = lx.Dataset.construct.from_idca(itin, crack=True)
d

"""
Explanation: The first line of the file contains column headers. After that, each line represents
an alternative available to one or more decision makers. In our sample data, we see the first 67
lines of data share a id_case of 1, indicating that they are 67 different itineraries
available to the first decision maker type.  An identidier of the alternatives is given by the
number in the column id_alt, although this number is simply a sequential counter within each case
in the raw data, and conveys no other information about the itinerary or its attributes.
The observed choices of the decision maker[s] are indicated in the column choice.
That column counts the number of travelers who face this choice set and chose the itinerary
described by this row in the file.
We can load this data easily using pandas.  We'll also set the index of the resulting DataFrame to
be the case and alt identifiers.
End of explanation
"""


