Example #1
0
        static void Main(string[] args)
        {
            //Syntheziser.Generate(10000);
            Caches.Initialize();
            IAlgorithm algo = AlgorithmLoader.Load("Algorithms.SimpleAlgorithm");
            //Sample configuration parsing
            String JsonString = File.ReadAllText(@"C:\Users\PaulJoakim\source\repos\Master\Repositories\Configs\config.txt");
            IDictionary <Guid, ISysComponent> components = JSONParser.ParseConfig(JsonString);
            List <CSVFormat> demand = CSVParser.Parse(@"C:\Users\PaulJoakim\Source\Repos\Master\Repositories\Demand\demand.csv").ToList();

            if (demand.Count == 0)
            {
                Console.WriteLine("No load demand data found, exiting");
                return;
            }

            int time = 0;

            foreach (var d in demand)
            {
                if (algo.CalculateSetpoints(components, d.Value) == -1)
                {
                    Console.WriteLine("Demand Not met, press any key to continue");
                    Console.ReadKey();
                    break;
                }
                //TODO: Take Snapshot
                time++;
                TakeSnapshot(time, components);
            }
            string path = Path.Combine(Environment.CurrentDirectory, "Output");

            Directory.CreateDirectory(path);

            foreach (var snap in Snapshots)
            {
                //var fileName = Path.Combine(path, String.Format("{0}_Snapshots.txt", snap.Key.ToString()));
                using (StreamWriter file = File.CreateText(Path.Combine(path, String.Format("{0}_Snapshots.txt", snap.Key.ToString()))))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, snap.Value, typeof(List <Snapshot>));
                }
                Dictionary <String, List <double> > series = new Dictionary <string, List <double> >();
                //int count = snapshots.Count;
                //int sampleRate = count / 3000;
                foreach (var sn in snap.Value)
                {
                    foreach (var key in sn.Snap)
                    {
                        if (series.TryGetValue(key.Key, out List <double> val))
                        {
                            val.Add(key.Value);
                        }
                        else
                        {
                            List <double> serie = new List <double>();
                            serie.Add(key.Value);
                            series.Add(key.Key, serie);
                        }
                    }
                }
                foreach (var serie in series)
                {
                    var newPath = Path.Combine(path, snap.Key.ToString());
                    Directory.CreateDirectory(newPath);
                    using (StreamWriter file = File.CreateText(Path.Combine(newPath, String.Format("{0}_Snapshot.txt", serie.Key))))
                    {
                        JsonSerializer serializer = new JsonSerializer();
                        //string json = JsonConvert.SerializeObject(serie);
                        //json = json.TrimEnd(']');
                        //json = json.TrimStart()
                        serializer.Serialize(file, serie.Value, typeof(List <double>));
                    }
                }
            }



            Console.WriteLine("States written to disk, press any key to exit");
            Console.ReadKey();
        }