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);
        }
Example #2
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