Changeset 6fa3d09 for src/main/java/it/finki/charitable/controller
- Timestamp:
- 01/05/22 21:51:57 (3 years ago)
- Branches:
- master
- Children:
- a64f926
- Parents:
- b8dc761
- Location:
- src/main/java/it/finki/charitable/controller
- Files:
-
- 2 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
Note:
See TracChangeset
for help on using the changeset viewer.