public IList <Cluster> GetList(Int32 allCount, ClusterFilter filter) { var usersData = new List <UserDto>(); var clustersData = new List <ClusterDto>(); Task.WaitAll(Task.Run(() => { usersData = Reliable(() => ReadUsers(allCount)); }), Task.Run(() => { if (filter.WithProperties) { clustersData = Reliable(() => ReadClusters(allCount)); } })); var grouppedByMac = usersData.GroupBy(d => d.Mac).ToDictionary(d => d.Key, d => (Double)d.Sum(u => u.XCount)); var weigtData = usersData.GroupBy(d => new { d.Mac, d.ClusterId }) .Select(d => new { d.Key.Mac, d.Key.ClusterId, Freq = d.Sum(f => f.XCount) / grouppedByMac[d.Key.Mac] }); if (filter.Id.HasValue) { weigtData = weigtData.Where(d => d.ClusterId + 1 == filter.Id.Value); } return(weigtData.GroupBy(d => d.ClusterId).Select(g => { var cluster = new Cluster { Id = g.Key + 1 }; cluster.Name = Convert.ToString(cluster.Id); if (filter.WithSize) { cluster.SizeHistory = new[] { new Tuple <TimeSpan, Double>(TimeSpan.Zero, g.Sum(gg => gg.Freq)) } } ; if (filter.WithUsers) { cluster.UsersInfo = g.OrderByDescending(gg => gg.Freq) .Select(gg => new Tuple <User, Double>(new User { MacAddress = gg.Mac }, gg.Freq)).ToList(); } if (filter.WithProperties) { cluster.Properties = clustersData.Where(c => c.ClusterId == cluster.Id).Select(c => new Property { Type = ClusterDto.types[c.ColumnId], Mean = c.Value }).ToList(); } return cluster; }).ToList()); }
public IList <Cluster> GetList(ClusterFilter filter) { var query = Session.QueryOver <ClusterDto>(); if (filter.Id.HasValue) { query = query.Where(c => c.Id == filter.Id.Value); } if (filter.WithSize) { Session.QueryOver <ClusterDto>() .Fetch(dto => dto.Sizes) .Eager.Fetch(dto => dto.Sizes[0].Learning) .Eager.Future(); } var clusters = query.Future().ToList(); if (filter.WithUsers) { foreach (var cluster in clusters) { var clusterId = cluster.Id; cluster.Users = Session.QueryOver <UserProfileDto>() .Fetch(p => p.User).Eager .Where(p => p.Cluster.Id == clusterId) .OrderBy(p => p.Probability) .Desc.Take(20).List(); } } if (filter.WithProperties) { foreach (var cluster in clusters) { var clusterId = cluster.Id; cluster.RProfile = Session.QueryOver <ClusterRProfileDto>().Where(p => p.Cluster.Id == clusterId).List(); cluster.NProfile = Session.QueryOver <ClusterNProfileDto>().Where(p => p.Cluster.Id == clusterId).List(); } } return(clusters.Select(dto => (Cluster)dto).ToList()); }
public IList <Cluster> GetList(Int32 allCount, ClusterFilter filter) { var clusters = new[] { new Cluster { Id = 1, Name = "Hive 1", SizeHistory = new[] { new Tuple <TimeSpan, double>(TimeSpan.Zero, 1) }, UsersInfo = new Collection <Tuple <User, double> > { new Tuple <User, double>(new User { MacAddress = "11" }, 0.9) }, Properties = new Collection <Property>() }, new Cluster { Id = 2, Name = "Hive 2", SizeHistory = new[] { new Tuple <TimeSpan, double>(TimeSpan.Zero, 2) }, UsersInfo = new Collection <Tuple <User, double> > { new Tuple <User, double>(new User { MacAddress = "13" }, 0.6), new Tuple <User, double>(new User { MacAddress = "16" }, 0.8), }, Properties = new Collection <Property>() } }.ToList(); if (filter.Id.HasValue) { clusters = clusters.Where(c => c.Id == filter.Id.Value).ToList(); } return(clusters); }