Skip to content

Commit

Permalink
Modified keys of dict data
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Jan 10, 2020
1 parent 7d33f4d commit 48e2b90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions pyrcs/line_data_cls/elrs_mileages.py
Expand Up @@ -426,7 +426,7 @@ def collect_mileage_file_by_elr(self, elr, parsed=True, confirmation_required=Tr
sub_headers = sub_line_name.text.split('\t')[1] if sub_line_name else ''

# Make a dict of line information
line_info = {'ELR_code': elr, 'Line': line_name, 'Sub-Line': sub_headers}
line_info = {'ELR': elr, 'Line': line_name, 'Sub-Line': sub_headers}

# Search for note
note_temp = min(parsed_content, key=len)
Expand Down Expand Up @@ -566,7 +566,7 @@ def get_conn_mileages(self, start_elr, end_elr, update=False, pickle_mileage_fil
end_file = self.fetch_mileage_file(end_elr, update, pickle_mileage_file, data_dir, verbose=verbose)

if start_file is not None and end_file is not None:
start_elr, end_elr = start_file['ELR_code'], end_file['ELR_code']
start_elr, end_elr = start_file['ELR'], end_file['ELR']
start_em, end_em = start_file[start_elr], end_file[end_elr]
key_pat = re.compile(r'(Current\s)|(One\s)|(Later\s)|(Usual\s)')
if isinstance(start_em, dict):
Expand All @@ -592,7 +592,7 @@ def get_conn_mileages(self, start_elr, end_elr, update=False, pickle_mileage_fil
conn_elr = conn_temp.iloc[j]
conn_em = self.fetch_mileage_file(conn_elr, update=update)
if conn_em is not None:
conn_elr = conn_em['ELR_code']
conn_elr = conn_em['ELR']
conn_em = conn_em[conn_elr]
if isinstance(conn_em, dict):
conn_em = conn_em[[k for k in conn_em.keys() if re.match(key_pat, k)][0]]
Expand Down
6 changes: 3 additions & 3 deletions pyrcs/other_assets_cls/signal_boxes.py
Expand Up @@ -53,7 +53,7 @@ def collect_signal_box_prefix_codes(self, initial, update=False, verbose=False):
signal_box_prefix_codes = load_pickle(path_to_pickle)

else:
sig_keys = [s + initial.upper() for s in ('Signal_boxes_', 'Last_updated_date_')]
sig_keys = [initial.upper(), 'Last_updated_date']

if initial.upper() not in list(self.Catalogue.keys()):
print("No data is available for signal box codes beginning with \"{}\".".format(initial.upper()))
Expand Down Expand Up @@ -102,11 +102,11 @@ def fetch_signal_box_prefix_codes(self, update=False, pickle_it=False, data_dir=
for x in string.ascii_lowercase]

# Select DataFrames only
signal_boxes_data = (item['Signal_boxes_{}'.format(x)] for item, x in zip(data, string.ascii_uppercase))
signal_boxes_data = (item[x] for item, x in zip(data, string.ascii_uppercase))
signal_boxes_data_table = pd.concat(signal_boxes_data, axis=0, ignore_index=True, sort=False)

# Get the latest updated date
last_updated_dates = (item['Last_updated_date_{}'.format(x)] for item, x in zip(data, string.ascii_uppercase))
last_updated_dates = (item['Last_updated_date'] for item in data)
latest_update_date = max(d for d in last_updated_dates if d != '')

# Create a dict to include all information
Expand Down

0 comments on commit 48e2b90

Please sign in to comment.