Statistiques
| Branche: | Révision:

root / GES_PAC / Model / SerieAnimal.cs @ 3fef487c

Historique | Voir | Annoter | Télécharger (2,616 ko)

1 9601eaf0 lbihannic

2 6f451cc1 lbihannic
using SQLite;
3
using System.ComponentModel.DataAnnotations.Schema;
4 9fd69a0e lbihannic
5 65ad7e66 Lucas Bihannic
namespace GES_PAC.Model
6
{
7
    public class SerieAnimal
8
    {
9 6f451cc1 lbihannic
        #region Propriétés
10
        [PrimaryKey, AutoIncrement]
11
        public int Id { get; set; }
12 65ad7e66 Lucas Bihannic
        public int NumeroBoite { get; set; }
13
        public double Poids { get; set; }
14 ba296a27 lbihannic
        public DateTime DatePesee { get; set; }
15 65ad7e66 Lucas Bihannic
        public string RFID { get; set; }
16
        public List<Mesure> Mesures { get; set; }
17
        public List<Comportement> Comportements { get; set; }
18 6f451cc1 lbihannic
        public int SerieId { get; set; }
19
        [ForeignKey("SerieId")]
20
        public Serie Serie { get; set; }
21 9fd69a0e lbihannic
        public bool IsOut { get; set; } = false;
22 6f451cc1 lbihannic
        #endregion
23 ba296a27 lbihannic
24 6f451cc1 lbihannic
        #region Constructeurs
25
        public SerieAnimal() { }
26 ba296a27 lbihannic
        public SerieAnimal(int numeroBoite, double poids, DateTime datePesee, string rFID)
27
        {
28
            NumeroBoite = numeroBoite;
29
            Poids = poids;
30
            DatePesee = datePesee;
31
            RFID = rFID;
32
            Mesures = [];
33
            Comportements = [];
34
        }
35 6f451cc1 lbihannic
        #endregion
36 fff89fc5 lbihannic
37
        public int GetMeasureCount()
38
        {
39
            return Mesures.Count();
40
        }
41
42
        internal void AddMeasure(Mesure newMeasure)
43
        {
44 6f451cc1 lbihannic
            newMeasure.SerieAnimal = this;
45 fff89fc5 lbihannic
            Mesures.Add(newMeasure);
46
        }
47 1019554c lbihannic
48
        public Mesure GetLastMeasure()
49
        {
50
            return Mesures.Last();
51
        }
52 e837cdf1 lbihannic
        public Mesure GetFirstMeasure()
53
        {
54
            return Mesures.First();
55
        }
56 9fd69a0e lbihannic
57
        public void AddBehaviour(Comportement newBehaviour)
58
        {
59 6f451cc1 lbihannic
            newBehaviour.SerieAnimal = this;
60 9fd69a0e lbihannic
            Comportements.Add(newBehaviour);
61
        }
62
63
        public bool HasBehaviour()
64
        {
65 e837cdf1 lbihannic
            return Comportements.Count != 0;
66
        }
67 9601eaf0 lbihannic
        public bool IsTimeWarning()
68
        {
69
            if (Mesures.Count == 0 || IsOut)
70
                return false;
71
            return (DateTime.Now - GetFirstMeasure().Time) > TimeSpan.FromHours(1);
72
        }
73
        public string GetFormatedTimeInChamber()
74 e837cdf1 lbihannic
        {
75
            if (Mesures.Count == 0)
76
                return "";
77
78
            TimeSpan timeInChamber;
79
            if (IsOut)
80
                timeInChamber = GetLastMeasure().Time - GetFirstMeasure().Time;
81
            else
82
                timeInChamber = DateTime.Now - GetFirstMeasure().Time;
83
84 9601eaf0 lbihannic
            return $"{timeInChamber.Hours:00}:{timeInChamber.Minutes:00}" + (IsTimeWarning() ? "⚠" : "");
85 9fd69a0e lbihannic
        }
86 3fef487c lbihannic
        public int GetMinInChamber()
87
        {
88
            if (Mesures.Count == 0)
89
                return 0;
90
            return (DateTime.Now - GetFirstMeasure().Time).Minutes;
91
        }
92 9601eaf0 lbihannic
        
93 65ad7e66 Lucas Bihannic
    }
94
}