Esempio n. 1
0
    def POST(self):
        web_input = web.input(pkgs_file={})
        if 'user_id' in web_input:
            user_id = web_input['user_id'].encode('utf8')
            user_dir = os.path.join(self.submissions_dir, user_id)
            logging.info("New recommendation for user %s" % user_id)

        uploaded_file = os.path.join(user_dir, "uploaded_file")
        with open(uploaded_file) as uploaded:
            if uploaded.readline().startswith('POPULARITY-CONTEST'):
                user = PopconSystem(uploaded_file, user_id)
            else:
                user = PkgsListSystem(uploaded_file, user_id)
        user.maximal_pkg_profile()
        if len(user.pkg_profile) < 10:
            error_msg = "Could not extract profile from uploaded file. It must have at least 10 applications."  # noqa
            logging.critical(error_msg)
            return render.error([error_msg], "/survey/", "START")
        else:
            # Check the remaining strategies and select a new one
            old_strategies = [
                dirs for root, dirs, files in os.walk(
                    os.path.join(self.submissions_dir, user_id))
            ]
            if old_strategies:
                strategies = [
                    s for s in self.strategies if s not in old_strategies[0]
                ]
                logging.info("Already used strategies %s" % old_strategies[0])
            else:
                strategies = self.strategies
            if not strategies:
                return render.thanks(user_id)
            selected_strategy = random.choice(strategies)
            logging.info("Selected \'%s\' from %s" %
                         (selected_strategy, strategies))
            self.set_rec_strategy(selected_strategy)
            prediction = self.rec.get_recommendation(user, 10).get_prediction()
            logging.info("Prediction for user %s" % user_id)
            logging.info(str(prediction))
            self.save_prediction(user_id, selected_strategy, prediction)

            # Load packages details
            recommendation = [result[0] for result in prediction]
            pkgs_details = []
            for pkg_name in recommendation:
                logging.info("Getting details of package %s" % pkg_name)
                pkg = DebianPackage(pkg_name)
                pkg.load_details()
                pkgs_details.append(pkg)

            if pkgs_details:
                logging.info("Rendering survey slide...")
                return render.survey(pkgs_details, user_id, selected_strategy,
                                     len(strategies))
            else:
                return render.error(
                    ["No recommendation produced for the uploaded file."],
                    "/survey/", "START")
Esempio n. 2
0
    def POST(self):
        web_input = web.input(pkgs_file={})
        if 'user_id' in web_input:
            user_id = web_input['user_id'].encode('utf8')
            user_dir = os.path.join(self.submissions_dir, user_id)
            logging.info("New recommendation for user %s" % user_id)

        uploaded_file = os.path.join(user_dir, "uploaded_file")
        with open(uploaded_file) as uploaded:
            if uploaded.readline().startswith('POPULARITY-CONTEST'):
                user = PopconSystem(uploaded_file, user_id)
            else:
                user = PkgsListSystem(uploaded_file, user_id)
        user.maximal_pkg_profile()
        if len(user.pkg_profile) < 10:
            error_msg = "Could not extract profile from uploaded file. It must have at least 10 applications."  # noqa
            logging.critical(error_msg)
            return render.error([error_msg], "/survey/", "START")
        else:
            # Check the remaining strategies and select a new one
            old_strategies = [dirs for root, dirs, files in
                              os.walk(os.path.join(self.submissions_dir,
                                                   user_id))]
            if old_strategies:
                strategies = [
                    s for s in self.strategies if s not in old_strategies[0]]
                logging.info("Already used strategies %s" % old_strategies[0])
            else:
                strategies = self.strategies
            if not strategies:
                return render.thanks(user_id)
            selected_strategy = random.choice(strategies)
            logging.info("Selected \'%s\' from %s" %
                         (selected_strategy, strategies))
            self.set_rec_strategy(selected_strategy)
            prediction = self.rec.get_recommendation(user, 10).get_prediction()
            logging.info("Prediction for user %s" % user_id)
            logging.info(str(prediction))
            self.save_prediction(user_id, selected_strategy, prediction)

            # Load packages details
            recommendation = [result[0] for result in prediction]
            pkgs_details = []
            for pkg_name in recommendation:
                logging.info("Getting details of package %s" % pkg_name)
                pkg = DebianPackage(pkg_name)
                pkg.load_details()
                pkgs_details.append(pkg)

            if pkgs_details:
                logging.info("Rendering survey slide...")
                return render.survey(pkgs_details, user_id, selected_strategy,
                                     len(strategies))
            else:
                return render.error(
                    ["No recommendation produced for the uploaded file."],
                    "/survey/", "START")
Esempio n. 3
0
 def GET(self, pkg_name):
     pkg = DebianPackage(pkg_name)
     pkg.load_details()
     return render_plain.package(pkg)
Esempio n. 4
0
 def GET(self, pkg_name):
     cfg = Config()
     pkg = DebianPackage(pkg_name) 
     pkg.load_details()
     return render_plain.package(pkg)