Skip to content

Commit

Permalink
Fix bug on train without pkgs on user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
LucianoPC committed Aug 7, 2016
1 parent 080a99d commit cd07dc7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 8 additions & 1 deletion apprecommender/main/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
from apprecommender.config import Config
from apprecommender.initialize import Initialize
from apprecommender.strategy import (MachineLearning, MachineLearningBVA,
MachineLearningBOW)
MachineLearningBOW,
MachineLearningTrainError)
from apprecommender.main import collect_user_data
from apprecommender.main.options import get_parser

SUCCESS = 0
ERROR_INIT = 1
ERROR_TRAIN = 2
PERMISSION_DENIED = 3
ERROR_INIT_TRAIN = 4


def parse_options(args, config):
Expand Down Expand Up @@ -64,6 +66,8 @@ def run(args):
MachineLearning.train(MachineLearningBOW)
except IOError:
return PERMISSION_DENIED
except MachineLearningTrainError:
return ERROR_INIT_TRAIN

return SUCCESS
elif args['contribute']:
Expand Down Expand Up @@ -91,6 +95,9 @@ def main():
print "Run: apprec.py --train"
elif result is PERMISSION_DENIED:
print "Please, run this command as sudo"
elif result is ERROR_INIT_TRAIN:
print 'Error: You need install more packages to use machine' \
' learning recommendations'

if __name__ == '__main__':
main()
14 changes: 13 additions & 1 deletion apprecommender/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ def run(self, rec, user, rec_size):
return result


class MachineLearningTrainError(Exception):

def __init__(self, value=''):
self.value = value

def __str__(self):
return repr(self.value)


class MachineLearning(ContentBased):

__metaclass__ = ABCMeta
Expand Down Expand Up @@ -284,7 +293,10 @@ def train(cls):
try:
MachineLearning.PKGS_CLASSIFICATIONS = ml_data.create_data(
labels)
cls.run_train(MachineLearning.PKGS_CLASSIFICATIONS)
if len(MachineLearning.PKGS_CLASSIFICATIONS) > 0:
cls.run_train(MachineLearning.PKGS_CLASSIFICATIONS)
else:
raise MachineLearningTrainError()
except IOError:
raise

Expand Down

0 comments on commit cd07dc7

Please sign in to comment.