Apollo  6.0
Open source self driving car software
data_collection_monitor.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *****************************************************************************/
16 
21 #pragma once
22 
23 #include <memory>
24 #include <string>
25 #include <unordered_map>
26 #include <vector>
27 
28 #include <boost/thread/shared_mutex.hpp>
29 
30 #include "gtest/gtest_prod.h"
31 
32 #include "nlohmann/json.hpp"
33 
34 #include "modules/canbus/proto/chassis.pb.h"
35 #include "modules/dreamview/proto/data_collection_table.pb.h"
36 
37 #include "cyber/cyber.h"
39 
44 namespace apollo {
45 namespace dreamview {
46 
47 typedef std::vector<Range> Category;
48 
55  public:
61 
65  void Start() override;
66 
70  void Stop() override;
71 
75  void Restart();
76 
80  nlohmann::json GetProgressAsJson() override;
81 
82  private:
83  void InitReaders();
84  void LoadConfiguration();
85  void ConstructCategories();
86  void ConstructCategoriesHelper(const std::string& scenario_name,
87  const Scenario& scenario, int feature_idx,
88  std::string current_category_name,
89  const Category& current_category);
90  void OnChassis(const std::shared_ptr<apollo::canbus::Chassis>& chassis);
91  bool IsCompliedWithCriteria(
92  const std::shared_ptr<apollo::canbus::Chassis>& chassis,
93  const Category& category);
94 
95  std::unique_ptr<cyber::Node> node_;
96 
97  // The table defines data collection requirements for calibration
98  DataCollectionTable data_collection_table_;
99 
100  // A map from scenario to its categories. Categories are collections
101  // of ranges from all possible combination of Feature x Range in a Scenario.
102  std::unordered_map<std::string, std::unordered_map<std::string, Category>>
103  scenario_to_categories_;
104 
105  // Number of frames that has been collected for each (scenario, category)
106  std::unordered_map<std::string, std::unordered_map<std::string, size_t>>
107  category_frame_count_;
108 
109  // Number of consecutive frames that has been collected for each (scenario,
110  // category).
111  std::unordered_map<std::string, std::unordered_map<std::string, size_t>>
112  category_consecutive_frame_count_;
113 
114  // Store overall and each category progress in percentage
115  nlohmann::json current_progress_json_;
116 
117  // Mutex to protect concurrent access to current_progress_json_.
118  // NOTE: Use boost until we have std version of rwlock support.
119  boost::shared_mutex mutex_;
120 
121  FRIEND_TEST(DataCollectionMonitorTest, UpdateCollectionProgress);
122  FRIEND_TEST(DataCollectionMonitorTest, ConstructCategories);
123 };
124 
125 } // namespace dreamview
126 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
A base class that monitor progress for Fuel client.
Definition: fuel_monitor.h:39
void Restart()
restart monitoring collection progress
DataCollectionMonitor()
Constructor of DataCollectionMonitor.
void Stop() override
stop monitoring collection progress
nlohmann::json GetProgressAsJson() override
return collection progress of categories and overall as json
std::vector< Range > Category
Definition: data_collection_monitor.h:47
void Start() override
start monitoring collection progress
A module that monitor data collection progress for calibration purpose.
Definition: data_collection_monitor.h:54