root / GES_PAC / Model / Serie.cs @ 3fef487c
Historique | Voir | Annoter | Télécharger (3,721 ko)
1 | 6f451cc1 | lbihannic | using SQLite; |
---|---|---|---|
2 | using System.ComponentModel.DataAnnotations.Schema; |
||
3 | 9fd69a0e | lbihannic | |
4 | 65ad7e66 | Lucas Bihannic | namespace GES_PAC.Model |
5 | { |
||
6 | public class Serie |
||
7 | { |
||
8 | ba296a27 | lbihannic | #region Propriétés |
9 | 6f451cc1 | lbihannic | [PrimaryKey, AutoIncrement] |
10 | public int Id { get; set; } |
||
11 | public int JourneeId { get; set; } |
||
12 | [ForeignKey("JourneeId")] |
||
13 | public Journee Journee { get; set; } |
||
14 | 65ad7e66 | Lucas Bihannic | public DateTime Time { get; set; } |
15 | public DateTime MiseAJeun { get; set; } |
||
16 | public double Temperature { get; set; } |
||
17 | public double Humidite { get; set; } |
||
18 | public double Pression { get; set; } |
||
19 | 1019554c | lbihannic | public List<SerieAnimal> SeriesAnimales { get; set; } = []; |
20 | ba296a27 | lbihannic | #endregion |
21 | 09d4a0de | lbihannic | |
22 | ba296a27 | lbihannic | #region Constructeurs |
23 | 6f451cc1 | lbihannic | public Serie() { } |
24 | 09d4a0de | lbihannic | public Serie(DateTime Time, DateTime MiseAJeun, double Temperature, double Humidite, double Pression) |
25 | { |
||
26 | this.Time = Time; |
||
27 | this.MiseAJeun = MiseAJeun; |
||
28 | this.Temperature = Temperature; |
||
29 | this.Humidite = Humidite; |
||
30 | this.Pression = Pression; |
||
31 | SeriesAnimales = []; |
||
32 | } |
||
33 | ba296a27 | lbihannic | #endregion |
34 | |||
35 | #region Méthodes |
||
36 | public void AddSerieAnimal(SerieAnimal serieAnimal) |
||
37 | { |
||
38 | 6f451cc1 | lbihannic | serieAnimal.Serie = this; |
39 | 1019554c | lbihannic | var existing = SeriesAnimales.FirstOrDefault(s => s.NumeroBoite == serieAnimal.NumeroBoite); |
40 | if (existing != null) |
||
41 | SeriesAnimales.Remove(existing); |
||
42 | ba296a27 | lbihannic | SeriesAnimales.Add(serieAnimal); |
43 | } |
||
44 | fff89fc5 | lbihannic | |
45 | 9fd69a0e | lbihannic | public int GetMeasureNumberByNumeroBoite(int nb) |
46 | { |
||
47 | var sa = SeriesAnimales.FirstOrDefault(sa => sa.NumeroBoite == nb); |
||
48 | if (sa == null) |
||
49 | return 0; |
||
50 | return sa.GetMeasureCount(); |
||
51 | } |
||
52 | |||
53 | public bool GetHasBehaviourByNumeroBoite(int nb) |
||
54 | { |
||
55 | var sa = SeriesAnimales.FirstOrDefault(sa => sa.NumeroBoite == nb); |
||
56 | if (sa == null) |
||
57 | return false; |
||
58 | return sa.HasBehaviour(); |
||
59 | } |
||
60 | 12ddf7ef | lbihannic | public bool GetIsInByNumeroBoite(int numeroBoite) |
61 | fff89fc5 | lbihannic | { |
62 | 12ddf7ef | lbihannic | var serieAnimal = SeriesAnimales.FirstOrDefault(sa => sa.NumeroBoite == numeroBoite); |
63 | if (serieAnimal == null || !serieAnimal.Mesures.Any()) |
||
64 | return true; |
||
65 | return !serieAnimal?.IsOut ?? true; |
||
66 | fff89fc5 | lbihannic | } |
67 | |||
68 | 1019554c | lbihannic | public Mesure? GetLastMeasureByNumeroBoite(int numeroBoite) |
69 | { |
||
70 | var serieAnimal = SeriesAnimales.FirstOrDefault(sa => sa.NumeroBoite == numeroBoite); |
||
71 | if (serieAnimal == null || !serieAnimal.Mesures.Any()) |
||
72 | return null; |
||
73 | return serieAnimal.GetLastMeasure(); |
||
74 | } |
||
75 | |||
76 | 12ddf7ef | lbihannic | internal void AddMeasure(Mesure newMeasure, int numBoite, bool isAnimalOut) |
77 | fff89fc5 | lbihannic | { |
78 | 12ddf7ef | lbihannic | var sa = SeriesAnimales.Select(sa => sa).Where(sa => sa.NumeroBoite == numBoite).First(); |
79 | sa.AddMeasure(newMeasure); |
||
80 | if (isAnimalOut) |
||
81 | sa.IsOut = true; |
||
82 | fff89fc5 | lbihannic | } |
83 | 9fd69a0e | lbihannic | |
84 | internal void AddBehaviour(Comportement newBehaviour, int numBoite, bool isAnimalOut) |
||
85 | { |
||
86 | var sa = SeriesAnimales.Select(sa => sa).Where(sa => sa.NumeroBoite == numBoite).First(); |
||
87 | sa.AddBehaviour(newBehaviour); |
||
88 | if (isAnimalOut) |
||
89 | sa.IsOut = true; |
||
90 | } |
||
91 | 4e39035b | lbihannic | |
92 | public int GetAnimalCount() |
||
93 | { |
||
94 | return SeriesAnimales.Count(); |
||
95 | } |
||
96 | public int GetMeasureCount() |
||
97 | { |
||
98 | return SeriesAnimales.Sum(sa => sa.GetMeasureCount()); |
||
99 | } |
||
100 | public int GetBehaviourCount() |
||
101 | { |
||
102 | return SeriesAnimales.Sum(sa => sa.Comportements.Count()); |
||
103 | } |
||
104 | e837cdf1 | lbihannic | public SerieAnimal? GetSerieAnimalByNumBoite(int numBoite) |
105 | { |
||
106 | return SeriesAnimales.FirstOrDefault(sa => sa.NumeroBoite == numBoite); |
||
107 | } |
||
108 | ba296a27 | lbihannic | #endregion |
109 | 65ad7e66 | Lucas Bihannic | } |
110 | } |