-
Notifications
You must be signed in to change notification settings - Fork 34
Fix path of pickle files (broken so far) #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d66e9f7
e474462
45ca893
8ffeb76
9fb6085
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from django.test import TestCase | ||
from django.core.urlresolvers import reverse | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class RecoTest(TestCase): | ||
|
||
def setUp(self): | ||
User.objects.create_user(username='test', password='test') | ||
|
||
def test_reco(self, **kwargs): | ||
self.client.login(username='test', password='test') | ||
reco_url = reverse('get-reco-algo-list', args=['svd', 'all']) | ||
self.assertEqual(reco_url, '/data/reco/svd/all.json') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
|
||
class UserTest(TestCase): | ||
|
||
def setUp(self): | ||
self.User = get_user_model() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,22 @@ def __init__(self): | |
self.nb_users = None | ||
self.nb_works = None | ||
|
||
def get_backup_path(self, filename): | ||
if filename is None: | ||
filename = self.get_backup_filename() | ||
return os.path.join(PICKLE_DIR, filename) | ||
|
||
def has_backup(self, filename=None): | ||
if filename is None: | ||
filename = self.get_backup_filename() | ||
return os.path.isfile(self.get_backup_path(filename)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about : There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trop long je pense. |
||
|
||
def save(self, filename): | ||
with open(os.path.join(PICKLE_DIR, filename), 'wb') as f: | ||
with open(self.get_backup_path(filename), 'wb') as f: | ||
pickle.dump(self, f, pickle.HIGHEST_PROTOCOL) | ||
|
||
def load(self, filename): | ||
with open(os.path.join(PICKLE_DIR, filename), 'rb') as f: | ||
with open(self.get_backup_path(filename), 'rb') as f: | ||
backup = pickle.load(f) | ||
return backup | ||
|
||
|
@@ -29,5 +39,8 @@ def set_parameters(self, nb_users, nb_works): | |
def get_shortname(self): | ||
return 'algo' | ||
|
||
def get_backup_filename(self): | ||
return '%s.pickle' % self.get_shortname() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using @Property. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's a property, I should call it backup_filename, right? (without the get) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. I think that either a function or a property is fine here. |
||
|
||
def __str__(self): | ||
return '[%s]' % self.get_shortname().upper() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import random | ||
from collections import Counter, namedtuple | ||
from mangaki.utils.values import rating_values | ||
from mangaki.utils.common import PICKLE_DIR | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMHO, that should go in Django Settings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK mais please, futur commit lorsqu'on aura mis les tests. |
||
import numpy as np | ||
from datetime import datetime | ||
|
||
|
@@ -24,11 +25,11 @@ def __init__(self): | |
self.datetime = datetime.now() | ||
|
||
def save(self, filename): | ||
with open(os.path.join('pickles', filename), 'wb') as f: | ||
with open(os.path.join(PICKLE_DIR, filename), 'wb') as f: | ||
pickle.dump(self, f, pickle.HIGHEST_PROTOCOL) | ||
|
||
def load(self, filename): | ||
with open(os.path.join('pickles', filename), 'rb') as f: | ||
with open(os.path.join(PICKLE_DIR, filename), 'rb') as f: | ||
backup = pickle.load(f) | ||
self.anonymized = backup.anonymized | ||
self.encode_user = backup.encode_user | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
|
||
def get_reco_algo(user, algo_name='knn', category='all'): | ||
chrono = Chrono(is_enabled=CHRONO_ENABLED, connection=connection) | ||
chrono = Chrono(is_enabled=CHRONO_ENABLED) | ||
|
||
already_rated_works = Rating.objects.filter(user=user).values_list('work_id', flat=True) | ||
|
||
|
@@ -48,13 +48,12 @@ def get_reco_algo(user, algo_name='knn', category='all'): | |
chrono.save('get all %d interesting ratings' % queryset.count()) | ||
|
||
dataset = Dataset() | ||
backup_filename = '%s.pickle' % algo_name | ||
if os.path.isfile(os.path.join('pickles', backup_filename)): # When Algo class will be there: 'if algo.has_backup():' | ||
algo = ALGOS[algo_name]() | ||
algo.load(backup_filename) | ||
dataset.load('ratings-' + backup_filename) | ||
algo = ALGOS[algo_name]() | ||
if algo.has_backup(): | ||
algo.load(algo.get_backup_filename()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's frequent to use the default filename, consider use it as a default argument for the load method. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je pense juste que je ne peux pas mettre There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Je pense que juste |
||
dataset.load('ratings-' + algo.get_backup_filename()) | ||
else: | ||
dataset, algo = fit_algo(algo_name, queryset, backup_filename) | ||
dataset, algo = fit_algo(algo_name, queryset, algo.get_backup_filename()) | ||
|
||
chrono.save('fit %s' % algo.get_shortname()) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why WALS is removed ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The answer is in the commit title: “Since TensorFlow 1.0, MangakiWALS models cannot be saved anymore” ^^'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's definitely right. My bad for not reading your commit title! But you should have summarized it in your PR message, maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is now an issue :) #274