• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2019 Huawei Technologies Co., Ltd
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 
17 #pragma once
18 #ifndef MINDSPORE_CCSRC_MINDDATA_MINDRECORD_STATISTICS_H
19 #define MINDSPORE_CCSRC_MINDDATA_MINDRECORD_STATISTICS_H
20 
21 #include <iostream>
22 #include <memory>
23 #include <string>
24 #include <vector>
25 
26 #include "minddata/mindrecord/include/common/log_adapter.h"
27 #include "minddata/mindrecord/include/common/shard_pybind.h"
28 #include "minddata/mindrecord/include/common/shard_utils.h"
29 #include "minddata/mindrecord/include/shard_error.h"
30 #include "minddata/mindrecord/include/mindrecord_macro.h"
31 #include "pybind11/pybind11.h"
32 
33 namespace mindspore {
34 namespace mindrecord {
35 class MINDRECORD_API Statistics {
36  public:
37   /// \brief save the statistic and its description
38   /// \param[in] desc the statistic's description
39   /// \param[in] statistics the statistic needs to be saved
40   static std::shared_ptr<Statistics> Build(std::string desc, const json &statistics);
41 
42   ~Statistics() = default;
43 
44   /// \brief compare two statistics to judge if they are equal
45   /// \param b another statistics to be judged
46   /// \return true if they are equal,false if not
47   bool operator==(const Statistics &b) const;
48 
49   /// \brief get the description
50   /// \return the description
51   std::string GetDesc() const;
52 
53   /// \brief get the statistic
54   /// \return json format of the statistic
55   json GetStatistics() const;
56 
57   /// \brief decode the bson statistics to json
58   /// \param[in] encodedStatistics the bson type of statistics
59   /// \return json type of statistic
60   void SetStatisticsID(int64_t id);
61 
62   /// \brief get the statistics id
63   /// \return the int64 statistics id
64   int64_t GetStatisticsID() const;
65 
66  private:
67   /// \brief validate the statistic
68   /// \return true / false
69   static bool Validate(const json &statistics);
70 
71   static bool LevelRecursive(json level);
72 
73   Statistics() = default;
74 
75   std::string desc_;
76   json statistics_;
77   int64_t statistics_id_ = -1;
78 };
79 }  // namespace mindrecord
80 }  // namespace mindspore
81 
82 #endif  // MINDSPORE_CCSRC_MINDDATA_MINDRECORD_STATISTICS_H
83