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; }