using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Text; using XMLParser; namespace XMLProgramm { class CSVWriter { FileStream handle = null; int handleOffset; void writeToFile(string content) { content += Environment.NewLine; byte[] bytes = Encoding.UTF8.GetBytes(content); handle.Write(bytes,0,bytes.Length); handle.Flush(); handleOffset += bytes.Length; } public CSVWriter() { handle = File.Create("./data.csv"); handleOffset = 0; string WriteHeader = "Inspektionsdatum#Anzahl Straßenablaufe#Länge über 5m#SonstigeLeitungen#Sonstige Länge über 5m#Hauptkanallänge"; writeToFile(WriteHeader); } public void Save() { handle.Close(); } internal void WriteDay(Dictionary calculated, List inspektionenAmTag) { int anzahlStraßenablaufe = (int)calculated[ECalculatedResult.STRASSENABLAUFANZAHL]; int sonstigeLeitungen = (int)calculated[ECalculatedResult.SONSTIGEANZAHL]; decimal Strassenablaufzulage = calculated[ECalculatedResult.STRASSENABLAUFLAENGEZULAGEMETER]; decimal Sonstigezulage = calculated[ECalculatedResult.SONSTIGELAENGEZULAGEMETER]; decimal HauptkanalLänge = calculated[ECalculatedResult.HAUPTKANALLAENGE]; KanalObjekt last = inspektionenAmTag.Last(); string entry = last.Inspektionsdaten.OptischeInspektion.Inspektionsdatum + "#"+anzahlStraßenablaufe+"#"+Strassenablaufzulage+"#"+sonstigeLeitungen+"#"+Sonstigezulage+"#"+HauptkanalLänge; writeToFile(entry); } } class Program { static void Main(string[] args) { CSVWriter csvWriter = new CSVWriter(); List objekte = new List(); DirectoryInfo info = new DirectoryInfo("./"); FileInfo[] daten = info.GetFiles("*.xml"); foreach(FileInfo aktuell in daten) { XMLParse ser = new XMLParse(aktuell.FullName); objekte.AddRange(ser.KanalObjekte); } IEnumerable datums = objekte.OrderBy(d => d.Inspektionsdaten.OptischeInspektion.Inspektionstime).Select(x => x.Inspektionsdaten.OptischeInspektion.Inspektionsdatum).Distinct(); decimal gesamt = 0.0m; //Dictionary s = CalculateDay(objekte.FindAll(x => x.Inspektionsdaten.OptischeInspektion.Inspektionsdatum.Equals("05.08.2021"))); foreach(string datum in datums) { List InspektionenAmTag = objekte.FindAll(x => x.Inspektionsdaten.OptischeInspektion.Inspektionsdatum.Equals(datum)); Dictionary s = Calculate.CalculateDay(InspektionenAmTag); csvWriter.WriteDay(s,InspektionenAmTag); Console.WriteLine("Umsatz am : "+datum + " " + s[ECalculatedResult.GESAMTUMSATZ]); gesamt +=s[ECalculatedResult.GESAMTUMSATZ]; //if(datum.Equals("05.08.2021")) Debugger.Break(); } int anzahlTage = datums.Count(); decimal Durchschnitt = gesamt / anzahlTage; int prognosedays = 63; Console.WriteLine(string.Format("Tage : {0} \nGesamt umsatz: {1}\nDurchschnitt : {2}\nPrognose für {3} tage {4}",anzahlTage,gesamt,Durchschnitt,prognosedays,prognosedays*Durchschnitt)); } } }