Skip to content

Commit

Permalink
Merge pull request #91 from dianarrmiranda/82-evolucao-fase-vinha
Browse files Browse the repository at this point in the history
82 evolucao fase vinha
  • Loading branch information
jnluis authored Dec 18, 2023
2 parents 507b8ff + 69f0df0 commit b26c99f
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package pt.ua.ies.vineTrack.entity;

import java.sql.Date;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.*;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.time.temporal.WeekFields;
import java.util.*;

Expand Down Expand Up @@ -75,6 +77,60 @@ public void receiveMessage(String message) {

trackService.saveTrack(track);

// evolve the vine
// get the last reset track
List<Track> lastResetTrack = trackService.getLastResetTrackByVineId(vineId);
// if there is no reset track, the start date is the date of the creation of the vine
Date startDate = lastResetTrack.isEmpty() ? vine.getDate() : Date.from(lastResetTrack.get(0).getDate().atZone(ZoneId.systemDefault()).toInstant());
// make it a LocalDate
LocalDate startDateLocalDate = startDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();

System.out.println("startDateLocalDate: " + startDateLocalDate);
System.out.println("d: " + d);
// display how many days have passed since the creation of the vine
System.out.println("Days since the creation of the vine: " + ChronoUnit.DAYS.between(startDateLocalDate, d));

// if the phase is 'bud' and it has been 2 weeks since the creation of the vine, evolve to 'flower'
if (vine.getPhase().equals("bud")) {
// the current date is d
// if the difference between the two dates is 14 days or more, evolve to 'flower'
if (!d.isBefore(startDateLocalDate.plusDays(14))) {
vine.setPhase("flower");
vineService.save(vine);
}
}
// if the phase is 'flower' and it has been 6 weeks since the creation of the vine, evolve to 'fruit'
if (vine.getPhase().equals("flower")) {
// the current date is d
// if the difference between the two dates is 42 days or more, evolve to 'fruit'
if (!d.isBefore(startDateLocalDate.plusDays(56))) { // 14 + 42 = 56
vine.setPhase("fruit");
vineService.save(vine);
}
}
// if the phase is 'fruit' and it has been 2 months since the creation of the vine, evolve to 'ripen'
if (vine.getPhase().equals("fruit")) {
// the current date is d
// if the difference between the two dates is 60 days or more, evolve to 'ripen'
if (!d.isBefore(startDateLocalDate.plusDays(116))) { // 56 + 60 = 116
vine.setPhase("ripen");
vineService.save(vine);
}
}
// if the phase is 'ripen' and it has been 2 months since the creation of the vine, evolve to 'bud'
if (vine.getPhase().equals("ripen")) {
// the current date is d
// if the difference between the two dates is 60 days or more, evolve to 'bud'
if (!d.isBefore(startDateLocalDate.plusDays(176))) { // 116 + 60 = 176
vine.setPhase("bud");
vineService.save(vine);

// create a new track indicating that the vine has been reset
Track resetTrack = new Track("reset", date, 0, vine, t.toString(), d.toString());
trackService.saveTrack(resetTrack);
}
}

// only save the 10 most recent moisture tracks for each vine
trackService.removeOldTracks("moisture", vineId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,7 @@ public interface TrackRepo extends JpaRepository<Track, Integer> {

@Query("SELECT t FROM Track t WHERE t.type = 'waterConsumptionWeek' AND t.vine.id = ?1")
List<Track> getWaterConsumptionWeekTracksByVineId(int vineId);

@Query("SELECT t FROM Track t WHERE t.type = 'reset' AND t.vine.id = ?1 ORDER BY t.date DESC")
List<Track> getLastResetTrackByVineId(int vineId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,8 @@ public List<Track> getTracksByVineId(Integer vineId) {
public List<Track> getWaterConsumptionWeekTracksByVineId(int vineId) {
return trackRepo.getWaterConsumptionWeekTracksByVineId(vineId);
}

public List<Track> getLastResetTrackByVineId(int vineId) {
return trackRepo.getLastResetTrackByVineId(vineId);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion projVineTracker/dataGenerator/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def moisture(self):

elif values[1][-2] - values[0][-2] > 0:
# vai aumentar até cheagar ao valor de humidade ideal
ideal = {'bud': [70, 80], 'flower': [80, 90], 'fruit': [80, 90], 'maturity': [60, 70]}
ideal = {'bud': [70, 80], 'flower': [80, 90], 'fruit': [80, 90], 'ripen': [60, 70]}

idealValues = ideal[phase]

Expand Down

0 comments on commit b26c99f

Please sign in to comment.