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 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]");
        }
/* 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..."); }
                    }
                }
            }
        }
Пример #4
0
        /********* 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