Skip to content

Commit

Permalink
Finding issues with the queries in postgresql - this at least gets them
Browse files Browse the repository at this point in the history
running, but the issue needs more investigation
  • Loading branch information
coleifer committed May 28, 2010
1 parent 64effbd commit 3ed81c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ratings/tests/settings.py
@@ -1,4 +1,6 @@
DATABASE_ENGINE = 'sqlite3'
DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'test_main'

INSTALLED_APPS = [
'django.contrib.auth',
Expand Down
11 changes: 7 additions & 4 deletions ratings/utils.py
Expand Up @@ -35,8 +35,8 @@ def sim_euclidean_distance(ratings_queryset, factor_a, factor_b):
%(ratings_table)s AS r1,
%(ratings_table)s AS r2
WHERE
r1.%(filter_field)s = "%(lookup_a)s" AND
r2.%(filter_field)s = "%(lookup_b)s" AND
r1.%(filter_field)s = '%(lookup_a)s' AND
r2.%(filter_field)s = '%(lookup_b)s' AND
r1.%(match_on)s = r2.%(match_on)s
%(queryset_filter)s
"""
Expand Down Expand Up @@ -95,8 +95,8 @@ def sim_pearson_correlation(ratings_queryset, factor_a, factor_b):
%(ratings_table)s AS r1,
%(ratings_table)s AS r2
WHERE
r1.%(filter_field)s = "%(lookup_a)s" AND
r2.%(filter_field)s = "%(lookup_b)s" AND
r1.%(filter_field)s = '%(lookup_a)s' AND
r2.%(filter_field)s = '%(lookup_b)s' AND
r1.%(match_on)s = r2.%(match_on)s
%(queryset_filter)s
"""
Expand Down Expand Up @@ -126,6 +126,9 @@ def sim_pearson_correlation(ratings_queryset, factor_a, factor_b):
return 0

sum1, sum2, sum1_sq, sum2_sq, psum, sample_size = result

if sum1 is None or sum2 is None or sample_size == 0:
return 0

num = psum - (sum1 * sum2 / sample_size)
den = sqrt((sum1_sq - pow(sum1, 2) / sample_size) * (sum2_sq - pow(sum2, 2) / sample_size))
Expand Down

0 comments on commit 3ed81c0

Please sign in to comment.