Ejemplo n.º 1
0
        static int Main(string[] args)
        {
            var options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return(4);
            }

            if (options.Args.Count != 3)
            {
                Console.Write(options.GetUsage());
                return(5);
            }

            String sinterconf  = options.Args[0];
            String infilename  = options.Args[1];
            String outfilename = options.Args[2];

            String workingDir      = Path.GetDirectoryName(sinterconf);
            String filenameBase    = Path.GetFileNameWithoutExtension(sinterconf);
            String performanceFile = Path.Combine(workingDir, filenameBase + "._time.txt");

            JArray inputsArray  = parseCSVInputs(infilename);
            JArray outputsArray = new JArray();

            List <sinter_AppError> runStatuses    = null;
            List <List <object> >  ts_byRunNumber = null;

            SinterProcess sp = new SinterProcess();

            sp.runSeries(sinterconf, null, inputsArray, options.Relaunch, options.Timelimit, ref outputsArray, ref runStatuses, ref ts_byRunNumber);

            writeOutCsv(outfilename, outputsArray);

            CsvFileWriter csvWriter    = new CsvFileWriter(performanceFile);
            string        headerString = "Open Time, Sinter Sent Time, Send Time, Run Time, Receive Time, Sinter Recieve Time";

            csvWriter.WriteLine(headerString);

            for (int ii = 0; ii < inputsArray.Count; ++ii)
            {
                csvWriter.WriteRow((List <object>)ts_byRunNumber[ii]);
            }
            csvWriter.Close();

            Console.WriteLine("FINISHED. PRESS ENTER KEY TO EXIT PROGRAM.");
            Console.ReadLine();
            return(0);
        }
Ejemplo n.º 2
0
        public void UnitTest1()
        {
            String sinterconf = Properties.Settings.Default.UnitsTestSinter;
            String infilename = Properties.Settings.Default.UnitsTestInputs;
            String workingDir = Properties.Settings.Default.UnitsWorkingDir;

            StreamReader inStream           = new StreamReader(infilename);
            StreamReader sinterConfigStream = new StreamReader(sinterconf);

            string inString           = inStream.ReadToEnd();
            string sinterConfigString = sinterConfigStream.ReadToEnd();

            inStream.Close();
            sinterConfigStream.Close();

            JArray injson  = (JArray)JToken.Parse(inString);
            JArray outjson = new JArray();
            List <sinter_AppError> runStatuses    = null;
            List <List <object> >  ts_byRunNumber = null;
            SinterProcess          sp             = new SinterProcess();

            sp.runSeries(sinterconf, null, injson, false, -1, ref outjson, ref runStatuses, ref ts_byRunNumber);

            Assert.IsTrue(runStatuses[0] == sinter_AppError.si_OKAY);

            //Verify the inputs
            Assert.IsTrue(212.0 == (double)outjson[0]["inputs"]["in.boil.celsius"]["value"]);
            Assert.IsTrue("degF" == (string)outjson[0]["inputs"]["in.boil.celsius"]["units"]);
            Assert.IsTrue(100.0 == (double)outjson[0]["inputs"]["in.boil.fahrenheit"]["value"]);
            Assert.IsTrue("degC" == (string)outjson[0]["inputs"]["in.boil.fahrenheit"]["units"]);
            Assert.IsTrue(-273.15 == (double)outjson[0]["inputs"]["in.misc.kelvin"]["value"][0]);
            Assert.IsTrue("degC" == (string)outjson[0]["inputs"]["in.misc.kelvin"]["units"]);

            //Verify the outputs
            Assert.IsTrue(sinter_HelperFunctions.fuzzyEquals(100.0, (double)outjson[0]["outputs"]["out.boil.celsius"]["value"], .00001));
            Assert.IsTrue("degC" == (string)outjson[0]["outputs"]["out.boil.celsius"]["units"]);
            Assert.IsTrue(sinter_HelperFunctions.fuzzyEquals(212.0, (double)outjson[0]["outputs"]["out.boil.fahrenheit"]["value"], .00001));
            Assert.IsTrue("degF" == (string)outjson[0]["outputs"]["out.boil.fahrenheit"]["units"]);
            Assert.IsTrue(sinter_HelperFunctions.fuzzyEquals(0, (double)outjson[0]["outputs"]["out.misc.kelvin"]["value"][0], .00001));
            Assert.IsTrue(sinter_HelperFunctions.fuzzyEquals(273.15, (double)outjson[0]["outputs"]["out.misc.kelvin"]["value"][1], .00001));
            Assert.IsTrue(sinter_HelperFunctions.fuzzyEquals(373.15, (double)outjson[0]["outputs"]["out.misc.kelvin"]["value"][2], .00001));
            Assert.IsTrue("K" == (string)outjson[0]["outputs"]["out.misc.kelvin"]["units"]);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Main
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        static int Main(string[] args)
        {
            var options = new Options();

            if (!CommandLine.Parser.Default.ParseArguments(args, options))
            {
                return(4);
            }

            if (options.Args.Count != 3)
            {
                Console.Write(options.GetUsage());
                return(5);
            }

            String sinterconf  = options.Args[0];
            String infilename  = options.Args[1];
            String outfilename = options.Args[2];

            String workingDir      = Path.GetDirectoryName(sinterconf);
            String filenameBase    = Path.GetFileNameWithoutExtension(sinterconf);
            String performanceFile = Path.Combine(workingDir, filenameBase + "._time.txt");

            StreamReader inStream = new StreamReader(infilename);

            //So, at the end of this we should have 1 or more input sets in the JArray inputsArray
            //The console version reads in json, the actual version just pulls the dictionary from the database
            string injson       = "";
            JToken inputJToken  = null;
            JArray inputsArray  = null; //Will be set if the input file is a set of runs
            JArray outputsArray = new JArray();

            try
            {
                injson      = inStream.ReadToEnd();
                inputJToken = JToken.Parse(injson);
                if (inputJToken is JArray)
                {
                    inputsArray = (JArray)inputJToken;
                }
                else if (inputJToken is JObject)
                {   //Console Sinter is expecting a JArray in the same format as the Gateway takes.  [ { Input = {...} }, { { Inputs = {...} } ]
                    inputsArray = new JArray();
                    JObject singleInputDict = (JObject)inputJToken;
                    JObject outterDict      = new JObject();
                    outterDict.Add("inputs", singleInputDict);
                    inputsArray.Add(outterDict);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception while running simulation: " + ex.Message);
            }
            finally
            {
                inStream.Close();
            }


            List <sinter_AppError> runStatuses    = null;
            List <List <object> >  ts_byRunNumber = null;

            //
            // NOTE: Implementation Detail WORKING DIRECTORY MUST CONTAIN SinterConfig File
            //
            SinterProcess sp = new SinterProcess();

            sp.runSeries(sinterconf, null, inputsArray,
                         options.Relaunch, options.Timelimit, ref outputsArray, ref runStatuses, ref ts_byRunNumber);

            JsonSerializerSettings jss = new JsonSerializerSettings();

            jss.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
            string       jsonOutput = JsonConvert.SerializeObject(outputsArray, Formatting.Indented, jss);
            StreamWriter outStream  = new StreamWriter(outfilename);

            outStream.WriteLine(jsonOutput);
            outStream.Close();

            CsvFileWriter csvWriter    = new CsvFileWriter(performanceFile);
            string        headerString = "Open Time, Sinter Sent Time, Send Time, Run Time, Receive Time, Sinter Recieve Time";

            csvWriter.WriteLine(headerString);

            for (int ii = 0; ii < inputsArray.Count; ++ii)
            {
                csvWriter.WriteRow((List <object>)ts_byRunNumber[ii]);
            }
            csvWriter.Close();

            Console.WriteLine("FINISHED. PRESS ENTER KEY TO EXIT PROGRAM.");
            Console.ReadLine();
            return(0);
        }