Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange counting #54

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

@Controller
public class IndexController {
public static final int TOTAL_AMOUNT_TO_SHOW = 3;
private FlashCardService flashCardService;

@Autowired
Expand All @@ -22,18 +23,20 @@ public void setFlashCardService(FlashCardService flashCardService) {
@RequestMapping("/")
public String index(Model model) {
StringBuilder ctaBuilder = new StringBuilder();
List<FlashCard> cards = flashCardService.getRandomFlashCards(5);
List<FlashCard> cards = flashCardService.getRandomFlashCards(TOTAL_AMOUNT_TO_SHOW);
ctaBuilder.append("Refresh your memory about ");
for (FlashCard card : cards) {
ctaBuilder.append(card.getTerm());
if (card != cards.get(cards.size() - 1)) {
ctaBuilder.append(", ");
}
}
ctaBuilder.append(" and ");
Long totalCount = flashCardService.getCurrentCount();
ctaBuilder.append(totalCount);
ctaBuilder.append(" more");
if (totalCount > TOTAL_AMOUNT_TO_SHOW) {
ctaBuilder.append(" and ");
ctaBuilder.append(totalCount - TOTAL_AMOUNT_TO_SHOW);
ctaBuilder.append(" more");
}
model.addAttribute("cta", ctaBuilder.toString());
model.addAttribute("flashCardCount", totalCount);
return "index";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public FlashCard getNextFlashCardBasedOnViews(Map<Long, Long> idToViewCounts) {
continue;
}
Long lowestScore = idToViewCounts.get(leastViewedId);
if (entry.getValue() >= lowestScore) {
break;
if (entry.getValue() < lowestScore) {
leastViewedId = entry.getKey();
}
leastViewedId = entry.getKey();
}
return flashCardRepository.findOne(leastViewedId);
}
Expand Down