SHARE
TWEET

Untitled

a guest Jan 20th, 2019 95 in 243 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "com.h"
  2. #include "graph.h"
  3. #include "json.hpp"
  4.  
  5. using json = nlohmann::json;
  6.  
  7. void graph::getData(wxString date, bool init)
  8. {
  9.  
  10.     int i = 0;
  11.     float y;
  12.  
  13.     mysqlpp::Connection conn(false);
  14.  
  15.     if(conn.connect(DB_DATABASE, DB_IPADRESS, DB_USERNAME, DB_PASSWORD)) {
  16.  
  17.         wxString in = (init) ? wxT("NOW") : date;
  18.  
  19.         wxString str = wxT(
  20.             "SELECT temperature FROM nesbyen_yr WHERE DATEDIFF(FROM_UNIXTIME(lastUpdate), NOW()) = 0 ORDER BY id ASC");
  21.         const char* stl = (const char*)str.mb_str(wxConvISO8859_1);
  22.  
  23.         mysqlpp::Query query = conn.query(stl);
  24.  
  25.         if(mysqlpp::UseQueryResult res = query.use()) {
  26.  
  27.             while(mysqlpp::Row row = res.fetch_row()) {
  28.  
  29.                 const char* rd = row["temperature"];
  30.                 std::string jh = rd;
  31.  
  32.                 json j = json::parse(jh);
  33.  
  34.                 std::string hei = j.at("value");
  35.                 y = std::stof(hei);
  36.  
  37.                 data.push_back(wxRealPoint(i, y));
  38.  
  39.                 i++;
  40.             }
  41.  
  42.         } else {
  43.             wxMessageBox(wxT("Tilkobling feilet.."), wxT("ERROR!"), wxICON_ERROR);
  44.         }
  45.     }
  46.  
  47. }
  48.  
  49. void graph::getGraphDataInitial()
  50. {
  51.     getData(wxT(""), 1);
  52. }
  53.  
  54. void graph::getGraphDataUpdate(wxString dateString)
  55. {
  56.  
  57.     //double f = serie->GetX(1);
  58.     //wxString tester;
  59.     //tester << f;
  60.     //wxMessageBox(tester, wxT("Nei"));
  61.     //dataset->BeginUpdate();
  62.     serie->UpdateX(5, -5);
  63.     dataset->DatasetChanged();
  64.     //dataset->EndUpdate();
  65. }
  66.  
  67. void graph::initialGraph()
  68. {
  69.  
  70.     plot = new XYPlot();
  71.  
  72.     dataset = new XYSimpleDataset();
  73.     getGraphDataInitial();
  74.  
  75.     serie = new XYSerie(data);
  76.     dataset->AddSerie(serie);
  77.  
  78.     renderer = new XYLineRenderer(true, true);
  79.     renderer->SetSeriePen(0, wxThePenList->FindOrCreatePen(*wxBLUE, 2, wxPENSTYLE_SOLID));
  80.     renderer->SetSerieSymbol(0, new CircleSymbol());
  81.  
  82.     rangeMarker = new RangeMarker(new FillAreaDraw(wxColour(80, 80, 255), wxColour(200, 200, 250)));
  83.     rangeMarker->SetHorizontalRange(0, -3);
  84.  
  85.     lineMarker = new LineMarker(wxColour(40, 102, 201), 2);
  86.     lineMarker->SetHorizontalLine(0);
  87.  
  88.     dataset->SetRenderer(renderer);
  89.     dataset->AddMarker(rangeMarker);
  90.     dataset->AddMarker(lineMarker);
  91.  
  92.     NumberAxis* leftAxis = new NumberAxis(AXIS_LEFT);
  93.     NumberAxis* bottomAxis = new NumberAxis(AXIS_BOTTOM);
  94.     leftAxis->SetTitle(wxT("Tittel venstre"));
  95.     bottomAxis->SetTitle(wxT("Tittel bunn"));
  96.     bottomAxis->SetFixedBounds(0, 24);
  97.  
  98.     plot->AddDataset(dataset);
  99.     plot->AddAxis(leftAxis);
  100.     plot->AddAxis(bottomAxis);
  101.     plot->LinkDataHorizontalAxis(0, 0);
  102.     plot->LinkDataVerticalAxis(0, 0);
  103.    
  104. }
  105.  
  106. Chart* graph::getGraph(wxString title)
  107. {
  108.  
  109.     initialGraph();
  110.     chart = new Chart(plot, title);
  111.  
  112.     return chart;
  113.  
  114. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top