Welcome to mirror list, hosted at ThFree Co, Russian Federation.

statistics.cpp « generator - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c226453cf1e81631b188a7b2d09d2430f8ca91d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "statistics.hpp"

#include "indexer/classificator.hpp"
#include "indexer/data_factory.hpp"
#include "indexer/feature_impl.hpp"
#include "indexer/feature_processor.hpp"

#include "geometry/triangle2d.hpp"

#include "base/logging.hpp"
#include "base/string_utils.hpp"

#include "std/iomanip.hpp"
#include "std/iostream.hpp"


using namespace feature;

namespace stats
{
  void FileContainerStatistic(string const & fPath)
  {
    try
    {
      FilesContainerR cont(fPath);
      cont.ForEachTag([&cont] (FilesContainerR::Tag const & tag)
      {
        cout << setw(10) << tag << " : " << cont.GetReader(tag).Size() << endl;
      });
    }
    catch (Reader::Exception const & ex)
    {
      LOG(LWARNING, ("Error reading file:", fPath, ex.Msg()));
    }
  }

  // 0.001 deg² ≈ 12.392 km² * cos(lat)
  double arrAreas[] = { 10, 20, 50, 100, 200, 500, 1000, 360*360*12400 };

  size_t GetAreaIndex(double s)
  {
    double const sInKm2 = s / 1000000;
    auto i = lower_bound(begin(arrAreas), end(arrAreas), sInKm2);
    ASSERT(i != end(arrAreas), ());
    return distance(arrAreas, i);
  }

  class AccumulateStatistic
  {
    MapInfo & m_info;

  public:
    AccumulateStatistic(MapInfo & info) : m_info(info) {}

    void operator() (FeatureType const & f, uint32_t)
    {
      f.ParseBeforeStatistic();

      FeatureType::inner_geom_stat_t const innerStats = f.GetInnerStatistic();

      m_info.m_inner[0].Add(innerStats.m_points);
      m_info.m_inner[1].Add(innerStats.m_strips);
      m_info.m_inner[2].Add(innerStats.m_size);

      // get geometry size for the best geometry
      FeatureType::geom_stat_t const geom = f.GetGeometrySize(FeatureType::BEST_GEOMETRY);
      FeatureType::geom_stat_t const trg = f.GetTrianglesSize(FeatureType::BEST_GEOMETRY);

      m_info.m_byPointsCount[CountType(geom.m_count)].Add(geom.m_size);
      m_info.m_byTrgCount[CountType(trg.m_count / 3)].Add(trg.m_size);

      uint32_t const allSize = innerStats.m_size + geom.m_size + trg.m_size;

      double len = 0.0;
      double area = 0.0;

      if (f.GetFeatureType() == feature::GEOM_LINE)
      {
        m2::PointD lastPoint;
        bool firstPoint = true;
        f.ForEachPoint([&len, &firstPoint, &lastPoint](const m2::PointD & pt)
        {
          if (firstPoint)
            firstPoint = false;
          else
            len += MercatorBounds::DistanceOnEarth(lastPoint, pt);
          lastPoint = pt;
        }, FeatureType::BEST_GEOMETRY);
      }
      else if (f.GetFeatureType() == feature::GEOM_AREA)
      {
        f.ForEachTriangle([&area](m2::PointD const & p1, m2::PointD const & p2, m2::PointD const & p3)
        {
          area += MercatorBounds::AreaOnEarth(p1, p2, p3);
        }, FeatureType::BEST_GEOMETRY);
      }

      m_info.m_byGeomType[f.GetFeatureType()].Add(allSize, len, area);

      f.ForEachType([this, allSize, len, area](uint32_t type)
      {
        m_info.m_byClassifType[ClassifType(type)].Add(allSize, len, area);
      });

      m_info.m_byAreaSize[AreaType(GetAreaIndex(area))].Add(trg.m_size, len, area);
    }
  };

  void CalcStatistic(string const & fPath, MapInfo & info)
  {
    AccumulateStatistic doProcess(info);
    feature::ForEachFromDat(fPath, doProcess);
  }

  void PrintInfo(string const & prefix, GeneralInfo const & info, bool measurements)
  {
    cout << prefix << ": size = " << info.m_size << "; count = " << info.m_count;
    if (measurements)
    {
      cout << "; length = " << uint64_t(info.m_length) << " m; area = " << uint64_t(info.m_area) << " m²";
    }
    cout << endl;
  }

  string GetKey(EGeomType type)
  {
    switch (type)
    {
    case GEOM_LINE: return "Line";
    case GEOM_AREA: return "Area";
    default: return "Point";
    }
  }

  string GetKey(CountType t)
  {
    return strings::to_string(t.m_val);
  }

  string GetKey(ClassifType t)
  {
    return classif().GetFullObjectName(t.m_val);
  }

  string GetKey(AreaType t)
  {
    return strings::to_string(arrAreas[t.m_val]);
  }

  template <class TSortCr, class TSet>
  void PrintTop(char const * prefix, TSet const & theSet)
  {
    cout << prefix << endl;

    vector<pair<typename TSet::key_type, typename TSet::mapped_type>> vec(theSet.begin(), theSet.end());

    sort(vec.begin(), vec.end(), TSortCr());

    size_t const count = min(static_cast<size_t>(10), vec.size());
    for (size_t i = 0; i < count; ++i)
    {
      cout << i << ". ";
      PrintInfo(GetKey(vec[i].first), vec[i].second, false);
    }
  }

  struct greater_size
  {
    template <class TInfo>
    bool operator() (TInfo const & r1, TInfo const & r2) const
    {
      return r1.second.m_size > r2.second.m_size;
    }
  };

  struct greater_count
  {
    template <class TInfo>
    bool operator() (TInfo const & r1, TInfo const & r2) const
    {
      return r1.second.m_count > r2.second.m_count;
    }
  };

  void PrintStatistic(MapInfo & info)
  {
    PrintInfo("DAT header", info.m_inner[2], false);
    PrintInfo("Points header", info.m_inner[0], false);
    PrintInfo("Strips header", info.m_inner[1], false);

    PrintTop<greater_size>("Top SIZE by Geometry Type", info.m_byGeomType);
    PrintTop<greater_size>("Top SIZE by Classificator Type", info.m_byClassifType);
    PrintTop<greater_size>("Top SIZE by Points Count", info.m_byPointsCount);
    PrintTop<greater_size>("Top SIZE by Triangles Count", info.m_byTrgCount);
    PrintTop<greater_size>("Top SIZE by Area", info.m_byAreaSize);
  }

  void PrintTypeStatistic(MapInfo & info)
  {
    for (auto it = info.m_byClassifType.begin(); it != info.m_byClassifType.end(); ++it)
    {
      PrintInfo(GetKey(it->first).c_str(), it->second, true);
    }
  }
}