/
LocalityViewModel.cs
114 lines (96 loc) · 3.09 KB
/
LocalityViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
using GalaSoft.MvvmLight;
using Microsoft.Maps.MapControl.WPF;
namespace Genesis.ViewModel
{
public class LocalityViewModel : ViewModelBase
{
public LocalityViewModel(Locality locality) {
Locality = locality;
}
private Locality locality = null;
public Locality Locality
{
get
{
return locality;
}
protected set
{
Set(() => Locality, ref locality, value);
}
}
public Location Location
{
get
{
if (locality.Location == null)
return null;
return new Location(locality.Location.Latitude.Value, locality.Location.Longitude.Value);
}
}
public string Name
{
get
{
return locality.Name;
}
set
{
locality.Name = value;
RaisePropertyChanged(() => Name);
}
}
public string Code
{
get
{
return locality.Code;
}
set
{
locality.Code = value;
RaisePropertyChanged(() => Code);
}
}
private double? frequency = null;
public double? Frequency
{
get
{
if (frequency == null)
{
Task.Factory.StartNew(() =>
{
using (GenesisContext c = new GenesisContext())
{
var locality = c.Localities.Single(l => l.Id == this.locality.Id);
var alleles = (from mouse in locality.Mice
from allAlleles in mouse.Alleles
where allAlleles.Allele.Gene.Name == "Btk"
group allAlleles by allAlleles.Allele.Value).ToArray();
double d = alleles.Where(a => a.Key == "d").Select(r => r.Count()).SingleOrDefault();
double m = alleles.Where(a => a.Key == "m").Select(r => r.Count()).SingleOrDefault();
if (d + m == 0)
{
return -1;
}
return m / (d + m);
}
}).ContinueWith(f => Frequency = f.Result, TaskScheduler.Current);
}
return frequency;
}
protected set
{
Set(() => Frequency, ref frequency, value);
}
}
}
}