Mercurial > hg > cc > cirrus_work
changeset 92:e56a7aad9ce9
attempt at reordering if necessary
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Tue, 05 Sep 2023 17:33:29 +0100 |
parents | 460f0599e8cd |
children | 25bd398a8035 |
files | bin/merge_date.py |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/bin/merge_date.py Tue Sep 05 17:32:46 2023 +0100 +++ b/bin/merge_date.py Tue Sep 05 17:33:29 2023 +0100 @@ -83,14 +83,25 @@ else: return key, None +dfq = [] # for reordering if needed + with open(sys.argv[1], 'rb') as df: - dl = df.readline() - dcnt += 1 + if dfq: + dl = dfq.pop(0) + else: + dl = df.readline() + dcnt += 1 dkey, ddate, dtime = dl.split(b'\t') while (xl:=nextLine()) is not None: xkey, xdate, xprops = xl.split(b' ', maxsplit=2) xkey1, xkey2 = keys(xkey) + if xkey2 is not None: + while dkey.startswith(xkey1) and dkey!=xkey2: + dfq.append(dl) + dl = df.readline() + dcnt += 1 + dkey, ddate, dtime = dl.split(b'\t') if (ddate != xdate or not dkey.startswith(xkey1) or (xkey2 is not None and dkey!=xkey2)): @@ -100,8 +111,8 @@ " xdate: %s\n" " ddate: %s\n" "k1, k2: |%s|%s|\n" - "FN: %s\n" - "xl: %s"%(xkey, dkey, xdate, ddate, xkey1, xkey2, FN, xl), + "FN: %s dcnt: %s\n" + "xl: %s"%(xkey, dkey, xdate, ddate, xkey1, xkey2, FN, dcnt, xl), file=sys.stderr) raise ValueError() NF.write(xl)