Skip to content

Instantly share code, notes, and snippets.

@atarkowska
Created July 4, 2016 13:19
Show Gist options
  • Save atarkowska/3012f9b18a21be651402ec81bce14209 to your computer and use it in GitHub Desktop.
Save atarkowska/3012f9b18a21be651402ec81bce14209 to your computer and use it in GitHub Desktop.
missing maps
import omero, os, traceback
import omero.gateway
import time, datetime
from omero.rtypes import *
from omero.rtypes import unwrap
host = "localhost"
port = 4064
rootpass = "ome"
user = "demo"
c = omero.client(host=host, port=port)
s = c.createSession(user, rootpass)
query = s.getQueryService()
update = s.getUpdateService()
expId = 2 #s.getAdminService().getEventContext().userId
p = omero.sys.ParametersI()
p.addString("ns", "openmicroscopy.org/omero/bulk_annotations")
p.addId(expId)
sqlcount = """
select count( distinct ial.id)
from ImageAnnotationLink as ial
join ial.child a
where
a.ns = :ns
and a.details.owner.id = :id
"""
print sqlcount
rv = query.projection(sqlcount, p)
rv = unwrap(rv)
pagecount = rv[0][0]
print "Map annotations count: ", pagecount
sql = """
select distinct ial
from ImageAnnotationLink as ial
join fetch ial.child a
where
a.ns = :ns
and a.details.owner.id = :id
order by a.id ASC
"""
empty_map = list()
limit = 1000
total_maps = 0
for page in xrange(1, (pagecount/limit)+2):
print 'PAGE', page, (page-1) * limit, limit
print 'total_maps', total_maps, 'emptyt', len(empty_map)
p.page((page-1) * limit, limit)
t_res = query.findAllByQuery(sql, p)
total_maps += len(t_res)
for ial in t_res:
if hasattr(ial.child, 'mapValue'):
ial.parent.unload()
ial.child.unload()
else:
empty_map.append(ial.child.id.val)
print 'RESULT', 'total_maps', total_maps
#print {k:v for (k,v) in duplicates.items() if v > 1}
print len(empty_map)
s.closeOnDestroy()
c.closeSession()
c.__del__()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment