コード例 #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            List <DateTime> evListDate = new List <DateTime>();
            int             evPattern;
            int             number;
            string          order;
            double          storageCapacity;

            evListDate.Add(DateTime.Parse("2016/11/04"));                                                      //559台分のEVデータセット日時
            evPattern       = 0;                                                                               //EVのエネルギー割当パターン:新クエリでは不使用
            number          = 559;                                                                             //EVの台数
            order           = "ORDER BY OutEndTime ASC ";                                                      //EVの優先度
            storageCapacity = 10;                                                                              //蓄電池容量[kWh]

            MicroGridBattery mgb = GetMicroGridBattery(evListDate, evPattern, number, order, storageCapacity); //グリッドの蓄電池を定義

            DateTime   dt;
            List <int> bID = new List <int>();
            List <int> pID = new List <int>(); //駐車場・駐輪場ID:本例では不使用
            int        peakPattern;
            double     rate;

            dt = DateTime.Parse("2015/07/31"); //マイクログリッドの対象日時
            for (int i = 1; i <= 17; i++)
            {
                bID.Add(i);    //建物ID:ここでは例として横国の建物すべてを対象とする
            }
            peakPattern = 0;   //最大±1h
            rate        = 1.0; //太陽光設置率100%

            MicroGridOneday mgo = GetMicroGridOneday(dt, bID, pID, mgb, peakPattern, rate);

            WriteToTextBox("-- 1日の需要・発電・差分・バッテリー導入差分・東電・ピークかどうか --");
            for (int i = 0; i < 24; i++)
            {
                WriteToTextBox(i + " : " + mgo.GetPowerLog(i) + " " + mgo.GetGeneration(i) + " " + mgo.GetDifferencePG(i) + " " + mgo.GetDifferencePGEV(i) + " " + mgo.GetDemand(i) + " " + mgo.Peaktime[i]);
            }
            WriteToTextBox("-- 1日の需要・発電・差分・バッテリー導入差分・東電・ピークかどうか --");

            //1時間ごとのPV余剰量やEVへの充電量・給電量は計算で導出可(以下)
            WriteToTextBox("-- 1日のPVの余剰量・EVへの充電量・EVからの給電量 --");
            for (int i = 0; i < 24; i++)
            {
                double overGeneration, EVCharge, EVDischarge;

                if (mgo.GetDifferencePG(i) < 0)                                         //PV発電超過
                {
                    overGeneration = -mgo.GetDifferencePG(i);                           //需要・発電相殺後の値(発電超過だと負の値になるため符号をひっくり返す)
                    EVCharge       = mgo.GetDifferencePGEV(i) - mgo.GetDifferencePG(i); //EV導入前の値と導入後の値の差分がバッテリーへの充電量
                }
                else
                {
                    overGeneration = 0;
                    EVCharge       = 0;
                }

                if (mgo.Peaktime[i] && mgo.GetDifferencePG(i) > 0)                   //ピーク時間帯かつPVの発電超過ではない
                {
                    EVDischarge = mgo.GetDifferencePG(i) - mgo.GetDifferencePGEV(i); //EV導入前の値と導入後の値の差分がバッテリーからの給電量
                }
                else
                {
                    EVDischarge = 0;
                }

                WriteToTextBox(i + " : " + overGeneration + " " + EVCharge + " " + EVDischarge);
            }
            WriteToTextBox("-- 1日のPVの余剰量・EVへの充電量・EVからの給電量 --");

            WriteToTextBox("PV・EV導入前のピーク時間帯エネルギー量[kWh] : " + mgo.GetBeforePeakEnergy());
            WriteToTextBox("PV・EV導入後のピーク時間帯エネルギー量[kWh] : " + mgo.GetAfterPeakEnergy());
            WriteToTextBox("PV・EV導入前のピーク時間帯最大電力[kW] : " + mgo.GetPeakBeforeMaxWatt());
            WriteToTextBox("PV・EV導入後のピーク時間帯最大電力[kW] : " + mgo.GetPeakAfterMaxWatt());
            WriteToTextBox("PV・EV導入前の余剰発電量[kWh] : " + mgo.GetBeforeOverGeneration());
            WriteToTextBox("PV・EV導入後の余剰発電量[kWh] : " + mgo.GetAfterOverGeneration());

            WriteToTextBox("-- 充キャパ・給ポテ(充給電なし) --");
            for (int i = 0; i < 24; i++)
            {
                WriteToTextBox(i + " : " + mgo.MicroGridBatteryBefore.GetAllChargeCapacity(i) + " " + mgo.MicroGridBatteryBefore.GetAllDischargeCapacity(i));
            }
            WriteToTextBox("-- 充キャパ・給ポテ(充給電なし) --");

            WriteToTextBox("-- 充キャパ・給ポテ(充給電あり) --");
            for (int i = 0; i < 24; i++)
            {
                WriteToTextBox(i + " : " + mgo.MicroGridBatteryAfter.GetAllChargeCapacity(i) + " " + mgo.MicroGridBatteryAfter.GetAllDischargeCapacity(i));
            }
            WriteToTextBox("-- 充キャパ・給ポテ(充給電あり) --");
        }
コード例 #2
0
        private MicroGridOneday GetMicroGridOneday(DateTime dt, List <int> bID, List <int> pID, MicroGridBattery mgb, int peakPattern, double rate) //マイクログリッドの1日の推移クラス生成
        {
            //引数
            //dt : 需要・発電ログの日時
            //bID : 横国見える化の区画ID
            //pID : 駐車場・駐輪場ID
            //mgb : MicroGridBattery
            //peakPattern : 電力ピークのパターン(最大±1hは"0"・最大±2hは"1"・大きい順2hは"2"・大きい順3hは"3"・大きい順4hは"4")
            //rate : 太陽光設置率

            MicroGridOneday MGO; //返り値用

            double square = 0;   //対象の建物, 駐車場・駐輪場の面積(MicroGridOnedayのコンストラクタには必要, 計算には使わないが)

            double[] consume    = new double[24];
            double[] generate   = new double[24];
            double[] difference = new double[24]; //電力需要(1時間毎), 電力発電(1時間毎), 差分
            int[]    tepco      = new int[24];    //TEPCO需要電力[MW]

            string        query;
            SqlCommand    cmd;
            SqlDataReader reader;
            int           index = 0; //配列用インデックス

            //以降各コンポーネントごとの取得処理を1つにまとめているためメソッドがとてつもなく長くなっているが
            //本来はもう少しコンパクトに書くべき(取得データごとにメソッドを分けるとか)
            #region squareの取得

            #region クエリ

            if (pID.Count > 0) //駐輪場の指定あり
            {
                query  = "SELECT bArea.BuildingConstructionArea + pArea.ParkingConstructionArea " + Environment.NewLine;
                query += "FROM " + Environment.NewLine;
                query += "( " + Environment.NewLine;
                query += "	SELECT SUM(ConstructionArea) BuildingConstructionArea "+ Environment.NewLine;
                query += "	FROM Building "+ Environment.NewLine;
                query += "  WHERE MeasureAreaClassID IN (" + bID[0];
                for (int i = 1; i < bID.Count; i++)
                {
                    query += ", " + bID[i] + "";
                }
                query += ") " + Environment.NewLine;
                query += "	GROUP BY MeasureAreaClassID "+ Environment.NewLine;
                query += ") bArea, " + Environment.NewLine;
                query += "( " + Environment.NewLine;
                query += "	SELECT SUM(ConstructionArea) ParkingConstructionArea "+ Environment.NewLine;
                query += "	FROM Parking "+ Environment.NewLine;
                query += "  WHERE ID IN (" + bID[0];
                for (int i = 1; i < pID.Count; i++)
                {
                    query += ", " + pID[i] + "";
                }
                query += ") " + Environment.NewLine;
                query += "	GROUP BY ID "+ Environment.NewLine;
                query += ") pArea " + Environment.NewLine;
            }
            else //駐輪場の指定なし
            {
                query  = "SELECT SUM(ConstructionArea) " + Environment.NewLine;
                query += "FROM Building " + Environment.NewLine;
                query += "WHERE MeasureAreaClassID IN (" + bID[0];
                for (int i = 1; i < bID.Count; i++)
                {
                    query += ", " + bID[i] + "";
                }
                query += ") " + Environment.NewLine;
                query += "GROUP BY MeasureAreaClassID " + Environment.NewLine;
            }
            #endregion

            try
            {
                sqlConnection1.Open();
                cmd    = new SqlCommand(query, sqlConnection1);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    square = (double)reader.GetInt32(0);
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                sqlConnection1.Close();
            }

            #endregion

            #region consumeの取得

            #region クエリ

            query  = "SELECT SUM(Energy) " + Environment.NewLine;
            query += "FROM BuildingPowerLog " + Environment.NewLine;
            query += "WHERE MeasureAreaClassID IN (" + bID[0];
            for (int i = 1; i < bID.Count; i++)
            {
                query += ", " + bID[i] + "";
            }
            query += ") " + Environment.NewLine;
            query += "AND CONVERT(Date, Date, 111) = '" + dt.ToShortDateString() + "' " + Environment.NewLine;
            query += "GROUP BY Date " + Environment.NewLine;
            query += "ORDER BY Date " + Environment.NewLine;

            #endregion

            try
            {
                sqlConnection1.Open();
                cmd    = new SqlCommand(query, sqlConnection1);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    consume[index] = (double)reader[0];
                    index++;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                sqlConnection1.Close();
            }

            #endregion

            #region generateの取得

            index = 0;

            #region クエリ

            if (pID.Count > 0) //駐輪場の指定あり
            {
                query  = "SELECT ROUND(bLog.bGenerateEnergy + pLog.pGenerateEnergy, 1) " + Environment.NewLine;
                query += "FROM " + Environment.NewLine;
                query += "( " + Environment.NewLine;
                query += "	SELECT Date, SUM(GenerateEnergy) bGenerateEnergy "+ Environment.NewLine;
                query += "	FROM BuildingSolarPowerLog "+ Environment.NewLine;
                query += "WHERE MeasureAreaClassID IN (" + bID[0];
                for (int i = 1; i < bID.Count; i++)
                {
                    query += ", " + bID[i] + "";
                }
                query += ") " + Environment.NewLine;
                query += "	AND CONVERT(Date, Date, 111) = '"+ dt.ToShortDateString() + "' " + Environment.NewLine;
                query += "	GROUP BY Date "+ Environment.NewLine;
                query += ")bLog, " + Environment.NewLine;
                query += "( " + Environment.NewLine;
                query += "	SELECT Date, SUM(GenerateEnergy) pGenerateEnergy "+ Environment.NewLine;
                query += "	FROM ParkingSolarPowerLog "+ Environment.NewLine;
                query += "  WHERE ID IN (" + pID[0];
                for (int i = 1; i < pID.Count; i++)
                {
                    query += ", " + pID[i] + "";
                }
                query += ") " + Environment.NewLine;
                query += "	AND CONVERT(Date, Date, 111) = '"+ dt.ToShortDateString() + "' " + Environment.NewLine;
                query += "	GROUP BY Date "+ Environment.NewLine;
                query += ")pLog " + Environment.NewLine;
                query += "WHERE bLog.Date = pLog.Date " + Environment.NewLine;
                query += "ORDER BY bLog.Date " + Environment.NewLine;
            }
            else
            {
                query  = "SELECT SUM(GenerateEnergy) " + Environment.NewLine;
                query += "FROM BuildingSolarPowerLog " + Environment.NewLine;
                query += "WHERE MeasureAreaClassID IN (" + bID[0];
                for (int i = 1; i < bID.Count; i++)
                {
                    query += ", " + bID[i] + "";
                }
                query += ") " + Environment.NewLine;
                query += "AND CONVERT(Date, Date, 111) = '" + dt.ToShortDateString() + "' " + Environment.NewLine;
                query += "GROUP BY Date " + Environment.NewLine;
                query += "ORDER BY Date " + Environment.NewLine;
            }

            #endregion

            try
            {
                sqlConnection1.Open();
                cmd    = new SqlCommand(query, sqlConnection1);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    generate[index] = (double)reader[0] * rate;
                    index++;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                sqlConnection1.Close();
            }

            #endregion

            #region differenceの取得

            for (int i = 0; i < 24; i++)
            {
                difference[i] = consume[i] - generate[i];
            }

            #endregion

            #region tepcoの取得

            index = 0;

            #region クエリ

            query  = "SELECT Energy * 10 " + Environment.NewLine;
            query += "FROM TEPCODemandData " + Environment.NewLine;
            query += "WHERE CONVERT(Date, Date, 111) = '" + dt.ToShortDateString() + "' " + Environment.NewLine;
            query += "ORDER BY Date " + Environment.NewLine;

            #endregion

            try
            {
                sqlConnection1.Open();
                cmd    = new SqlCommand(query, sqlConnection1);
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    tepco[index] = (int)reader.GetDouble(0);
                    index++;
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                sqlConnection1.Close();
            }

            #endregion

            MGO = new MicroGridOneday(square, consume, generate, difference, tepco, mgb, peakPattern);

            return(MGO);
        }