Commit f3443a10686e4c1e171833fdfa2e330b79d453dd
1 parent
27763f38
Exists in
master
and in
1 other branch
New config option 'survey_mode'
Showing
2 changed files
with
24 additions
and
14 deletions
Show diff stats
src/config.py
... | ... | @@ -38,7 +38,9 @@ class Config(): |
38 | 38 | self.debug = 0 |
39 | 39 | self.verbose = 0 |
40 | 40 | self.output = "/dev/null" |
41 | + self.survey_mode = 1 | |
41 | 42 | self.axi = "/var/lib/apt-xapian-index/index" |
43 | + self.dde_url = "http://dde.debian.net/dde/q/udd/packages/all/%s?t=json" | |
42 | 44 | self.popcon_index = os.path.expanduser("~/.app-recommender/popcon_index") |
43 | 45 | self.popcon_dir = os.path.expanduser("~/.app-recommender/popcon_dir") |
44 | 46 | self.clusters_dir = os.path.expanduser("~/.app-recommender/clusters_dir") |
... | ... | @@ -111,8 +113,10 @@ class Config(): |
111 | 113 | self.debug = self.read_option('general', 'debug') |
112 | 114 | self.debug = self.read_option('general', 'verbose') |
113 | 115 | self.output_filename = self.read_option('general', 'output') |
116 | + self.survey_mode = self.read_option('general', 'survey_mode') | |
114 | 117 | |
115 | 118 | self.axi = self.read_option('data_sources', 'axi') |
119 | + self.dde_url = self.read_option('data_sources', 'dde_url') | |
116 | 120 | self.popcon_index = os.path.expanduser(self.read_option('data_sources','popcon_index')) |
117 | 121 | self.popcon_dir = os.path.expanduser(self.read_option('data_sources', 'popcon_dir')) |
118 | 122 | self.index_mode = self.read_option('data_sources', 'index_mode') | ... | ... |
src/web/server.py
... | ... | @@ -29,7 +29,10 @@ class FeedbackForm(form.Form): |
29 | 29 | |
30 | 30 | class Index: |
31 | 31 | def GET(self): |
32 | - return render.index() | |
32 | + if Config().survey_mode: | |
33 | + return render.survey_index() | |
34 | + else: | |
35 | + return render.index() | |
33 | 36 | |
34 | 37 | class About: |
35 | 38 | def GET(self): |
... | ... | @@ -49,12 +52,12 @@ class Package: |
49 | 52 | return render_plain.package(result) |
50 | 53 | |
51 | 54 | def get_details_from_dde(self, pkg): |
52 | - json_source = "http://dde.debian.net/dde/q/udd/packages/all/%s?t=json" % pkg #FIXME: url goes to config | |
55 | + json_source = Config().dde_url % pkg | |
53 | 56 | json_data = json.load(urllib.urlopen(json_source)) |
54 | - # parsing tags: | |
57 | + # parse tags | |
55 | 58 | tags = self._debtags_list_to_dict(json_data['r']['tag']) |
56 | 59 | json_data['r']['tag'] = tags |
57 | - # formatting long description | |
60 | + # format long description | |
58 | 61 | json_data['r']['long_description'] = json_data['r']['long_description'].replace(' .\n','').replace('\n','<br />') |
59 | 62 | return json_data['r'] |
60 | 63 | |
... | ... | @@ -243,12 +246,14 @@ class AppRecommender: |
243 | 246 | pkg_details.append(Package().get_details_from_dde(pkg)) |
244 | 247 | except: |
245 | 248 | pkg_summaries[pkg] = "" |
246 | - | |
247 | - ### Temporarily rendering *survey* rather than *apprec* ### | |
248 | - #return render.apprec(recommendation, pkg_summaries, | |
249 | - # FeedbackForm(request.selected_strategies),request) | |
250 | - return render_plain.survey(recommendation, pkg_details, | |
251 | - FeedbackForm(request.selected_strategies),request) | |
249 | + if Config().survey_mode: | |
250 | + return render_plain.survey(recommendation, pkg_details, | |
251 | + FeedbackForm(request.selected_strategies), | |
252 | + request) | |
253 | + else: | |
254 | + return render.apprec(recommendation, pkg_summaries, | |
255 | + FeedbackForm(request.selected_strategies), | |
256 | + request) | |
252 | 257 | |
253 | 258 | def _recommends(self,request): |
254 | 259 | user = User(dict.fromkeys(request.pkgs_list,1),request.user_id) |
... | ... | @@ -256,7 +261,8 @@ class AppRecommender: |
256 | 261 | results = dict() |
257 | 262 | for strategy_str in request.selected_strategies: |
258 | 263 | self.rec.set_strategy(strategy_str) |
259 | - prediction = self.rec.get_recommendation(user).get_prediction(request.limit) | |
264 | + prediction = self.rec.get_recommendation(user,10).get_prediction() | |
265 | + print prediction | |
260 | 266 | results[strategy_str] = \ |
261 | 267 | [result[0] for result in prediction] |
262 | 268 | return results |
... | ... | @@ -286,10 +292,10 @@ render = web.template.render('templates/', base='layout') |
286 | 292 | render_plain = web.template.render('templates/') |
287 | 293 | |
288 | 294 | urls = ('/', 'Index', |
289 | - '/apprec', 'AppRecommender', | |
295 | + '/apprec', 'AppRecommender', | |
290 | 296 | '/thanks', 'Thanks', |
291 | - '/support', 'Support', | |
292 | - '/about', 'About', | |
297 | + '/support', 'Support', | |
298 | + '/about', 'About', | |
293 | 299 | '/package/(.*)', 'Package' |
294 | 300 | ) |
295 | 301 | ... | ... |