Пример #1
0
  public static Result nutritionSchedule() {
    TDEERule tdeeRule = new TDEERule();
    CalEatingRule calEatingRule = new CalEatingRule();
    NutritionRule nuRule = new NutritionRule();
    MeatRule meatRule = new MeatRule();
    VegetableRule vegetableRule = new VegetableRule();
    DrinkRule drinkRule = new DrinkRule();

    User thisUser = User.findById(Long.parseLong(session("userId")));
    double weight = thisUser.getWeight();
    boolean isGain = thisUser.isGain();
    double height = thisUser.getHeight();
    if (weight == 0 || height == 0) {
      flash("error", "Please fill your information.");
      return redirect(routes.Profile.index());
    }
    nuRule.setInput(weight, isGain);
    RulesEngine rulesEngine = aNewRulesEngine().withSilentMode(true).build();
    rulesEngine.registerRule(nuRule);

    meatRule.setInput(true);
    vegetableRule.setInput(true);
    drinkRule.setInput(true);
    rulesEngine.registerRule(meatRule);
    rulesEngine.registerRule(vegetableRule);
    rulesEngine.registerRule(drinkRule);

    rulesEngine.fireRules();

    List<Nutrition> nuList = nuRule.getResult();

    List<RawMaterial> meatList = meatRule.getResult().getAll();
    List<RawMaterial> vetList = vegetableRule.getResult().getAll();
    List<RawMaterial> drinkList = drinkRule.getResult().getAll();

    List<RawMaterial> rawMaterialList = new ArrayList<RawMaterial>(meatList);
    rawMaterialList.addAll(vetList);
    rawMaterialList.addAll(drinkList);

    List<String> tdees = new ArrayList<String>();
    List<String> eatingCals = new ArrayList<String>();
    RulesEngine rulesEngine_tdee = aNewRulesEngine().withSilentMode(true).build();
    RulesEngine rulesEngine_cal = aNewRulesEngine().withSilentMode(true).build();
    rulesEngine_tdee.registerRule(tdeeRule);
    rulesEngine_cal.registerRule(calEatingRule);
    for (int i = 0; i < 5; i++) {
      tdeeRule.setInput(weight, height, thisUser.getGender(), thisUser.getAge(), 1.2 + (i * 0.2));
      rulesEngine_tdee.fireRules();
      tdees.add(tdeeRule.getResult());
      calEatingRule.setInput(Double.parseDouble(tdees.get(i)), isGain);

      rulesEngine_cal.fireRules();
      eatingCals.add(calEatingRule.getResult());
    }
    return ok(nutrition_schedule.render(nuList, rawMaterialList, tdees, eatingCals));
  }
Пример #2
0
 private static void collectDatum(
     List<Project> projects,
     List<Posting> postings,
     List<Issue> issues,
     List<PullRequest> pullRequests,
     List<Milestone> milestones,
     int daysAgo) {
   // collect all postings, issues, pullrequests and milesotnes that are contained in the projects.
   for (Project project : projects) {
     if (AccessControl.isAllowed(UserApp.currentUser(), project.asResource(), Operation.READ)) {
       postings.addAll(Posting.findRecentlyCreatedByDaysAgo(project, daysAgo));
       issues.addAll(Issue.findRecentlyOpendIssuesByDaysAgo(project, daysAgo));
       pullRequests.addAll(PullRequest.findOpendPullRequestsByDaysAgo(project, daysAgo));
       milestones.addAll(Milestone.findOpenMilestones(project.id));
     }
   }
 }