Commit b3a013df authored by Romain Loth's avatar Romain Loth

remove buggy status filter from aggregations

parent 96aebc1b
...@@ -123,7 +123,7 @@ def email_exists(email): ...@@ -123,7 +123,7 @@ def email_exists(email):
def get_field_aggs(a_field, def get_field_aggs(a_field,
hapax_threshold=int(REALCONFIG['HAPAX_THRESHOLD']), hapax_threshold=int(REALCONFIG['HAPAX_THRESHOLD']),
users_status = "active"): users_status = "ALL"):
""" """
Use case: api/aggs?field=a_field Use case: api/aggs?field=a_field
--------------------------------- ---------------------------------
...@@ -167,17 +167,6 @@ def get_field_aggs(a_field, ...@@ -167,17 +167,6 @@ def get_field_aggs(a_field,
db = connect_db() db = connect_db()
db_c = db.cursor(DictCursor) db_c = db.cursor(DictCursor)
# constraints 1, if any
prefilters = []
if users_status != 'ALL':
prefilters.append( "scholars.record_status = \"%s\"" % users_status)
if len(prefilters):
pre_where = "WHERE "+" AND ".join(
['('+f+')' for f in prefilters]
)
else:
pre_where = ""
# constraints 2, if any # constraints 2, if any
postfilters = [] postfilters = []
...@@ -197,83 +186,72 @@ def get_field_aggs(a_field, ...@@ -197,83 +186,72 @@ def get_field_aggs(a_field,
if sql_tab == 'scholars': if sql_tab == 'scholars':
stmt = """ stmt = """
SELECT x, n FROM ( SELECT x, n FROM (
SELECT %(col)s AS x, COUNT(*) AS n, record_status SELECT %(col)s AS x, COUNT(*) AS n
FROM scholars FROM scholars
%(pre_filter)s
GROUP BY %(col)s GROUP BY %(col)s
) AS allcounts ) AS allcounts
%(post_filter)s %(post_filter)s
ORDER BY n DESC ORDER BY n DESC
""" % {'col': sql_col, 'pre_filter': pre_where, """ % {'col': sql_col, 'post_filter': post_where}
'post_filter': post_where}
elif sql_tab == 'affiliations': elif sql_tab == 'affiliations':
stmt = """ stmt = """
SELECT x, n FROM ( SELECT x, n FROM (
SELECT %(col)s AS x, COUNT(*) AS n, record_status SELECT %(col)s AS x, COUNT(*) AS n
FROM scholars FROM scholars
-- 0 or 1 -- 0 or 1
LEFT JOIN affiliations LEFT JOIN affiliations
ON scholars.affiliation_id = affiliations.affid ON scholars.affiliation_id = affiliations.affid
%(pre_filter)s
GROUP BY %(col)s GROUP BY %(col)s
) AS allcounts ) AS allcounts
%(post_filter)s
ORDER BY n DESC ORDER BY n DESC
""" % {'col': sql_col, 'pre_filter': pre_where, """ % {'col': sql_col, 'post_filter': post_where}
'post_filter': post_where}
elif sql_tab == 'linked_ids': elif sql_tab == 'linked_ids':
stmt = """ stmt = """
SELECT x, n FROM ( SELECT x, n FROM (
SELECT %(col)s AS x, COUNT(*) AS n, record_status SELECT %(col)s AS x, COUNT(*) AS n
FROM scholars FROM scholars
-- 0 or 1 -- 0 or 1
LEFT JOIN linked_ids LEFT JOIN linked_ids
ON scholars.luid = linked_ids.uid ON scholars.luid = linked_ids.uid
%(pre_filter)s
GROUP BY %(col)s GROUP BY %(col)s
) AS allcounts ) AS allcounts
%(post_filter)s %(post_filter)s
ORDER BY n DESC ORDER BY n DESC
""" % {'col': sql_col, 'pre_filter': pre_where, """ % {'col': sql_col, 'post_filter': post_where}
'post_filter': post_where}
elif sql_tab == 'keywords': elif sql_tab == 'keywords':
stmt = """ stmt = """
SELECT x, occs FROM ( SELECT x, occs FROM (
SELECT %(col)s AS x, COUNT(*) AS occs, record_status SELECT %(col)s AS x, COUNT(*) AS occs
FROM scholars FROM scholars
-- 0 or many -- 0 or many
LEFT JOIN sch_kw LEFT JOIN sch_kw
ON scholars.luid = sch_kw.uid ON scholars.luid = sch_kw.uid
LEFT JOIN keywords LEFT JOIN keywords
ON sch_kw.kwid = keywords.kwid ON sch_kw.kwid = keywords.kwid
%(pre_filter)s
GROUP BY %(col)s GROUP BY %(col)s
) AS allcounts ) AS allcounts
%(post_filter)s %(post_filter)s
ORDER BY occs DESC ORDER BY occs DESC
""" % {'col': sql_col, 'pre_filter': pre_where, """ % {'col': sql_col, 'post_filter': post_where}
'post_filter': post_where}
elif sql_tab == 'hashtags': elif sql_tab == 'hashtags':
stmt = """ stmt = """
SELECT x, occs FROM ( SELECT x, occs FROM (
SELECT %(col)s AS x, COUNT(*) AS occs, record_status SELECT %(col)s AS x, COUNT(*) AS occs
FROM scholars FROM scholars
-- 0 or many -- 0 or many
LEFT JOIN sch_ht LEFT JOIN sch_ht
ON scholars.luid = sch_ht.uid ON scholars.luid = sch_ht.uid
LEFT JOIN hashtags LEFT JOIN hashtags
ON sch_ht.htid = hashtags.htid ON sch_ht.htid = hashtags.htid
%(pre_filter)s
GROUP BY %(col)s GROUP BY %(col)s
) AS allcounts ) AS allcounts
%(post_filter)s %(post_filter)s
ORDER BY occs DESC ORDER BY occs DESC
""" % {'col': sql_col, 'pre_filter': pre_where, """ % {'col': sql_col, 'post_filter': post_where}
'post_filter': post_where}
mlog("DEBUGSQL", "get_field_aggs STATEMENT:\n-- SQL\n%s\n-- /SQL" % stmt) mlog("DEBUGSQL", "get_field_aggs STATEMENT:\n-- SQL\n%s\n-- /SQL" % stmt)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment