Révision 3fef487c
GES_PAC/App.xaml.cs | ||
---|---|---|
10 | 10 |
public App() |
11 | 11 |
{ |
12 | 12 |
InitializeComponent(); |
13 |
|
|
14 |
//var dbPath = Path.Combine(FileSystem.AppDataDirectory, "GES_PAC.db3"); |
|
15 |
//if (File.Exists(dbPath)) |
|
16 |
// File.Delete(dbPath); |
|
17 |
|
|
18 |
|
|
19 | 13 |
Db = new AppDbContext(); |
20 | 14 |
Db.Database.EnsureCreated(); |
21 | 15 |
|
22 | 16 |
_ = InitSmartEnumsAsync(); |
23 |
//_ = InitDb(); |
|
24 | 17 |
} |
25 | 18 |
|
26 | 19 |
protected override Window CreateWindow(IActivationState? activationState) |
... | ... | |
47 | 40 |
if (!await Db.TypeComportement.AnyAsync(c => c.Value == comportement.Value)) |
48 | 41 |
Db.TypeComportement.Add(comportement); |
49 | 42 |
} |
50 |
|
|
51 |
await Db.SaveChangesAsync(); |
|
52 |
} |
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
private async Task InitDb() |
|
57 |
{ |
|
58 |
//ONLY FOR TESTS |
|
59 |
var place = new Lieu("Elevage Langlade", "INRAE", "Mouton"); |
|
60 |
var person = new Personne("Bond", "James", "jamesbond@inrae.fr"); |
|
61 |
await Db.Personne.AddAsync(person); |
|
62 |
await Db.Lieu.AddAsync(place); |
|
63 | 43 |
await Db.SaveChangesAsync(); |
64 |
//ONLY FOR TESTS |
|
65 | 44 |
} |
66 | 45 |
} |
67 | 46 |
} |
GES_PAC/Controls/DoubleEntry.cs | ||
---|---|---|
4 | 4 |
{ |
5 | 5 |
public class DoubleEntry : Entry |
6 | 6 |
{ |
7 |
public static readonly BindableProperty DoubleValueProperty = |
|
8 |
BindableProperty.Create( |
|
9 |
nameof(DoubleValue), |
|
10 |
typeof(double?), |
|
11 |
typeof(DoubleEntry), |
|
12 |
default(double?), |
|
13 |
BindingMode.TwoWay, |
|
14 |
propertyChanged: OnDoubleValueChanged); |
|
15 |
|
|
16 |
public double? DoubleValue |
|
17 |
{ |
|
18 |
get => (double?)GetValue(DoubleValueProperty); |
|
19 |
set => SetValue(DoubleValueProperty, value); |
|
20 |
} |
|
21 |
|
|
7 | 22 |
public DoubleEntry() |
8 | 23 |
{ |
9 | 24 |
Keyboard = Keyboard.Numeric; |
... | ... | |
11 | 26 |
TextColor = Colors.Black; |
12 | 27 |
Placeholder = "0,0"; |
13 | 28 |
FontSize = 16; |
29 |
|
|
30 |
TextChanged += OnTextChanged; |
|
31 |
} |
|
32 |
|
|
33 |
private static void OnDoubleValueChanged(BindableObject bindable, object oldValue, object newValue) |
|
34 |
{ |
|
35 |
if (bindable is DoubleEntry entry && newValue is double val) |
|
36 |
{ |
|
37 |
var str = val.ToString(CultureInfo.CurrentCulture); |
|
38 |
if (entry.Text != str) |
|
39 |
entry.Text = str; |
|
40 |
} |
|
41 |
} |
|
42 |
|
|
43 |
private void OnTextChanged(object sender, TextChangedEventArgs e) |
|
44 |
{ |
|
45 |
var input = e.NewTextValue; |
|
46 |
|
|
47 |
if (string.IsNullOrWhiteSpace(input)) |
|
48 |
return; |
|
49 |
|
|
50 |
if (input.StartsWith(",")) |
|
51 |
{ |
|
52 |
MainThread.BeginInvokeOnMainThread(() => |
|
53 |
{ |
|
54 |
TextChanged -= OnTextChanged; |
|
55 |
Text = "0" + input; |
|
56 |
TextChanged += OnTextChanged; |
|
57 |
}); |
|
58 |
return; |
|
59 |
} |
|
60 |
if (double.TryParse(input, NumberStyles.Float, CultureInfo.CurrentCulture, out double value)) |
|
61 |
{ |
|
62 |
SetValue(DoubleValueProperty, value); |
|
63 |
} |
|
64 |
else |
|
65 |
{ |
|
66 |
SetValue(DoubleValueProperty, null); |
|
67 |
} |
|
14 | 68 |
} |
15 | 69 |
} |
16 | 70 |
} |
GES_PAC/Model/SerieAnimal.cs | ||
---|---|---|
83 | 83 |
|
84 | 84 |
return $"{timeInChamber.Hours:00}:{timeInChamber.Minutes:00}" + (IsTimeWarning() ? "⚠" : ""); |
85 | 85 |
} |
86 |
public int GetMinInChamber() |
|
87 |
{ |
|
88 |
if (Mesures.Count == 0) |
|
89 |
return 0; |
|
90 |
return (DateTime.Now - GetFirstMeasure().Time).Minutes; |
|
91 |
} |
|
86 | 92 |
|
87 | 93 |
} |
88 | 94 |
} |
GES_PAC/View/CreateMeasureView.xaml | ||
---|---|---|
55 | 55 |
<VerticalStackLayout> |
56 | 56 |
<Label Text="CH4 (ppm)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/> |
57 | 57 |
<Grid ColumnDefinitions="*,Auto" ColumnSpacing="5"> |
58 |
<controls:DoubleEntry Grid.Column="0" Text="{Binding ConcCH4, Mode=OneWayToSource, TargetNullValue=''}"/>
|
|
58 |
<controls:DoubleEntry DoubleValue="{Binding ConcCH4}"/>
|
|
59 | 59 |
<Label Grid.Column="1" |
60 | 60 |
Text="{Binding LastCH4, StringFormat='[{0} ppm]'}" |
61 | 61 |
FontSize="16" |
... | ... | |
76 | 76 |
<VerticalStackLayout> |
77 | 77 |
<Label Text="O2 (%)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/> |
78 | 78 |
<Grid ColumnDefinitions="*,Auto" ColumnSpacing="5"> |
79 |
<controls:DoubleEntry Grid.Column="0" Text="{Binding ConcO2, Mode=OneWayToSource, TargetNullValue=''}"/>
|
|
79 |
<controls:DoubleEntry DoubleValue="{Binding ConcO2}"/>
|
|
80 | 80 |
<Label Grid.Column="1" |
81 | 81 |
Text="{Binding LastO2, StringFormat='[{0} %]'}" |
82 | 82 |
FontSize="16" |
... | ... | |
97 | 97 |
<VerticalStackLayout> |
98 | 98 |
<Label Text="CO2 (%)" FontSize="14" TextColor="Gray" FontAttributes="Bold"/> |
99 | 99 |
<Grid ColumnDefinitions="*,Auto" ColumnSpacing="5"> |
100 |
<controls:DoubleEntry Grid.Column="0" Text="{Binding ConcCO2, Mode=OneWayToSource, TargetNullValue=''}"/>
|
|
100 |
<controls:DoubleEntry DoubleValue="{Binding ConcCO2}" />
|
|
101 | 101 |
<Label Grid.Column="1" |
102 | 102 |
Text="{Binding LastCO2, StringFormat='[{0} %]'}" |
103 | 103 |
FontSize="16" |
GES_PAC/View/ExportDataView.xaml | ||
---|---|---|
13 | 13 |
<ScrollView> |
14 | 14 |
<StackLayout Spacing="100"> |
15 | 15 |
|
16 |
<Label Text="Exporter les données" |
|
17 |
FontSize="22" |
|
18 |
FontAttributes="Bold" |
|
19 |
HorizontalOptions="Center"/> |
|
16 |
<Grid ColumnDefinitions="*,Auto,*" Padding="10"> |
|
20 | 17 |
|
21 |
<Label Text="{Binding DataFoundText}" |
|
18 |
<Label Text="Exporter" |
|
19 |
FontSize="22" |
|
20 |
Grid.Column="1" |
|
21 |
FontAttributes="Bold" |
|
22 |
HorizontalOptions="Center" |
|
23 |
VerticalOptions="Center"/> |
|
24 |
|
|
25 |
<Button Text="Vider DB" |
|
26 |
Command="{Binding ClearDataCommand}" |
|
27 |
Grid.Column="2" |
|
28 |
HorizontalOptions="End" |
|
29 |
VerticalOptions="Center" /> |
|
30 |
|
|
31 |
</Grid> |
|
32 |
|
|
33 |
<Label Text="{Binding DataFoundText}" |
|
22 | 34 |
FontSize="18" |
23 | 35 |
HorizontalOptions="Center"/> |
24 | 36 |
|
GES_PAC/ViewModel/Controls/ChamberButtonViewModel.cs | ||
---|---|---|
1 | 1 |
using GES_PAC.Model; |
2 | 2 |
using GES_PAC.View; |
3 |
using System.ComponentModel.Design; |
|
3 | 4 |
using System.Windows.Input; |
4 | 5 |
|
5 | 6 |
namespace GES_PAC.ViewModel.Controls |
... | ... | |
139 | 140 |
ButtonIsEnabled = true; |
140 | 141 |
ButtonLabel = "0"; |
141 | 142 |
TimeIn = ""; |
143 |
TimeColor = Colors.Black; |
|
142 | 144 |
} |
143 | 145 |
public void UpdateProperties() |
144 | 146 |
{ |
... | ... | |
164 | 166 |
_isSubscribed = false; |
165 | 167 |
} |
166 | 168 |
|
169 |
UpdateTimerColor(); |
|
167 | 170 |
ButtonIsEnabled = !AnimalSet.IsOut; |
168 | 171 |
ButtonBackgroundColor = AnimalSet.HasBehaviour() ? Colors.Yellow : Colors.LightGreen; |
169 | 172 |
ButtonLabel = measureCount.ToString(); |
170 | 173 |
TimeIn = AnimalSet.GetFormatedTimeInChamber(); |
171 |
TimeColor = AnimalSet.IsTimeWarning() ? Colors.Red : Colors.Black; |
|
172 | 174 |
} |
173 | 175 |
|
174 | 176 |
|
... | ... | |
186 | 188 |
public void OnTimerTick(object? sender, EventArgs e) |
187 | 189 |
{ |
188 | 190 |
TimeIn = AnimalSet?.GetFormatedTimeInChamber() ?? ""; |
189 |
TimeColor = AnimalSet?.IsTimeWarning() ?? false ? Colors.Red : Colors.Black; |
|
191 |
UpdateTimerColor(); |
|
192 |
} |
|
193 |
public void UpdateTimerColor() |
|
194 |
{ |
|
195 |
var nbMesure = AnimalSet?.GetMeasureCount() ?? 0; |
|
196 |
var min = AnimalSet?.GetMinInChamber() ?? 0; |
|
197 |
|
|
198 |
if (nbMesure == 1 && min >= 25 || |
|
199 |
nbMesure == 2 && (min >= 50 || (AnimalSet.GetLastMeasure().Conc_CO2 > 2 && min >= 40)) || |
|
200 |
AnimalSet?.IsTimeWarning() == true) |
|
201 |
TimeColor = Colors.Red; |
|
190 | 202 |
} |
191 | 203 |
|
192 | 204 |
#endregion |
GES_PAC/ViewModel/CreateMeasureViewModel.cs | ||
---|---|---|
241 | 241 |
LastTime = "Dernière mesure : " + (int)(DateTime.Now - LastMeasure.Time).TotalMinutes + " min"; |
242 | 242 |
UpdateColors(); |
243 | 243 |
} |
244 |
else |
|
245 |
{ |
|
246 |
ConcCH4 = 0.0; |
|
247 |
ConcO2 = 20.9; |
|
248 |
ConcCO2 = 0.0; |
|
249 |
} |
|
244 | 250 |
} |
245 | 251 |
private void UpdateColors() |
246 | 252 |
{ |
GES_PAC/ViewModel/CreateSetViewModel.cs | ||
---|---|---|
30 | 30 |
get => _dateTimeMAJ.TimeOfDay; |
31 | 31 |
set |
32 | 32 |
{ |
33 |
_dateTimeMAJ = _dateTimeMAJ.Date + value; |
|
33 |
var today = DateTime.Today; |
|
34 |
var now = DateTime.Now; |
|
35 |
var proposedTime = today + value; |
|
36 |
|
|
37 |
if (proposedTime > now.AddHours(6)) |
|
38 |
_dateTimeMAJ = today.AddDays(-1) + value; |
|
39 |
else |
|
40 |
_dateTimeMAJ = today + value; |
|
41 |
|
|
34 | 42 |
OnPropertyChanged(); |
35 | 43 |
ValidateForm(); |
36 | 44 |
} |
37 | 45 |
} |
38 | 46 |
|
47 |
|
|
39 | 48 |
public double? Temperature |
40 | 49 |
{ |
41 | 50 |
get => _temperature; |
GES_PAC/ViewModel/ExportDataViewModel.cs | ||
---|---|---|
40 | 40 |
#region Commandes |
41 | 41 |
public ICommand ExportJSONCommand { get; } |
42 | 42 |
public ICommand ExportCSVCommand { get; } |
43 |
public ICommand ClearDataCommand { get; } |
|
43 | 44 |
#endregion |
44 | 45 |
|
45 | 46 |
#region Constructeur |
... | ... | |
47 | 48 |
{ |
48 | 49 |
ExportJSONCommand = new Command(ExportJSON); |
49 | 50 |
ExportCSVCommand = new Command(ExportCSV); |
51 |
ClearDataCommand = new Command(ClearData); |
|
50 | 52 |
|
51 | 53 |
DayList = JourneeViewModel.Instance?.Journees ?? null; |
52 | 54 |
HasData = DayList != null && DayList.Count > 0; |
... | ... | |
86 | 88 |
#endif |
87 | 89 |
} |
88 | 90 |
|
91 |
private async void ClearData() |
|
92 |
{ |
|
93 |
if (IsBusy) return; |
|
94 |
IsBusy = true; |
|
95 |
App.Db.MesureCalibration.RemoveRange(App.Db.MesureCalibration); |
|
96 |
App.Db.Calibration.RemoveRange(App.Db.Calibration); |
|
97 |
App.Db.Mesure.RemoveRange(App.Db.Mesure); |
|
98 |
App.Db.Comportement.RemoveRange(App.Db.Comportement); |
|
99 |
App.Db.SerieAnimal.RemoveRange(App.Db.SerieAnimal); |
|
100 |
App.Db.Serie.RemoveRange(App.Db.Serie); |
|
101 |
App.Db.Journee.RemoveRange(App.Db.Journee); |
|
102 |
App.Db.Personne.RemoveRange(App.Db.Personne); |
|
103 |
App.Db.Lieu.RemoveRange(App.Db.Lieu); |
|
104 |
|
|
105 |
var place = new Lieu("Elevage Langlade", "INRAE", "Mouton"); |
|
106 |
var person = new Personne("Bond", "James", "jamesbond@inrae.fr"); |
|
107 |
App.Db.Personne.Add(person); |
|
108 |
App.Db.Lieu.Add(place); |
|
109 |
|
|
110 |
await App.Db.SaveChangesAsync(); |
|
111 |
IsBusy = false; |
|
112 |
} |
|
113 |
|
|
89 | 114 |
#endregion |
90 | 115 |
} |
91 | 116 |
} |
GES_PAC/ViewModel/JourneeViewModel.cs | ||
---|---|---|
25 | 25 |
public async Task InitAsync() |
26 | 26 |
{ |
27 | 27 |
var journees = await App.Db.Journee |
28 |
.Include(j => j.Responsable) |
|
29 |
.Include(j => j.Lieu) |
|
28 | 30 |
.Include(j => j.Calibrations) |
29 | 31 |
.ThenInclude(c => c.Mesures) |
30 | 32 |
.ThenInclude(m => m.Type) |
... | ... | |
38 | 40 |
.ThenInclude(sa => sa.Comportements) |
39 | 41 |
.ToListAsync(); |
40 | 42 |
|
41 |
|
|
42 | 43 |
foreach (var j in journees) |
43 | 44 |
{ |
44 | 45 |
foreach (var c in j.Calibrations) |
Formats disponibles : Unified diff