public void AddUserData(System.IO.StreamReader sr) { UserData = new Users(); UserData.Create(sr); }
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; }