Changeset 6fa3d09
- Timestamp:
- 01/05/22 21:51:57 (3 years ago)
- Branches:
- master
- Children:
- a64f926
- Parents:
- b8dc761
- Location:
- src/main
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/it/finki/charitable/controller/DonationPostController.java
rb8dc761 r6fa3d09 16 16 import java.time.Duration; 17 17 import java.time.LocalDate; 18 import java.time.LocalDateTime; 18 19 import java.util.*; 19 20 import java.util.stream.Collectors; … … 67 68 return "upload"; 68 69 } 70 if (dateDue.isBefore(LocalDate.now())) 71 { 72 model.addAttribute("error", true); 73 return "upload"; 74 } 69 75 70 76 DonationPost post = new DonationPost(); … … 269 275 post.setTotalFundsCollected(post.getTotalFundsCollected() + donatedAmount); 270 276 271 if(post.getRiskFactor() != 101 ) {277 if(post.getRiskFactor() != 101 && post.getRiskFactor() != 102) { 272 278 post.setRiskFactor(getRisk(post)); 273 279 } … … 317 323 318 324 private Integer getRisk(DonationPost post) { 319 float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays()+1); 320 float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1); 321 322 System.out.println(dailyAverage + " " + neededAverage); 323 int risk = (int) (dailyAverage / neededAverage * 100); 324 325 if(risk > 100) { 326 risk = 100; 327 } 328 329 if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) { 330 risk = 0; 331 } 332 325 int risk; 333 326 if(post.getFundsNeeded() <= post.getTotalFundsCollected()) { 334 risk = 101; 335 } 336 327 risk = 102; 328 } 329 else 330 { 331 if (LocalDate.now().isAfter(post.getDateDue())) 332 { 333 risk=0; 334 } 335 else 336 { 337 float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays()+1); 338 float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1); 339 340 if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) { 341 float hour=(float) LocalDateTime.now().getHour(); 342 float mins=(float) LocalDateTime.now().getMinute(); 343 hour=hour+(mins/(float)60); 344 float hourlyAverage=(dailyAverage/(float)24); 345 float neededhourlyAverage=(post.getFundsNeeded() - post.getTotalFundsCollected())/((float)24-hour); 346 risk = (int) (hourlyAverage/neededhourlyAverage*100); 347 if (risk>100) 348 { 349 risk=100; 350 } 351 352 } 353 else 354 { 355 System.out.println(dailyAverage + " " + neededAverage); 356 risk = (int) (dailyAverage / neededAverage * 100); 357 358 if(risk > 100) { 359 risk = 100; 360 } 361 } 362 } 363 } 337 364 return risk; 338 365 } -
src/main/java/it/finki/charitable/controller/UserProfileController.java
rb8dc761 r6fa3d09 14 14 import org.springframework.web.bind.annotation.RequestParam; 15 15 16 import java.time.Duration; 17 import java.time.LocalDate; 18 import java.time.LocalDateTime; 16 19 import java.util.List; 17 20 … … 116 119 post.getFundsCollected().add(funds); 117 120 post.setTotalFundsCollected(post.getTotalFundsCollected() + amount); 121 post.setRiskFactor(getRisk(post)); 118 122 donationPostService.save(post); 119 123 } … … 130 134 return null; 131 135 } 136 private Integer getRisk(DonationPost post) { 137 int risk; 138 if(post.getFundsNeeded() <= post.getTotalFundsCollected()) { 139 risk = 102; 140 } 141 else 142 { 143 if (LocalDate.now().isAfter(post.getDateDue())) 144 { 145 risk=0; 146 } 147 else 148 { 149 float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays()+1); 150 float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1); 151 152 if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) { 153 float hour=(float) LocalDateTime.now().getHour(); 154 float mins=(float) LocalDateTime.now().getMinute(); 155 hour=hour+(mins/(float)60); 156 float hourlyAverage=(dailyAverage/(float)24); 157 float neededhourlyAverage=(post.getFundsNeeded() - post.getTotalFundsCollected())/((float)24-hour); 158 risk = (int) (hourlyAverage/neededhourlyAverage*100); 159 if (risk>100) 160 { 161 risk=100; 162 } 163 164 } 165 else 166 { 167 System.out.println(dailyAverage + " " + neededAverage); 168 risk = (int) (dailyAverage / neededAverage * 100); 169 170 if(risk > 100) { 171 risk = 100; 172 } 173 } 174 } 175 } 176 return risk; 177 } 132 178 } 179 -
src/main/java/it/finki/charitable/util/AutomaticEvents.java
rb8dc761 r6fa3d09 12 12 import java.time.Duration; 13 13 import java.time.LocalDate; 14 import java.time.LocalDateTime; 14 15 import java.util.List; 15 16 import java.util.stream.Collectors; … … 60 61 61 62 donationPosts.forEach(post -> { 62 float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays() + 1); 63 float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1); 63 int risk; 64 if(post.getFundsNeeded() <= post.getTotalFundsCollected()) { 65 risk = 102; 66 } 67 else 68 { 69 if (LocalDate.now().isAfter(post.getDateDue())) 70 { 71 risk=0; 72 } 73 else 74 { 75 float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays() + 1); 76 float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1); 64 77 65 System.out.println(dailyAverage + " " + neededAverage); 66 int risk = (int) (dailyAverage / neededAverage * 100); 78 if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) { 79 float hour=(float) LocalDateTime.now().getHour(); 80 float mins=(float) LocalDateTime.now().getMinute(); 81 hour=hour+(mins/(float)60); 82 float hourlyAverage=(dailyAverage/(float)24); 83 float neededhourlyAverage=(post.getFundsNeeded() - post.getTotalFundsCollected())/((float)24-hour); 84 risk = (int) (hourlyAverage/neededhourlyAverage*100); 85 if (risk>100) 86 { 87 risk=100; 88 } 89 } 90 else 91 { 92 System.out.println(dailyAverage + " " + neededAverage); 93 risk = (int) (dailyAverage / neededAverage * 100); 67 94 68 if(risk > 100) { 69 risk = 100; 95 if(risk > 100) { 96 risk = 100; 97 } 98 } 70 99 } 71 72 if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) {73 risk = 0;74 100 } 75 76 if(post.getFundsNeeded() <= post.getTotalFundsCollected()) {77 risk = 101;78 }79 80 101 post.setRiskFactor(risk); 81 102 donationPostService.save(post); -
src/main/resources/templates/album.html
rb8dc761 r6fa3d09 55 55 <h4 th:text="${post.title}" style="height: 60px"></h4> 56 56 <p class="card-text text-truncate" style="height: 45px" th:text="${post.description}"></p> 57 <span th:if="${post.riskFactor < 101}" class="" style="color: black; margin-left: 62%;">Chance: <small th:text="${post.riskFactor}"></small></span> 58 <span th:unless="${post.riskFactor < 101}" style="color: black; margin-left: 62%;">Chance: unavailable</span> 57 <span th:if="${post.riskFactor == 100}" class="" style="color: black; margin-left: 62%;">Chance: <small th:text="${post.riskFactor+'+'}"></small></span> 58 <span th:if="${post.riskFactor < 100}" class="" style="color: black; margin-left: 62%;">Chance: <small th:text="${post.riskFactor}"></small></span> 59 <span th:if="${post.riskFactor == 101}" style="color: black; margin-left: 46%;">Chance: too early to calculate</span> 60 <span th:if="${post.riskFactor == 102}" style="color: black; margin-left: 61%;">Donation completed!</span> 59 61 <div class="d-flex justify-content-between align-items-center"> 60 62 <div class="btn-group"> -
src/main/resources/templates/login.html
rb8dc761 r6fa3d09 27 27 <button class="w-100 btn btn-lg btn-primary" type="submit">Sign in</button> 28 28 </form> 29 <a th:href="@{/oauth2/authorization/google}" class="btn btn- primary">Continue with google</a>30 <a th:href="@{/oauth2/authorization/facebook}" class="btn btn- primary">Continue with facebook</a>29 <a th:href="@{/oauth2/authorization/google}" class="btn btn-warning" style="width:200px; margin-top:20px;">Continue with Google</a> 30 <a th:href="@{/oauth2/authorization/facebook}" class="btn btn-info"style="width:200px; margin-top:20px;">Continue with Facebook</a> 31 31 <p th:if="${param.error != null}" class="text-danger">Incorrect username or password</p> 32 32 <p th:if="${successValidation}" class="text-success">Account validated</p> -
src/main/resources/templates/post.html
rb8dc761 r6fa3d09 53 53 <h5>Date due:</h5> 54 54 <p th:text="${post.dateDue}"></p> 55 <h5>Chance:</h5> 56 <p th:if="${post.riskFactor<100}" th:text="${post.riskFactor}"></p> 57 <p th:if="${post.riskFactor==100}" th:text="${post.riskFactor+'+'}"></p> 58 <p th:if="${post.riskFactor==101}">too early to calculate</p> 59 <p th:if="${post.riskFactor==102}">Donation completed!</p> 55 60 <h5>Bank account:</h5> 56 61 <p th:text="${post.bankAccount}"></p>
Note:
See TracChangeset
for help on using the changeset viewer.