File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -38,14 +38,27 @@ class Summary final
3838 {
3939 lock_guard_type guard (m_lock);
4040
41- m_sales[s.id ()].inc_sold (s.sold ());
42- m_sales[s.id ()].inc_revenue (s.revenue ());
41+ const auto & id = s.id ();
42+
43+ // not found
44+ if (m_sales.find (id) == m_sales.end ()) {
45+ m_sales[id] = s;
46+ return ;
47+ }
48+
49+ // found
50+ m_sales[id].inc_sold (s.sold ());
51+ m_sales[id].inc_revenue (s.revenue ());
4352 }
4453
4554 minmax_sales_type minmax_sales () const
4655 {
4756 lock_guard_type guard (m_lock);
4857
58+ if (m_sales.empty ()) {
59+ return minmax_sales_type ();
60+ }
61+
4962 // algorithm
5063 auto ret = std::minmax_element (
5164 std::begin (m_sales), std::end (m_sales),
Original file line number Diff line number Diff line change @@ -103,11 +103,15 @@ try
103103 std::this_thread::sleep_for (time_interval * 1s);
104104 // cout << "log_cycle" << endl;
105105
106+ // auto info = sum.minmax_sales();
107+ // cout << "log_cycle get info" << endl;
108+
106109 using json_t = nlohmann::json;
107110
108111 json_t j;
109112
110113 j[" count" ] = static_cast <int >(count);
114+ j[" minmax" ] = sum.minmax_sales ();// {info.first, info.second};
111115
112116 auto res = cpr::Post (
113117 cpr::Url{http_addr},
You can’t perform that action at this time.
0 commit comments