public void Update(ClusterTable ct) { MyLib.Task.Utility.UITask(() => { var orignalCategory = ct.Categories.GetEnumerator(); foreach (var item in this.Categories) { orignalCategory.MoveNext(); if (orignalCategory.Current != null) { foreach (var item2 in orignalCategory.Current.Layer) { item2.Value.Comunities.Clear(); foreach (ComunityEx item3 in item.GetLayer(item2.Key).Comunities) { item3.OrignalComunity.IsHub = item3.IsHub; item2.Value.Comunities.Add(item3.OrignalComunity); } } } } }); }
public void CreateRandom(ClusterTable ct, int seed) { Dictionary<Category, Category> cDic = new Dictionary<Category, Category>(); foreach (var item in ct.Categories) { var c = new Category() { KeyName = item.KeyName, Name = item.Name }; Categories.Add(c); cDic.Add(item, c); item.Update(); } random = new Random(seed); foreach (var item in ct.LayerGroup) { List<Models.Comunity> comunityList = new List<Models.Comunity>(); List<Models.Layer> layerList = new List<Models.Layer>(); foreach (var layer in item.Items) { comunityList.AddRange(layer.Comunities); // layer.Comunities.Clear(); } foreach (var item2 in Categories) { var l = item2.GetLayer(item.Name); layerList.Add(l); } int c = 0; foreach (var comunity in comunityList.OrderBy(n => random.NextDouble())) { var cc = new ComunityEx(comunity); if (cc.Lock) { cDic[cc.OrignalComunity.Category].GetLayer(item.Name).Comunities.Add(cc); } else { layerList[c % layerList.Count].Comunities.Add(cc); c++; } comunityList.Add(cc); ComunityDic.Add(comunity.Id, cc); ComunityList.Add(cc); } LayerGroup.Add(item.Name, new LayerGroup() { Name = item.Name, Items = new System.Collections.ObjectModel.ObservableCollection<Layer>(layerList) }); } }
public static void CreateLayerGroup(ClusterTable clusterTable) { clusterTable.LayerGroup = new List<LayerGroup>(); List<string> layerNameList = new List<string>(); foreach (var item in clusterTable.Categories) { foreach (var item2 in item.Layer) { layerNameList.Add(item2.Value.Name); } } layerNameList = layerNameList.Where(n => n != null).Distinct().OrderBy(n => n).ToList(); foreach (var item in layerNameList) { var lg = new LayerGroup() { Name = item, Items = new System.Collections.ObjectModel.ObservableCollection<Layer>() }; clusterTable.LayerGroup.Add(lg); foreach (var item2 in clusterTable.Categories) { if (item2.Layer.ContainsKey(item) == false) { item2.Layer.Add(item, new Layer()); } lg.Items.Add(item2.Layer[item]); } } }
public static ClusterTable Create(System.IO.StreamReader sr, out IEnumerable<string> errList) { Dictionary<string, Category> categoryDic = new Dictionary<string, Category>(); Dictionary<string, List<Layer>> layerListDic = new Dictionary<string, List<Layer>>(); List<Comunity> comunityList = new List<Comunity>(); foreach (var item in TSVFile.ReadLines(sr, out errList)) { Comunity comunity = new Comunity() { Id = item.GetIntValue("Community_Id"), // Count = item.GetIntValue("User_Idのカウント", 0), ImageUrl = item.GetValue("Image_Url", string.Empty), // Index = item.GetDoubleValue("Index"), Name = item.GetValue("Community_Name") }; string categoryStr = item.GetValue("帰属系"); string layer = item.GetValue("レイヤー"); Category category = null; if (categoryDic.ContainsKey(categoryStr)) { category = categoryDic[categoryStr]; } else { categoryDic.Add(categoryStr, new Category() { KeyName = categoryStr, Name = item.GetValue("系名", string.Empty) }); category = categoryDic[categoryStr]; category.CategoryAttributeList = new List<CategoryAttribute>(); foreach (var item2 in item.GetValue("系指標", string.Empty).Split(',')) { var array = item2.Split(':'); if (array.Length == 1) { category.CategoryAttributeList.Add(new CategoryAttribute() { Name = string.Empty, Value = array[0] }); } else { category.CategoryAttributeList.Add(new CategoryAttribute() { Name = array[0], Value = array[1] }); } } } if (category.Layer.ContainsKey(layer)) { category.Layer[layer].Comunities.Add(comunity); } else { category.Layer.Add(layer, new Layer() { Name = layer, Category = category }); category.Layer[layer].Comunities.Add(comunity); } } var clusterTable = new ClusterTable(); clusterTable.Categories = new System.Collections.ObjectModel.ObservableCollection<Category>(); clusterTable.LayerGroup = new List<LayerGroup>(); clusterTable.CategoryAttributeGroup = new System.Collections.ObjectModel.ObservableCollection<CategoryAttributeGroup>(); List<string> layerNameList = new List<string>(); List<string> categoryAttributeNameList = new List<string>(); foreach (var item in categoryDic) { foreach (var item2 in item.Value.Layer) { layerNameList.Add(item2.Value.Name); } foreach (var item2 in item.Value.CategoryAttributeList) { categoryAttributeNameList.Add(item2.Name); } } layerNameList = layerNameList.Distinct().OrderBy(n => n).ToList(); categoryAttributeNameList = categoryAttributeNameList.Distinct().ToList(); Dictionary<string, CategoryAttributeGroup> categoryAttributeGroupDic = new Dictionary<string, CategoryAttributeGroup>(); foreach (var item in categoryDic) { clusterTable.Categories.Add(item.Value); foreach (var item2 in layerNameList) { if (layerListDic.ContainsKey(item2)) { layerListDic[item2].Add(item.Value.GetLayer(item2)); } else { layerListDic.Add(item2, new List<Layer>() { item.Value.GetLayer(item2) }); } } foreach (var item2 in categoryAttributeNameList) { var attribute = item.Value.CategoryAttributeList.Where(n => n.Name == item2).FirstOrDefault(); if (attribute != null) { if (categoryAttributeGroupDic.ContainsKey(item2)) { categoryAttributeGroupDic[item2].Items.Add(attribute); } else { categoryAttributeGroupDic.Add(item2, new CategoryAttributeGroup() { Name = item2, Items = new System.Collections.ObjectModel.ObservableCollection<CategoryAttribute>() }); categoryAttributeGroupDic[item2].Items.Add(attribute); } } else { attribute = new CategoryAttribute(); if (categoryAttributeGroupDic.ContainsKey(item2)) { categoryAttributeGroupDic[item2].Items.Add(attribute); } else { categoryAttributeGroupDic.Add(item2, new CategoryAttributeGroup() { Name = item2, Items = new System.Collections.ObjectModel.ObservableCollection<CategoryAttribute>() }); categoryAttributeGroupDic[item2].Items.Add(attribute); } } } } foreach (var item2 in categoryAttributeGroupDic.Values) { clusterTable.CategoryAttributeGroup.Add(item2); } CreateLayerGroup(clusterTable); //foreach (var item in layerNameList) //{ // var lg = new LayerGroup() { Name = item, Items = new System.Collections.ObjectModel.ObservableCollection<Layer>() }; // clusterTable.LayerGroup.Add(lg); // foreach (var item2 in categoryDic.Values) // { // if (item2.Layer.ContainsKey(item)==false) // { // item2.Layer.Add(item, new Layer()); // } // lg.Items.Add(item2.Layer[item]); // } //} comunityList.Clear(); foreach (var item in layerListDic.Values) { foreach (var item2 in item) { comunityList.AddRange(item2.Comunities); } } clusterTable.CreateRelation(); return clusterTable; }
public static ClusterTable CreateDataForTransaction(System.IO.StreamReader sr, int clusterNum, Dictionary<string, List<string>> layerDicData, string[] containItems,Dictionary<string,string> nayoseDic, out IEnumerable<string> errList) { var clusterTable = new ClusterTable(); clusterTable.Categories = new System.Collections.ObjectModel.ObservableCollection<Category>(); clusterTable.LayerGroup = new List<LayerGroup>(); clusterTable.CategoryAttributeGroup = new System.Collections.ObjectModel.ObservableCollection<CategoryAttributeGroup>(); ///レイヤー構造の作成 for (int i = 0; i < clusterNum; i++) { clusterTable.Categories.Add(new Category() { KeyName = "C_" + i }); } Random random = new Random(); Dictionary<string, Comunity> comnutyDic = new Dictionary<string, Comunity>(); int item_id = 0; foreach (var layer in layerDicData) { foreach (var item in layer.Value) { Comunity comunity = new Comunity() { Id = item_id, Name = item.Split(',').First() }; comunity.GetImageData(); if (comnutyDic.ContainsKey(item) == false) { comnutyDic.Add(item, comunity); } foreach (var item2 in nayoseDic.Where(n=>n.Value == item).Select(n=>n.Key)) { if(comnutyDic.ContainsKey(item2)==false) { comnutyDic.Add(item2, comunity); } } var r = random.Next(clusterNum); clusterTable.Categories[r].GetLayer(layer.Key).Comunities.Add(comunity); item_id++; } } CreateLayerGroup(clusterTable); //関係データの挿入 clusterTable.CreateComunityDic(); foreach (var item in clusterTable.comunityDic.Values) { item.UserIds = new List<int>(); item.Relations.Clear(); } List<string> list = new List<string>(); List<int> idList = new List<int>(); string tmp_id = string.Empty; int u_id = 0; int u_count = 0; List<string> itemList = new List<string>(); HashSet<string> hash = new HashSet<string>(containItems); Dictionary<string, int> userIdDic = new Dictionary<string, int>(); Users users = new Users(); foreach (var line in TSVFile.ReadLines(sr, out errList)) { u_id = userIdDic.GetValueOrAdd(line.GetValue(0), u_count++); var c_name = line.GetValue(1, string.Empty); var array = line.Line.Split('\t').ToArray(3); if (array[1].IsNullOrEmpty()== false) { if (containItems.Length == 0 || (containItems.Length > 0 && hash.Contains(array[1]))) { if (array[2].IsNullOrEmpty()) { comnutyDic[array[1]].AddUserId(u_id); } else { users.Add(u_id, array[2], array[1]); } } itemList.Clear(); itemList.Add(c_name); } } list.AddRange(errList); errList = list; clusterTable.CreateRelation(); clusterTable.SetAllUser(); clusterTable.UserData = users; clusterTable.Update(); return clusterTable; }