root / GES_PAC / Model / SerieAnimal.cs @ 6f451cc1
Historique | Voir | Annoter | Télécharger (2,434 ko)
1 |
|
---|---|
2 |
using SQLite; |
3 |
using System.ComponentModel.DataAnnotations.Schema; |
4 |
|
5 |
namespace GES_PAC.Model |
6 |
{ |
7 |
public class SerieAnimal |
8 |
{ |
9 |
#region Propriétés |
10 |
[PrimaryKey, AutoIncrement] |
11 |
public int Id { get; set; } |
12 |
public int NumeroBoite { get; set; } |
13 |
public double Poids { get; set; } |
14 |
public DateTime DatePesee { get; set; } |
15 |
public string RFID { get; set; } |
16 |
public List<Mesure> Mesures { get; set; } |
17 |
public List<Comportement> Comportements { get; set; } |
18 |
public int SerieId { get; set; } |
19 |
[ForeignKey("SerieId")] |
20 |
public Serie Serie { get; set; } |
21 |
public bool IsOut { get; set; } = false; |
22 |
#endregion |
23 |
|
24 |
#region Constructeurs |
25 |
public SerieAnimal() { } |
26 |
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 |
#endregion |
36 |
|
37 |
public int GetMeasureCount() |
38 |
{ |
39 |
return Mesures.Count(); |
40 |
} |
41 |
|
42 |
internal void AddMeasure(Mesure newMeasure) |
43 |
{ |
44 |
newMeasure.SerieAnimal = this; |
45 |
Mesures.Add(newMeasure); |
46 |
} |
47 |
|
48 |
public Mesure GetLastMeasure() |
49 |
{ |
50 |
return Mesures.Last(); |
51 |
} |
52 |
public Mesure GetFirstMeasure() |
53 |
{ |
54 |
return Mesures.First(); |
55 |
} |
56 |
|
57 |
public void AddBehaviour(Comportement newBehaviour) |
58 |
{ |
59 |
newBehaviour.SerieAnimal = this; |
60 |
Comportements.Add(newBehaviour); |
61 |
} |
62 |
|
63 |
public bool HasBehaviour() |
64 |
{ |
65 |
return Comportements.Count != 0; |
66 |
} |
67 |
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 |
{ |
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 |
return $"{timeInChamber.Hours:00}:{timeInChamber.Minutes:00}" + (IsTimeWarning() ? "⚠" : ""); |
85 |
} |
86 |
|
87 |
} |
88 |
} |