Skip to content

Commit

Permalink
update to wdunit ingest code and save to the representations table
Browse files Browse the repository at this point in the history
  • Loading branch information
stuchalk committed Dec 17, 2024
1 parent f7a48ae commit d1e3cac
Show file tree
Hide file tree
Showing 3 changed files with 46,498 additions and 10 deletions.
32 changes: 22 additions & 10 deletions dashboard/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,7 @@
print("found class '" + str(c.name) + "'")
exit()

# get list of units on Wikidata
# get list of units on Wikidata
if choice == 'wdu':
# units = wdunits() # call class to update wdunits if working on wikidata OR download from wd and parse below
Expand All @@ -632,10 +633,10 @@
repsysids = {"qudt": 10, "iev": 21, "igb": 3, "ncit": 9, "ucum": 2, "unece": 6, "uom": 13, "wolf": 20, "wur": 23}

units = None
file = f'umis_units_query_111524.json'
file = f'umis_units_query_121724.json'
if os.path.exists(os.path.join(BASE_DIR, STATIC_URL, file)):
# read in the file
with open(os.path.join(BASE_DIR, STATIC_URL, file), 'r') as f:
# read in the file (open function has read as default so not added)
with open(os.path.join(BASE_DIR, STATIC_URL, file)) as f:
tmp = f.read()
units = json.loads(tmp)
f.close()
Expand Down Expand Up @@ -667,22 +668,26 @@
wu = Wdunits(cls=unit['cls'], unit=unit['unit'], quant=unit['quant'], factor=unit['factor'],
curl=unit['curl'], uurl=unit['uurl'], qurl=unit['qurl'], added=date.today(), updated=dt
)
print("added")
else:
# check for unit representation data and add if the field is empty
wu = found[0]
print("found")

# if missing add wd unit class if available
if not wu.wdclass_id:
cls = Wdclasses.objects.filter(url__exact=unit['curl'])
if cls:
wu.wdclass_id = cls[0].id

# get and add wd unit class if available
cls = Wdclasses.objects.filter(url__exact=unit['curl'])
if cls:
wu.wdclass_id = cls[0].id
# save to wdunits table
wu.save()

# add any unit reps to the representations table
for ufld in uflds:
repsysid, strng = None, None
if unit[ufld]:
# find unit string in the strng table
if ufld in unit.keys():
# find (or add) unit string in the strng table
strng = Strngs.objects.get(string=unit[ufld])
if not strng:
# add new unit string
Expand All @@ -691,6 +696,13 @@
repsysid = repsysids[ufld]
rep = Representations.objects.get(repsystem__id=repsysid, strng_id=strng.id)
if rep:
if rep.wdunit_id and rep.onwd == "yes":
print("representation " + unit[ufld] + " already added")
continue
print(rep.__dict__)
print(unit)
exit()

# update representation entry with wdunit_id
rep.wdunit_id = wu.id
rep.onwd = 'yes'
Expand All @@ -706,7 +718,7 @@

print("added '" + wu.unit + "' (" + str(wu.id) + ")")
cnt += 1
if cnt > 0:
if cnt > 4:
exit()


Expand Down
1 change: 1 addition & 0 deletions dashboard/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# move reps from wdunits table to the representations table as links
def movereps(sys):
""" move reps from wdunits table to the representations table as links """
repsysids = {"qudt": 10, "iev": 21, "igb": 3, "ncit": 9, "ucum": 2, "unece": 6, "uom": 13, "wolf": 20, "wur": 23}
repsysid = repsysids[sys]
wtmp = None
Expand Down
Loading

0 comments on commit d1e3cac

Please sign in to comment.