123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Diagnostics;
- using System.Windows.Forms;
- using System.Collections.Concurrent;
- using System.Runtime.InteropServices;
- using System.Timers;
- using System.Threading;
- using System.Data.SqlClient;
- using System.Data;
- using System.Text.RegularExpressions;
- namespace DataGateWayProject
- {
- class Parsing
- {
-
- Thread _thread;
- ConcurrentDictionary<string, float[]> RawData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> NowData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> AverageData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> AddData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> OnData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> Add2Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> Now2Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpAverageData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpAddData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpNowData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpOnData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpNow2Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpAdd2Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> TmpRawData = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> Exp_Raw_Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> Exp_Fifteen_Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, float[]> Exp_Hour_Data = new ConcurrentDictionary<string, float[]>();
- ConcurrentDictionary<string, string> Matching_Tag = new ConcurrentDictionary<string, string>();
- ConcurrentDictionary<string, string> Value_Modify = new ConcurrentDictionary<string, string>();
- ConcurrentDictionary<string, float[]> COV_Dic = new ConcurrentDictionary<string, float[]>();
-
-
-
-
-
-
- static double enthalpy_proc(double curtTemp, double relatvHum)
- {
- double retValue = 0.0;
- double tmpValue1, tmpValue2;
- tmpValue1 = (Math.Exp(((((6.18145E-12 * curtTemp - 0.000000003429809) * curtTemp + 0.000001113417) * curtTemp - 0.0002986334) *
- curtTemp + 0.07265429) * curtTemp - 5.111336) * 760) * (relatvHum / 100);
- tmpValue2 = (Math.Exp(((((6.18145E-12 * curtTemp - 0.000000003429809) * curtTemp + 0.000001113417) * curtTemp - 0.0002986334) * 39 + 0.07265429) *
- curtTemp - 5.111336) * 760) * (relatvHum / 100);
- retValue = ((0.288 * curtTemp + 727.344 * (0.622 * tmpValue1 / (760 - tmpValue2))) / 1.2) * 4.186;
- return retValue;
- }
-
-
-
-
-
-
- static double absoluteHumidity_proc(double curtTemp, double relatvHum)
- {
- double retValue = 0.0;
- double enthalpyValue;
- enthalpyValue = enthalpy_proc(curtTemp, relatvHum);
- retValue = (enthalpyValue - 1.006 * curtTemp) / (1.805 * curtTemp + 2501);
- return retValue;
- }
- private string[] temp;
- public string SettingFileParsing()
- {
- Stopwatch SW = new Stopwatch();
- string sTemp1;
- SW.Reset();
- SW.Start();
- LogFileCreate LFC = new LogFileCreate();
- int count_modify_value = 0;
- StreamReader MatchingDic = new StreamReader("SettingFile.csv", Encoding.GetEncoding("euc-kr"));
- string[] Matching_Key_Value;
- while (!MatchingDic.EndOfStream)
- {
- string s = MatchingDic.ReadLine();
- if (!(s.Length > 0))
- {
- continue;
- }
- Matching_Key_Value = s.Split(',');
- Matching_Tag.TryAdd(Matching_Key_Value[3], Matching_Key_Value[0]);
- }
- MatchingDic.Close();
- MatchingDic.Dispose();
- StreamReader Modify_Value = new StreamReader("Modify_Value.csv", Encoding.GetEncoding("euc-kr"));
- string[] temp_Modify_Value;
- while (!Modify_Value.EndOfStream)
- {
- string s = Modify_Value.ReadLine();
- if (!(s.Length > 0))
- {
- continue;
- }
- temp_Modify_Value = s.Split(',');
- Value_Modify.TryAdd(temp_Modify_Value[3].Trim(), temp_Modify_Value[2].Trim());
- count_modify_value++;
- }
- Modify_Value.Close();
- Modify_Value.Dispose();
- LFC.Log("[Parsing] 동작시작");
- float value = 0;
- for (int TypeSelect = 0; TypeSelect < 9; TypeSelect++)
- {
- try
- {
- LFC.Log("[Parsing] 연산시작 Type : " + TypeSelect);
- StreamReader sr = new StreamReader("SettingFile.csv", Encoding.GetEncoding("euc-kr"));
- while (!sr.EndOfStream)
- {
- string s = sr.ReadLine();
- if (!(s.Length > 0))
- {
- continue;
- }
- temp = s.Split(',');
- temp[0] = temp[0].Trim();
- temp[1] = temp[1].Trim();
- temp[2] = temp[2].Trim();
- temp[4] = temp[4].Trim();
-
- if (temp[4] == "1")
- {
- Readini Ri_cool = new Readini();
- Ri_cool.ReadData();
- if ((DateTime.Now > DateTime.Parse(Ri_cool.CoolDayFromgs.Trim())) || (DateTime.Now < DateTime.Parse(Ri_cool.CoolDayTogs.Trim())))
- {
- continue;
- }
- }
- else if (temp[4] == "2")
- {
- Readini Ri_heat = new Readini();
- Ri_heat.ReadData();
- if ((DateTime.Now > DateTime.Parse(Ri_heat.HeatDayFromgs.Trim())) && (DateTime.Now < DateTime.Parse(Ri_heat.HeatDayTogs.Trim())))
- {
- continue;
- }
- }
-
- string[] PointDivid = temp[0].Split('.');
- string TmpValue = "";
- string TmpTemp = "";
- string TmpHumidity = "";
- if (temp[0] == "#")
- {
- continue;
- }
-
-
-
-
- if (temp[1] == "HumidityTemp")
- {
- Readini HT_Point = new Readini();
- HT_Point.ReadData();
- double tmpWetBulb = 0;
- if (!GetData_From_iCos.Key_Value_Dic.ContainsKey(HT_Point.TempPoint))
- {
- TmpTemp = "0";
- }
- else
- {
- TmpTemp = GetData_From_iCos.Key_Value_Dic[HT_Point.TempPoint];
- }
- if (!GetData_From_iCos.Key_Value_Dic.ContainsKey(HT_Point.HumidityPoint))
- {
- TmpHumidity = "0";
- }
- else
- {
- TmpHumidity = GetData_From_iCos.Key_Value_Dic[HT_Point.HumidityPoint];
- }
- double enthalpyValue = enthalpy_proc(Convert.ToDouble(TmpTemp), Convert.ToDouble(TmpHumidity));
- double ah_trhValue = absoluteHumidity_proc(Convert.ToDouble(TmpTemp), Convert.ToDouble(TmpHumidity));
- double tmpCurtTemp = Convert.ToDouble(TmpTemp);
- double tempCal = 0;
- for (int cal = 0; cal < 100; cal++)
- {
- tempCal = (4.2 * (ah_trhValue - absoluteHumidity_proc(tmpCurtTemp, 100)));
- if (tempCal == 0)
- {
- break;
- }
- tmpWetBulb = (enthalpyValue - enthalpy_proc(tmpCurtTemp, 100)) / tempCal;
- if (tmpWetBulb < 0.1) break;
- tmpCurtTemp = tmpCurtTemp - 0.1;
- }
- value = (float)(tmpCurtTemp);
- if (value.GetType() == typeof(DBNull))
- {
- value = 0;
- LFC.Log("[Parsging] Null 값 들어옴 : " + temp[0] + temp[1] + temp[2] + value);
- }
- value = (float)Math.Round(value, 4, MidpointRounding.AwayFromZero);
- }
-
-
- else
- {
- if (!GetData_From_iCos.Key_Value_Dic.ContainsKey(temp[1]))
- {
- TmpValue = "0";
- }
- else
- {
- TmpValue = GetData_From_iCos.Key_Value_Dic[temp[1]];
- }
- value = (float)Convert.ToDouble(TmpValue);
- if (value.GetType() == typeof(DBNull))
- {
- value = 0;
- LFC.Log(temp[0] + temp[1] + temp[2] + "Null 값이 들어왔습니다." + value);
- }
- value = (float)Math.Round(value, 4, MidpointRounding.AwayFromZero);
- }
- if (count_modify_value > 0 && (Value_Modify.ContainsKey(temp[0]) == true))
- {
- MSScriptControl.ScriptControl sc = new MSScriptControl.ScriptControl();
- sc.Language = "VBScript";
- string Pattern = "Tag" + @"\d{1,5}";
- Regex regex = new Regex(Pattern);
- string Exp = Value_Modify[temp[0]];
- foreach (Match match in regex.Matches(Exp))
- {
- string Tag_Name = Convert.ToString(match);
-
- Exp = Exp.Replace(Tag_Name, value.ToString());
- }
- value = (float)Convert.ToDouble(sc.Eval(Exp));
- }
- float[] values = new float[14];
- values[0] = value;
- values[1] = 1;
- values[2] = float.Parse(PointDivid[0]);
- values[3] = float.Parse(PointDivid[1]);
- values[4] = float.Parse(PointDivid[2]);
- values[5] = float.Parse(PointDivid[3]);
-
- values[13] = value;
- if (RawData.ContainsKey(temp[0]) == false)
- {
- RawData.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp1ValueRaw = RawData[temp[0]];
- Tmp1ValueRaw[0] = values[0];
- Tmp1ValueRaw[7] = TypeSelect;
- RawData.TryUpdate(temp[0], Tmp1ValueRaw, values);
- }
- if (temp[2].Equals(Convert.ToString(TypeSelect)))
- {
- switch (TypeSelect)
- {
- case 1:
-
- if (AverageData.ContainsKey(temp[0]) == false)
- {
- AverageData.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp1Value = AverageData[temp[0]];
- Tmp1Value[0] = Tmp1Value[0] + values[0];
- Tmp1Value[1] = Tmp1Value[1] + values[1];
- Tmp1Value[7] = TypeSelect;
- Tmp1Value[13] = values[13];
- AverageData.TryUpdate(temp[0], Tmp1Value, values);
- }
- break;
- case 2:
-
-
- if (value < 0)
- value = 0;
- if (AddData.ContainsKey(temp[0]) == false)
- {
- AddData.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp1Value2 = AddData[temp[0]];
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Tmp1Value2[6] += value - Tmp1Value2[0];
-
-
- Tmp1Value2[0] = value;
- Tmp1Value2[1] = Tmp1Value2[1] + values[1];
- Tmp1Value2[7] = TypeSelect;
- Tmp1Value2[13] = values[13];
-
- AddData.AddOrUpdate(temp[0], Tmp1Value2, (k, v) => Tmp1Value2);
- }
- break;
-
- case 3:
-
- if (NowData.ContainsKey(temp[0]) == false)
- {
- NowData.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp1Value5 = NowData[temp[0]];
- Tmp1Value5[0] = value;
- Tmp1Value5[7] = TypeSelect;
- NowData.TryUpdate(temp[0], Tmp1Value5, values);
- }
- break;
- case 4:
-
- if (value < 0)
- value = 0;
- if (OnData.ContainsKey(temp[0]) == false)
- {
- OnData.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp1Value3 = OnData[temp[0]];
- Tmp1Value3[0] = Tmp1Value3[0] + values[0];
- Tmp1Value3[1] = Tmp1Value3[1] + values[1];
- Tmp1Value3[7] = TypeSelect;
- Tmp1Value3[13] = values[13];
- OnData.TryUpdate(temp[0], Tmp1Value3, values);
- }
- break;
- case 5:
-
- if (value < 0)
- value = 0;
- if (Add2Data.ContainsKey(temp[0]) == false)
- {
- Add2Data.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp6Value = Add2Data[temp[0]];
- Tmp6Value[0] = Tmp6Value[0] + values[0];
- Tmp6Value[1] = Tmp6Value[1] + values[1];
- Tmp6Value[7] = TypeSelect;
- Tmp6Value[13] = values[13];
- Add2Data.TryUpdate(temp[0], Tmp6Value, values);
- }
- break;
- case 6:
-
- if (value < 0)
- value = 0;
- if (Now2Data.ContainsKey(temp[0]) == false)
- {
- Now2Data.TryAdd(temp[0], values);
- }
- else
- {
- float[] Tmp1Value4 = Now2Data[temp[0]];
- Tmp1Value4[0] = Tmp1Value4[0] + values[0];
- Tmp1Value4[1] = Tmp1Value4[1] + values[1];
- Tmp1Value4[7] = TypeSelect;
- Tmp1Value4[13] = values[13];
- Now2Data.TryUpdate(temp[0], Tmp1Value4, values);
- }
-
- break;
- case 7:
- OneMinute_Insert OMI = new OneMinute_Insert();
- OMI.OneMin_Insert(values[2], values[0]);
- OMI.PeakCheck(values[0]);
- break;
- case 8:
- break;
- }
- }
- }
- sr.Close();
- sr.Dispose();
- }
- catch (Exception e)
- {
- LFC.Log("[Parsing] 에러발생 : " + e);
- }
- }
-
- SW.Stop();
- sTemp1 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 연산시간 : " + sTemp1 + Environment.NewLine);
-
- int TmpMinNow = Convert.ToInt32(DateTime.Now.Minute.ToString());
- if ((TmpMinNow % 15) == 0)
- {
- _thread = new Thread(new ThreadStart(Thread_Test1));
- _thread.Start();
- }
- string CompleteTime = DateTime.Now.Minute.ToString();
- return CompleteTime;
- }
- public void Thread_Test1()
- {
- try
- {
- DateTime TmpDate = DateTime.Now;
- int TmpMinNow = Convert.ToInt32(TmpDate.Minute.ToString());
- string Hour = (TmpDate).ToString("yyyy-MM-dd HH:00:00.000");
- LogFileCreate LFC = new LogFileCreate();
- Expression_Process EP = new Expression_Process();
-
- Stopwatch SW = new Stopwatch();
- string sTemp1;
- SW.Reset();
- SW.Start();
-
- #region CopyData
- TmpAverageData = new ConcurrentDictionary<string, float[]>(AverageData);
- TmpAddData = new ConcurrentDictionary<string, float[]>(AddData);
- TmpNowData = new ConcurrentDictionary<string, float[]>(NowData);
- TmpOnData = new ConcurrentDictionary<string, float[]>(OnData);
- TmpAdd2Data = new ConcurrentDictionary<string, float[]>(Add2Data);
- TmpNow2Data = new ConcurrentDictionary<string, float[]>(Now2Data);
- TmpRawData = new ConcurrentDictionary<string, float[]>(RawData);
- #endregion
- SW.Stop();
- sTemp1 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 데이터 복사한 시간 : "+ sTemp1);
-
-
- string sTemp2;
- SW.Reset();
- SW.Start();
- #region Data_Calculate
- AverageCal_Min(TmpAverageData, TmpMinNow);
- AddCal_Min(TmpAddData, TmpMinNow);
- NowCal_Min(TmpNowData, TmpMinNow);
- OnCal_Min(TmpOnData, TmpMinNow);
- Add2Cal_Min(TmpAdd2Data, TmpMinNow);
- Now2Cal_Min(TmpNow2Data, TmpMinNow);
- #endregion
- var Tmp_Expression_result_FifMin = TmpAverageData.Union(TmpAddData).Union(TmpNowData).Union(TmpOnData).Union(TmpAdd2Data).Union(TmpNow2Data).ToDictionary(k => k.Key, v => v.Value);
- EP.ReadCSV_Passing_Expression(RawData, TmpMinNow, "Raw", Matching_Tag);
- EP.ReadCSV_Passing_Expression(Tmp_Expression_result_FifMin, TmpMinNow, "FiftMin", Matching_Tag);
- SW.Stop();
- sTemp2 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 15분 데이터 계산한 시간 : " +sTemp2);
-
-
- My_DB_DML DBI = new My_DB_DML();
- string sTemp_delete;
- SW.Reset();
- SW.Start();
-
- DBI.DB_Min_Delete(TmpAverageData, TmpMinNow);
- DBI.DB_Min_Delete(TmpAddData, TmpMinNow);
- DBI.DB_Min_Delete(TmpOnData, TmpMinNow);
- DBI.DB_Min_Delete(TmpAdd2Data, TmpMinNow);
- DBI.DB_Min_Delete(TmpNow2Data, TmpMinNow);
- SW.Stop();
- sTemp_delete = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 15분 데이터 삭제한 시간 : " + sTemp_delete);
- string sTemp3;
- SW.Reset();
- SW.Start();
-
- #region 15분삽입
- DBI.DB_Min_Insert(TmpAverageData, TmpMinNow);
- DBI.DB_Min_Insert(TmpAddData, TmpMinNow);
- DBI.DB_Min_Insert(TmpNowData, TmpMinNow);
- DBI.DB_Min_Insert(TmpOnData, TmpMinNow);
- DBI.DB_Min_Insert(TmpAdd2Data, TmpMinNow);
- DBI.DB_Min_Insert(TmpNow2Data, TmpMinNow);
- RawCal(TmpMinNow);
- #endregion
- SW.Stop();
- sTemp3 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 15분 데이터 삽입한 시간 : "+ sTemp3);
- string sTemp_Now;
- SW.Reset();
- SW.Start();
-
- DBI.DB_Min_Insert_Now(TmpAverageData, TmpMinNow);
- DBI.DB_Min_Insert_Now(TmpAddData, TmpMinNow);
- DBI.DB_Min_Insert_Now(TmpOnData, TmpMinNow);
- DBI.DB_Min_Insert_Now(TmpAdd2Data, TmpMinNow);
- DBI.DB_Min_Insert_Now(TmpNow2Data, TmpMinNow);
-
- SW.Stop();
- sTemp_Now = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 15분 현재값 삽입한 시간 : " + sTemp_Now);
- string sTemp4;
- SW.Reset();
- SW.Start();
-
- #region Hour_Data_Calculate
- HourCalCulate_Average(TmpAverageData, TmpMinNow);
- HourCalCulate_Add(TmpAddData, TmpMinNow);
- HourCalCulate_Now(TmpNowData, TmpMinNow);
- HourCalCulate_On(TmpOnData, TmpMinNow);
- HourCalCulate_Add2(TmpAdd2Data, TmpMinNow);
- HourCalCulate_Now2(TmpNow2Data, TmpMinNow);
- #endregion
-
- SW.Stop();
- sTemp4 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 시간 데이터 연산한 시간 : " + sTemp4);
- var Tmp_Expression_result_Hour = TmpAverageData.Union(TmpAddData).Union(TmpNowData).Union(TmpOnData).Union(TmpAdd2Data).Union(TmpNow2Data).ToDictionary(k => k.Key, v => v.Value);
- EP.ReadCSV_Passing_Expression(Tmp_Expression_result_Hour, TmpMinNow, "Hour", Matching_Tag);
-
- string sTemp5;
- SW.Reset();
- SW.Start();
-
- DBI.DB_Hour_Update(TmpAverageData, TmpMinNow, Hour);
- DBI.DB_Hour_Update(TmpAddData, TmpMinNow, Hour);
- if (TmpMinNow == 00)
- {
- DBI.DB_Hour_Update(TmpNowData, TmpMinNow, Hour);
- }
- DBI.DB_Hour_Update(TmpOnData, TmpMinNow, Hour);
- DBI.DB_Hour_Update(TmpAdd2Data, TmpMinNow, Hour);
- DBI.DB_Hour_Update(TmpNow2Data, TmpMinNow, Hour);
-
- SW.Stop();
- sTemp5 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 시간 데이터 삽입한 시간 : " + sTemp5);
- string sTemp6;
- SW.Reset();
- SW.Start();
- #region Daily_Update
- DBI.DB_Day_Update(TmpAverageData, TmpMinNow, Hour);
- SW.Stop();
- sTemp6 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 하루 데이터 삽입한 시간(평균) : "+ sTemp6);
- string sTemp7;
- SW.Reset();
- SW.Start();
- DBI.DB_Day_Update(TmpAddData, TmpMinNow, Hour);
- SW.Stop();
- sTemp7 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 하루 데이터 삽입한 시간(적산) : " + sTemp7);
- string sTemp8;
- SW.Reset();
- SW.Start();
- DBI.DB_Day_Update(TmpNowData, TmpMinNow, Hour);
- SW.Stop();
- sTemp8 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 하루 데이터 삽입한 시간(현재) : " + sTemp8);
-
- string sTemp10;
- SW.Reset();
- SW.Start();
- DBI.DB_Day_Update(TmpAdd2Data, TmpMinNow, Hour);
- SW.Stop();
- sTemp10 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 하루 데이터 삽입한 시간(적산2) : " + sTemp10);
- string sTemp11;
- SW.Reset();
- SW.Start();
- DBI.DB_Day_Update(TmpNow2Data, TmpMinNow, Hour);
- SW.Stop();
- sTemp11 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 하루 데이터 삽입한 시간(현재2) : " + sTemp11);
- string sTemp9;
- SW.Reset();
- SW.Start();
- DBI.DB_Day_Update(TmpOnData, TmpMinNow, Hour);
- SW.Stop();
- sTemp9 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 하루 데이터 삽입한 시간(가동시간) : " + sTemp9);
- #endregion
-
- #region Dic_Clear
- TmpAverageData.Clear();
- TmpAddData.Clear();
- TmpNowData.Clear();
- TmpOnData.Clear();
- TmpNow2Data.Clear();
- TmpAdd2Data.Clear();
- TmpRawData.Clear();
- #endregion
-
-
- SW.Stop();
- sTemp1 = SW.Elapsed.ToString();
- LFC.Log("[Parsing] 스레드 연산 시간 : "+ sTemp1 + Environment.NewLine);
-
- _thread.Abort();
- LFC.Log("[Parsing] 스레드 종료");
- }
- catch (Exception e)
- {
- LogFileCreate LFC = new LogFileCreate();
- LFC.Log("[Parsing] 에러 발생 :" + e);
- }
- finally
- {
-
- #region Dic_Clear
- TmpAverageData.Clear();
- TmpAddData.Clear();
- TmpNowData.Clear();
- TmpOnData.Clear();
- TmpNow2Data.Clear();
- TmpAdd2Data.Clear();
- TmpRawData.Clear();
- #endregion
- }
- }
-
-
-
-
- public void AverageCal_Min(IDictionary<string, float[]> AvrDic, int Min)
- {
-
- foreach (KeyValuePair<string, float[]> kv in AvrDic)
- {
-
- float[] TmpValue = kv.Value;
- TmpValue[0] = TmpValue[0] / TmpValue[1];
- int CheckData = Select_MinTime_Data(Min);
- TmpValue[CheckData] = TmpValue[0];
- TmpAverageData.TryUpdate(kv.Key, TmpValue, kv.Value);
-
- TmpValue[0] = 0;
- TmpValue[1] = 0;
- AverageData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
-
-
-
-
- public void AddCal_Min(IDictionary<string, float[]> AddDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in AddDic)
- {
- float[] TmpValue = kv.Value;
- int CheckData = Select_MinTime_Data(Min);
- TmpValue[CheckData] = TmpValue[6];
- TmpAddData.TryUpdate(kv.Key, TmpValue, kv.Value);
- TmpValue[6] = 0;
- TmpValue[1] = 0;
- AddData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
-
-
-
-
- public void NowCal_Min(IDictionary<string, float[]> NowDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in NowDic)
- {
- float[] TmpValue = kv.Value;
- int CheckData = Select_MinTime_Data(Min);
- TmpValue[CheckData] = TmpValue[0];
- TmpNowData.TryUpdate(kv.Key, TmpValue, kv.Value);
- TmpValue[0] = 0;
- TmpValue[1] = 0;
- NowData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
-
-
-
-
- public void OnCal_Min(IDictionary<string, float[]> OnDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in OnDic)
- {
- float[] TmpValue = kv.Value;
- int CheckData = Select_MinTime_Data(Min);
- TmpValue[CheckData] = TmpValue[0];
- TmpOnData.TryUpdate(kv.Key, TmpValue, kv.Value);
- TmpValue[0] = 0;
- TmpValue[1] = 0;
- OnData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
-
-
-
-
- public void Add2Cal_Min(IDictionary<string, float[]> Add2Dic, int Min)
- {
-
- foreach (KeyValuePair<string, float[]> kv in Add2Dic)
- {
-
- float[] TmpValue = kv.Value;
- TmpValue[0] = (TmpValue[0] / TmpValue[1]) / 4;
- int CheckData = Select_MinTime_Data(Min);
- TmpValue[CheckData] = TmpValue[0];
- TmpAdd2Data.TryUpdate(kv.Key, TmpValue, kv.Value);
-
- TmpValue[0] = 0;
- TmpValue[1] = 0;
- Add2Data.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public void Now2Cal_Min(IDictionary<string, float[]> Now2Dic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in Now2Dic)
- {
- float[] TmpValue = kv.Value;
- if (TmpValue[0] > 0)
- {
- TmpValue[0] = 1;
- }
- else
- {
- TmpValue[0] = 0;
- }
- int CheckData = Select_MinTime_Data(Min);
- TmpValue[CheckData] = TmpValue[0];
- TmpNow2Data.TryUpdate(kv.Key, TmpValue, kv.Value);
- TmpValue[0] = 0;
- TmpValue[1] = 0;
- Now2Data.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- private StringBuilder RawCal_sb = new StringBuilder();
- public void RawCal(int Min)
- {
-
- if ((Min % 15) == 0)
- {
- My_DB_DML MDD = new My_DB_DML();
- string strcon = MDD.ConnDBInfo();
- string query = "";
- string InsertDate = DateTime.Now.ToString("yyyy-MM-dd HH:" + Min + ":00.000");
- using (SqlConnection conn = new SqlConnection(strcon))
- {
- conn.Open();
- foreach (KeyValuePair<string, float[]> kv in TmpRawData)
- {
- float[] TmpValue = kv.Value;
- RawCal_sb.Append("INSERT INTO BemsMonitoringPointHistory15minRawData(SiteId,FacilityTypeId,FacilityCode,PropertyId,CreatedDateTime,CurrentValue) ");
- RawCal_sb.Append("VALUES(" + TmpValue[2] + "," + TmpValue[3] + "," + TmpValue[4] + "," + TmpValue[5] + ",'" + InsertDate + "'," + Math.Round(TmpValue[0], 4, MidpointRounding.AwayFromZero) + ")");
- query = RawCal_sb.ToString();
-
-
- SqlCommand cmd = new SqlCommand(query, conn);
- cmd.ExecuteNonQuery();
- cmd.Dispose();
- RawCal_sb.Clear();
- }
- conn.Close();
- conn.Dispose();
- }
- }
- }
-
-
-
-
- public int Select_MinTime_Data(int Min)
- {
- int Check = 0;
- switch (Min)
- {
- case 00:
- Check = 11;
- break;
- case 15:
- Check = 8;
- break;
- case 30:
- Check = 9;
- break;
- case 45:
- Check = 10;
- break;
- }
- return Check;
- }
- public void HourCalCulate_Average(IDictionary<string, float[]> AvDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in AvDic)
- {
- float[] TmpValue = kv.Value;
- switch (Min)
- {
- case 00:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10] + TmpValue[11]) / 4; break;
- case 15:
- TmpValue[12] = TmpValue[8]; break;
- case 30:
- TmpValue[12] = (TmpValue[8] + TmpValue[9]) / 2; break;
- case 45:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10]) / 3; break;
- }
- TmpAverageData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public void HourCalCulate_Add(IDictionary<string, float[]> AddDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in AddDic)
- {
- float[] TmpValue = kv.Value;
- switch (Min)
- {
- case 00:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10] + TmpValue[11]); break;
- case 15:
- TmpValue[12] = TmpValue[8]; break;
- case 30:
- TmpValue[12] = (TmpValue[8] + TmpValue[9]); break;
- case 45:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10]); break;
- }
- TmpAddData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public void HourCalCulate_Now(IDictionary<string, float[]> NowDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in NowDic)
- {
- float[] TmpValue = kv.Value;
- switch (Min)
- {
- case 00:
- TmpValue[12] = (TmpValue[11]); break;
- case 15:
- TmpValue[12] = TmpValue[8]; break;
- case 30:
- TmpValue[12] = (TmpValue[9]); break;
- case 45:
- TmpValue[12] = (TmpValue[10]); break;
- }
- TmpNowData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public void HourCalCulate_On(IDictionary<string, float[]> OnDic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in OnDic)
- {
- float[] TmpValue = kv.Value;
- switch (Min)
- {
- case 00:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10] + TmpValue[11]); break;
- case 15:
- TmpValue[12] = TmpValue[8]; break;
- case 30:
- TmpValue[12] = (TmpValue[8] + TmpValue[9]); break;
- case 45:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10]); break;
- }
- TmpOnData.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public void HourCalCulate_Add2(IDictionary<string, float[]> Add2Dic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in Add2Dic)
- {
- float[] TmpValue = kv.Value;
- switch (Min)
- {
- case 00:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10] + TmpValue[11]); break;
- case 15:
- TmpValue[12] = TmpValue[8]; break;
- case 30:
- TmpValue[12] = (TmpValue[8] + TmpValue[9]); break;
- case 45:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10]); break;
- }
- TmpAdd2Data.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public void HourCalCulate_Now2(IDictionary<string, float[]> Now2Dic, int Min)
- {
- foreach (KeyValuePair<string, float[]> kv in Now2Dic)
- {
- float[] TmpValue = kv.Value;
- switch (Min)
- {
- case 00:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10] + TmpValue[11]);
- break;
- case 15:
- TmpValue[12] = TmpValue[8]; break;
- case 30:
- TmpValue[12] = (TmpValue[8] + TmpValue[9]); break;
- case 45:
- TmpValue[12] = (TmpValue[8] + TmpValue[9] + TmpValue[10]); break;
- }
- if (TmpValue[12] > 1)
- {
- TmpValue[12] = 1;
- }
- else
- {
- TmpValue[12] = 0;
- }
- TmpNow2Data.TryUpdate(kv.Key, TmpValue, kv.Value);
- }
- }
- public string[] TagParsing()
- {
- string[] TagSum = new string[2];
- string[] CSVReadLine = new string[2];
- int count = 0;
- StringBuilder Sb = new StringBuilder();
- StreamReader sr = new StreamReader("TagSetFile.csv", Encoding.GetEncoding("euc-kr"));
- while (!sr.EndOfStream)
- {
-
- string temp = sr.ReadLine();
- if (!(temp.Length > 0))
- {
- continue;
- }
- CSVReadLine = temp.Split(',');
- CSVReadLine[1] = CSVReadLine[1].Trim();
- Sb.Append(CSVReadLine[1] + ",");
- count++;
- }
- sr.Close();
- sr.Dispose();
- TagSum[0] = Sb.ToString();
- TagSum[0] = TagSum[0].Substring(0, TagSum[0].Length - 1);
- TagSum[1] = Convert.ToString(count);
- Sb.Clear();
- return TagSum;
- }
- }
- }
|