ActiveData-ETL/vendor/tuid/util.py

33 строки
901 B
Python

# encoding: utf-8
#
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from collections import namedtuple
def map_to_array(pairs):
"""
MAP THE (tuid, line) PAIRS TO A SINGLE ARRAY OF TUIDS
:param pairs:
:return:
"""
if pairs:
pairs = [TuidMap(*p) for p in pairs]
max_line = max(p.line for p in pairs)
tuids = [None] * max_line
for p in pairs:
if p.line: # line==0 IS A PLACEHOLDER FOR FILES THAT DO NOT EXIST
tuids[p.line-1] = p.tuid
return tuids
else:
return None
# Used for increasing readability
# Can be accessed with tmap_obj.line, tmap_obj.tuid
TuidMap = namedtuple(str("TuidMap"), [str("tuid"), str("line")])
MISSING = TuidMap(-1, 0)