Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Fórum Group Data Within 5 Hours Maximum
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; // aljodav // http://rextester.com/users/376 namespace Rextester { using Test=Rextester.Program; class Cfg{ // Configuration public string Mr{get;set;} // Master Name public string Cd{get;set;} // Child Name public int Hs{get;set;} // Hours } class PoD{ // Point Data ➡ must be in ascending order for the property It. public int Id{get;set;} // Data Id public string Dn{get;set;} // Data Description public DateTime It{get;set;} // Insert Date Time public string Mr{get;set;} // Master Name public string Cd{get;set;} // Child Name public int Ct{get;set;} // Count } class Program { List<Cfg> GetCfgs(){ return new List<Cfg>{ /**/new Cfg{Mr="Master1",Cd="Child1",Hs=5}, new Cfg{Mr="Master1",Cd="Child2",Hs=5}, new Cfg{Mr="Master2",Cd="Child1",Hs=5}, }; } List<PoD> GetPoDs(){ return new List<PoD>{ /**/new PoD{Id=1,Dn="Dn of 1",It= new DateTime(2016,9,8,3,0,1),Mr="Master1",Cd="Child1"}, new PoD{Id=1,Dn="Dn-of-1",It= new DateTime(2016,9,8,3,0,1),Mr="Master1",Cd="Child2"}, new PoD{Id=2,Dn="Dn of 2",It= new DateTime(2016,9,8,4,0,1),Mr="Master1",Cd="Child1"}, new PoD{Id=2,Dn="Dn-of-2",It= new DateTime(2016,9,8,4,0,1),Mr="Master2",Cd="Child1"}, new PoD{Id=3,Dn="Dn of 3",It= new DateTime(2016,9,8,5,0,1),Mr="Master1",Cd="Child1"}, new PoD{Id=3,Dn="Dn-of-3",It= new DateTime(2016,9,8,5,0,1),Mr="Master1",Cd="Child3"}, new PoD{Id=4,Dn="Dn of 4",It= new DateTime(2016,9,8,9,0,1),Mr="Master1",Cd="Child1"}, new PoD{Id=4,Dn="Dn-of-4",It= new DateTime(2016,9,8,9,0,1),Mr="Master3",Cd="Child1"}, }; } public static void Main(string[] args) { Test t= new Test(); List<Cfg> cfgs= t.GetCfgs(); List<PoD> pods= t.GetPoDs(); pods.ForEach(p=>p.Ct=1); pods.Sort((x,y)=>x.It.CompareTo(y.It)); cfgs.ForEach(c=> { Console.WriteLine("\n{0}\n\t➡ {1}, {2}", new string('-',50),c.Mr,c.Cd); string mr= c.Mr,cd= c.Cd;int hs= c.Hs; List<PoD> podsSeld= new List<PoD>(); PoD first= pods.Where(p=>mr==p.Mr&&cd==p.Cd).FirstOrDefault(); if(first!=default(PoD)){ PoD last= pods.Where(p=>mr==p.Mr&&cd==p.Cd&&((p.It-first.It).Hours<=hs)).Last(); int ct= pods.Where(p=>mr==p.Mr&&cd==p.Cd&&((p.It-first.It).Hours<=hs)).Count(); last.Ct=ct; podsSeld.Add(last); } podsSeld.AddRange( pods.Where(p=>mr==p.Mr&&cd==p.Cd&&((p.It-first.It).Hours>hs)) ); podsSeld.ForEach(p=>Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}",p.Id,p.Dn,p.It,p.Mr,p.Cd,p.Ct)); }); Console.WriteLine("\n\nHello, world!"); } } }
run
|
edit
|
history
|
help
0
hihi
4647
Remove xmlns and select signle node
Hello word
asxsdf
Card Shuffling
merge 2 sorted array
How to find second largest integer in an array using only one loop?
asxsdf
Dynamic properties in Dynamic object