-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.py
More file actions
41 lines (33 loc) · 1.17 KB
/
Copy pathcommon.py
File metadata and controls
41 lines (33 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import json
from pymongo import MongoClient
config = json.load(open('.config'))
tmdb_key = config['tmdb_api_key']
client = MongoClient(config['host'], config['port'])
database = client[config['database']]
meta = database[config['collections']['meta']]
users = database[config['collections']['users']]
movies = database[config['collections']['movies']]
user_similarity = database[config['collections']['user_similarity']]
deviations = database[config['collections']['deviations']]
metadata = None
user_age_range = None
def initialize():
global metadata
global user_age_range
metadata = meta.find({}, {'_id': 0, 'zip_codes': 0}).next()
user_age_range = users.aggregate([{
'$group': {
'_id': 0,
'max': {'$max': '$age'},
'min': {'$min': '$age'}
} }]).next()
if len(list(database.list_collections())) != 0:
initialize()
def normalize(old_value, old_max, old_min, new_max, new_min):
old_range = (old_max - old_min)
if old_range == 0:
new_value = new_min
else:
new_range = (new_max - new_min)
new_value = (((old_value - old_min) * new_range) / float(old_range)) + new_min
return new_value