public void writeYieldCSV() { List <string> header = new List <string>(); List <string> body = new List <string>(); Dictionary <string, string> exportData = this.exportYieldDataDictionary(); foreach (string key in exportData.Keys) { header.Add(key); body.Add(exportData[key]); } //WRITING DATA TO FILES: int lightsourcescount = this.registeredLightSources.Count; int registered_surfaces_count = this.registeredPerformanceObjects.Count; int exportFieldsCount = this.exportFields.Count; string fullcsvheader = this.exportpath + this.yieldtablefilename.Replace("%o", "l" + lightsourcescount + "s" + registered_surfaces_count + "e" + exportFieldsCount) + "_header.csv"; string fullcsvbody = this.exportpath + this.yieldtablefilename.Replace("%o", "l" + lightsourcescount + "s" + registered_surfaces_count + "e" + exportFieldsCount) + "_body.csv"; string fullcsvfilename = this.exportpath + this.yieldtablefilename.Replace("%o", "l" + lightsourcescount + "s" + registered_surfaces_count + "e" + exportFieldsCount) + ".csv"; /* If the data should be appended and the file already exists */ bool appendcsv = (this.csvdatawritemode == APPEND); if (appendcsv) { if (!File.Exists(fullcsvfilename)) { Console.WriteLine("Creating file to append CSV data to: " + fullcsvfilename); appendcsv = false; } else { Console.WriteLine("Appending CSV data to: " + fullcsvfilename); } } else { Console.WriteLine("(over)Writing CSV data to: " + fullcsvfilename); } using (StreamWriter bodycsvwritestream = new StreamWriter(fullcsvbody, appendcsv)) { bodycsvwritestream.WriteLine(TraceJournal.csvLine(body)); } using (StreamWriter headercsvwritestream = new StreamWriter(fullcsvheader, false)) { headercsvwritestream.WriteLine(TraceJournal.csvLine(header)); } using (StreamWriter fullcsvwritestream = new StreamWriter(fullcsvfilename, this.csvdatawritemode == APPEND)) { if (!appendcsv) { fullcsvwritestream.WriteLine(TraceJournal.csvLine(header)); } fullcsvwritestream.WriteLine(TraceJournal.csvLine(body)); } }
public void configHistogramOutput(XElement xhistogram) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; Scientrace.Histogram1d hist = new Scientrace.Histogram1d(tj); hist.export = this.X.getXBool(xhistogram, "Export", hist.export); hist.angle_histogram_resolution = this.X.getXDouble(xhistogram, "Resolution", hist.angle_histogram_resolution); hist.angle_histogram_from = this.X.getXDouble(xhistogram, "FromAngle", hist.angle_histogram_from); hist.angle_histogram_to = this.X.getXDouble(xhistogram, "ToAngle", hist.angle_histogram_to); hist.angle_histogram_csv_filename = this.X.getXStringByName(xhistogram, "Filename", hist.angle_histogram_csv_filename); tj.exportables.Add(hist); }
public Dictionary <string, string> exportYieldDataDictionary() { Dictionary <string, string> retdict = new Dictionary <string, string>(); this.addConfigVariablesToDictionary(retdict); this.safeAddToDict(retdict, "Timestamp", this.timestamp); // REPLACED LINE BELOW. //retdict.Add("Timestamp", this.timestamp); double total_intensity = 0; double total_shine_duration = 0; foreach (Scientrace.LightSource lightsource in this.registeredLightSources) { string tag_prefix = lightsource.tag + "-"; //this.safeAddToDict(retdict,"light source", lightsource.tag); // REPLACED LINE BELOW. //retdict.Add("light source",lightsource.tag); this.safeAddToDict(retdict, tag_prefix + "cpu time (s)", lightsource.shine_duration.TotalSeconds.ToString()); // REPLACED LINE BELOW. //retdict.Add("cpu time (s)",lightsource.shine_duration.TotalSeconds.ToString()); this.safeAddToDict(retdict, tag_prefix + "#traces", lightsource.traceCount().ToString()); // REPLACED LINE BELOW. //retdict.Add("#traces",lightsource.traceCount().ToString()); this.safeAddToDict(retdict, tag_prefix + "intensity", lightsource.total_lightsource_intensity.ToString()); // REPLACED LINE BELOW. //retdict.Add("intensity",lightsource.total_lightsource_intensity.ToString()); this.safeAddToDict(retdict, tag_prefix + "weighted_intensity", lightsource.weighted_intensity.ToString()); // REPLACED LINE BELOW. //retdict.Add("weighted_intensity",lightsource.weighted_intensity.ToString()); total_intensity = total_intensity + lightsource.total_lightsource_intensity; total_shine_duration = total_shine_duration + lightsource.shine_duration.TotalSeconds; } double total_revenue = 0; int isolarcellcount = 1; foreach (Scientrace.PhysicalObject3d solarcell in this.registeredPerformanceObjects) { retdict.Add("solarcell-" + isolarcellcount, solarcell.tag); foreach (Scientrace.LightSource lightsource in this.registeredLightSources) { retdict.Add(this.ensureUniqueKey(lightsource.tag + "-yield", retdict), (lightsource.revenueForObject(solarcell) / lightsource.total_lightsource_intensity).ToString()); retdict.Add(this.ensureUniqueKey(lightsource.tag + "-weighted_sum", retdict), ((lightsource.revenueForObject(solarcell) / lightsource.total_lightsource_intensity) * lightsource.weighted_intensity).ToString()); } //retdict.Add("total_revenue-"+isolarcellcount,solarcell.getTotalRevenue().ToString()); retdict.Add(solarcell.tag + "-yield", (solarcell.getTotalRevenue() / total_intensity).ToString()); total_revenue = total_revenue + solarcell.getTotalRevenue(); isolarcellcount++; } retdict.Add("total light intensity", total_intensity.ToString()); retdict.Add("total revenue", total_revenue.ToString()); retdict.Add("total yield", (total_revenue / total_intensity).ToString()); foreach (string aKey in this.exportFields.Keys) { retdict.Add(aKey, TraceJournal.stringToCsv(exportFields[aKey])); } return(retdict); }
public void configX3DOutput(XElement xx3d) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.exportx3d = this.X.getXBool(xx3d, "Export", true); tj.x3d_line_thickness = this.X.getXDouble(xx3d, "LineWidth", 0); tj.x3d_draw_direction_arrows = this.X.getXBool(xx3d, "DrawArrows", true); ScientraceXMLParser.readCameraSettings(xx3d); //Console.WriteLine("WRITING DATA IS " + tj.exportdata.ToString()); tj.x3dfilename = this.X.getXStringByName(xx3d, "Filename", "3dview_" + tj.getSourceFilenameNoExt() + ".x3d"); }
public void configHistogram2dOutput(XElement xhistogram) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; Scientrace.Histogram2d hist = new Scientrace.Histogram2d(tj); hist.export = this.X.getXBool(xhistogram, "Export", hist.export); hist.angle_histogram_resolution = this.X.getXDouble(xhistogram, "Resolution", hist.angle_histogram_resolution); hist.angle_histogram_from = this.X.getXDouble(xhistogram, "FromAngle", hist.angle_histogram_from); hist.angle_histogram_to = this.X.getXDouble(xhistogram, "ToAngle", hist.angle_histogram_to); hist.angle_histogram_csv_filename = this.X.getXStringByName(xhistogram, "Filename", hist.angle_histogram_csv_filename); hist.tag = this.X.getXStringByName(xhistogram, "Tag", hist.tag); hist.referenceVector = this.X.getXNzVectorByName(xhistogram, "Ref", new Scientrace.NonzeroVector(1, 0, 0)); tj.exportables.Add(hist); Console.WriteLine("Hist2d added:" + hist.tag); }
public void configXMLOutput(XElement xxml) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.xml_display_lightsource = this.X.getXBool(xxml, "DisplayCustomTraces", false); tj.xml_display_preprocessed = this.X.getXBool(xxml, "DisplayPreProcessed", false); tj.xml_export_lightsources = this.X.getXBool(xxml, "Export", tj.xml_export_lightsources); tj.xml_export_preprocessed = this.X.getXBool(xxml, "Export", tj.xml_export_preprocessed); tj.xml_export_lightsources = this.X.getXBool(xxml, "ExportCustomTraces", tj.xml_export_lightsources); tj.xml_export_preprocessed = this.X.getXBool(xxml, "ExportPreProcessed", tj.xml_export_preprocessed); tj.xml_export_filename = this.X.getXStringByName(xxml, "Filename", "xml_%o_" + tj.getSourceFilenameNoExt() + ".scx"); }
public void parseConfiguration() { Console.WriteLine(">>> loading configuration file: " + this.configfilename); Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.source_filename = this.configfilename; string xmlsource = this.preProcess(this.configfilename); tj.xml_export_preprocessed_string = xmlsource; this.sctxp = new ScientraceXMLParser(XDocument.Parse(xmlsource)); this.env = this.sctxp.parseEnvironment(); this.sctxp.parseOutput(); }
public void configDataOutput(XElement xdata) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.exportyieldtablehtml = this.X.getXBool(xdata, "ExportHTML", true); tj.exportyieldtablecsv = this.X.getXBool(xdata, "ExportCSV", true); tj.yieldtablefilename = this.X.getXStringByName(xdata, "Filename", tj.getSourceFilenameNoExt() + "_%o"); string htmlwritemode = this.X.getXStringByName(xdata, "HTMLWriteMode", "append"); string csvwritemode = this.X.getXStringByName(xdata, "CSVWriteMode", "append"); switch (htmlwritemode) { case "append": { tj.htmldatawritemode = Scientrace.TraceJournal.APPEND; break; } case "write": { tj.htmldatawritemode = Scientrace.TraceJournal.WRITE; break; } default: { throw new XMLException("Unknown data output WriteMode"); //break; //unreachable } } //end switch switch (csvwritemode) { case "append": { tj.csvdatawritemode = Scientrace.TraceJournal.APPEND; break; } case "write": { tj.csvdatawritemode = Scientrace.TraceJournal.WRITE; break; } default: { throw new XMLException("Unknown data output WriteMode"); //break; //unreachable } } //end switch csv }
public void appendWriteDictionary <T, U>(string csv_filename, Dictionary <T, U> aDictionary) { bool write_headers = !System.IO.File.Exists(csv_filename); using (StreamWriter histogram_csv_writestream = new StreamWriter(csv_filename, true)) { //Only write header (keys) for new file: if (write_headers) { Console.Write("Writing data to new file: " + csv_filename); histogram_csv_writestream.WriteLine(TraceJournal.csvLine(new List <T>(aDictionary.Keys))); } else { Console.Write("Appending data to: " + csv_filename); } //Always write data (values) - duh histogram_csv_writestream.WriteLine(TraceJournal.csvLine(new List <U>(aDictionary.Values))); } Console.WriteLine(" [done]"); }
public void configSVGOutput(XElement xsvg) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.exportPDPSources = new HashSet <Scientrace.PDPSource> { }; if (this.X.getXBool(xsvg, "ExportAngles", true)) { tj.exportPDPSources.Add(Scientrace.PDPSource.AngleWheel); } if (this.X.getXBool(xsvg, "ExportWavelengths", true)) { tj.exportPDPSources.Add(Scientrace.PDPSource.Wavelength); } //Console.WriteLine("PDPSOURCESCOUNT:"+tj.exportPDPSources.Count); tj.svg_export_photoncloud = this.X.getXBool(xsvg, "PhotonCloud", false); tj.exportsvg = this.X.getXBool(xsvg, "Export", true); tj.svg_export_legends = this.X.getXBool(xsvg, "Legends", tj.exportsvg); tj.svgfilename = this.X.getXStringByName(xsvg, "Filename", tj.getSourceFilenameNoExt() + "_%o.svg"); tj.svggrid = this.X.getXBool(xsvg, "Grid", true); tj.spotdiagonalfraction = this.X.getXDouble(xsvg, "SpotSizeFraction", 1.0 / 200.0); }
/// <summary> /// Parsing Scientrace output. /// </summary> /// <param name="xoutput"> /// A <see cref="XElement"/> /// </param> public void parseXOutput(XElement xoutput) { //Console.WriteLine("PARSING XOUTPUT"); Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.setPath(this.X.getXString(xoutput.Attribute("Path"), "./out_" + tj.getSourceFilenameNoExt())); if (!tj.checkPath()) { Console.WriteLine("PARSER MESSAGE: output dir not valid. Unable to write output."); return; } else { //Console.WriteLine("OUTPUT DIR OK"); } XElement xx3d = xoutput.Element("X3D"); //if (xx3d != null) this.configX3DOutput(xx3d); this.configHistograms(xoutput); XElement xdata = xoutput.Element("YieldData"); //if (xdata != null) this.configDataOutput(xdata); XElement xsvg = xoutput.Element("SVG"); // if (xsvg != null) this.configSVGOutput(xsvg); XElement xxml = xoutput.Element("XML"); //if (xxml != null) this.configXMLOutput(xxml); XElement xphotondump = xoutput.Element("PhotonDump"); //if (xphotondump != null) this.configPhotonDumpOutput(xphotondump); }
public TraceJournalExportableHistogram(TraceJournal aTJ) : base(aTJ) { }
public TraceJournalExportable(TraceJournal aTraceJournal) { this.tj = aTraceJournal; }
public Histogram1d(TraceJournal aTJ) : base(aTJ) { this.tag="histogram"; }
/* End of Dictionary Export methods */ public void writePhotondumpCSV(Scientrace.PhysicalObject3d anObject) { Scientrace.Location loc2d; List <string> header = new List <string>(); // FIELDS: IDENTIFIER DIRX DIRY DIRZ SURFACEANGLE LOCX LOCY LOCZ ... // ... 2DLOCX 2DLOCY 2DLOCZ WAVELENGTH RGBCOLOUR DISTANCE INTENSITY INTENSITYFRACTION header.Add("IDENTIFIER"); header.Add("DIRX"); header.Add("DIRY"); header.Add("DIRZ"); header.Add("SURFACEANGLE"); header.Add("LOCX"); header.Add("LOCY"); header.Add("LOCZ"); header.Add("2DLOCX"); header.Add("2DLOCY"); header.Add("2DLOCZ"); header.Add("WAVELENGTH"); header.Add("RGBCOLOR"); header.Add("DISTANCE"); header.Add("CASUALTYINTENSITY"); header.Add("TRACESOURCEINTENSITY"); header.Add("INTENSITYFRACTION"); header.Add("Pol1DirX"); header.Add("Pol1DirY"); header.Add("Pol1DirZ"); header.Add("Pol1Len"); header.Add("Pol2DirX"); header.Add("Pol2DirY"); header.Add("Pol2DirZ"); header.Add("Pol2Len"); //string csvphotondumpfilename = this.exportpath+this.config_id.Replace("%","-")+this.yieldtablefilename.Replace("%o", anObject.tag)+".tracedump.csv"; string csvphotondumpfilename = this.exportpath + this.photondumpfilename.Replace("%o", anObject.tag); using (StreamWriter csvphotondumpwritestream = new StreamWriter(csvphotondumpfilename)) { csvphotondumpwritestream.WriteLine(TraceJournal.csvLine(header)); foreach (Scientrace.Spot casualty in this.spots) { if (casualty == null) { Console.WriteLine("WARNING: Casualty null value found. That's weird..."); } List <string> body = new List <string>(); if (casualty.object3d == anObject) { try { loc2d = anObject.get2DLoc(casualty.loc); body.Add(casualty.trace.traceid); // IDENTIFIER body.Add(casualty.trace.traceline.direction.x.ToString()); // DIRX body.Add(casualty.trace.traceline.direction.y.ToString()); // DIRY body.Add(casualty.trace.traceline.direction.z.ToString()); // DIRZ body.Add(anObject.getSurfaceNormal().angleWith(casualty.trace.traceline.direction).ToString()); body.Add(casualty.loc.x.ToString()); //LOCX body.Add(casualty.loc.y.ToString()); //LOCY body.Add(casualty.loc.z.ToString()); //LOCZ body.Add(loc2d.x.ToString()); //2DLOCX body.Add(loc2d.y.ToString()); //2DLOCY body.Add(loc2d.z.ToString()); //2DLOCZ body.Add(casualty.trace.wavelenght.ToString()); body.Add(this.wavelengthToRGB(casualty.trace.wavelenght)); body.Add(casualty.trace.tracedistance.ToString()); body.Add(casualty.intensity.ToString()); body.Add(casualty.trace.original_intensity.ToString()); body.Add(casualty.intensityFraction.ToString()); body.Add(casualty.pol_vec_1.x.ToString()); body.Add(casualty.pol_vec_1.y.ToString()); body.Add(casualty.pol_vec_1.z.ToString()); body.Add(casualty.pol_vec_1.length.ToString()); body.Add(casualty.pol_vec_2.x.ToString()); body.Add(casualty.pol_vec_2.y.ToString()); body.Add(casualty.pol_vec_2.z.ToString()); body.Add(casualty.pol_vec_2.length.ToString()); csvphotondumpwritestream.WriteLine(TraceJournal.csvLine(body)); } catch { Console.WriteLine("Some of the attributes messed up..."); } } } } }
public Histogram1d(TraceJournal aTJ) : base(aTJ) { this.tag = "histogram"; }
public static void reset() { TraceJournal.instance = null; }
public void configPhotonDumpOutput(XElement xphotondump) { Scientrace.TraceJournal tj = Scientrace.TraceJournal.Instance; tj.exportphotondump = this.X.getXBool(xphotondump, "Export", false); tj.photondumpfilename = this.X.getXStringByName(xphotondump, "Filename", "dump_%o_" + tj.getSourceFilenameNoExt() + ".csv"); }
/********* CONSIDERING DistributionSquares ******************/ //TODO: remove methode below public void old_writeYieldCSV() { List <string> header = new List <string>(); List <string> body = new List <string>(); //CONFIG ID CONTAINS SEVERAL DATAFIELDS: string[] cids = this.config_id.Split('%'); string[] cdescs = this.config_description.Split('%'); for (int icids = 0; icids < cids.Length; icids++) { //writing headers header.Add(TraceJournal.stringToCsv(cdescs[icids])); body.Add(TraceJournal.stringToCsv(cids[icids])); /*xheader.Add(new XElement("td", cdescs[icids])); * xrow.Add(new XElement("td", cids[icids]));*/ } header.Add("TimeStamp"); body.Add(TraceJournal.stringToCsv(this.timestamp)); double total_intensity = 0; double total_shine_duration = 0; foreach (Scientrace.LightSource lightsource in this.registeredLightSources) { header.Add(TraceJournal.stringToCsv("lightsource")); body.Add(TraceJournal.stringToCsv(lightsource.tag)); /* header.Add(this.stringToCsv("direction X")); * body.Add(this.doubleToCsv(lightsource.direction.x)); * header.Add(this.stringToCsv("Y")); * body.Add(this.doubleToCsv(lightsource.direction.y)); * header.Add(this.stringToCsv("Z")); * body.Add(this.doubleToCsv(lightsource.direction.z)); */ header.Add(TraceJournal.stringToCsv("calculation time (s)")); body.Add(TraceJournal.doubleToCsv(lightsource.shine_duration.TotalSeconds)); header.Add(TraceJournal.stringToCsv("number of traces")); body.Add(TraceJournal.intToCsv(lightsource.traceCount())); header.Add(TraceJournal.stringToCsv("intensity")); body.Add(TraceJournal.doubleToCsv(lightsource.total_lightsource_intensity)); header.Add(TraceJournal.stringToCsv("weighted_intensity")); body.Add(TraceJournal.doubleToCsv(lightsource.weighted_intensity)); total_intensity = total_intensity + lightsource.total_lightsource_intensity; total_shine_duration = total_shine_duration + lightsource.shine_duration.TotalSeconds; } double total_revenue = 0; foreach (Scientrace.PhysicalObject3d solarcell in this.registeredPerformanceObjects) { header.Add(TraceJournal.stringToCsv("solarcell")); body.Add(TraceJournal.stringToCsv(solarcell.tag)); foreach (Scientrace.LightSource lightsource in this.registeredLightSources) { header.Add(TraceJournal.stringToCsv(lightsource.tag + "-yield")); body.Add(TraceJournal.doubleToCsv(lightsource.revenueForObject(solarcell) / lightsource.total_lightsource_intensity)); header.Add(TraceJournal.stringToCsv(lightsource.tag + "-weighted_sum")); body.Add(TraceJournal.doubleToCsv((lightsource.revenueForObject(solarcell) / lightsource.total_lightsource_intensity) * lightsource.weighted_intensity)); } header.Add(TraceJournal.stringToCsv("total_revenue")); body.Add(TraceJournal.doubleToCsv(solarcell.getTotalRevenue())); header.Add(TraceJournal.stringToCsv(solarcell.tag + "-yield")); body.Add(TraceJournal.doubleToCsv(solarcell.getTotalRevenue() / total_intensity)); total_revenue = total_revenue + solarcell.getTotalRevenue(); } header.Add(TraceJournal.stringToCsv("total light intensity")); body.Add(TraceJournal.doubleToCsv(total_intensity)); header.Add(TraceJournal.stringToCsv("total revenue")); body.Add(TraceJournal.doubleToCsv(total_revenue)); header.Add(TraceJournal.stringToCsv("total yield")); body.Add(TraceJournal.doubleToCsv(total_revenue / total_intensity)); /*header.Add(this.stringToCsv("total yield (%)")); * body.Add(this.stringToCsv((100*total_revenue/total_intensity)+"%"));*/ /*header.Add(this.stringToCsv("total time(s)")); * body.Add(this.doubleToCsv(total_shine_duration));*/ IDictionaryEnumerator e = this.exportFields.GetEnumerator(); while (e.MoveNext()) { header.Add(TraceJournal.stringToCsv(e.Key.ToString())); //both key and value are already Strings... but anyway body.Add(TraceJournal.stringToCsv(e.Value.ToString())); } //WRITING DATA TO FILES: int lightsourcescount = this.registeredLightSources.Count; int solarcellcount = this.registeredPerformanceObjects.Count; int exportFieldsCount = this.exportFields.Count; string fullcsvheader = this.exportpath + this.yieldtablefilename.Replace("%o", "l" + lightsourcescount + "s" + solarcellcount + "e" + exportFieldsCount) + "_header.csv"; string fullcsvbody = this.exportpath + this.yieldtablefilename.Replace("%o", "l" + lightsourcescount + "s" + solarcellcount + "e" + exportFieldsCount) + "_body.csv"; string fullcsvfilename = this.exportpath + this.yieldtablefilename.Replace("%o", "l" + lightsourcescount + "s" + solarcellcount + "e" + exportFieldsCount) + ".csv"; /* If the data should be appended and the file already exists */ bool appendcsv = (this.csvdatawritemode == APPEND); if (appendcsv) { if (!File.Exists(fullcsvfilename)) { Console.WriteLine("Creating file to append CSV data to: " + fullcsvfilename); appendcsv = false; } else { Console.WriteLine("Appending CSV data to: " + fullcsvfilename); } } else { Console.WriteLine("(over)Writing CSV data to: " + fullcsvfilename); } using (StreamWriter bodycsvwritestream = new StreamWriter(fullcsvbody, appendcsv)) { bodycsvwritestream.WriteLine(TraceJournal.csvLine(body)); } using (StreamWriter headercsvwritestream = new StreamWriter(fullcsvheader, false)) { headercsvwritestream.WriteLine(TraceJournal.csvLine(header)); } using (StreamWriter fullcsvwritestream = new StreamWriter(fullcsvfilename, this.csvdatawritemode == APPEND)) { if (!appendcsv) { fullcsvwritestream.WriteLine(TraceJournal.csvLine(header)); } fullcsvwritestream.WriteLine(TraceJournal.csvLine(body)); } } // end old_writeYieldCSV