private HeatingCoolingDegreeDays HeatingCoolingDegreeDaysValueOf(ReadingsQueryResult result, List <WeatherData> weatherDataList) { HeatingCoolingDegreeDays hcdd = new HeatingCoolingDegreeDays { CDD = 0.0, HDD = 0.0, }; foreach (WeatherData weatherData in weatherDataList) { if (!weatherData.AvgTmp.HasValue) { throw new Exception("WeatherData.AvgTmp is null for " + weatherData.ZipCode + " on " + weatherData.RDate); } else if (result.B5 > 0 && weatherData.AvgTmp >= result.B5) { hcdd.CDD += (weatherData.AvgTmp.Value - result.B5); } else if (result.B3 > 0 && weatherData.AvgTmp < result.B3) { hcdd.HDD += (result.B3 - weatherData.AvgTmp.Value); } } return(hcdd); }
private HeatingCoolingDegreeDays HeatingCoolingDegreeDaysValueOf(ReadingsQueryResult result, List <WeatherData> weatherDataList) { HeatingCoolingDegreeDays hcdd = new HeatingCoolingDegreeDays(); hcdd.CDD = 0.0; hcdd.HDD = 0.0; if (result.B3 == 0 && result.B5 == 0) { return(hcdd); } foreach (WeatherData weatherData in weatherDataList) { if (result.B5 > 0) { if (weatherData.AvgTmp >= result.B5) { hcdd.CDD = hcdd.CDD + (weatherData.AvgTmp.Value - result.B5); } } else if (result.B3 > 0) { if (weatherData.AvgTmp <= result.B3) { hcdd.HDD = hcdd.HDD + (result.B3 - weatherData.AvgTmp.Value); } } } return(hcdd); }
private void DoCalculation(ReadingsQueryResult result, HeatingCoolingDegreeDays heatingCoolingDegreeDays) { // Normalized Energy Usage = E = B1(DAYS) + B2(HDDB3) + B4(CDDB5) double? resultAsDouble = (result.B1 * result.Days) + (result.B2 * heatingCoolingDegreeDays.HDD) + (result.B4 * heatingCoolingDegreeDays.CDD); decimal resultAsDecimal = decimal.Round(Convert.ToDecimal(resultAsDouble), 4, MidpointRounding.AwayFromZero); bool success = _weatherRepository.InsertWthExpUsage(result.RdngID, resultAsDecimal); if (success) { Log.Debug($"Inserted into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} (actual usage: {result.Units}) ... " + $"B1: {result.B1} Days: {result.Days}, " + $"B2: {result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD}, " + $"B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD}, " + $"AccID/UtilID/UnitID: {result.AccID}/{result.UtilID}/{result.UnitID}, R2: {result.R2}."); _actualWthExpUsageInserts++; } else { Log.Error($"FAILED attempt: insert into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: " + $"{result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"AccID/UtilID/UnitID: {result.AccID}/{result.UtilID}/{result.UnitID}, R2: {result.R2}"); } }
private decimal CalculateExpUsageForNomalizing(ReadingsQueryResult result, HeatingCoolingDegreeDays heatingCoolingDegreeDays) { double? resultAsDouble = (result.B1 * result.Days) + (result.B2 * heatingCoolingDegreeDays.HDD) + (result.B4 * heatingCoolingDegreeDays.CDD); decimal resultAsDecimal = decimal.Round(Convert.ToDecimal(resultAsDouble), 4, MidpointRounding.AwayFromZero); return(resultAsDecimal); }
private decimal CalculateExpUsage(ReadingsQueryResult result, HeatingCoolingDegreeDays heatingCoolingDegreeDays) { // Normalized Energy Usage = E = B1(DAYS) + B2(HDDB3) + B4(CDDB5) double? resultAsDouble = (result.B1 * result.Days) + (result.B2 * heatingCoolingDegreeDays.HDD) + (result.B4 * heatingCoolingDegreeDays.CDD); decimal resultAsDecimal = decimal.Round(Convert.ToDecimal(resultAsDouble), 4, MidpointRounding.AwayFromZero); bool success = _weatherRepository.InsertWthExpUsage(result.RdngID, resultAsDecimal, result.AccID, result.UtilID, result.RUnitID); if (success) { Log.Information($"Inserted into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: {result.B2} " + $"B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"RdngUnitID: {result.RUnitID} WthNormalParamsUnitID: {result.WnpUnitID}"); actualWthExpUsageInserts++; } else { Log.Error($"FAILED attempt: insert into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: " + $"{result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"RdngUnitID: {result.RUnitID} WthNormalParamsUnitID: {result.WnpUnitID}"); } return(resultAsDecimal); }
private bool[] DoCalculation(ReadingsQueryResult result, HeatingCoolingDegreeDays heatingCoolingDegreeDays) { double resultAsDouble = (result.B1 * result.Days) + (result.B2 * heatingCoolingDegreeDays.HDD) + (result.B4 * heatingCoolingDegreeDays.CDD); decimal resultAsDecimal = decimal.Round(Convert.ToDecimal(resultAsDouble), 4, MidpointRounding.AwayFromZero); bool existed = _weatherRepository.GetWthExpUsageExists(result.RdngID); bool success; if (existed) { success = _weatherRepository.UpdateWthExpUsage(result.RdngID, resultAsDecimal); } else { success = _weatherRepository.InsertWthExpUsage(result.RdngID, resultAsDecimal); } if (existed && success) { Log.Debug($"Updated WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} (actual usage: {result.Units}) ... " + $"B1: {result.B1} Days: {result.Days}, " + $"B2: {result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD}," + $" B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD}, " + $"AccID/UtilID/UnitID: {result.AccID}/{result.UtilID}/{result.UnitID}, R2: {result.R2}."); } else if (existed && !success) { Log.Error($"Failed attempt: Update WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} (actual usage: {result.Units}) ... " + $"B1: {result.B1} Days: {result.Days}, " + $"B2: {result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD}, " + $"B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD}, " + $"AccID/UtilID/UnitID: {result.AccID}/{result.UtilID}/{result.UnitID}, R2: {result.R2}."); } else if (!existed && success) { Log.Debug($"Inserted into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} (actual usage: {result.Units}) ... " + $"B1: {result.B1} Days: {result.Days}, " + $"B2: {result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD}, " + $"B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD}, " + $"AccID/UtilID/UnitID: {result.AccID}/{result.UtilID}/{result.UnitID}, R2: {result.R2}."); } else if (!existed && !success) { Log.Error($"Failed attempt: Insert into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} (actual usage: {result.Units}) ... " + $"B1: {result.B1} Days: {result.Days}, " + $"B2: {result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD}, " + $"B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD}, " + $"AccID/UtilID/UnitID: {result.AccID}/{result.UtilID}/{result.UnitID}, R2: {result.R2}."); } return(new bool[] { success, existed }); }
private HeatingCoolingDegreeDays HeatingCoolingDegreeDaysValueOf(ReadingsQueryResult result, List <WeatherData> weatherDataList) { HeatingCoolingDegreeDays hcdd = new HeatingCoolingDegreeDays(); hcdd.CDD = 0.0; hcdd.HDD = 0.0; if (result.B3 == 0 && result.B5 == 0) { return(hcdd); } foreach (WeatherData weatherData in weatherDataList) { if (!weatherData.AvgTmp.HasValue) { throw new Exception($"WeatherData.AvgTmp is null for {weatherData.ZipCode} on {weatherData.RDate}"); } //else if (result.B5 > 0) //{ // if (weatherData.AvgTmp >= result.B5) // { // hcdd.CDD = hcdd.CDD + (weatherData.AvgTmp.Value - result.B5); // } //} //else if (result.B3 > 0) //{ // if (weatherData.AvgTmp <= result.B3) // { // hcdd.HDD = hcdd.HDD + (result.B3 - weatherData.AvgTmp.Value); // } //} if (result.B5 > 0 && weatherData.AvgTmp >= result.B5) { hcdd.CDD = hcdd.CDD + (weatherData.AvgTmp.Value - result.B5); } if (result.B3 > 0 && weatherData.AvgTmp <= result.B3) { hcdd.HDD = hcdd.HDD + (result.B3 - weatherData.AvgTmp.Value); } } return(hcdd); }
private bool[] DoCalculation(ReadingsQueryResult result, HeatingCoolingDegreeDays heatingCoolingDegreeDays) { double resultAsDouble = (result.B1 * result.Days) + (result.B2 * heatingCoolingDegreeDays.HDD) + (result.B4 * heatingCoolingDegreeDays.CDD); decimal resultAsDecimal = decimal.Round(Convert.ToDecimal(resultAsDouble), 4, MidpointRounding.AwayFromZero); bool exists = _weatherRepository.GetWthExpUsageExists(result.RdngID); bool success; if (exists) { success = _weatherRepository.UpdateWthExpUsage(result.RdngID, resultAsDecimal); } else { success = _weatherRepository.InsertWthExpUsage(result.RdngID, resultAsDecimal); } if (exists && success) { Log.Information($"Update WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: {result.B2} " + $"B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"RdngUnitID: {result.RUnitID} WthNormalParamsUnitID: {result.WnpUnitID}"); } else if (exists && !success) { Log.Error($"FAILED attempt: Update WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: " + $"{result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"RdngUnitID: {result.RUnitID} WthNormalParamsUnitID: {result.WnpUnitID}"); } else if (!exists && success) { Log.Information($"Inserted into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: {result.B2} " + $"B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"RdngUnitID: {result.RUnitID} WthNormalParamsUnitID: {result.WnpUnitID}"); } else if (!exists && !success) { Log.Error($"FAILED attempt: Insert into WthExpUsage >> RdngID: {result.RdngID} WthExpUsage: {resultAsDecimal} ... B1: {result.B1} B2: " + $"{result.B2} B3: {result.B3} Hdd: {heatingCoolingDegreeDays.HDD} B4: {result.B4} B5: {result.B5} Cdd: {heatingCoolingDegreeDays.CDD} " + $"RdngUnitID: {result.RUnitID} WthNormalParamsUnitID: {result.WnpUnitID}"); } return(new bool[] { exists, success }); }
private void InsertMyReadings(ReadingsQueryResult reading) { string Sql = @"Insert into Readings (RdngID, ExpUsage, AccID, UtilID, UnitID, Units, DateStart, DateEnd, Days) Values (@RdngID, @ExpUsage, @AccID, @UtilID, @UnitID, @Units, @DateStart, @DateEnd, @Days)"; using (IDbConnection db = new SqlConnection(_myConnectionString)) { int rowsAffected = db.Execute(Sql, new { reading.RdngID, reading.ExpUsage, reading.AccID, reading.UtilID, UnitID = reading.RUnitID, reading.Units, reading.DateStart, reading.DateEnd, reading.Days }); } }
public List <ReadingsQueryResult> GetReadingsFromExpUsageOriginalCorrected(AccordResult accord) { List <WthNormalParams> myParams = new List <WthNormalParams>(); List <ReadingsQueryResult> allReadings = new List <ReadingsQueryResult>(); string Sql = @"select wnp.AccID, wnp.UtilID, wnp.UnitID, weu.ExpUsage, weu.RdngID from WthNormalParams wnp join WthExpUsage weu on wnp.AccID = weu.AccID and wnp.UtilID = weu.UtilID and wnp.UnitID = weu.UnitID where wnp.R2_New > 0.8 and wnp.AccID = @AccID and wnp.UtilID = @UtilID and wnp.UnitID = @UnitID"; //where wnp.R2_New > 0.8;"; using (IDbConnection db = new SqlConnection(_myConnectionString)) { myParams = db.Query <WthNormalParams>(Sql, new { accord.AccID, accord.UtilID, accord.UnitID }).AsList(); } var myParamsGroups = myParams.GroupBy(p => new { p.AccID, p.UtilID, p.UnitID }); foreach (var group in myParamsGroups) { List <WthNormalParams> wthNormalParams = group.ToList(); foreach (WthNormalParams wnp in wthNormalParams) { ReadingsQueryResult reading = new ReadingsQueryResult(); string Sql2 = @"select RdngID, AccID, UtilID, UnitID as RUnitID, ExpUsage, Units, DateStart, DateEnd, Days from Readings where RdngID = @RdngID;"; using (IDbConnection db = new SqlConnection(_myConnectionString)) { reading = db.Query <ReadingsQueryResult>(Sql2, new { wnp.RdngID }).First(); } allReadings.Add(reading); //string Sql2 = @"select AccID, UtilID, UnitID as RUnitID, RdngID, Units, DateStart, DateEnd, Days from Readings // where RdngID = @RdngID;"; //try //{ // using (IDbConnection db = new SqlConnection(_jitWebData3ConnectionString)) // { // reading = db.Query<ReadingsQueryResult>(Sql2, new { wnp.RdngID }).First(); // } // reading.ExpUsage = wnp.ExpUsage; // allReadings.Add(reading); // try // { // InsertMyReadings(reading); // } // catch (Exception e) { Console.WriteLine(e.Message + " " + e.StackTrace); } //} catch (Exception e) // { // Console.WriteLine(e.Message + " " + wnp.RdngID); // } } } return(allReadings); }