Skip to content

Commit

Permalink
Modify names of dat folders and files
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Sep 18, 2019
1 parent 5673ddd commit 41909b8
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 70 deletions.
18 changes: 9 additions & 9 deletions pyrcs/line_data_cls/crs_nlc_tiploc_stanox.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ def __init__(self, data_dir=None):
self.URL = self.HomeURL + '/crs/CRS0.shtm'
self.Catalogue = get_catalogue(self.URL)
self.Date = get_last_updated_date(self.URL, parsed=True, date_type=False)
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line_data", "crs_nlc_tiploc_stanox")
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", "crs-nlc-tiploc-stanox")
self.CurrentDataDir = copy.copy(self.DataDir)

# Change directory to "dat\\line_data\\crs_nlc_tiploc_stanox\\" and sub-directories
# Change directory to "dat\\line-data\\crs-nlc-tiploc-stanox\\" and sub-directories
def cd_lc(self, *sub_dir):
path = self.DataDir
for x in sub_dir:
path = os.path.join(path, x)
return path

# Change directory to "dat\\line_data\\crs_nlc_tiploc_stanox\\dat" and sub-directories
# Change directory to "dat\\line-data\\crs-nlc-tiploc-stanox\\dat" and sub-directories
def cdd_lc(self, *sub_dir):
path = self.cd_lc("dat")
for x in sub_dir:
Expand Down Expand Up @@ -113,7 +113,7 @@ def collect_additional_crs_note(self, confirmation_required=True, verbose=False)
else:
additional_crs_note.update({'Alternative_CRS': x})
additional_crs_note.update({'Note': notes})
save_pickle(additional_crs_note, self.cd_lc("additional_crs_note.pickle"), verbose)
save_pickle(additional_crs_note, self.cd_lc("additional-crs-note.pickle"), verbose)

except Exception as e:
print("Failed to collect/update additional note for CRS. {}.".format(e))
Expand All @@ -123,7 +123,7 @@ def collect_additional_crs_note(self, confirmation_required=True, verbose=False)

# Fetch note about CRS
def fetch_additional_crs_note(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "additional_crs_note.pickle"
pickle_filename = "additional-crs-note.pickle"
path_to_pickle = self.cd_lc(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down Expand Up @@ -158,7 +158,7 @@ def collect_other_systems_codes(self, confirmation_required=True, verbose=False)
codes = [tables[i] for i in range(len(tables)) if i % 2 != 0]
# Make a dict
other_systems_codes = dict(zip(system_names, codes))
save_pickle(other_systems_codes, self.cd_lc("other_systems_codes.pickle"), verbose)
save_pickle(other_systems_codes, self.cd_lc("other-systems-codes.pickle"), verbose)

except Exception as e:
print("Failed to collect location codes for other systems. {}.".format(e))
Expand All @@ -168,7 +168,7 @@ def collect_other_systems_codes(self, confirmation_required=True, verbose=False)

# Fetch the data for other systems
def fetch_other_systems_codes(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "other_systems_codes.pickle"
pickle_filename = "other-systems-codes.pickle"
path_to_pickle = self.cd_lc(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down Expand Up @@ -197,7 +197,7 @@ def collect_location_codes_by_initial(self, initial, update=False, verbose=False
[str]} date of when the data was last updated)
"""
assert initial in string.ascii_letters
path_to_pickle = self.cd_lc("a_z", initial.lower() + ".pickle")
path_to_pickle = self.cd_lc("a-z", initial.lower() + ".pickle")

if os.path.isfile(path_to_pickle) and not update:
location_codes_data = load_pickle(path_to_pickle)
Expand Down Expand Up @@ -334,7 +334,7 @@ def fetch_location_codes(self, update=False, pickle_it=False, data_dir=None, ver

if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, "crs_nlc_tiploc_stanox_codes.pickle")
path_to_pickle = os.path.join(self.CurrentDataDir, "crs-nlc-tiploc-stanox-codes.pickle")
save_pickle(location_codes, path_to_pickle, verbose=True)

return location_codes
Expand Down
24 changes: 12 additions & 12 deletions pyrcs/line_data_cls/electrification.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ def __init__(self, data_dir=None):
self.URL = self.HomeURL + '/electrification/mast_prefix0.shtm'
self.Catalogue = get_catalogue(self.URL)
self.Date = get_last_updated_date(self.URL, parsed=True, date_type=False)
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line_data", 'electrification')
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", 'electrification')
self.CurrentDataDir = copy.copy(self.DataDir)

# Change directory to "dat\\line_data\\electrification" and sub-directories
# Change directory to "dat\\line-data\\electrification" and sub-directories
def cd_elec(self, *sub_dir):
path = self.DataDir
for x in sub_dir:
path = os.path.join(path, x)
return path

# Change directory to "dat\\line_data\\electrification\\dat" and sub-directories
# Change directory to "dat\\line-data\\electrification\\dat" and sub-directories
def cdd_elec(self, *sub_dir):
path = self.cd_elec("dat")
for x in sub_dir:
Expand Down Expand Up @@ -95,7 +95,7 @@ def collect_codes_for_national_network(self, confirmation_required=True, verbose
last_updated_date = get_last_updated_date(url)
codes_for_ole.update({'Last_updated_date': last_updated_date})

path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "_") + ".pickle")
path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "-") + ".pickle")
save_pickle(codes_for_ole, path_to_pickle, verbose)

except Exception as e:
Expand All @@ -106,7 +106,7 @@ def collect_codes_for_national_network(self, confirmation_required=True, verbose

# Fetch codes for national network
def fetch_codes_for_national_network(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "national_network.pickle"
pickle_filename = "national-network.pickle"
path_to_pickle = self.cd_elec(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down Expand Up @@ -195,7 +195,7 @@ def collect_codes_for_independent_lines(self, confirmation_required=True, verbos
last_updated_date = get_last_updated_date(url)
codes_for_independent_lines.update({'Last_updated_date': last_updated_date})

path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "_") + ".pickle")
path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "-") + ".pickle")
save_pickle(codes_for_independent_lines, path_to_pickle, verbose)

except Exception as e:
Expand All @@ -206,7 +206,7 @@ def collect_codes_for_independent_lines(self, confirmation_required=True, verbos

# Fetch codes for independent lines
def fetch_codes_for_independent_lines(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "independent_lines.pickle"
pickle_filename = "independent-lines.pickle"
path_to_pickle = self.cd_elec(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down Expand Up @@ -240,7 +240,7 @@ def collect_codes_for_ohns(self, confirmation_required=True, verbose=False):
last_updated_date = get_last_updated_date(url)
ohns = {'Codes': neutral_sections_data, 'Last_updated_date': last_updated_date}

path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "_") + ".pickle")
path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "-") + ".pickle")
save_pickle(ohns, path_to_pickle, verbose)

except Exception as e:
Expand All @@ -251,7 +251,7 @@ def collect_codes_for_ohns(self, confirmation_required=True, verbose=False):

# Fetch codes for Overhead line electrification neutral sections (OHNS)
def fetch_codes_for_ohns(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "national_network_neutral_sections.pickle"
pickle_filename = "national-network-neutral-sections.pickle"
path_to_pickle = self.cd_elec(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down Expand Up @@ -314,7 +314,7 @@ def collect_codes_for_energy_tariff_zones(self, confirmation_required=True, verb
last_updated_date = get_last_updated_date(url)
codes_for_energy_tariff_zones.update({'Last_updated_date': last_updated_date})

path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "_") + ".pickle")
path_to_pickle = self.cd_elec(title_name.lower().replace(" ", "-") + ".pickle")
save_pickle(codes_for_energy_tariff_zones, path_to_pickle, verbose)

except Exception as e:
Expand All @@ -325,7 +325,7 @@ def collect_codes_for_energy_tariff_zones(self, confirmation_required=True, verb

# Fetch codes for Overhead line electrification neutral sections (OHNS)
def fetch_codes_for_energy_tariff_zones(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "national_network_energy_tariff_zones.pickle"
pickle_filename = "national-network-energy-tariff-zones.pickle"
path_to_pickle = self.cd_elec(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down Expand Up @@ -358,7 +358,7 @@ def fetch_electrification_codes(self, update=False, pickle_it=False, data_dir=No
electrification_codes = dict(zip(items, [national_network, independent_lines, ohns, energy_tariff_zones]))

if pickle_it and data_dir:
pickle_filename = "electrification_codes.pickle"
pickle_filename = "electrification-codes.pickle"
self.CurrentDataDir = regulate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(electrification_codes, path_to_pickle, verbose=True)
Expand Down
13 changes: 7 additions & 6 deletions pyrcs/line_data_cls/line_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ def __init__(self, data_dir=None):
self.Name = 'Railway line names'
self.URL = self.HomeURL + '/misc/line_names.shtm'
self.Date = get_last_updated_date(self.URL, parsed=True, date_type=False)
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line_data", "line_names")
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", "line-names")
self.CurrentDataDir = copy.copy(self.DataDir)

# Change directory to "dat\\line_data\\line_names" and sub-directories
# Change directory to "dat\\line-data\\line-names" and sub-directories
def cd_ln(self, *sub_dir):
path = self.DataDir
for x in sub_dir:
path = os.path.join(path, x)
return path

# Change directory to "dat\\line_data\\line_names\\dat" and sub-directories
# Change directory to "dat\\line-data\\line-names\\dat" and sub-directories
def cdd_ln(self, *sub_dir):
path = self.cd_ln("dat")
for x in sub_dir:
Expand Down Expand Up @@ -86,7 +86,7 @@ def parse_route_column(x):

line_names_data = {'Line_names': line_names, 'Last_updated_date': last_updated_date}

save_pickle(line_names_data, self.cd_ln("line_names.pickle"), verbose)
save_pickle(line_names_data, self.cd_ln("line-names.pickle"), verbose)

except Exception as e:
print("Failed to collect line names. {}".format(e))
Expand All @@ -96,7 +96,7 @@ def parse_route_column(x):

# Get the data of line names either locally or from online
def fetch_line_names(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "line_names.pickle"
pickle_filename = "line-names.pickle"
path_to_pickle = self.cd_ln(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand All @@ -105,11 +105,12 @@ def fetch_line_names(self, update=False, pickle_it=False, data_dir=None, verbose
else:
line_names_data = self.collect_line_names(confirmation_required=False,
verbose=False if data_dir or not verbose else True)
if line_names_data: # line_names is not None
if line_names_data: # line-names is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(line_names_data, path_to_pickle, verbose=True)
else:
print("No data of the railway line names has been collected.")

return line_names_data
12 changes: 6 additions & 6 deletions pyrcs/line_data_cls/lor_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ def __init__(self, data_dir=None):
self.URL = self.HomeURL + '/pride/pride0.shtm'
self.Catalogue = get_catalogue(self.URL)
self.Date = get_last_updated_date(self.URL, parsed=True, date_type=False)
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line_data", "lor_codes")
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", "lor-codes")
self.CurrentDataDir = copy.copy(self.DataDir)

# Change directory to "dat\\line_data\\lor_codes" and sub-directories
# Change directory to "dat\\line-data\\lor-codes" and sub-directories
def cd_lor(self, *sub_dir):
path = self.DataDir
for x in sub_dir:
path = os.path.join(path, x)
return path

# Change directory to "dat\\line_data\\lor_codes\\dat" and sub-directories
# Change directory to "dat\\line-data\\lor-codes\\dat" and sub-directories
def cdd_lor(self, *sub_dir):
path = self.cd_lor("dat")
for x in sub_dir:
Expand Down Expand Up @@ -176,7 +176,7 @@ def fetch_lor_codes(self, update=False, pickle_it=False, data_dir=None, verbose=
lor_codes_data.update({'Latest_update_date': latest_update_date})

if pickle_it and data_dir:
pickle_filename = "lor_codes.pickle"
pickle_filename = "lor-codes.pickle"
self.CurrentDataDir = regulate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(lor_codes_data, path_to_pickle, verbose)
Expand Down Expand Up @@ -210,7 +210,7 @@ def collect_elr_lor_converter(self, confirmation_required=True, verbose=False):
#
elr_lor_converter = {'ELR_LOR_converter': elr_lor_dat, 'Last_updated_date': get_last_updated_date(url)}

save_pickle(elr_lor_converter, self.cd_lor("elr_lor_converter.pickle"), verbose)
save_pickle(elr_lor_converter, self.cd_lor("elr-lor-converter.pickle"), verbose)

except Exception as e:
print("Failed to collect \"ELR/LOR converter\". {}".format(e))
Expand All @@ -220,7 +220,7 @@ def collect_elr_lor_converter(self, confirmation_required=True, verbose=False):

# Fetch ELR/LOR converter
def fetch_elr_lor_converter(self, update=False, pickle_it=False, data_dir=None, verbose=False):
pickle_filename = "elr_lor_converter.pickle"
pickle_filename = "elr-lor-converter.pickle"
path_to_pickle = self.cd_lor(pickle_filename)

if os.path.isfile(path_to_pickle) and not update:
Expand Down
6 changes: 3 additions & 3 deletions pyrcs/line_data_cls/track_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ def __init__(self, data_dir=None):
h3 = h3.find_next_sibling('h3') # Move on
self.Catalogue = items
self.Date = get_last_updated_date(self.URL, parsed=True, date_type=False)
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line_data", "track_diagrams")
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", "track_diagrams")
self.CurrentDataDir = copy.copy(self.DataDir)

# Change directory to "...dat\\line_data\\track_diagrams\\" and sub-directories
# Change directory to "...dat\\line-data\\track_diagrams\\" and sub-directories
def cd_td(self, *sub_dir):
path = self.DataDir
for x in sub_dir:
path = os.path.join(path, x)
return path

# Change directory to "dat\\line_data\\track_diagrams\\dat" and sub-directories
# Change directory to "dat\\line-data\\track_diagrams\\dat" and sub-directories
def cdd_td(self, *sub_dir):
path = self.cd_td("dat")
for x in sub_dir:
Expand Down
Loading

0 comments on commit 41909b8

Please sign in to comment.