rda-python-icoads 1.0.10__tar.gz → 1.0.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of rda-python-icoads might be problematic. Click here for more details.
- {rda_python_icoads-1.0.10/src/rda_python_icoads.egg-info → rda_python_icoads-1.0.12}/PKG-INFO +3 -2
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/pyproject.toml +1 -1
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/PgIMMA.py +144 -102
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/cleanicoads.py +6 -6
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/fillicoads.py +29 -8
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/imma1_subset.py +4 -2
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12/src/rda_python_icoads.egg-info}/PKG-INFO +3 -2
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/LICENSE +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/MANIFEST.in +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/README.md +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/setup.cfg +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/R3.0-stat_doc.pdf +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/README_R3.0_Subset.html +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/__init__.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/checkicoads.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/countattm.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/countattmvar.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/counticoads.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/countsst.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/fillinventory.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/fillitable.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/fillmonth.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/fixiidx.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/maxsst.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/msg +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/msg3.0_subset_readme.txt +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/msg3_subset.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/msg_download.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/msgsubset.f +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/rdimma1_csv.f +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/writeicoads.py +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/SOURCES.txt +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/dependency_links.txt +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/entry_points.txt +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/requires.txt +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/top_level.txt +0 -0
- {rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/tests/test_icoads.py +0 -0
{rda_python_icoads-1.0.10/src/rda_python_icoads.egg-info → rda_python_icoads-1.0.12}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_icoads
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.12
|
|
4
4
|
Summary: RDA python package to manage RDA ICOADS datasets
|
|
5
5
|
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/NCAR/rda-python-icoads
|
|
@@ -12,6 +12,7 @@ Requires-Python: >=3.7
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: rda_python_common
|
|
15
|
+
Dynamic: license-file
|
|
15
16
|
|
|
16
17
|
RDA python package to manage RDA ICOADS datasets.
|
|
17
18
|
|
|
@@ -313,6 +313,7 @@ ISUPPL = { # stti = '99' attl = 0 (variable lenth)
|
|
|
313
313
|
TABLECOUNT = 12
|
|
314
314
|
IMMA_NAMES = ['icoreloc', 'icorereg', 'iicoads', 'iimmt5', 'imodqc', 'imetavos',
|
|
315
315
|
'inocn', 'iecr', 'ireanqc', 'iivad', 'iuida', 'isuppl']
|
|
316
|
+
CHK_NAMES = ['iimmt5', 'imodqc', 'imetavos', 'inocn', 'iecr', 'ireanqc', 'iivad', 'isuppl']
|
|
316
317
|
|
|
317
318
|
#
|
|
318
319
|
# define IMMA sections, core + attms
|
|
@@ -342,6 +343,9 @@ MUNIQUE = {
|
|
|
342
343
|
'iivad' : ['arci', 'cdi']
|
|
343
344
|
}
|
|
344
345
|
|
|
346
|
+
IVADSC = 'ivaddb1'
|
|
347
|
+
CNTLSC = 'cntldb1'
|
|
348
|
+
|
|
345
349
|
MULTI_NAMES = []
|
|
346
350
|
ATTI2NAME = {}
|
|
347
351
|
ATTCPOS = INVENTORY = CURTIDX = CURIIDX = 0
|
|
@@ -358,10 +362,13 @@ ATTM_VARS = {}
|
|
|
358
362
|
MISSING = -999999
|
|
359
363
|
ERROR = -999999
|
|
360
364
|
LEADUID = 0
|
|
365
|
+
CURRN3 = -1
|
|
361
366
|
CHKEXIST = 0
|
|
362
367
|
UIDLENGTH = 0 # uid record len
|
|
363
368
|
UIDOFFSET = 0 # uid value offset
|
|
364
369
|
ATTMNAME = None # standalone attm section name to fill
|
|
370
|
+
DATE2TIDX = {}
|
|
371
|
+
TBLSTATUS = {}
|
|
365
372
|
|
|
366
373
|
#
|
|
367
374
|
# initialize the table information
|
|
@@ -395,6 +402,7 @@ def identify_attm_name(line):
|
|
|
395
402
|
UIDOFFSET = 4
|
|
396
403
|
UIDLENGTH = 15
|
|
397
404
|
atti = line[15:17]
|
|
405
|
+
CURRN3 = int(line[12])
|
|
398
406
|
else:
|
|
399
407
|
atti = None
|
|
400
408
|
|
|
@@ -423,16 +431,15 @@ def cache_field_info(aname, var, uidopt = 0):
|
|
|
423
431
|
#
|
|
424
432
|
# append the individual fields and return imma records for one line input
|
|
425
433
|
#
|
|
426
|
-
def get_imma_records(
|
|
434
|
+
def get_imma_records(cdate, line, records):
|
|
427
435
|
|
|
428
|
-
global CURIIDX
|
|
436
|
+
global CURIIDX
|
|
429
437
|
llen = len(line)
|
|
430
438
|
if llen == 0: return records
|
|
431
439
|
|
|
432
440
|
if CURIUID: # got core section already
|
|
433
441
|
coreidx = 2
|
|
434
442
|
offset = UIDLENGTH
|
|
435
|
-
uid = CURIUID
|
|
436
443
|
else:
|
|
437
444
|
coreidx = 0
|
|
438
445
|
offset = 0
|
|
@@ -450,7 +457,7 @@ def get_imma_records(line, cdate, records):
|
|
|
450
457
|
#48 if aname == 'iivad': pgrec['cdi'] = PgUtil.adddate('2014-01-01', 0, 0, I36(pgrec['cdi']), 'YYYMMDD')
|
|
451
458
|
if aname not in records: records[aname] = initialize_attm_records(imma[3])
|
|
452
459
|
if CURIUID:
|
|
453
|
-
append_one_attm(
|
|
460
|
+
append_one_attm(cdate, imma[0], imma[3], pgrec, records[aname])
|
|
454
461
|
else:
|
|
455
462
|
pgrecs[aname] = pgrec
|
|
456
463
|
|
|
@@ -459,32 +466,29 @@ def get_imma_records(line, cdate, records):
|
|
|
459
466
|
|
|
460
467
|
if CURIUID: return records
|
|
461
468
|
|
|
462
|
-
if 'iuida' not in pgrecs: PgLOG.pglog("Miss UID attm: " + line, PgLOG.LGEREX)
|
|
463
|
-
uid = pgrecs['iuida']['uid']
|
|
464
|
-
records['icoreloc']['date'].append(cdate)
|
|
465
|
-
|
|
466
469
|
for aname in pgrecs:
|
|
467
470
|
imma = IMMAS[aname]
|
|
468
|
-
append_one_attm(
|
|
471
|
+
append_one_attm(cdate, imma[0], imma[3], pgrecs[aname], records[aname])
|
|
469
472
|
|
|
470
473
|
return records
|
|
471
474
|
|
|
472
475
|
#
|
|
473
476
|
# append the individual fields and return imma records for one line of multi-attm record
|
|
474
477
|
#
|
|
475
|
-
def get_imma_multiple_records(line, records):
|
|
478
|
+
def get_imma_multiple_records(cdate, line, records):
|
|
476
479
|
|
|
477
480
|
llen = len(line)
|
|
478
481
|
if llen == 0: return records
|
|
479
482
|
uid = line[4:10]
|
|
480
483
|
offset = 15
|
|
484
|
+
CURRN3 = int(line[12])
|
|
481
485
|
aname = ATTI2NAME[line[15:17]]
|
|
482
486
|
imma = IMMAS[aname]
|
|
483
487
|
if aname not in records: records[aname] = initialize_attm_records(imma[3])
|
|
484
488
|
|
|
485
489
|
while (llen-offset) > 3:
|
|
486
490
|
pgrec = get_one_attm(imma[3], offset, line)
|
|
487
|
-
append_one_attm(
|
|
491
|
+
append_one_attm(cdate, imma[0], imma[3], pgrec, records[aname])
|
|
488
492
|
offset += imma[2]
|
|
489
493
|
|
|
490
494
|
return records
|
|
@@ -551,11 +555,10 @@ def set_imma_field(line):
|
|
|
551
555
|
if not pgrec: return 0
|
|
552
556
|
|
|
553
557
|
if not uid: PgLOG.pglog("Miss UID attm: " + line, PgLOG.LGEREX)
|
|
554
|
-
if not get_itidx_date(uid): return 0
|
|
555
558
|
|
|
556
|
-
tname = "{}
|
|
557
|
-
if PgDBI.pgget(tname, "", "iidx = {} AND {}"
|
|
558
|
-
return PgDBI.pgupdt(tname, pgrec, "iidx = {}"
|
|
559
|
+
tname = f"{IVADSC}.{FIELDINFO['aname']}_{CURTIDX}"
|
|
560
|
+
if PgDBI.pgget(tname, "", f"iidx = {CURIIDX} AND {cnd}"): return 0
|
|
561
|
+
return PgDBI.pgupdt(tname, pgrec, f"iidx = {CURIIDX}", PgLOG.LGEREX)
|
|
559
562
|
|
|
560
563
|
#
|
|
561
564
|
# get all field values for a single attm
|
|
@@ -584,20 +587,18 @@ def get_one_attm(attm, offset, line):
|
|
|
584
587
|
#
|
|
585
588
|
def initialize_attm_records(attm):
|
|
586
589
|
|
|
587
|
-
pgrecs = {'iidx' : [], '
|
|
590
|
+
pgrecs = {'iidx' : [], 'date' : []}
|
|
588
591
|
for var in attm: pgrecs[var] = []
|
|
589
|
-
if 'yr' in attm: pgrecs['date'] = []
|
|
590
592
|
|
|
591
593
|
return pgrecs
|
|
592
594
|
|
|
593
595
|
#
|
|
594
596
|
# append one attm record to the multiple attm records
|
|
595
597
|
#
|
|
596
|
-
def append_one_attm(
|
|
598
|
+
def append_one_attm(cdate, aidx, attm, pgrec, pgrecs):
|
|
597
599
|
|
|
598
|
-
global IMMA_COUNTS
|
|
599
600
|
pgrecs['iidx'].append(CURIIDX)
|
|
600
|
-
|
|
601
|
+
pgrecs['date'].append(cdate)
|
|
601
602
|
for var in attm: pgrecs[var].append(pgrec[var])
|
|
602
603
|
IMMA_COUNTS[aidx] += 1 # row index for individual table
|
|
603
604
|
|
|
@@ -606,7 +607,7 @@ def append_one_attm(uid, aidx, attm, pgrec, pgrecs):
|
|
|
606
607
|
#
|
|
607
608
|
def get_imma_counts(line, acnts):
|
|
608
609
|
|
|
609
|
-
global CURIIDX
|
|
610
|
+
global CURIIDX
|
|
610
611
|
llen = len(line)
|
|
611
612
|
if llen == 0: return acnts
|
|
612
613
|
|
|
@@ -655,8 +656,8 @@ def add_imma_records(cdate, records):
|
|
|
655
656
|
|
|
656
657
|
global INVENTORY, CURTIDX
|
|
657
658
|
if INVENTORY and IMMA_NAMES[0] in records: # add counting record into inventory table
|
|
658
|
-
|
|
659
|
-
if
|
|
659
|
+
rcnt = len(records[IMMA_NAMES[0]]['iidx'])
|
|
660
|
+
if rcnt > 0: INVENTORY = add_inventory_record(INVENTORY['fname'], cdate, rcnt, INVENTORY)
|
|
660
661
|
if CURTIDX < INVENTORY['tidx']: CURTIDX = INVENTORY['tidx']
|
|
661
662
|
tidx = CURTIDX
|
|
662
663
|
else:
|
|
@@ -665,7 +666,7 @@ def add_imma_records(cdate, records):
|
|
|
665
666
|
for i in range(TABLECOUNT):
|
|
666
667
|
if not IMMA_COUNTS[i]: continue
|
|
667
668
|
aname = IMMA_NAMES[i]
|
|
668
|
-
acnts[i] = add_records_to_table(aname, str(tidx), records[aname], cdate)
|
|
669
|
+
acnts[i] = add_records_to_table(IVADSC, aname, str(tidx), records[aname], cdate)
|
|
669
670
|
IMMA_COUNTS[i] = 0
|
|
670
671
|
|
|
671
672
|
iuida = records['iuida'] if 'iuida' in records else None
|
|
@@ -678,18 +679,20 @@ def add_imma_records(cdate, records):
|
|
|
678
679
|
#
|
|
679
680
|
def read_attm_for_date(aname, cdate, tidx = None):
|
|
680
681
|
|
|
681
|
-
|
|
682
|
+
global CURTIDX
|
|
683
|
+
if not tidx:
|
|
682
684
|
tidx = date2tidx(cdate)
|
|
683
|
-
if tidx
|
|
685
|
+
if not tidx: return None
|
|
686
|
+
CURTIDX = tidx
|
|
684
687
|
|
|
685
|
-
|
|
688
|
+
table = f"{IVADSC}.{aname}_{tidx}"
|
|
689
|
+
if aname in CHK_NAMES and not check_table_status(table): return None
|
|
690
|
+
return PgDBI.pgmget(table, "*", f"date = '{cdate}' ORDER BY iidx", PgLOG.LGEREX)
|
|
686
691
|
|
|
687
|
-
|
|
688
|
-
if not PgDBI.pgcheck(table): return None
|
|
689
|
-
loctable = "{}_{}".format(IMMA_NAMES[0], tidx)
|
|
690
|
-
jtables = "{} a, {} b".format(table, loctable)
|
|
692
|
+
def check_table_status(table):
|
|
691
693
|
|
|
692
|
-
|
|
694
|
+
if table not in TBLSTATUS: TBLSTATUS[table] = True if PgDBI.pgcheck(table) else False
|
|
695
|
+
return TBLSTATUS[table]
|
|
693
696
|
|
|
694
697
|
#
|
|
695
698
|
# read core records for given date
|
|
@@ -702,26 +705,60 @@ def read_coreloc_for_date(cdate, tidx = None):
|
|
|
702
705
|
if not tidx: return None
|
|
703
706
|
CURTIDX = tidx
|
|
704
707
|
|
|
705
|
-
return PgDBI.pgmget("{}
|
|
708
|
+
return PgDBI.pgmget(f"{IVADSC}.icoreloc_{tidx}", '*', f"date = '{cdate}' ORDER BY iidx")
|
|
709
|
+
|
|
710
|
+
def uid2iidx_tidx(uid, tidx):
|
|
711
|
+
|
|
712
|
+
uidx = uid[0:2].lower()
|
|
713
|
+
suid = uid[2:6]
|
|
714
|
+
table = f"{CNTLSC}.itidx_{uidx}"
|
|
715
|
+
cond = f"suid = '{suid}' AND tidx = {tidx}"
|
|
716
|
+
pgrec = PgDBI.pgget(table, "iidx", cond, PgLOG.LGEREX)
|
|
717
|
+
if not pgrec:
|
|
718
|
+
PgLOG.pglog(f"{suid}-{tidx}: suid-tidx not in {table}", PgLOG.LGEREX)
|
|
719
|
+
|
|
720
|
+
return pgrec['iidx']
|
|
721
|
+
|
|
722
|
+
def uid2iidx_date(uid, date):
|
|
723
|
+
|
|
724
|
+
uidx = uid[0:2].lower()
|
|
725
|
+
suid = uid[2:6]
|
|
726
|
+
table = f"{CNTLSC}.itidx_{uidx}"
|
|
727
|
+
cond = f"suid = '{suid}' AND date = {date}"
|
|
728
|
+
pgrec = PgDBI.pgget(table, "iidx", cond, PgLOG.LGEREX)
|
|
729
|
+
if not pgrec:
|
|
730
|
+
PgLOG.pglog(f"{suid}-{date}: suid-date not in {table}", PgLOG.LGEREX)
|
|
731
|
+
|
|
732
|
+
return pgrec['iidx']
|
|
733
|
+
|
|
734
|
+
def uid2iidx_rn3(uid, rn3):
|
|
735
|
+
|
|
736
|
+
uidx = uid[0:2].lower()
|
|
737
|
+
suid = uid[2:6]
|
|
738
|
+
table = f"{CNTLSC}.itidx_{uidx}"
|
|
739
|
+
cond = f"suid = '{suid}' AND rn3 = {rn3}"
|
|
740
|
+
pgrec = PgDBI.pgget(table, "iidx", cond, PgLOG.LGEREX)
|
|
741
|
+
if not pgrec:
|
|
742
|
+
PgLOG.pglog(f"{suid}-{rn3}: suid-rn3 not in {table}", PgLOG.LGEREX)
|
|
743
|
+
|
|
744
|
+
return pgrec['iidx']
|
|
706
745
|
|
|
707
746
|
#
|
|
708
747
|
# read attm record for given uid
|
|
709
748
|
#
|
|
710
749
|
def read_attm_for_uid(aname, uid, tidx):
|
|
711
750
|
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
table =
|
|
715
|
-
if not PgDBI.pgcheck(table): return None
|
|
716
|
-
|
|
717
|
-
return PgDBI.pgget(table, "*", "uid = '{}'".format(uid), PgLOG.LGEREX)
|
|
751
|
+
iidx = uid2iidx_tidx(uid, tidx)
|
|
752
|
+
table = f"{IVADSC}.{aname}_{tidx}"
|
|
753
|
+
return PgDBI.pgget(table, "*", f"iidx = '{iidx}'", PgLOG.LGEREX)
|
|
718
754
|
|
|
719
755
|
#
|
|
720
756
|
# read core records for given uid
|
|
721
757
|
#
|
|
722
758
|
def read_coreloc_for_uid(uid, tidx):
|
|
723
759
|
|
|
724
|
-
|
|
760
|
+
iidx = uid2iidx_tidx(uid, tidx)
|
|
761
|
+
return PgDBI.pgget(f"{IVADSC}.icoreloc_{tidx}", '*', f"iidx = {iidx}")
|
|
725
762
|
|
|
726
763
|
#
|
|
727
764
|
# write IMMA records to file
|
|
@@ -774,15 +811,15 @@ def write_imma_records(fh, cdate, tidx, dumpall):
|
|
|
774
811
|
tidx = date2tidx(cdate)
|
|
775
812
|
if not tidx: return None
|
|
776
813
|
|
|
777
|
-
dcnd = "date = '{}' ORDER BY iidx"
|
|
778
|
-
mtable = "{}
|
|
814
|
+
dcnd = f"date = '{cdate}' ORDER BY iidx"
|
|
815
|
+
mtable = f"{IVADSC}.icoreloc_{tidx}"
|
|
779
816
|
pgrecs = PgDBI.pgmget(mtable, "*", dcnd)
|
|
780
817
|
if not pgrecs: return None
|
|
781
818
|
acnts[0] = count = len(pgrecs['iidx'])
|
|
782
819
|
minidx = pgrecs['iidx'][0]
|
|
783
820
|
jcnd = "m.iidx = n.iidx AND " + dcnd
|
|
784
|
-
tcnd = "tidx = {} AND attm ="
|
|
785
|
-
atable = "
|
|
821
|
+
tcnd = f"tidx = {tidx} AND attm ="
|
|
822
|
+
atable = f"{CNTLSC}.iattm"
|
|
786
823
|
|
|
787
824
|
lines = ['']*count
|
|
788
825
|
attcs = [-2]*count
|
|
@@ -794,9 +831,9 @@ def write_imma_records(fh, cdate, tidx, dumpall):
|
|
|
794
831
|
for a in range(1, TABLECOUNT):
|
|
795
832
|
aname = IMMA_NAMES[a]
|
|
796
833
|
if aname in MUNIQUE: continue
|
|
797
|
-
if PgDBI.pgget(atable, "", "{} '{}'"
|
|
798
|
-
ntable = "{}_{}"
|
|
799
|
-
pgrecs = PgDBI.pgmget("{} m, {} n"
|
|
834
|
+
if PgDBI.pgget(atable, "", f"{tcnd} '{aname}'"):
|
|
835
|
+
ntable = f"{IVADSC}.{aname}_{tidx}"
|
|
836
|
+
pgrecs = PgDBI.pgmget(f"{mtable} m, {ntable} n", "n.*", jcnd)
|
|
800
837
|
if not pgrecs: continue
|
|
801
838
|
acnts[a] = len(pgrecs['iidx'])
|
|
802
839
|
if dumpall and aname == "iuida":
|
|
@@ -810,9 +847,9 @@ def write_imma_records(fh, cdate, tidx, dumpall):
|
|
|
810
847
|
for a in range(1, TABLECOUNT):
|
|
811
848
|
aname = IMMA_NAMES[a]
|
|
812
849
|
if MUNIQUE[aname] is None: continue
|
|
813
|
-
if PgDBI.pgget(atable, "", "{} '{}'"
|
|
814
|
-
ntable = "{}_{}"
|
|
815
|
-
pgrecs = PgDBI.pgmget("{} m, {} n"
|
|
850
|
+
if PgDBI.pgget(atable, "", f"{tcnd} '{aname}'"):
|
|
851
|
+
ntable = f"{IVADSC}.{aname}_{tidx}"
|
|
852
|
+
pgrecs = PgDBI.pgmget(f"{mtable} m, {ntable} n", "n.*", jcnd)
|
|
816
853
|
if not pgrecs: continue
|
|
817
854
|
acnts[a] = len(pgrecs['iidx'])
|
|
818
855
|
append_imma_lines(aname, minidx, acnts[a], pgrecs, ulines, lines, attcs)
|
|
@@ -899,10 +936,10 @@ def count_imma_records(cdate, tidx, cntall):
|
|
|
899
936
|
tidx = date2tidx(cdate)
|
|
900
937
|
if not tidx: return None
|
|
901
938
|
|
|
902
|
-
atable = "
|
|
903
|
-
tcnd = "tidx = {}"
|
|
904
|
-
dcnd = "date = '{}'"
|
|
905
|
-
mtable = "{}
|
|
939
|
+
atable = f"{CNTLSC}.iattm"
|
|
940
|
+
tcnd = f"tidx = {tidx}"
|
|
941
|
+
dcnd = f"date = '{cdate}'"
|
|
942
|
+
mtable = f"{IVADSC}.icoreloc_{tidx}"
|
|
906
943
|
jcnd = "m.iidx = n.iidx AND " + dcnd
|
|
907
944
|
acnts[0] = PgDBI.pgget(mtable, "", dcnd)
|
|
908
945
|
if not acnts[0]: return None
|
|
@@ -910,9 +947,9 @@ def count_imma_records(cdate, tidx, cntall):
|
|
|
910
947
|
for i in range(1,TABLECOUNT):
|
|
911
948
|
aname = IMMA_NAMES[i]
|
|
912
949
|
if not cntall and aname in MUNIQUE: continue
|
|
913
|
-
if PgDBI.pgget(atable, "", "{} AND attm = '{}'"
|
|
914
|
-
ntable = "{}_{}"
|
|
915
|
-
acnts[i] = PgDBI.pgget("{} m, {} n"
|
|
950
|
+
if PgDBI.pgget(atable, "", f"{tcnd} AND attm = '{aname}'"):
|
|
951
|
+
ntable = f"{IVADSC}.{aname}_{tidx}"
|
|
952
|
+
acnts[i] = PgDBI.pgget(f"{mtable} m, {ntable} n", "", jcnd)
|
|
916
953
|
|
|
917
954
|
return acnts
|
|
918
955
|
|
|
@@ -922,12 +959,12 @@ def count_imma_records(cdate, tidx, cntall):
|
|
|
922
959
|
def add_inventory_record(fname, cdate, count, inventory, cntopt = 0):
|
|
923
960
|
|
|
924
961
|
didx = 0
|
|
925
|
-
table = "
|
|
962
|
+
table = f"{CNTLSC}.inventory"
|
|
926
963
|
|
|
927
964
|
if cntopt == 2:
|
|
928
|
-
cnd = "date = '{}'"
|
|
965
|
+
cnd = f"date = '{cdate}'"
|
|
929
966
|
pgrec = PgDBI.pgget(table, "didx, count", cnd, PgLOG.LGEREX)
|
|
930
|
-
if not pgrec: PgLOG.pglog("{}: error get record for {}"
|
|
967
|
+
if not pgrec: PgLOG.pglog(f"{table}: error get record for {cnd}", PgLOG.LGEREX)
|
|
931
968
|
count = pgrec['count']
|
|
932
969
|
didx = pgrec['didx']
|
|
933
970
|
record = {}
|
|
@@ -944,9 +981,9 @@ def add_inventory_record(fname, cdate, count, inventory, cntopt = 0):
|
|
|
944
981
|
record['tcount'] = count
|
|
945
982
|
|
|
946
983
|
if didx:
|
|
947
|
-
cnd = "didx = {}"
|
|
984
|
+
cnd = f"didx = {didx}"
|
|
948
985
|
if not PgDBI.pgupdt(table, record, cnd, PgLOG.LGEREX):
|
|
949
|
-
PgLOG.pglog("{}: error update table for {}"
|
|
986
|
+
PgLOG.pglog(f"{table}: error update table for {cnd}", PgLOG.LGEREX)
|
|
950
987
|
else:
|
|
951
988
|
didx = PgDBI.pgadd(table, record, PgLOG.LGEREX|PgLOG.AUTOID)
|
|
952
989
|
|
|
@@ -967,15 +1004,16 @@ def get_attm_names(tidx):
|
|
|
967
1004
|
aindices = []
|
|
968
1005
|
attms = {}
|
|
969
1006
|
acnt = 0
|
|
970
|
-
|
|
971
|
-
|
|
1007
|
+
cnd = f"tidx = {tidx}"
|
|
1008
|
+
pgrecs = PgDBI.pgmget(f"{CNTLSC}.iattm", "attm", cnd, PgLOG.LGEREX)
|
|
1009
|
+
if not pgrecs: PgLOG.pglog(f"miss iattm record for {cnd}", PgLOG.LGEREX)
|
|
972
1010
|
for aname in pgrecs['attm']: attms[aname] = 1
|
|
973
1011
|
|
|
974
1012
|
for i in range(1, TABLECOUNT):
|
|
975
1013
|
aname = IMMA_NAMES[i]
|
|
976
1014
|
if aname in attms:
|
|
977
1015
|
anames.append(aname)
|
|
978
|
-
atables.append("{}_{}"
|
|
1016
|
+
atables.append(f"{IVADSC}.{aname}_{tidx}")
|
|
979
1017
|
aindices.append(i)
|
|
980
1018
|
acnt += 1
|
|
981
1019
|
|
|
@@ -986,7 +1024,7 @@ def get_attm_names(tidx):
|
|
|
986
1024
|
#
|
|
987
1025
|
def get_attm_line(aname, atable, iidx, pgrec):
|
|
988
1026
|
|
|
989
|
-
if not pgrec: pgrec = PgDBI.pgget(atable, "*", "iidx = {}"
|
|
1027
|
+
if not pgrec: pgrec = PgDBI.pgget(atable, "*", f"iidx = {iidx}", PgLOG.LGEREX)
|
|
990
1028
|
return build_one_attm_line(aname, pgrec) if pgrec else None
|
|
991
1029
|
|
|
992
1030
|
#
|
|
@@ -994,7 +1032,7 @@ def get_attm_line(aname, atable, iidx, pgrec):
|
|
|
994
1032
|
#
|
|
995
1033
|
def get_multiple_attm_line(aname, atable, iidx):
|
|
996
1034
|
|
|
997
|
-
pgrecs = PgDBI.pgmget(atable, "*", "iidx = {} ORDER BY lidx"
|
|
1035
|
+
pgrecs = PgDBI.pgmget(atable, "*", f"iidx = {iidx} ORDER BY lidx", PgLOG.LGEREX)
|
|
998
1036
|
icnt = (len(pgrecs['lidx']) if pgrecs else 0)
|
|
999
1037
|
if not icnt: return (0, None)
|
|
1000
1038
|
|
|
@@ -1079,24 +1117,24 @@ def get_itidx_date(uid):
|
|
|
1079
1117
|
global CURIUID, CURIIDX, CURTIDX
|
|
1080
1118
|
uidx = uid[0:2].lower()
|
|
1081
1119
|
suid = uid[2:6]
|
|
1082
|
-
table = "
|
|
1083
|
-
|
|
1084
|
-
pgrec = PgDBI.pgget(table, "*",
|
|
1085
|
-
if not pgrec:
|
|
1120
|
+
table = f"{CNTLSC}.itidx_{uidx}"
|
|
1121
|
+
cond = f"suid = '{suid}' AND rn3 = {CURRN3}"
|
|
1122
|
+
pgrec = PgDBI.pgget(table, "*", cond, PgLOG.LGEREX)
|
|
1123
|
+
if not pgrec:
|
|
1124
|
+
msg = "{}-{}: suid-rn3 not in {}".format(suid, CURRN3, table)
|
|
1125
|
+
if CURRN3 < 0:
|
|
1126
|
+
PgLOG.pglog(msg + "\nProvide a RN3 (>= 0) to proceed", PgLOG.LGEREX)
|
|
1127
|
+
else:
|
|
1128
|
+
return PgLOG.pglog(msg + ", SKIP it", PgLOG.WARNLG)
|
|
1086
1129
|
|
|
1087
1130
|
if CHKEXIST: # check
|
|
1088
|
-
table = "{}_{
|
|
1089
|
-
cnd = "iidx = {
|
|
1090
|
-
if ATTMNAME in MUNIQUE:
|
|
1091
|
-
for fname in MUNIQUE[ATTMNAME]:
|
|
1092
|
-
cnd += " AND {} = '{}'".format(fname, pgrec[fname])
|
|
1093
|
-
|
|
1131
|
+
table = f"{IVADSC}.{ATTMNAME}_{pgrec['tidx']}"
|
|
1132
|
+
cnd = f"iidx = {pgrec['iidx']}"
|
|
1094
1133
|
if PgDBI.pgget(table, "", cnd): return None
|
|
1095
1134
|
|
|
1096
1135
|
CURIUID = uid
|
|
1097
1136
|
CURIIDX = pgrec['iidx']
|
|
1098
1137
|
CURTIDX = pgrec['tidx']
|
|
1099
|
-
|
|
1100
1138
|
return pgrec['date']
|
|
1101
1139
|
|
|
1102
1140
|
#
|
|
@@ -1137,15 +1175,18 @@ def get_record_date(yr, mo, dy):
|
|
|
1137
1175
|
#
|
|
1138
1176
|
def date2tidx(cdate, getend = True):
|
|
1139
1177
|
|
|
1140
|
-
|
|
1178
|
+
if cdate in DATE2TIDX: return DATE2TIDX[cdate]
|
|
1179
|
+
table = f"{CNTLSC}.inventory"
|
|
1141
1180
|
pgrec = PgDBI.pgget(table, "tidx", "date = '{}'".format(cdate), PgLOG.LGEREX)
|
|
1142
|
-
if pgrec:
|
|
1181
|
+
if pgrec:
|
|
1182
|
+
DATE2TIDX[cdate] = pgrec['tidx']
|
|
1183
|
+
return pgrec['tidx']
|
|
1143
1184
|
|
|
1144
1185
|
if getend:
|
|
1145
|
-
cnd = "date < '{}'"
|
|
1186
|
+
cnd = f"date < '{cdate}'"
|
|
1146
1187
|
pgrec = PgDBI.pgget(table, "max(tidx) tidx", cnd, PgLOG.LGEREX)
|
|
1147
1188
|
else:
|
|
1148
|
-
cnd = "date > '{}'"
|
|
1189
|
+
cnd = f"date > '{cdate}'"
|
|
1149
1190
|
pgrec = PgDBI.pgget(table, "min(tidx) tidx", cnd, PgLOG.LGEREX)
|
|
1150
1191
|
if pgrec:
|
|
1151
1192
|
return pgrec['tidx']
|
|
@@ -1157,7 +1198,7 @@ def date2tidx(cdate, getend = True):
|
|
|
1157
1198
|
#
|
|
1158
1199
|
def iidx2date(iidx):
|
|
1159
1200
|
|
|
1160
|
-
pgrec = PgDBI.pgget("
|
|
1201
|
+
pgrec = PgDBI.pgget(f"{CNTLSC}.inventory", "date", f"miniidx <= {iidx} AND maxiidx >= {iidx}", PgLOG.LGEREX)
|
|
1161
1202
|
return (pgrec['date'] if pgrec else None)
|
|
1162
1203
|
|
|
1163
1204
|
#
|
|
@@ -1173,7 +1214,7 @@ def number2name(cn, fn):
|
|
|
1173
1214
|
for i in range(2, TABLECOUNT):
|
|
1174
1215
|
aname = IMMA_NAMES[i]
|
|
1175
1216
|
if cn == int(IMMAS[aname][1]): break
|
|
1176
|
-
if i >= TABLECOUNT: PgLOG.pglog("{}: Cannot find Component"
|
|
1217
|
+
if i >= TABLECOUNT: PgLOG.pglog(f"{cn}: Cannot find Component", PgLOG.LGEREX)
|
|
1177
1218
|
elif fn < 17:
|
|
1178
1219
|
offset = 1
|
|
1179
1220
|
aname = IMMA_NAMES[0]
|
|
@@ -1187,7 +1228,7 @@ def number2name(cn, fn):
|
|
|
1187
1228
|
NUM2NAME[key] = [fname, aname]
|
|
1188
1229
|
return NUM2NAME[key]
|
|
1189
1230
|
|
|
1190
|
-
PgLOG.pglog("{}: Cannot find field name in Component '{}'"
|
|
1231
|
+
PgLOG.pglog(f"{fn}: Cannot find field name in Component '{aname}'", PgLOG.LGEREX)
|
|
1191
1232
|
|
|
1192
1233
|
#
|
|
1193
1234
|
# get component number and field number from give field name
|
|
@@ -1265,7 +1306,7 @@ def order_attm_variables(attm, aname = None):
|
|
|
1265
1306
|
#
|
|
1266
1307
|
def get_inventory_record(didx = 0, cntopt = 0):
|
|
1267
1308
|
|
|
1268
|
-
table = "
|
|
1309
|
+
table = f"{CNTLSC}.inventory"
|
|
1269
1310
|
|
|
1270
1311
|
if not didx:
|
|
1271
1312
|
if cntopt == 2:
|
|
@@ -1290,7 +1331,7 @@ def get_inventory_record(didx = 0, cntopt = 0):
|
|
|
1290
1331
|
#
|
|
1291
1332
|
def get_inventory_didx(cdate, prev):
|
|
1292
1333
|
|
|
1293
|
-
table = "
|
|
1334
|
+
table = f"{CNTLSC}.inventory"
|
|
1294
1335
|
fld = "didx, date"
|
|
1295
1336
|
if prev:
|
|
1296
1337
|
cnd = "date < '{}' ORDER BY date DECS".format(cdate)
|
|
@@ -1305,9 +1346,9 @@ def get_inventory_didx(cdate, prev):
|
|
|
1305
1346
|
#
|
|
1306
1347
|
# initialize the global indices
|
|
1307
1348
|
#
|
|
1308
|
-
def init_current_indices(leaduid = 0, chkexist = 0):
|
|
1349
|
+
def init_current_indices(leaduid = 0, chkexist = 0, rn3 = 0):
|
|
1309
1350
|
|
|
1310
|
-
global UIDIDX, CURIIDX, CURTIDX, CURIUID, AUTHREFS, LEADUID, CHKEXIST
|
|
1351
|
+
global UIDIDX, CURIIDX, CURTIDX, CURIUID, AUTHREFS, LEADUID, CHKEXIST, CURRN3
|
|
1311
1352
|
# leading info for iuida
|
|
1312
1353
|
UIDIDX = IMMAS['iuida'][0]
|
|
1313
1354
|
CURIIDX = 0
|
|
@@ -1316,6 +1357,7 @@ def init_current_indices(leaduid = 0, chkexist = 0):
|
|
|
1316
1357
|
AUTHREFS = {}
|
|
1317
1358
|
LEADUID = leaduid
|
|
1318
1359
|
CHKEXIST = chkexist
|
|
1360
|
+
CURRN3 = rn3
|
|
1319
1361
|
|
|
1320
1362
|
#
|
|
1321
1363
|
# initialize indices for givn date
|
|
@@ -1329,7 +1371,7 @@ def init_indices_for_date(cdate, fname):
|
|
|
1329
1371
|
CURIIDX = INVENTORY['maxiidx']
|
|
1330
1372
|
CURTIDX = INVENTORY['tidx']
|
|
1331
1373
|
else:
|
|
1332
|
-
pgrec = PgDBI.pgget("
|
|
1374
|
+
pgrec = PgDBI.pgget(f"{CNTLSC}.inventory", "*", "date = '{}'".format(cdate), PgLOG.LGEREX)
|
|
1333
1375
|
if not pgrec: PgLOG.pglog("{}: give date not in inventory yet".format(cdate), PgLOG.LGEREX)
|
|
1334
1376
|
if CURIIDX < pgrec['miniidx']:
|
|
1335
1377
|
CURIIDX = pgrec['miniidx'] - 1
|
|
@@ -1343,21 +1385,21 @@ def update_control_tables(cdate, acnts, iuida, tidx = 0):
|
|
|
1343
1385
|
if not tidx: tidx = date2tidx(cdate)
|
|
1344
1386
|
|
|
1345
1387
|
if iuida and acnts[0]:
|
|
1346
|
-
tname = "cntldb.itidx"
|
|
1347
1388
|
records = {}
|
|
1348
1389
|
for i in range(acnts[UIDIDX]):
|
|
1349
1390
|
auid = iuida['uid'][i][0:2].lower()
|
|
1350
1391
|
if auid not in records:
|
|
1351
|
-
records[auid] = {'suid' : [], '
|
|
1392
|
+
records[auid] = {'iidx' : [], 'suid' : [], 'rn3' : [], 'date' : [], 'tidx' : []}
|
|
1352
1393
|
records[auid]['suid'].append(iuida['uid'][i][2:6])
|
|
1394
|
+
records[auid]['rn3'].append(iuida['rn3'][i])
|
|
1353
1395
|
records[auid]['date'].append(cdate)
|
|
1354
1396
|
records[auid]['tidx'].append(tidx)
|
|
1355
1397
|
records[auid]['iidx'].append(iuida['iidx'][i])
|
|
1356
1398
|
|
|
1357
1399
|
for auid in records:
|
|
1358
|
-
add_records_to_table(
|
|
1400
|
+
add_records_to_table(CNTLSC, 'itidx', auid, records[auid], cdate)
|
|
1359
1401
|
|
|
1360
|
-
tname = "
|
|
1402
|
+
tname = f"{CNTLSC}.iattm"
|
|
1361
1403
|
dname = tname + "_daily"
|
|
1362
1404
|
for i in range(TABLECOUNT):
|
|
1363
1405
|
if not acnts[i]: continue
|
|
@@ -1383,12 +1425,12 @@ def update_control_tables(cdate, acnts, iuida, tidx = 0):
|
|
|
1383
1425
|
#
|
|
1384
1426
|
# add records to a table
|
|
1385
1427
|
#
|
|
1386
|
-
def add_records_to_table(tname, suffix, records, cdate):
|
|
1428
|
+
def add_records_to_table(scname, tname, suffix, records, cdate):
|
|
1387
1429
|
|
|
1388
|
-
table = "{}_{}"
|
|
1389
|
-
if not
|
|
1390
|
-
pgcmd = PgDBI.get_pgddl_command(tname)
|
|
1391
|
-
PgLOG.pgsystem(
|
|
1430
|
+
table = f"{scname}.{tname}_{suffix}"
|
|
1431
|
+
if not check_table_status(table):
|
|
1432
|
+
pgcmd = PgDBI.get_pgddl_command(tname = tname, suf = suffix, scname = scname)
|
|
1433
|
+
if PgLOG.pgsystem(pgcmd, PgLOG.LGWNEX): TBLSTATUS[table] = True
|
|
1392
1434
|
|
|
1393
1435
|
cnt = PgDBI.pgmadd(table, records, PgLOG.LGEREX)
|
|
1394
1436
|
s = 's' if cnt > 1 else ''
|
|
@@ -1409,13 +1451,13 @@ def match_imma_records(cdate, t1, t2, w, e, s, n, vt):
|
|
|
1409
1451
|
tinfo = TINFO[cdate]
|
|
1410
1452
|
if not tinfo: return 0
|
|
1411
1453
|
else:
|
|
1412
|
-
tinfo = PgDBI.pgget("
|
|
1454
|
+
tinfo = PgDBI.pgget(f"{CNTLSC}.itable", "*", "bdate <= '{}' AND edate >= '{}'".format(cdate, cdate), PgLOG.LGWNEX)
|
|
1413
1455
|
if not tinfo:
|
|
1414
1456
|
TINFO[cdate] = 0
|
|
1415
1457
|
return 0
|
|
1416
1458
|
|
|
1417
1459
|
# match time/latitude
|
|
1418
|
-
mrecs = PgDBI.pgmget("
|
|
1460
|
+
mrecs = PgDBI.pgmget(f"{IVADSC}.icoreloc_{tinfo['tidx']}", "*",
|
|
1419
1461
|
"date = '{}' AND hr BETWEEN {} AND {} AND lat BETWEEN {} AND {}".format(cdate, t1, t2, s, n), PgLOG.LGWNEX)
|
|
1420
1462
|
if not mrecs: return 0 # no match
|
|
1421
1463
|
|
|
@@ -1451,7 +1493,7 @@ def match_imma_vars(tinfo, mrec, vt):
|
|
|
1451
1493
|
name = vt[v]
|
|
1452
1494
|
if name not in mrecs:
|
|
1453
1495
|
if name in tinfo:
|
|
1454
|
-
mrecs[name] = PgDBI.pgget("{}_{}"
|
|
1496
|
+
mrecs[name] = PgDBI.pgget(f"{IVADSC}.{name}_{tidx}", "*", f"iidx = {iidx}")
|
|
1455
1497
|
if not mrecs[name]: mrecs[name] = 0
|
|
1456
1498
|
else:
|
|
1457
1499
|
mrecs[name] = 0
|
|
@@ -68,7 +68,7 @@ def main():
|
|
|
68
68
|
PgLOG.pgexit()
|
|
69
69
|
|
|
70
70
|
PgLOG.PGLOG['LOGFILE'] = "icoads.log"
|
|
71
|
-
PgDBI.
|
|
71
|
+
PgDBI.set_scname(dbname = 'ivaddb', scname = PgIMMA.IVADSC, lnname = 'ivaddb', dbhost = PgLOG.PGLOG['PMISCHOST'])
|
|
72
72
|
PgLOG.cmdlog("cleanicoads {}".format(' '.join(argv)))
|
|
73
73
|
set_table_info()
|
|
74
74
|
clean_imma_data()
|
|
@@ -80,7 +80,7 @@ def main():
|
|
|
80
80
|
#
|
|
81
81
|
def set_table_info():
|
|
82
82
|
|
|
83
|
-
table = "
|
|
83
|
+
table = f"{PgIMMA.CNTLSC}.inventory"
|
|
84
84
|
if PVALS['edate']:
|
|
85
85
|
PVALS['dcnd'] = "date BETWEEN '{}' AND '{}'".format(PVALS['bdate'], PVALS['edate'])
|
|
86
86
|
else:
|
|
@@ -97,7 +97,7 @@ def set_table_info():
|
|
|
97
97
|
#
|
|
98
98
|
def clean_imma_data():
|
|
99
99
|
|
|
100
|
-
table = "
|
|
100
|
+
table = f"{PgIMMA.CNTLSC}.inventory"
|
|
101
101
|
|
|
102
102
|
for i in range(PVALS['tcnt']):
|
|
103
103
|
tidx = PVALS['tinfo']['tidx'][i]
|
|
@@ -127,7 +127,7 @@ def clean_imma_data_for_tidx(tidx, cnd):
|
|
|
127
127
|
#
|
|
128
128
|
def clean_one_attm_for_tidx(aname, tidx, cnd):
|
|
129
129
|
|
|
130
|
-
table = "{}_{}"
|
|
130
|
+
table = f"{PgIMMA.IVADSC}.{aname}_{tidx}"
|
|
131
131
|
if not PgDBI.pgcheck(table): return 0 # not record to delete
|
|
132
132
|
|
|
133
133
|
if aname == 'iuida': clean_itidx_for_tidx(table, cnd)
|
|
@@ -144,7 +144,7 @@ def clean_one_attm_for_tidx(aname, tidx, cnd):
|
|
|
144
144
|
#
|
|
145
145
|
def clean_itidx_for_tidx(table, cnd):
|
|
146
146
|
|
|
147
|
-
tname = "
|
|
147
|
+
tname = f"{PgIMMA.CNTLSC}.itidx"
|
|
148
148
|
uids = PgDBI.pgmget(table, "distinct (substring(uid, 1, 2)) uida", cnd, PgLOG.LGEREX)
|
|
149
149
|
ucnt = len(uids['uida']) if uids else 0
|
|
150
150
|
for i in range(ucnt):
|
|
@@ -159,7 +159,7 @@ def clean_itidx_for_tidx(table, cnd):
|
|
|
159
159
|
#
|
|
160
160
|
def clean_iattm_for_tidx(aname, tidx, cnt):
|
|
161
161
|
|
|
162
|
-
table = "
|
|
162
|
+
table = f"{PgIMMA.CNTLSC}.iattm"
|
|
163
163
|
cnd = "attm = '{}' AND tidx = {}".format(aname, tidx)
|
|
164
164
|
pgrec = {'count' : cnt}
|
|
165
165
|
PgDBI.pgupdt(table, pgrec, cnd, PgLOG.LGWNEX)
|
|
@@ -33,8 +33,10 @@ PVALS = {
|
|
|
33
33
|
def main():
|
|
34
34
|
|
|
35
35
|
addinventory = leaduid = chkexist = 0
|
|
36
|
+
rn3 = -1
|
|
36
37
|
argv = sys.argv[1:]
|
|
37
|
-
|
|
38
|
+
|
|
39
|
+
option = None
|
|
38
40
|
for arg in argv:
|
|
39
41
|
if arg == "-b":
|
|
40
42
|
PgLOG.PGLOG['BCKGRND'] = 1
|
|
@@ -44,32 +46,51 @@ def main():
|
|
|
44
46
|
leaduid = 1
|
|
45
47
|
elif arg == "-e":
|
|
46
48
|
chkexist = 1
|
|
49
|
+
elif arg == "-r":
|
|
50
|
+
option = 'r'
|
|
47
51
|
elif arg == "-i":
|
|
48
52
|
addinventory = 1
|
|
49
53
|
elif re.match(r'^-', arg):
|
|
50
54
|
PgLOG.pglog(arg + ": Invalid Option", PgLOG.LGWNEX)
|
|
55
|
+
elif option == 'f':
|
|
56
|
+
get_imma_filelist(arg)
|
|
57
|
+
option = None
|
|
58
|
+
elif option == 'r':
|
|
59
|
+
rn3 = int(arg)
|
|
60
|
+
option = None
|
|
51
61
|
else:
|
|
52
62
|
PVALS['files'].append(arg)
|
|
53
63
|
|
|
54
64
|
if not PVALS['files']:
|
|
55
|
-
print("Usage: fillicoads [-a] [-e] [-i] [-u]
|
|
65
|
+
print("Usage: fillicoads [-a] [-e] [-f InputFile] [-i] [-r RN3] [-u] FileList")
|
|
56
66
|
print(" At least one file name needs to fill icoads data into Postgres Server")
|
|
57
67
|
print(" Option -a: add all attms, including multi-line ones, such as IVAD and REANQC")
|
|
68
|
+
print(" Option -f: provide a filename holding a list of IMMA1 files")
|
|
58
69
|
print(" Option -i: add daily counting records into inventory table")
|
|
70
|
+
print(" Option -r: the Third digit of IMMA release number")
|
|
59
71
|
print(" Option -u: standalone attachment records with leading 6-character UID")
|
|
60
72
|
print(" Option -e: check existing record before adding attm")
|
|
61
73
|
sys.exit(0)
|
|
62
74
|
|
|
63
75
|
PgLOG.PGLOG['LOGFILE'] = "icoads.log"
|
|
64
|
-
PgDBI.
|
|
65
|
-
|
|
76
|
+
PgDBI.set_scname(dbname = 'ivaddb', scname = PgIMMA.IVADSC, lnname = 'ivaddb', dbhost = PgLOG.PGLOG['PMISCHOST'])
|
|
77
|
+
|
|
66
78
|
PgLOG.cmdlog("fillicoads {}".format(' '.join(argv)))
|
|
67
|
-
PgIMMA.init_current_indices(leaduid, chkexist)
|
|
79
|
+
PgIMMA.init_current_indices(leaduid, chkexist, rn3)
|
|
68
80
|
PVALS['names'] = '/'.join(PgIMMA.IMMA_NAMES)
|
|
69
81
|
fill_imma_data(addinventory)
|
|
70
82
|
PgLOG.cmdlog()
|
|
71
83
|
PgLOG.pgexit()
|
|
72
84
|
|
|
85
|
+
#
|
|
86
|
+
# read in imma file list from a given file name
|
|
87
|
+
#
|
|
88
|
+
def get_imma_filelist(fname):
|
|
89
|
+
|
|
90
|
+
with open(fname, "r") as f:
|
|
91
|
+
for line in f.readlines():
|
|
92
|
+
PVALS['files'].append(line.strip())
|
|
93
|
+
|
|
73
94
|
#
|
|
74
95
|
# fill up imma data
|
|
75
96
|
#
|
|
@@ -103,14 +124,14 @@ def process_imma_file(fname, addinventory):
|
|
|
103
124
|
idate = cdate = PgIMMA.get_imma_date(line)
|
|
104
125
|
if cdate:
|
|
105
126
|
PgIMMA.init_indices_for_date(cdate, iname)
|
|
106
|
-
records = PgIMMA.get_imma_records(
|
|
127
|
+
records = PgIMMA.get_imma_records(cdate, line, records)
|
|
107
128
|
break
|
|
108
129
|
line = IMMA.readline()
|
|
109
130
|
|
|
110
131
|
line = IMMA.readline()
|
|
111
132
|
while line:
|
|
112
133
|
if PVALS['uatti'] and line[0:2] == PVALS['uatti']:
|
|
113
|
-
records = PgIMMA.get_imma_multiple_records(line, records)
|
|
134
|
+
records = PgIMMA.get_imma_multiple_records(cdate, line, records)
|
|
114
135
|
else:
|
|
115
136
|
idate = PgIMMA.get_imma_date(line)
|
|
116
137
|
if idate:
|
|
@@ -120,7 +141,7 @@ def process_imma_file(fname, addinventory):
|
|
|
120
141
|
records = {}
|
|
121
142
|
cdate = idate
|
|
122
143
|
PgIMMA.init_indices_for_date(cdate, iname)
|
|
123
|
-
records = PgIMMA.get_imma_records(
|
|
144
|
+
records = PgIMMA.get_imma_records(idate, line, records)
|
|
124
145
|
line = IMMA.readline()
|
|
125
146
|
|
|
126
147
|
IMMA.close()
|
|
@@ -607,10 +607,12 @@ def join_attm_fields(aname, record):
|
|
|
607
607
|
def subset_table_index(fname, tidx, bdate, edate):
|
|
608
608
|
|
|
609
609
|
atables = {}
|
|
610
|
-
PgDBI.
|
|
610
|
+
PgDBI.set_scname(dbname = 'ivaddb', scname = PgIMMA.IVADSC, lnname = 'ivaddb', dbhost = PgLOG.PGLOG['PMISCHOST'])
|
|
611
611
|
|
|
612
|
+
tname = f"{PgIMMA.CTNLSC}.iattm"
|
|
612
613
|
for aname in PVALS['anames']:
|
|
613
|
-
|
|
614
|
+
cnd = f"tidx = {tidx} AND attm = '{aname}'"
|
|
615
|
+
atables[aname] = PgDBI.pgget(tname, "", cnd, PgLOG.LGEREX)
|
|
614
616
|
|
|
615
617
|
dstep = int(PgUtil.diffdate(edate, bdate)/PSTEP)
|
|
616
618
|
if dstep == 0: dstep = 1
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12/src/rda_python_icoads.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: rda_python_icoads
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.12
|
|
4
4
|
Summary: RDA python package to manage RDA ICOADS datasets
|
|
5
5
|
Author-email: Zaihua Ji <zji@ucar.edu>
|
|
6
6
|
Project-URL: Homepage, https://github.com/NCAR/rda-python-icoads
|
|
@@ -12,6 +12,7 @@ Requires-Python: >=3.7
|
|
|
12
12
|
Description-Content-Type: text/markdown
|
|
13
13
|
License-File: LICENSE
|
|
14
14
|
Requires-Dist: rda_python_common
|
|
15
|
+
Dynamic: license-file
|
|
15
16
|
|
|
16
17
|
RDA python package to manage RDA ICOADS datasets.
|
|
17
18
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/R3.0-stat_doc.pdf
RENAMED
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/README_R3.0_Subset.html
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/fillinventory.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads/msg3.0_subset_readme.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/requires.txt
RENAMED
|
File without changes
|
{rda_python_icoads-1.0.10 → rda_python_icoads-1.0.12}/src/rda_python_icoads.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|