| 576 | } |
| 577 | |
| 578 | void SqlFile_Impl::insertIlluminanceMap(const std::string& t_zoneName, const std::string& t_name, const std::string& t_environmentName, |
| 579 | const std::vector<DateTime>& t_times, const std::vector<double>& t_xs, const std::vector<double>& t_ys, |
| 580 | double t_z, const std::vector<Matrix>& t_maps) { |
| 581 | boost::optional<int> zoneIndex = execAndReturnFirstInt("select ZoneIndex from zones where ZoneName=?;", t_zoneName); |
| 582 | |
| 583 | if (!zoneIndex) { |
| 584 | throw std::runtime_error("Unknown zone name: " + t_zoneName); |
| 585 | } |
| 586 | |
| 587 | if (t_times.size() != t_maps.size()) { |
| 588 | throw std::runtime_error("Number of times does not match number of maps"); |
| 589 | } |
| 590 | |
| 591 | int mapIndex = getNextIndex("daylightmaps", "MapNumber"); |
| 592 | |
| 593 | std::string referencePt1 = "RefPt1=(" + boost::lexical_cast<std::string>(t_xs.front()) + ":" + boost::lexical_cast<std::string>(t_ys.front()) |
| 594 | + ":" + boost::lexical_cast<std::string>(t_z) + ")"; |
| 595 | |
| 596 | std::string referencePt2 = "RefPt1=(" + boost::lexical_cast<std::string>(t_xs.back()) + ":" + boost::lexical_cast<std::string>(t_ys.back()) + ":" |
| 597 | + boost::lexical_cast<std::string>(t_z) + ")"; |
| 598 | |
| 599 | std::stringstream mapInsert; |
| 600 | mapInsert << "insert into daylightmaps (MapNumber, MapName, Environment, Zone, ReferencePt1, ReferencePt2, Z) values (" << mapIndex << ", " << "'" |
| 601 | << t_name << "', " << "'" << t_environmentName << "', " << *zoneIndex << ", " << "'" << referencePt1 << "', " << "'" << referencePt2 |
| 602 | << "', " << t_z << ");"; |
| 603 | |
| 604 | execAndThrowOnError(mapInsert.str()); |
| 605 | |
| 606 | int hourlyReportIndex = getNextIndex("daylightmaphourlyreports", "HourlyReportIndex"); |
| 607 | |
| 608 | // E+ added the "Year" field to the DaylightMapHourlyReports in version 9.2.0 (NREL/EnergyPlus#7235) |
| 609 | // assignment of PreparedStatement does not work, so use a pointer to statement to handle the case where you do or do not have Year |
| 610 | std::shared_ptr<PreparedStatement> stmt1; |
| 611 | if (hasIlluminanceMapYear()) { |
| 612 | stmt1 = std::make_shared<PreparedStatement>( |
| 613 | "insert into daylightmaphourlyreports (HourlyReportIndex, MapNumber, Year, Month, DayOfMonth, Hour) values (?, ?, ?, ?, ?, ?)", m_db, true); |
| 614 | } else { |
| 615 | stmt1 = std::make_shared<PreparedStatement>( |
| 616 | "insert into daylightmaphourlyreports (HourlyReportIndex, MapNumber, Month, DayOfMonth, Hour) values (?, ?, ?, ?, ?)", m_db, true); |
| 617 | } |
| 618 | |
| 619 | for (size_t dateidx = 0; dateidx < t_times.size(); ++dateidx) { |
| 620 | int b = 0; |
| 621 | stmt1->bind(++b, hourlyReportIndex); |
| 622 | stmt1->bind(++b, mapIndex); |
| 623 | |
| 624 | DateTime dt = t_times[dateidx]; |
| 625 | |
| 626 | int year = dt.date().year(); |
| 627 | int monthOfYear = dt.date().monthOfYear().value(); |
| 628 | int dayOfMonth = dt.date().dayOfMonth(); |
| 629 | int hours = dt.time().hours(); |
| 630 | // EnergyPlus deals in a 00:00:01 -> 24:00:00 world instead of |
| 631 | // 00:00:00 -> 23:59:59 hrs that the real world uses, so |
| 632 | // we are going to adjust for that, so we subtract an hour, |
| 633 | // to get it back to the previous day, then we will replace |
| 634 | // the hours with 24 |
| 635 | // \sa illuminanceMapHourlyReportIndex |
nothing calls this directly
no test coverage detected