コード例 #1
0
        public async Task <IActionResult> PutSmartGrid([FromRoute] int id, [FromBody] SmartGrid smartGrid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != smartGrid.SmartGridId)
            {
                return(BadRequest());
            }

            _context.Entry(smartGrid).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SmartGridExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #2
0
        public async Task <IActionResult> PutSmartGrid([FromRoute] int id, [FromBody] SmartGrid smartGrid)
        {
            if (SmartGridExists(id))
            {
                _repo.Update(smartGrid);
                return(Ok(smartGrid));
            }

            return(NoContent());
        }
コード例 #3
0
        public void Delete(SmartGrid s)
        {
            var producers = context.Prosumers.Where(b => EF.Property <int>(b, "ProducerForeignKey") == s.SmartGridId).ToList();
            var consumers = context.Prosumers.Where(b => EF.Property <int>(b, "ConsumerForeignKey") == s.SmartGridId).ToList();

            context.Prosumers.RemoveRange(producers);
            context.Prosumers.RemoveRange(consumers);

            context.SmartGrids.Remove(s);
            Save();
        }
コード例 #4
0
        public async Task <IActionResult> PostSmartGrid([FromBody] SmartGrid smartGrid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _repo.Add(smartGrid);

            return(CreatedAtAction("GetSmartGrid", new { id = smartGrid.SmartGridId }, smartGrid));
        }
コード例 #5
0
        public async Task <IActionResult> PostSmartGrid([FromBody] SmartGrid smartGrid)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.SmartGrids.Add(smartGrid);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetSmartGrid", new { id = smartGrid.SmartGridId }, smartGrid));
        }
コード例 #6
0
ファイル: SmartGridsController.cs プロジェクト: AHS-AU/DAB
        // POST: api/SmartGrids
        public async Task <HttpResponseMessage> Post(SmartGrid smartGrid)
        {
            var content          = JsonConvert.SerializeObject(smartGrid);
            var buf              = System.Text.Encoding.UTF8.GetBytes(content);
            var byteArrayContent = new ByteArrayContent(buf);

            byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var responseBody = await mHttpClient.PostAsync(new Uri(mApiUrl), byteArrayContent);

            return(responseBody);
        }
コード例 #7
0
ファイル: MapGrid.cs プロジェクト: dashqasar/GoogleMap
 void Awake()
 {
     if (Root == null)
         Root = transform;
     int dim = 2 * MapRadius + 1;
     InitCells(dim, dim);
     Width = dim * UnitsPerTile;
     Height = dim * UnitsPerTile;
     Dict = new LRUSpriteDictionary((dim + 1) * (dim + 1));
     Grid = new SmartGrid<RenderCell, RefCountedSprite>(Cells.ToArray(), dim, dim);
     _loadedPosition = new MapUtils.ProjectedPos(MapRadius, MapRadius, ZoomLevel, 0, 0);
     _position = new Vector3();
 }
コード例 #8
0
    protected virtual void Awake()
    {
        smartGrid = this.gameObject.AddComponent <SmartGrid>();
        smartGrid.Init(this);
        gameObject.layer = LayerMask.NameToLayer("Rooms");

        EnvironmentTiles = new List <EnvironmentTile>();

        obstacles   = new List <Vector2>();
        Environment = new List <Vector2>();

        grid = new GameObject()
        {
            name = "Grid"
        };
        grid.transform.parent = this.transform;

        floorGrid = new GameObject()
        {
            name = "Floor"
        };
        floorGrid.transform.parent = grid.transform;

        wallGrid = new GameObject()
        {
            name = "Walls"
        };
        wallGrid.transform.parent = grid.transform;

        EnvironmentGrid = new GameObject()
        {
            name = "Environment"
        };
        EnvironmentGrid.transform.parent = grid.transform;

        areasGrid = new GameObject()
        {
            name = "Areas"
        };
        areasGrid.transform.parent = grid.transform;
    }
コード例 #9
0
 public void Update(SmartGrid s)
 {
     context.SmartGrids.Update(s);
     Save();
 }
コード例 #10
0
 public void Add(SmartGrid s)
 {
     context.SmartGrids.Add(s);
     Save();
 }
コード例 #11
0
        static void Main(string[] args)
        {
            // Variables
            TradersRepoController mTradersRepoController = new TradersRepoController();
            ProsumerController    mProsumerController    = new ProsumerController();
            SmartGridsController  mSmartGridsController  = new SmartGridsController();

            // Clear SmartGrid
            ClearSmartGrid(mSmartGridsController);

            // Clear Trades
            ClearTraders(mTradersRepoController);

            /// Clear Prosumers
            ClearProsumers(mProsumerController);

            /// Populate Prosumers
            PopulateProsumers(mProsumerController);

            // Find Producer and Consumer
            List <Prosumer> mProducerList = mProsumerController.GetProsumerWithProduction("Overproducing").Result.ToList();
            List <Prosumer> mConsumerList = mProsumerController.GetProsumerWithProduction("Underproducing").Result.ToList();

            // Insert Producers and Consumer into SmartGrid object
            SmartGrid mSmartGrid = new SmartGrid();

            mSmartGrid.Producers = mProducerList;
            mSmartGrid.Consumers = mConsumerList;

            // Post SmartGrid to SmartGrid Database
            mSmartGridsController.Post(mSmartGrid).Wait();

            // Get All from SmartGrid
            var AllSmartGrid = mSmartGridsController.GetAllSmartGridsAsync().Result.LastOrDefault();
            var mProducers   = AllSmartGrid.Producers;
            var mConsumers   = AllSmartGrid.Consumers;

            // Calculate Producers- and Consumers kWhAmount
            var ProducersAmount = 0;
            var ConsumersAmount = 0;

            foreach (var v in mProducers)
            {
                ProducersAmount += v.KWhAmount;
            }
            foreach (var v in mConsumers)
            {
                ConsumersAmount += v.KWhAmount;
            }
            var difference = Math.Abs(ProducersAmount) - Math.Abs(ConsumersAmount);

            Console.WriteLine("\nDifference: " + difference);
            Console.WriteLine("Producers Amount: " + Math.Abs(ProducersAmount));
            Console.WriteLine("Consumers Amount: " + Math.Abs(ConsumersAmount));

            // Let's Trade
            int loopCounter = 0;

            foreach (var consumer in mConsumers)
            {
                loopCounter++;
                Console.WriteLine("\n******************** Consumer " + loopCounter + " *******************\n");
                foreach (var producer in mProducers)
                {
                    if (consumer.KWhAmount == 0)
                    {
                        continue;
                    }
                    if (producer.KWhAmount == 0)
                    {
                        continue;
                    }

                    //Console.WriteLine(">> " + producer.Name + " is selling " + Math.Abs(producer.KWhAmount) + " kWh");
                    //Console.WriteLine(">> " + consumer.Name + " is buying " + Math.Abs(consumer.KWhAmount) + " kWh\n");
                    if (Math.Abs(consumer.KWhAmount) < producer.KWhAmount)
                    {
                        producer.KWhAmount += consumer.KWhAmount;
                        Console.WriteLine(">>>> TRADE: " + consumer.Name + " has bought " + Math.Abs(consumer.KWhAmount) + " kWh from " + producer.Name);
                        Trader trader = new Trader()
                        {
                            ProducerId     = producer.ProsumerId.ToString(),
                            ConsumerId     = consumer.ProsumerId.ToString(),
                            KWhTransferred = Math.Abs(consumer.KWhAmount).ToString(),
                            TransferDate   = DateTime.Now
                        };
                        mTradersRepoController.Post(trader).Wait();
                        consumer.KWhAmount = 0;
                        mProsumerController.Put(producer.ProsumerId, producer).Wait();
                        mProsumerController.Put(consumer.ProsumerId, consumer).Wait();
                    }
                    else if (Math.Abs(consumer.KWhAmount) > producer.KWhAmount)
                    {
                        consumer.KWhAmount += producer.KWhAmount;
                        Console.WriteLine(">>>> TRADE: " + consumer.Name + " has bought " + Math.Abs(producer.KWhAmount) + " kWh from " + producer.Name);
                        Trader trader = new Trader()
                        {
                            ProducerId     = producer.ProsumerId.ToString(),
                            ConsumerId     = consumer.ProsumerId.ToString(),
                            KWhTransferred = producer.KWhAmount.ToString(),
                            TransferDate   = DateTime.Now
                        };
                        mTradersRepoController.Post(trader).Wait();
                        producer.KWhAmount = 0;
                        mProsumerController.Put(producer.ProsumerId, producer).Wait();
                        mProsumerController.Put(consumer.ProsumerId, consumer).Wait();
                    }
                    Console.WriteLine(producer.Name + " is selling " + producer.KWhAmount + " and " +
                                      consumer.Name + " is buying " + Math.Abs(consumer.KWhAmount));
                }
                if (consumer.KWhAmount != 0)
                {
                    Console.WriteLine("Buyer is missing " + Math.Abs(consumer.KWhAmount) +
                                      ", but he somehow manages to get free kWh from the powerplant (happy ending)");
                    consumer.KWhAmount = 0;
                }
            }

            // Remove Consumers and Producers if their kWhAmount equals 0.
            foreach (var producer in mProducers.ToList())
            {
                if (producer.KWhAmount == 0)
                {
                    mProducers.Remove(producer);
                }
            }
            foreach (var consumer in mConsumers.ToList())
            {
                if (consumer.KWhAmount == 0)
                {
                    mConsumers.Remove(consumer);
                }
            }

            // Post the SmartGrid
            mSmartGrid.Producers = mProducers;
            mSmartGrid.Consumers = mConsumers;
            mSmartGridsController.Post(mSmartGrid).Wait();

            // Check difference now and how much involved powerplant was as buy/sell
            if (difference > 0)
            {
                Console.WriteLine("\nSold " + difference + " kWh to powerplant");
            }
            else
            {
                Console.WriteLine("\nBought " + Math.Abs(difference) + " kWh from powerplant");
            }

            Console.WriteLine("\n\nProgram has finished ...");
            Console.ReadLine();
        }