public Param_Extra(Param_Extra extra) : base(extra) { this.@group = extra.@group; this.rows = extra.rows; this.users = extra.users; this.machines = extra.machines; this.F = extra.F; this.H = extra.H; }
public void ExpandGroupBySearchingBasedOnUserID(Entity_sheet1 input, Entity_sheet1_Extra output) { List <Entity_sheet1.Param> list = input.sheets[0].list.Clone().ToList(); List <Param_Extra> retVal = new List <Param_Extra>(); List <Entity_sheet1.Param> currentGroup = new List <Entity_sheet1.Param>(); currentGroup.Add(list[0]); list.RemoveAt(0); int groupNumber = 1; int groupCount; int countUniqueMachineID; int countUniqueUserID; int countLicenseF; int countLicenseH; while (list.Count > 0) { // if still in the same group base on IP check if (currentGroup[currentGroup.Count - 1].IP.Equals(list[0].IP)) { currentGroup.Add(list[0]); list.RemoveAt(0); } else // this row belongs to another group based on IP check, so now let process the previous group { // base on UserID, find matched rows in the full list to amend to this group for (int i = 0; i < currentGroup.Count; i++) { Entity_sheet1.Param param = currentGroup[i]; List <Entity_sheet1.Param> temp = list.FindAll(x => x.Userid.Equals(param.Userid)).ToList(); for (int j = 0; j < temp.Count; j++) { list.Remove(temp[j]); } currentGroup.AddRange(temp); } // statistic about this group groupCount = currentGroup.Count; countUniqueMachineID = currentGroup.Select(x => x.MachineId).Distinct().Count(); countUniqueUserID = currentGroup.Select(x => x.Userid).Distinct().Count(); countLicenseF = currentGroup.GroupBy(x => x.MachineId) .Select(g => new { machineId = g.Key, licenseType = g.FirstOrDefault().LicenseType }).ToList() .FindAll(x => x.licenseType.Equals("F")).Count; countLicenseH = currentGroup.GroupBy(x => x.MachineId) .Select(g => new { machineId = g.Key, licenseType = g.FirstOrDefault().LicenseType }).ToList() .FindAll(x => x.licenseType.Equals("H")).Count; // let group by ip then sort by ip count within this group currentGroup = currentGroup.GroupBy(x => x.IP).OrderByDescending(g => g.Count()) .SelectMany(g => g).ToList(); // finish current group for (int i = 0; i < currentGroup.Count; i++) { Param_Extra pe = new Param_Extra(currentGroup[i]); pe.group = groupNumber; pe.rows = groupCount; pe.machines = countUniqueMachineID; pe.users = countUniqueUserID; pe.F = countLicenseF; pe.H = countLicenseH; retVal.Add(pe); } currentGroup.Clear(); // next group if (list.Count == 0) { break; } currentGroup.Add(list[0]); list.RemoveAt(0); ++groupNumber; } } if (currentGroup.Count > 0) { // statistic about this group groupCount = currentGroup.Count; countUniqueMachineID = currentGroup.Select(x => x.MachineId).Distinct().Count(); countUniqueUserID = currentGroup.Select(x => x.Userid).Distinct().Count(); countLicenseF = currentGroup.GroupBy(x => x.MachineId) .Select(g => new { machineId = g.Key, licenseType = g.FirstOrDefault().LicenseType }).ToList() .FindAll(x => x.licenseType.Equals("F")).Count; countLicenseH = currentGroup.GroupBy(x => x.MachineId) .Select(g => new { machineId = g.Key, licenseType = g.FirstOrDefault().LicenseType }).ToList() .FindAll(x => x.licenseType.Equals("H")).Count; // finish current group for (int i = 0; i < currentGroup.Count; i++) { Param_Extra pe = new Param_Extra(currentGroup[i]); pe.group = groupNumber; pe.rows = groupCount; pe.machines = countUniqueMachineID; pe.users = countUniqueUserID; pe.F = countLicenseF; pe.H = countLicenseH; retVal.Add(pe); } currentGroup.Clear(); } output.list = retVal; }
public ParamModified(Param_Extra extra) : base(extra) { }