Index: src/main/java/it/finki/charitable/controller/DonationPostController.java
===================================================================
--- src/main/java/it/finki/charitable/controller/DonationPostController.java	(revision b8dc7612c4ce79e01dfe5fa1fe25e62186eefcdb)
+++ src/main/java/it/finki/charitable/controller/DonationPostController.java	(revision 6fa3d09676dd857ffb2e01b1fe551601384c9682)
@@ -16,4 +16,5 @@
 import java.time.Duration;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -67,4 +68,9 @@
             return "upload";
         }
+        if (dateDue.isBefore(LocalDate.now()))
+        {
+            model.addAttribute("error", true);
+            return "upload";
+        }
 
         DonationPost post = new DonationPost();
@@ -269,5 +275,5 @@
         post.setTotalFundsCollected(post.getTotalFundsCollected() + donatedAmount);
 
-        if(post.getRiskFactor() != 101) {
+        if(post.getRiskFactor() != 101 && post.getRiskFactor() != 102) {
             post.setRiskFactor(getRisk(post));
         }
@@ -317,22 +323,43 @@
 
     private Integer getRisk(DonationPost post) {
-        float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays()+1);
-        float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1);
-
-        System.out.println(dailyAverage + " " + neededAverage);
-        int risk = (int) (dailyAverage / neededAverage * 100);
-
-        if(risk > 100) {
-            risk = 100;
-        }
-
-        if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) {
-            risk = 0;
-        }
-
+        int risk;
         if(post.getFundsNeeded() <= post.getTotalFundsCollected()) {
-            risk = 101;
-        }
-
+            risk = 102;
+        }
+        else
+        {
+            if (LocalDate.now().isAfter(post.getDateDue()))
+            {
+                risk=0;
+            }
+            else
+            {
+                float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays()+1);
+                float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1);
+
+                if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) {
+                    float hour=(float) LocalDateTime.now().getHour();
+                    float mins=(float) LocalDateTime.now().getMinute();
+                    hour=hour+(mins/(float)60);
+                    float hourlyAverage=(dailyAverage/(float)24);
+                    float neededhourlyAverage=(post.getFundsNeeded() - post.getTotalFundsCollected())/((float)24-hour);
+                    risk = (int) (hourlyAverage/neededhourlyAverage*100);
+                    if (risk>100)
+                    {
+                        risk=100;
+                    }
+
+                }
+                else
+                {
+                    System.out.println(dailyAverage + " " + neededAverage);
+                    risk = (int) (dailyAverage / neededAverage * 100);
+
+                    if(risk > 100) {
+                        risk = 100;
+                    }
+                }
+            }
+        }
         return risk;
     }
Index: src/main/java/it/finki/charitable/controller/UserProfileController.java
===================================================================
--- src/main/java/it/finki/charitable/controller/UserProfileController.java	(revision b8dc7612c4ce79e01dfe5fa1fe25e62186eefcdb)
+++ src/main/java/it/finki/charitable/controller/UserProfileController.java	(revision 6fa3d09676dd857ffb2e01b1fe551601384c9682)
@@ -14,4 +14,7 @@
 import org.springframework.web.bind.annotation.RequestParam;
 
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.List;
 
@@ -116,4 +119,5 @@
             post.getFundsCollected().add(funds);
             post.setTotalFundsCollected(post.getTotalFundsCollected() + amount);
+            post.setRiskFactor(getRisk(post));
             donationPostService.save(post);
         }
@@ -130,3 +134,46 @@
         return null;
     }
+    private Integer getRisk(DonationPost post) {
+        int risk;
+        if(post.getFundsNeeded() <= post.getTotalFundsCollected()) {
+            risk = 102;
+        }
+        else
+        {
+            if (LocalDate.now().isAfter(post.getDateDue()))
+            {
+                risk=0;
+            }
+            else
+            {
+                float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays()+1);
+                float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1);
+
+                if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) {
+                    float hour=(float) LocalDateTime.now().getHour();
+                    float mins=(float) LocalDateTime.now().getMinute();
+                    hour=hour+(mins/(float)60);
+                    float hourlyAverage=(dailyAverage/(float)24);
+                    float neededhourlyAverage=(post.getFundsNeeded() - post.getTotalFundsCollected())/((float)24-hour);
+                    risk = (int) (hourlyAverage/neededhourlyAverage*100);
+                    if (risk>100)
+                    {
+                        risk=100;
+                    }
+
+                }
+                else
+                {
+                    System.out.println(dailyAverage + " " + neededAverage);
+                    risk = (int) (dailyAverage / neededAverage * 100);
+
+                    if(risk > 100) {
+                        risk = 100;
+                    }
+                }
+            }
+        }
+        return risk;
+    }
 }
+
Index: src/main/java/it/finki/charitable/util/AutomaticEvents.java
===================================================================
--- src/main/java/it/finki/charitable/util/AutomaticEvents.java	(revision b8dc7612c4ce79e01dfe5fa1fe25e62186eefcdb)
+++ src/main/java/it/finki/charitable/util/AutomaticEvents.java	(revision 6fa3d09676dd857ffb2e01b1fe551601384c9682)
@@ -12,4 +12,5 @@
 import java.time.Duration;
 import java.time.LocalDate;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -60,22 +61,42 @@
 
         donationPosts.forEach(post -> {
-            float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays() + 1);
-            float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1);
+            int risk;
+            if(post.getFundsNeeded() <= post.getTotalFundsCollected()) {
+                risk = 102;
+            }
+            else
+            {
+                if (LocalDate.now().isAfter(post.getDateDue()))
+                {
+                    risk=0;
+                }
+                else
+                {
+                    float dailyAverage = post.getTotalFundsCollected() / (Duration.between(post.getCreatedAt().atTime(0, 0, 0), LocalDate.now().atTime(0, 0, 0)).toDays() + 1);
+                    float neededAverage = (post.getFundsNeeded() - post.getTotalFundsCollected()) / (Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays()+1);
 
-            System.out.println(dailyAverage + " " + neededAverage);
-            int risk = (int) (dailyAverage / neededAverage * 100);
+                    if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) {
+                        float hour=(float) LocalDateTime.now().getHour();
+                        float mins=(float) LocalDateTime.now().getMinute();
+                        hour=hour+(mins/(float)60);
+                        float hourlyAverage=(dailyAverage/(float)24);
+                        float neededhourlyAverage=(post.getFundsNeeded() - post.getTotalFundsCollected())/((float)24-hour);
+                        risk = (int) (hourlyAverage/neededhourlyAverage*100);
+                        if (risk>100)
+                        {
+                            risk=100;
+                        }
+                    }
+                    else
+                    {
+                    System.out.println(dailyAverage + " " + neededAverage);
+                    risk = (int) (dailyAverage / neededAverage * 100);
 
-            if(risk > 100) {
-                risk = 100;
+                    if(risk > 100) {
+                        risk = 100;
+                    }
+                    }
             }
-
-            if(Duration.between(LocalDate.now().atTime(0, 0, 0), post.getDateDue().atTime(0, 0, 0)).toDays() == 0) {
-                risk = 0;
             }
-
-            if(post.getFundsNeeded() <= post.getTotalFundsCollected()) {
-                risk = 101;
-            }
-
             post.setRiskFactor(risk);
             donationPostService.save(post);
