Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
AndrewVSutherland
GitHub Repository: AndrewVSutherland/lmfdb
Path: blob/main/scripts/reports/inventory_patchup.py
1128 views
1
#A collection of functions usesd to patch up uploads which had bugs
2
3
import lmfdb.inventory_app.lmfdb_inventory as inv
4
import lmfdb.inventory_app.inventory_db_core as idc
5
6
7
def amend_collection_info(inv_db):
8
""" Fixes missing or empty string collection Notes and Info for every db
9
"""
10
11
a=list(inv_db.collection_ids.find())
12
dummy_info = {} #Dummy per collection info, containing basic fields we want included
13
for field in inv.info_editable_fields:
14
dummy_info[field] = None
15
16
for collection in a:
17
if collection['INFO'] == '' or collection['NOTES'] == '':
18
print('Fixing ', collection['name'])
19
idc.set_coll(inv_db, collection['db_id'], collection['name'], collection['name'], {'description':''}, dummy_info)
20
21
def get_sample_of_table(inv_db, table_name, size=10, condition=None):
22
23
if condition and type(condition) is not dict:
24
raise TypeError('Condition must be dict')
25
if condition:
26
curs = inv_db[table_name].aggregate([ {'$match':condition}, {'$sample':{'size':int(size)} } ] )
27
else:
28
curs = inv_db[table_name].aggregate([{'$sample':{'size':int(size)}}])
29
return list(curs)
30
31