FACT++  1.0
void StateMachineSmartFACT::UpdateAstronomy ( )
inlineprivate

Definition at line 2370 of file smartfact.cc.

References Moon::Angle(), Moon::az, Nova::ZdAzPosn::az, color(), Moon::color, Moon::Color(), Moon::description, Moon::fRise, Moon::fSet, Moon::fTransit, Time::GetAsStr(), Nova::GetHrzFromEqu(), if(), Time::JavaDate(), Time::JD(), HTML::kBlue, HTML::kGreen, HTML::kRed, HTML::kWhite, HTML::kYellow, Moon::state, Moon::visible, Moon::zd, and Nova::ZdAzPosn::zd.

2371  {
2372  Time now;
2373 
2374  CalcCoordinates(now.JD());
2375 
2376  fSun = Sun (now);
2377  fMoon = Moon(now);
2378 
2379  vector<string> color(8, HTML::kWhite);
2380  color[fSun.state] = HTML::kBlue;
2381 
2382  ostringstream out;
2383  out << setprecision(3);
2384  out << now.JavaDate() << '\n';
2385  out << color[4] << '\t' << fSun.fSunRise18.GetAsStr("%H:%M") << '\n';
2386  out << color[5] << '\t' << fSun.fSunRise12.GetAsStr("%H:%M") << '\n';
2387  out << color[6] << '\t' << fSun.fSunRise06.GetAsStr("%H:%M") << '\n';
2388  out << color[7] << '\t' << fSun.fSunRise00.GetAsStr("%H:%M") << '\n';
2389 
2390  out << color[0] << '\t' << fSun.fSunSet00.GetAsStr("%H:%M") << '\n';
2391  out << color[1] << '\t' << fSun.fSunSet06.GetAsStr("%H:%M") << '\n';
2392  out << color[2] << '\t' << fSun.fSunSet12.GetAsStr("%H:%M") << '\n';
2393  out << color[3] << '\t' << fSun.fSunSet18.GetAsStr("%H:%M") << '\n';
2394 
2395  ofstream(fPath+"/sun.data") << out.str();
2396 
2397  color.assign(3, HTML::kWhite);
2399 
2400  out.str("");
2401  out << now.JavaDate() << '\n';
2402 
2403  out << color[0] << '\t' << fMoon.fRise.GetAsStr("%H:%M") << '\n';
2404  out << color[1] << '\t' << fMoon.fTransit.GetAsStr("%H:%M") << '\n';
2405  out << color[2] << '\t' << fMoon.fSet.GetAsStr("%H:%M") << '\n';
2406 
2407  out << (fSun.isday?HTML::kWhite:fMoon.color) << '\t' << fMoon.description << '\n';
2408 
2409  if (!fMoon.visible)
2410  out << HTML::kWhite << "\t&mdash;\t\n";
2411  else
2412  {
2413  string col = HTML::kWhite;
2414  if (!fSun.isday)
2415  {
2416  col = HTML::kGreen;
2417  if (fMoon.zd>25)
2418  col = HTML::kYellow;
2419  if (fMoon.zd>45 && fMoon.zd<80)
2420  col = HTML::kRed;
2421  if (fMoon.zd>=80)
2422  col = HTML::kRed;
2423  }
2424  out << col << '\t' << fMoon.zd << '\t' << GetDir(fMoon.az) << '\n';
2425  }
2426 
2427  ostringstream out2, out3, out4;
2428  out2 << setprecision(3);
2429  out2 << now.JavaDate() << '\n';
2430  out3 << now.JavaDate() << '\n';
2431  out4 << now.JavaDate() << '\n';
2432 
2433  struct Entry
2434  {
2435  string name;
2436  float value;
2437  int color;
2438  Entry(const string &n, float v, int c) : name(n), value(v), color(c%8) { }
2439 
2440  const string &Col() const
2441  {
2442  // If this list is updatd the number count in the constructor needs
2443  // to be updated, too
2444  static const string hcol[] = { "888", "8cf", "c8f", "bbb", "8fc", "cf8", "f8c", "fc8" };
2445  return hcol[color];
2446  }
2447 
2448  vector<float> GetColor(double scale, double offset=0) const
2449  {
2450  vector<float> rc(3);
2451  rc[0] = double(Col()[0])*scale/126+offset;
2452  rc[1] = double(Col()[1])*scale/126+offset;
2453  rc[2] = double(Col()[2])*scale/126+offset;
2454  return rc;
2455  }
2456  };
2457 
2458  multimap<Time, Entry> culmination;
2459  multimap<Time, Entry> lightcond;
2460  vector<vector<float>> alt;
2461  vector<vector<float>> cur;
2462 
2463 #ifdef HAVE_NOVA
2464  int ccol = 0;
2465  int lcol = 0;
2466 
2467  /*const*/ pair<vector<float>, pair<Time, float>> vism = GetVisibility();
2468  if (!vism.first.empty())
2469  {
2470  const Entry entry("Moon", vism.second.second, ccol);
2471  culmination.insert(make_pair(vism.second.first, entry));
2472  const vector<float> col = entry.GetColor(75, 15);
2473  vism.first.insert(vism.first.begin(), col.begin(), col.end());
2474  alt.push_back(vism.first);
2475 
2476  ccol++;
2477  }
2478 #endif
2479 
2480 #ifdef HAVE_SQL
2481  try
2482  {
2483  const mysqlpp::StoreQueryResult res =
2484  Database(fDatabase).query("SELECT fSourceName, fRightAscension, fDeclination FROM Source WHERE fSourceTypeKEY=1").store();
2485 
2486  out << HTML::kWhite << '\t';
2487  out2 << HTML::kWhite << '\t';
2488  out3 << HTML::kWhite << '\t';
2489  out4 << HTML::kWhite << '\t';
2490 
2491  for (vector<mysqlpp::Row>::const_iterator v=res.begin(); v<res.end(); v++)
2492  {
2493  const string name = (*v)[0].c_str();
2494  const double ra = (*v)[1];
2495  const double dec = (*v)[2];
2496 #ifdef HAVE_NOVA
2497  Nova::EquPosn pos;
2498  pos.ra = ra*15;
2499  pos.dec = dec;
2500 
2501  const Nova::ZdAzPosn hrz = Nova::GetHrzFromEqu(pos, now.JD());
2502 
2503  /*const*/ pair<vector<float>, pair<Time, float>> vis = GetVisibility(&pos);
2504  if (!vis.first.empty())
2505  {
2506  const Entry entry(name, vis.second.second, ccol);
2507  culmination.insert(make_pair(vis.second.first, entry));
2508  const vector<float> col = entry.GetColor(75, 15);
2509  vis.first.insert(vis.first.begin(), col.begin(), col.end());
2510  alt.push_back(vis.first);
2511 
2512  ccol++;
2513 
2514  /*const*/ pair<vector<float>, pair<Time, float>> lc = GetLightCondition(pos);
2515  if (!lc.first.empty())
2516  {
2517  const Entry entry2(name, lc.second.second, lcol);
2518  lightcond.insert(make_pair(lc.second.first, entry2));
2519  const vector<float> col2 = entry2.GetColor(100);
2520  lc.first.insert(lc.first.begin(), col2.begin(), col2.end());
2521  cur.push_back(lc.first);
2522 
2523  lcol++;
2524  }
2525  }
2526 
2527  string col = HTML::kWhite;
2528  if (hrz.zd<85)
2529  col = HTML::kRed;
2530  if (hrz.zd<65)
2531  col = HTML::kYellow;
2532  if (hrz.zd<30)
2533  col = HTML::kGreen;
2534 
2535  out2 << "<tr bgcolor='" << col << "'>";
2536  out2 << "<td>" << name << "</td>";
2537  if (hrz.zd<85)
2538  {
2539  out2 << "<td>" << hrz.zd << "&deg;</td>";
2540  out2 << "<td>" << GetDir(hrz.az) << "</td>";
2541  }
2542  else
2543  out2 << "<td/><td/>";
2544  out2 << "</tr>";
2545 #endif
2546  const int32_t angle = fMoon.Angle(ra, dec);
2547 
2548  out << "<tr bgcolor='" << Moon::Color(angle) << "'>";
2549  out << "<td>" << name << "</td>";
2550  out << "<td>" << round(angle) << "&deg;</td>";
2551  out << "</tr>";
2552  }
2553 
2554  for (auto it=culmination.begin(); it!=culmination.end(); it++)
2555  {
2556  const Entry &e = it->second;
2557  if (it!=culmination.begin())
2558  out3 << ", ";
2559  out3 << "<B#" << e.Col() << ">" << e.name << "</B>";
2560  if (e.value>0)
2561  out3 << " [" << nearbyint(90-e.value) << "&deg;]";
2562  }
2563 
2564  out4 << setprecision(3);
2565 
2566  for (auto it=lightcond.begin(); it!=lightcond.end(); it++)
2567  {
2568  const Entry &e = it->second;
2569  if (it!=lightcond.begin())
2570  out4 << ", ";
2571  out4 << "<B#" << e.Col() << ">" << e.name << "</B>";
2572  if (e.value>0)
2573  out4 << " [" << nearbyint(e.value) << "]";
2574  }
2575 
2576  const Time st = fSun.fSunSet12;;
2577  const Time rs = fSun.fSunRise12;
2578 
2579  ostringstream title;
2580  title << st.GetAsStr("%H:%M");
2581  title << " / ";
2582  title << ((rs>st?rs-st:st-rs)/20).minutes();
2583  title << "' / ";
2584  title << rs.GetAsStr("%H:%M");
2585 
2586  out << '\n';
2587  out2 << '\n';
2588  out3 << '\n';
2589  out4 << '\n';
2590  out << HTML::kWhite << '\t' << Time()-now << '\n';
2591  out2 << HTML::kWhite << '\t' << Time()-now << '\n';
2592 
2593  WriteBinaryVec(now, "hist-visibility", alt, 75, 15, "Alt "+title.str());
2594  WriteBinaryVec(now, "hist-current-prediction", cur, 100, 0, "I " +title.str());
2595  }
2596  catch (const exception &e)
2597  {
2598  out << '\n';
2599  out2 << '\n';
2600  out << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n';
2601  out2 << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n';
2602  out3 << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n';
2603  out4 << HTML::kWhite << '\t' << "ERROR - "+string(e.what()) << '\n';
2604  }
2605 #endif
2606 
2607  ofstream(fPath+"/moon.data") << out.str();
2608  ofstream(fPath+"/source-list.data") << out2.str();
2609  ofstream(fPath+"/visibility.data") << out3.str();
2610  ofstream(fPath+"/current-prediction.data") << out4.str();
2611  }
string description
Definition: smartfact.cc:326
int state
Definition: moon.cc:32
static const string kYellow
Definition: smartfact.cc:75
uint64_t JavaDate() const
Definition: Time.h:111
Adds some functionality to boost::posix_time::ptime for our needs.
Definition: Time.h:30
Definition: moon.cc:13
double zd
Definition: nova.h:30
void WriteBinaryVec(const Time &tm, const string &fname, const vector< T > &vec, double scale, double offset=0, const string &title="", const string &col="")
Definition: smartfact.cc:689
double JD() const
Definition: Time.h:87
double zd
Definition: moon.cc:21
Time fTransit
Definition: moon.cc:29
static const string kBlue
Definition: smartfact.cc:78
static const string kWhite
Definition: smartfact.cc:74
double az
Definition: moon.cc:22
Time fSet
Definition: moon.cc:30
static const string kGreen
Definition: smartfact.cc:77
HrzPosn GetHrzFromEqu(const EquPosn &equ, const LnLatPosn &obs, double jd)
Definition: nova.h:75
static string Color(double angle)
Definition: smartfact.cc:425
double az
Definition: nova.h:31
Time fRise
Definition: moon.cc:28
function color(col)
Definition: color.js:31
if(extraDns) new Dns
string GetDir(const double angle)
Definition: smartfact.cc:653
double Angle(double r, double d) const
Definition: moon.cc:95
string color
Definition: smartfact.cc:327
static const string kRed
Definition: smartfact.cc:76
std::string GetAsStr(const char *fmt="%Y-%m-%d %H:%M:%S") const
Definition: Time.cc:240
bool visible
Definition: moon.cc:26
Definition: smartfact.cc:85

+ Here is the call graph for this function: