Ilya_Bykonya

Untitled

Jun 20th, 2024
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <functional>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <iostream>
  5. #include <numeric>
  6. #include <cstdint>
  7. #include <thread>
  8. #include <chrono>
  9. #include <deque>
  10. #include <array>
  11. using namespace std::chrono_literals;
  12.  
  13.  
  14. namespace std {
  15. template<typename Type, size_t size>
  16. std::ostream& operator<<(std::ostream& out, const std::array<Type, size>& collection) {
  17. out << '[';
  18. std::copy(collection.begin(), collection.end(), std::ostream_iterator<Type>{ out, " "});
  19. out << ']';
  20. return out;
  21. }
  22.  
  23.  
  24. template<typename Type>
  25. std::ostream& operator<<(std::ostream& out, const std::deque<Type>& collection) {
  26. out << '[';
  27. std::copy(collection.begin(), collection.end(), std::ostream_iterator<Type>{ out, " "});
  28. out << ']';
  29. return out;
  30. }
  31. }
  32.  
  33. // Опрос
  34. std::array<uint16_t, 12> get_sensor_info() {
  35. std::array<uint16_t, 12> result{};
  36. std::generate(result.begin(), result.end(), rand);
  37. std::this_thread::sleep_for(0.1s);
  38. return result;
  39. }
  40.  
  41.  
  42. int main() {
  43. // std::array<std::deque<uint16_t>, 12> snapshots{};
  44. // for(const auto start_time = std::chrono::steady_clock::now(); std::chrono::steady_clock::now() - start_time < 1s;) {
  45. // auto snapshot = get_sensor_info();
  46. // for(auto index = 0; index < 12; ++index) {
  47. // snapshots[index].push_back(snapshot[index]);
  48. // }
  49. // }
  50. // std::copy(snapshots.begin(), snapshots.end(), std::ostream_iterator<std::deque<uint16_t>>{ std::cout, "\n" });
  51.  
  52.  
  53. // std::cout << "Average on 2: " << std::accumulate(snapshots[2].begin(), snapshots[2].end(), double{ 0.0 }, std::plus<>{}) / snapshots.size() << std::endl;
  54.  
  55. // ===========================================================================================
  56.  
  57. // std::deque<std::array<uint16_t, 12>> snapshots{};
  58. // for(const auto start_time = std::chrono::steady_clock::now(); std::chrono::steady_clock::now() - start_time < 1s;) {
  59. // snapshots.push_back(get_sensor_info());
  60. // }
  61. // std::copy(snapshots.begin(), snapshots.end(), std::ostream_iterator<std::array<uint16_t, 12>>{ std::cout, "\n" });
  62.  
  63. // std::cout << "Average on 2: " << std::accumulate(snapshots.begin(), snapshots.end(), double{ 0.0 }, [](double sum, const std::array<uint16_t, 12>& snapshot)->double {
  64. // return sum + snapshot[2];
  65. // }) / snapshots.size() << std::endl;
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment