Commit d3b38af6458ff163af669a4687834ce194307898
Exists in
master
and in
1 other branch
Merge branch 'master' of github.com:tassia/AppRecommender
Showing
6 changed files
with
70 additions
and
29 deletions
Show diff stats
src/data.py
@@ -271,11 +271,12 @@ class PopconXapianIndex(xapian.WritableDatabase): | @@ -271,11 +271,12 @@ class PopconXapianIndex(xapian.WritableDatabase): | ||
271 | class KMedoidsClustering(cluster.KMeansClustering): | 271 | class KMedoidsClustering(cluster.KMeansClustering): |
272 | 272 | ||
273 | def __init__(self,data,distance,max_data=100): | 273 | def __init__(self,data,distance,max_data=100): |
274 | - if len(data)<max_data: | ||
275 | - data_sample = data | ||
276 | - else: | ||
277 | - data_sample = random.sample(data,max_data) | ||
278 | - cluster.KMeansClustering.__init__(self, data_sample, distance) | 274 | + # if len(data)<max_data: |
275 | + # data_sample = data | ||
276 | + # else: | ||
277 | + # data_sample = random.sample(data,max_data) | ||
278 | + # cluster.KMeansClustering.__init__(self, data_sample, distance) | ||
279 | + cluster.KMeansClustering.__init__(self, data, distance) | ||
279 | self.distanceMatrix = {} | 280 | self.distanceMatrix = {} |
280 | for submission in self._KMeansClustering__data: | 281 | for submission in self._KMeansClustering__data: |
281 | self.distanceMatrix[submission.user_id] = {} | 282 | self.distanceMatrix[submission.user_id] = {} |
@@ -332,7 +333,13 @@ class KMedoidsClustering(cluster.KMeansClustering): | @@ -332,7 +333,13 @@ class KMedoidsClustering(cluster.KMeansClustering): | ||
332 | """ | 333 | """ |
333 | Generate n clusters and return their medoids. | 334 | Generate n clusters and return their medoids. |
334 | """ | 335 | """ |
335 | - medoids_distances = [self.getMedoid(cluster) for cluster in self.getclusters(n)] | 336 | + #medoids_distances = [self.getMedoid(cluster) for cluster in self.getclusters(n)] |
337 | + medoids_distances = [] | ||
338 | + for cluster in self.getclusters(n): | ||
339 | + type(cluster) | ||
340 | + print cluster | ||
341 | + medoids_distances.append(self.getMedoid(cluster)) | ||
342 | + print medoids_distances | ||
336 | medoids = [m[0] for m in medoids_distances] | 343 | medoids = [m[0] for m in medoids_distances] |
337 | dispersion = sum([m[1] for m in medoids_distances]) | 344 | dispersion = sum([m[1] for m in medoids_distances]) |
338 | logging.info("Clustering completed and the following medoids were found: %s" % [c.user_id for c in medoids]) | 345 | logging.info("Clustering completed and the following medoids were found: %s" % [c.user_id for c in medoids]) |
src/examples/clustering.py
@@ -36,7 +36,7 @@ if __name__ == '__main__': | @@ -36,7 +36,7 @@ if __name__ == '__main__': | ||
36 | begin_time = datetime.datetime.now() | 36 | begin_time = datetime.datetime.now() |
37 | logging.info("Clustering computation started at %s" % begin_time) | 37 | logging.info("Clustering computation started at %s" % begin_time) |
38 | 38 | ||
39 | - cl = PopconClusteredData(cfg) | 39 | + cl = PopconXapianIndex(cfg) |
40 | 40 | ||
41 | end_time = datetime.datetime.now() | 41 | end_time = datetime.datetime.now() |
42 | logging.info("Clustering computation completed at %s" % end_time) | 42 | logging.info("Clustering computation completed at %s" % end_time) |
src/web/static/coda-slider-2.0/javascripts/jquery.coda-slider-2.0.js
@@ -99,9 +99,9 @@ $.fn.codaSlider = function(settings) { | @@ -99,9 +99,9 @@ $.fn.codaSlider = function(settings) { | ||
99 | $('#coda-nav-right-' + sliderCount + ' a').click(function(){ | 99 | $('#coda-nav-right-' + sliderCount + ' a').click(function(){ |
100 | navClicks++; | 100 | navClicks++; |
101 | if (currentPanel == panelCount) { | 101 | if (currentPanel == panelCount) { |
102 | - this.style.display = 'none'; // Button display none; | ||
103 | - document.getElementById("controls-form").style.display = 'block'; // Show buttons controls; | ||
104 | - document.getElementById("coda-slider-1").style.display = 'none'; // Description hidden; | 102 | + $(this).hide("fast"); // Button display none; |
103 | + $(".show-end").show("fast"); // Show buttons controls; | ||
104 | + $(".hide-end").hide("fast"); // Description hidden; | ||
105 | return false; | 105 | return false; |
106 | offset = 0; | 106 | offset = 0; |
107 | currentPanel = 1; | 107 | currentPanel = 1; |
src/web/static/css/survey.css
@@ -38,6 +38,16 @@ display: block; | @@ -38,6 +38,16 @@ display: block; | ||
38 | z-index: 3; | 38 | z-index: 3; |
39 | } | 39 | } |
40 | 40 | ||
41 | +#controls-form label#tip-finish .tip { | ||
42 | +margin-top: -50px; | ||
43 | +left: 90px; | ||
44 | +} | ||
45 | + | ||
46 | +#controls-form label#tip-continue .tip { | ||
47 | +margin-top: -80px; | ||
48 | +right: -60px; | ||
49 | +} | ||
50 | + | ||
41 | .innertube { | 51 | .innertube { |
42 | margin: 30px; | 52 | margin: 30px; |
43 | } | 53 | } |
@@ -73,16 +83,13 @@ display: none; | @@ -73,16 +83,13 @@ display: none; | ||
73 | } | 83 | } |
74 | 84 | ||
75 | .screenshot { | 85 | .screenshot { |
76 | -float: right; | 86 | +float: left; |
77 | margin: 5px; | 87 | margin: 5px; |
78 | } | 88 | } |
79 | 89 | ||
80 | -.content-pkg ul { | ||
81 | -list-style: none; | ||
82 | -} | ||
83 | - | ||
84 | .content-pkg ul li { | 90 | .content-pkg ul li { |
85 | margin-bottom: 10px; | 91 | margin-bottom: 10px; |
92 | +font-size: | ||
86 | } | 93 | } |
87 | 94 | ||
88 | .radioButton, | 95 | .radioButton, |
@@ -106,6 +113,10 @@ z-index: 2; | @@ -106,6 +113,10 @@ z-index: 2; | ||
106 | cursor: pointer; | 113 | cursor: pointer; |
107 | } | 114 | } |
108 | 115 | ||
116 | +#continue-button { | ||
117 | +float: right; | ||
118 | +} | ||
119 | + | ||
109 | .radioButton:hover, | 120 | .radioButton:hover, |
110 | #next-button:hover, | 121 | #next-button:hover, |
111 | #controls-form input:hover { | 122 | #controls-form input:hover { |
@@ -128,24 +139,30 @@ width: 180px; | @@ -128,24 +139,30 @@ width: 180px; | ||
128 | float: right; | 139 | float: right; |
129 | } | 140 | } |
130 | 141 | ||
131 | -#controls-form, | ||
132 | #next-button { | 142 | #next-button { |
133 | text-align: center; | 143 | text-align: center; |
134 | position: absolute; | 144 | position: absolute; |
135 | -top: 120px; | 145 | +top: 90px; |
136 | right: 65px; | 146 | right: 65px; |
137 | width: 150px; | 147 | width: 150px; |
138 | height: 20px; | 148 | height: 20px; |
149 | +float: right; | ||
139 | z-index: 3; | 150 | z-index: 3; |
140 | } | 151 | } |
141 | 152 | ||
142 | #controls-form { | 153 | #controls-form { |
143 | -top: 90px; | ||
144 | -right: 85px; | ||
145 | -height: auto; | 154 | +position: absolute; |
155 | +top: 390px; | ||
156 | +width: 600px; | ||
157 | +margin-right: auto; | ||
158 | +margin-left: auto; | ||
159 | +text-align: center; | ||
160 | +height: 20px; | ||
161 | +z-index: 3; | ||
146 | } | 162 | } |
147 | 163 | ||
148 | 164 | ||
165 | + | ||
149 | /* | 166 | /* |
150 | * Package Box | 167 | * Package Box |
151 | */ | 168 | */ |
src/web/survey.py
@@ -79,12 +79,13 @@ class Package: | @@ -79,12 +79,13 @@ class Package: | ||
79 | class Request: | 79 | class Request: |
80 | def __init__(self,web_input,submissions_dir,user_id=0,pkgs_list=0): | 80 | def __init__(self,web_input,submissions_dir,user_id=0,pkgs_list=0): |
81 | self.strategy = "" | 81 | self.strategy = "" |
82 | + print "Request from user",user_id | ||
82 | if user_id: | 83 | if user_id: |
83 | self.user_id = user_id | 84 | self.user_id = user_id |
84 | self.outputdir = os.path.join(submissions_dir,user_id) | 85 | self.outputdir = os.path.join(submissions_dir,user_id) |
85 | else: | 86 | else: |
86 | self.outputdir = tempfile.mkdtemp(prefix='',dir=submissions_dir) | 87 | self.outputdir = tempfile.mkdtemp(prefix='',dir=submissions_dir) |
87 | - print "created dir %s",self.outputdir | 88 | + print ("created dir %s" % self.outputdir) |
88 | self.user_id = self.outputdir.lstrip(submissions_dir) | 89 | self.user_id = self.outputdir.lstrip(submissions_dir) |
89 | 90 | ||
90 | if pkgs_list: | 91 | if pkgs_list: |
@@ -169,6 +170,7 @@ class Survey: | @@ -169,6 +170,7 @@ class Survey: | ||
169 | request = Request(web_input,self.submissions_dir) | 170 | request = Request(web_input,self.submissions_dir) |
170 | else: | 171 | else: |
171 | user_id = web_input['user_id'].encode('utf8') | 172 | user_id = web_input['user_id'].encode('utf8') |
173 | + print "Continue", user_id | ||
172 | with open("./submissions/%s/packages_list" % user_id) as packages_list: | 174 | with open("./submissions/%s/packages_list" % user_id) as packages_list: |
173 | pkgs_list = [line.strip() for line in packages_list.readlines()] | 175 | pkgs_list = [line.strip() for line in packages_list.readlines()] |
174 | request = Request(web_input,self.submissions_dir,user_id,pkgs_list) | 176 | request = Request(web_input,self.submissions_dir,user_id,pkgs_list) |
@@ -181,9 +183,14 @@ class Survey: | @@ -181,9 +183,14 @@ class Survey: | ||
181 | old_strategies = [dirs for root, dirs, files in | 183 | old_strategies = [dirs for root, dirs, files in |
182 | os.walk(os.path.join(self.submissions_dir, | 184 | os.walk(os.path.join(self.submissions_dir, |
183 | request.user_id))] | 185 | request.user_id))] |
184 | - print "OLD Strategies", old_strategies[0] | ||
185 | - strategies = [s for s in self.strategies if s not in old_strategies[0]] | 186 | + if old_strategies: |
187 | + strategies = [s for s in self.strategies if s not in old_strategies[0]] | ||
188 | + print "OLD Strategies", old_strategies[0] | ||
189 | + else: | ||
190 | + strategies = self.strategies | ||
186 | print "LEFT",strategies | 191 | print "LEFT",strategies |
192 | + if not strategies: | ||
193 | + return render.thanks(user_id) | ||
187 | request.strategy = random.choice(strategies) | 194 | request.strategy = random.choice(strategies) |
188 | print "selected",request.strategy | 195 | print "selected",request.strategy |
189 | self.rec.set_strategy(request.strategy) | 196 | self.rec.set_strategy(request.strategy) |
src/web/templates/survey.html
@@ -25,18 +25,26 @@ $var jsfiles: static/coda-slider-2.0/javascripts/jquery-1.3.2.min.js static/coda | @@ -25,18 +25,26 @@ $var jsfiles: static/coda-slider-2.0/javascripts/jquery-1.3.2.min.js static/coda | ||
25 | 25 | ||
26 | <h1>AppRecommender Survey</h1> | 26 | <h1>AppRecommender Survey</h1> |
27 | 27 | ||
28 | +<div class="show-end" style="display: none;"> | ||
29 | + | ||
30 | +<p> | ||
31 | +A class <b>show-end</b> ou <b>hide-end</b> mostra um elemento ou esconde um elemento ao final do último Next. | ||
32 | +</p> | ||
33 | + | ||
34 | +</div> | ||
35 | + | ||
36 | + | ||
28 | <form action="/save" method="post" enctype="multipart/form-data" name="surveyform"> | 37 | <form action="/save" method="post" enctype="multipart/form-data" name="surveyform"> |
29 | 38 | ||
30 | <input type="hidden" name="user_id" value=$request.user_id> | 39 | <input type="hidden" name="user_id" value=$request.user_id> |
31 | <input type="hidden" name="strategy" value=$request.strategy> | 40 | <input type="hidden" name="strategy" value=$request.strategy> |
32 | -<div id="controls-form" style="display: none;"><!-- display show in the end form --> | 41 | +<div id="controls-form" style="display: none;" class="show-end"><!-- display show in the end form --> |
33 | <label for="finish_button" id="tip-finish"> | 42 | <label for="finish_button" id="tip-finish"> |
34 | <!--<div class="tip important"> | 43 | <!--<div class="tip important"> |
35 | <p>Conclude your participation in this survey</p> | 44 | <p>Conclude your participation in this survey</p> |
36 | </div>--> | 45 | </div>--> |
37 | <input id="finish-button" name="finish_button" type="submit" value="Finish" class="glass" /> | 46 | <input id="finish-button" name="finish_button" type="submit" value="Finish" class="glass" /> |
38 | </label> | 47 | </label> |
39 | -<br /> | ||
40 | <label for="strategy_button" id="tip-continue"> | 48 | <label for="strategy_button" id="tip-continue"> |
41 | <!--<div class="tip tip"> | 49 | <!--<div class="tip tip"> |
42 | <p>Evaluate more suggestions </p> | 50 | <p>Evaluate more suggestions </p> |
@@ -45,7 +53,7 @@ $var jsfiles: static/coda-slider-2.0/javascripts/jquery-1.3.2.min.js static/coda | @@ -45,7 +53,7 @@ $var jsfiles: static/coda-slider-2.0/javascripts/jquery-1.3.2.min.js static/coda | ||
45 | </label> | 53 | </label> |
46 | </div><!-- id="controls-form" --> | 54 | </div><!-- id="controls-form" --> |
47 | 55 | ||
48 | -<div class="coda-slider-wrapper"> | 56 | +<div class="coda-slider-wrapper hide-end"> |
49 | <div class="coda-slider preload" id="coda-slider-1"> | 57 | <div class="coda-slider preload" id="coda-slider-1"> |
50 | $for pkg in pkg_details: | 58 | $for pkg in pkg_details: |
51 | <div class="panel"> | 59 | <div class="panel"> |
@@ -79,6 +87,10 @@ $for pkg in pkg_details: | @@ -79,6 +87,10 @@ $for pkg in pkg_details: | ||
79 | </div>--> | 87 | </div>--> |
80 | </label> | 88 | </label> |
81 | <br style="clear: both;" /> | 89 | <br style="clear: both;" /> |
90 | + </div><!-- #panel-controls --> | ||
91 | + <div class="content-pkg"> | ||
92 | + <ul> | ||
93 | + <li><b>Description</b>: | ||
82 | <div class="screenshot"> | 94 | <div class="screenshot"> |
83 | <a class="link-thumb" rel="facebox" | 95 | <a class="link-thumb" rel="facebox" |
84 | href="http://screenshots.debian.net/screenshot/$pkg['package']?.jpg" | 96 | href="http://screenshots.debian.net/screenshot/$pkg['package']?.jpg" |
@@ -86,9 +98,7 @@ $for pkg in pkg_details: | @@ -86,9 +98,7 @@ $for pkg in pkg_details: | ||
86 | <img src="http://screenshots.debian.net/thumbnail/$pkg['package']" | 98 | <img src="http://screenshots.debian.net/thumbnail/$pkg['package']" |
87 | alt="Screenshot $pkg['package']" /></a> | 99 | alt="Screenshot $pkg['package']" /></a> |
88 | </div><!-- screenshot --> | 100 | </div><!-- screenshot --> |
89 | - </div><!-- #panel-controls --> | ||
90 | - <div class="content-pkg"> | ||
91 | - <li><b>Description</b>: <br />$:pkg['long_description']</li> | 101 | + <br />$:pkg['long_description']</li> |
92 | $if pkg['homepage']: | 102 | $if pkg['homepage']: |
93 | <li><b>Homepage</b>: $pkg['homepage']</li> | 103 | <li><b>Homepage</b>: $pkg['homepage']</li> |
94 | $if pkg['task']: | 104 | $if pkg['task']: |