Changeset 6fa3d09 for src/main/java/it/finki/charitable/util
- Timestamp:
- 01/05/22 21:51:57 (3 years ago)
- Branches:
- master
- Children:
- a64f926
- Parents:
- b8dc761
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note:
See TracChangeset
for help on using the changeset viewer.