Merge lp:~dobey/unity-scope-click/multistar into lp:unity-scope-click

Proposed by dobey
Status: Merged
Approved by: dobey
Approved revision: 446
Merged at revision: 456
Proposed branch: lp:~dobey/unity-scope-click/multistar
Merge into: lp:unity-scope-click
Diff against target: 103 lines (+52/-1)
4 files modified
libclickscope/click/utils.cpp (+23/-0)
libclickscope/click/utils.h (+1/-0)
libclickscope/tests/test_utils.cpp (+25/-0)
scope/clickstore/store-query.cpp (+3/-1)
To merge this branch: bzr merge lp:~dobey/unity-scope-click/multistar
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Needs Fixing
Alejandro J. Cura (community) Approve
Review via email: mp+294019@code.launchpad.net

Commit message

Use 5 stars for visualizing the rating value.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

This should be moved to its own function, and needs some unit tests.

review: Needs Fixing
445. By dobey

Refactor to separate method with tests.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

We don't check whatever comes in the json for pkg.rating, so please add tests for -1.0 and 6.0.

review: Needs Fixing
446. By dobey

Bound the rating betwen 0.0 and 5.0 for star rendering.

Revision history for this message
Alejandro J. Cura (alecu) wrote :

Looks great

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libclickscope/click/utils.cpp'
2--- libclickscope/click/utils.cpp 2014-07-25 22:06:11 +0000
3+++ libclickscope/click/utils.cpp 2016-05-17 18:05:09 +0000
4@@ -57,6 +57,29 @@
5 return s.str();
6 }
7
8+std::string click::Formatter::render_rating_stars(double rating)
9+{
10+ std::ostringstream ss;
11+ int rounded;
12+
13+ // Only support values of rating between 0.0 and 5.0
14+ if (rating < 0.0f) {
15+ rounded = 0;
16+ } else if (rating > 5.0f) {
17+ rounded = 5;
18+ } else {
19+ rounded = round(rating);
20+ }
21+
22+ for (int i = 0; i < rounded; i++) {
23+ ss << "★";
24+ }
25+ for (int j = 0; j < 5 - rounded; j++) {
26+ ss << "☆";
27+ }
28+ return ss.str();
29+}
30+
31 using namespace boost::posix_time;
32
33 time_input_facet* build_input_facet(std::stringstream& ss)
34
35=== modified file 'libclickscope/click/utils.h'
36--- libclickscope/click/utils.h 2014-07-25 05:35:28 +0000
37+++ libclickscope/click/utils.h 2016-05-17 18:05:09 +0000
38@@ -55,6 +55,7 @@
39 {
40 public:
41 static std::string human_readable_filesize(long num_bytes);
42+ static std::string render_rating_stars(double rating);
43 };
44
45 } // namespace click
46
47=== modified file 'libclickscope/tests/test_utils.cpp'
48--- libclickscope/tests/test_utils.cpp 2014-07-25 20:25:49 +0000
49+++ libclickscope/tests/test_utils.cpp 2016-05-17 18:05:09 +0000
50@@ -92,6 +92,31 @@
51 ASSERT_EQ(click::Formatter::human_readable_filesize(42*1024*1024+512*1024+512), "42.5 MiB");
52 }
53
54+TEST_F(UtilsTest, testRatingStarsFull)
55+{
56+ ASSERT_EQ(click::Formatter::render_rating_stars(2.0f), "★★☆☆☆");
57+}
58+
59+TEST_F(UtilsTest, testRatingStarsHalf)
60+{
61+ ASSERT_EQ(click::Formatter::render_rating_stars(3.5f), "★★★★☆");
62+}
63+
64+TEST_F(UtilsTest, testRatingStarsQuarter)
65+{
66+ ASSERT_EQ(click::Formatter::render_rating_stars(3.25f), "★★★☆☆");
67+}
68+
69+TEST_F(UtilsTest, testRatingStarsNegative)
70+{
71+ ASSERT_EQ(click::Formatter::render_rating_stars(-1.0f), "☆☆☆☆☆");
72+}
73+
74+TEST_F(UtilsTest, testRatingStarOverload)
75+{
76+ ASSERT_EQ(click::Formatter::render_rating_stars(6.0f), "★★★★★");
77+}
78+
79 class TestableDate : public click::Date
80 {
81 public:
82
83=== modified file 'scope/clickstore/store-query.cpp'
84--- scope/clickstore/store-query.cpp 2016-05-10 14:56:11 +0000
85+++ scope/clickstore/store-query.cpp 2016-05-17 18:05:09 +0000
86@@ -35,6 +35,7 @@
87 #include <click/key_file_locator.h>
88 #include <click/qtbridge.h>
89 #include <click/departments-db.h>
90+#include <click/utils.h>
91
92 #include <unity/scopes/Annotation.h>
93 #include <unity/scopes/CategoryRenderer.h>
94@@ -298,7 +299,8 @@
95 std::string price = _("FREE");
96 std::stringstream ss;
97 ss << std::fixed << std::setprecision(1);
98- ss << "☆ " << pkg.rating;
99+ ss << click::Formatter::render_rating_stars(pkg.rating);
100+ ss << " " << pkg.rating;
101 std::string rating{ss.str()};
102
103 bool was_purchased = false;

Subscribers

People subscribed via source and target branches

to all changes: