aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2011-04-22 18:24:00 +0200
committerJochen Topf <jochen@topf.org>2011-04-22 18:24:00 +0200
commit41c2246d1492a1789edf9e038af64a89d765c5b4 (patch)
treee4cd3b5399b353c984bc4140d8d217b1e484a435
parent3688d2b9e9668ab199ad41173fcf6629350e9a1a (diff)
downloadtaginfo-41c2246d1492a1789edf9e038af64a89d765c5b4.tar
taginfo-41c2246d1492a1789edf9e038af64a89d765c5b4.tar.gz
Cleanup
-rw-r--r--tagstats/Makefile2
-rw-r--r--tagstats/geodistribution.hpp68
-rw-r--r--tagstats/tagstats.cpp2
-rw-r--r--tagstats/tagstats_handler.hpp73
4 files changed, 75 insertions, 70 deletions
diff --git a/tagstats/Makefile b/tagstats/Makefile
index d777ed3..4570de7 100644
--- a/tagstats/Makefile
+++ b/tagstats/Makefile
@@ -33,7 +33,7 @@ tagstats: tagstats.cpp tagstats_handler.hpp string_store.hpp geodistribution.hpp
$(CXX) $(CXXFLAGS) -o $@ $< $(LDFLAGS) $(LIB_PROTOBUF) $(LIB_GD) $(LIB_SQLITE)
check:
- cppcheck --enable=all *.cpp *.hpp
+ cppcheck --enable=all tagstats.cpp
install:
install -m 755 -g root -o root -d $(DESTDIR)/usr/bin
diff --git a/tagstats/geodistribution.hpp b/tagstats/geodistribution.hpp
index c246564..30a1303 100644
--- a/tagstats/geodistribution.hpp
+++ b/tagstats/geodistribution.hpp
@@ -7,30 +7,39 @@
class GeoDistribution {
-public:
-
static const int resolution_y = 360;
static const int resolution_x = 2 * resolution_y;
- static const int image_size_y = resolution_y;
- static const int image_size_x = resolution_x;
-
-private:
+ typedef std::bitset<resolution_x * resolution_y> geo_distribution_t;
- std::bitset<resolution_x * resolution_y> *location;
+ /**
+ * Contains a pointer to a bitset that gives us the distribution.
+ * If only one grid cell is used so far, this pointer is NULL. Only
+ * if more than one grid cell is used, we dynamically create an
+ * object for this.
+ */
+ geo_distribution_t *distribution;
+ /**
+ * Number of grid cells.
+ * Will be 0 in the beginning, 1 if there is only one grid cell and
+ * 2 if there are two or more.
+ */
int cells;
- int loc;
- static std::bitset<resolution_x * resolution_y> location_all;
+ /// If there is only one grid cell location, this is where its kept
+ int location;
+
+ /// Overall distribution
+ static geo_distribution_t distribution_all;
public:
- GeoDistribution() : location(NULL), cells(0), loc(-1) {
+ GeoDistribution() : distribution(NULL), cells(0), location(-1) {
}
~GeoDistribution() {
- delete location;
+ delete distribution;
}
/**
@@ -47,21 +56,21 @@ public:
int n = resolution_x * y + x;
if (cells == 0) {
- loc = n;
+ location = n;
cells++;
- location_all[n] = true;
+ distribution_all[n] = true;
} else if (cells == 1) {
- if (loc != n) {
- location = new std::bitset<resolution_x * resolution_y>;
- (*location)[loc] = true;
- location_all[loc] = true;
- (*location)[n] = true;
- location_all[n] = true;
+ if (location != n) {
+ distribution = new geo_distribution_t;
+ (*distribution)[location] = true;
+ distribution_all[location] = true;
+ (*distribution)[n] = true;
+ distribution_all[n] = true;
cells++;
}
} else {
- (*location)[n] = true;
- location_all[n] = true;
+ (*distribution)[n] = true;
+ distribution_all[n] = true;
}
}
@@ -75,16 +84,16 @@ public:
* @returns Pointer to memory area with PNG image.
*/
void *create_png(int *size) {
- gdImagePtr im = gdImageCreate(image_size_x, image_size_y);
+ gdImagePtr im = gdImageCreate(resolution_x, resolution_y);
int bgColor = gdImageColorAllocate(im, 0, 0, 0);
gdImageColorTransparent(im, bgColor);
int fgColor = gdImageColorAllocate(im, 180, 0, 0);
- if (location) {
+ if (distribution) {
int n=0;
for (int y=0; y < resolution_y; y++) {
for (int x=0; x < resolution_x; x++) {
- if ((*location)[n]) {
+ if ((*distribution)[n]) {
cells++;
gdImageSetPixel(im, x, y, fgColor);
}
@@ -92,8 +101,8 @@ public:
}
}
} else {
- int y = loc / resolution_x;
- int x = loc - y;
+ int y = location / resolution_x;
+ int x = location - y;
gdImageSetPixel(im, x, y, fgColor);
}
@@ -122,11 +131,14 @@ public:
* object.
*/
static int count_all_set_cells() {
- return location_all.count();
+ return distribution_all.count();
}
+ /**
+ * Resets the distribution storage for the overall distribution.
+ */
static void reset() {
- location_all.reset();
+ distribution_all.reset();
}
};
diff --git a/tagstats/tagstats.cpp b/tagstats/tagstats.cpp
index 718c4bc..c2fa7b0 100644
--- a/tagstats/tagstats.cpp
+++ b/tagstats/tagstats.cpp
@@ -7,7 +7,7 @@
#include "geodistribution.hpp"
#include "tagstats_handler.hpp"
-std::bitset<GeoDistribution::resolution_x * GeoDistribution::resolution_y> GeoDistribution::location_all;
+GeoDistribution::geo_distribution_t GeoDistribution::distribution_all;
class MyTagStatsHandler : public Osmium::Handler::Base {
diff --git a/tagstats/tagstats_handler.hpp b/tagstats/tagstats_handler.hpp
index be60b57..61a5f80 100644
--- a/tagstats/tagstats_handler.hpp
+++ b/tagstats/tagstats_handler.hpp
@@ -2,7 +2,6 @@
#define TAGSTATS_HANDLER_HPP
#include <google/sparse_hash_map>
-#include <bitset>
#include <string>
#include <fstream>
@@ -135,7 +134,7 @@ class TagStatsHandler : public Osmium::Handler::Base {
time_t timer;
- key_hash_map_t tags_stat;
+ key_hash_map_t tags_stat;
time_t max_timestamp;
@@ -152,9 +151,8 @@ class TagStatsHandler : public Osmium::Handler::Base {
#ifdef TAGSTATS_COUNT_KEY_COMBINATIONS
void _update_key_combination_hash(Osmium::OSM::Object *object) {
-// KeyStats *stat;
key_hash_map_t::iterator tsi1, tsi2;
- const char /*other_key,*/ *key1, *key2;
+ const char *key1, *key2;
int tag_count = object->tag_count();
for (int i=0; i<tag_count; i++) {
@@ -179,17 +177,15 @@ class TagStatsHandler : public Osmium::Handler::Base {
Osmium::Sqlite::Statement *statement_insert_into_key_distributions = db->prepare("INSERT INTO key_distributions (key, png) VALUES (?, ?);");
db->begin_transaction();
- key_hash_map_t::iterator tags_iterator;
- for (tags_iterator = tags_stat.begin(); tags_iterator != tags_stat.end(); tags_iterator++) {
- const char *key = tags_iterator->first;
- KeyStats *stat = tags_iterator->second;
+ for (key_hash_map_t::iterator it = tags_stat.begin(); it != tags_stat.end(); it++) {
+ KeyStats *stat = it->second;
int size;
void *ptr = stat->node_distribution.create_png(&size);
sum_size += size;
statement_insert_into_key_distributions
- ->bind_text(key)
- ->bind_blob(ptr, size)
+ ->bind_text(it->first) // column: key
+ ->bind_blob(ptr, size) // column: png
->execute();
stat->node_distribution.free_png(ptr);
@@ -246,11 +242,10 @@ public:
}
int tag_count = object->tag_count();
- key_hash_map_t::iterator tags_iterator;
for (int i=0; i<tag_count; i++) {
const char* key = object->get_tag_key(i);
- tags_iterator = tags_stat.find(key);
+ key_hash_map_t::iterator tags_iterator = tags_stat.find(key);
if (tags_iterator == tags_stat.end()) {
stat = new KeyStats();
tags_stat.insert(std::pair<const char *, KeyStats *>(string_store->add(key), stat));
@@ -307,7 +302,7 @@ public:
std::cerr << "sizeof(user_hash_map_t) = " << sizeof(user_hash_map_t) << std::endl;
#endif // TAGSTATS_COUNT_USERS
- std::cerr << "sizeof(std::bitset<x_size*y_size>) = " << sizeof(std::bitset<GeoDistribution::resolution_x * GeoDistribution::resolution_y>) << std::endl;
+ std::cerr << "sizeof(GeoDistribution) = " << sizeof(GeoDistribution) << std::endl;
std::cerr << "sizeof(KeyStats) = " << sizeof(KeyStats) << std::endl << std::endl;
_print_memory_usage();
@@ -359,22 +354,20 @@ public:
uint64_t user_hash_buckets=0;
#endif // TAGSTATS_COUNT_USERS
- key_hash_map_t::iterator tags_iterator;
- value_hash_map_t::iterator values_iterator;
- for (tags_iterator = tags_stat.begin(); tags_iterator != tags_stat.end(); tags_iterator++) {
+ for (key_hash_map_t::iterator tags_iterator = tags_stat.begin(); tags_iterator != tags_stat.end(); tags_iterator++) {
KeyStats *stat = tags_iterator->second;
values_hash_size += stat->values_hash.size();
values_hash_buckets += stat->values_hash.bucket_count();
- for (values_iterator = stat->values_hash.begin(); values_iterator != stat->values_hash.end(); values_iterator++) {
+ for (value_hash_map_t::iterator values_iterator = stat->values_hash.begin(); values_iterator != stat->values_hash.end(); values_iterator++) {
statement_insert_into_tags
- ->bind_text(tags_iterator->first)
- ->bind_text(values_iterator->first)
- ->bind_int64(values_iterator->second.all())
- ->bind_int64(values_iterator->second.nodes())
- ->bind_int64(values_iterator->second.ways())
- ->bind_int64(values_iterator->second.relations())
+ ->bind_text(tags_iterator->first) // column: key
+ ->bind_text(values_iterator->first) // column: value
+ ->bind_int64(values_iterator->second.all()) // column: count_all
+ ->bind_int64(values_iterator->second.nodes()) // column: count_nodes
+ ->bind_int64(values_iterator->second.ways()) // column: count_ways
+ ->bind_int64(values_iterator->second.relations()) // column: count_relations
->execute();
}
@@ -384,21 +377,21 @@ public:
#endif // TAGSTATS_COUNT_USERS
statement_insert_into_keys
- ->bind_text(tags_iterator->first)
- ->bind_int64(stat->key.all())
- ->bind_int64(stat->key.nodes())
- ->bind_int64(stat->key.ways())
- ->bind_int64(stat->key.relations())
- ->bind_int64(stat->values_hash.size())
- ->bind_int64(stat->values.nodes())
- ->bind_int64(stat->values.ways())
- ->bind_int64(stat->values.relations())
+ ->bind_text(tags_iterator->first) // column: key
+ ->bind_int64(stat->key.all()) // column: count_all
+ ->bind_int64(stat->key.nodes()) // column: count_nodes
+ ->bind_int64(stat->key.ways()) // column: count_ways
+ ->bind_int64(stat->key.relations()) // column: count_relations
+ ->bind_int64(stat->values_hash.size()) // column: values_all
+ ->bind_int64(stat->values.nodes()) // column: values_nodes
+ ->bind_int64(stat->values.ways()) // column: values_ways
+ ->bind_int64(stat->values.relations()) // column: values_relations
#ifdef TAGSTATS_COUNT_USERS
- ->bind_int64(stat->user_hash.size())
+ ->bind_int64(stat->user_hash.size()) // column: users_all
#else
->bind_int64(0)
#endif // TAGSTATS_COUNT_USERS
- ->bind_int64(stat->node_distribution.get_cells())
+ ->bind_int64(stat->node_distribution.get_cells()) // column: grids
->execute();
#ifdef TAGSTATS_COUNT_KEY_COMBINATIONS
@@ -408,12 +401,12 @@ public:
for (key_combination_hash_map_t::iterator it = stat->key_combination_hash.begin(); it != stat->key_combination_hash.end(); it++) {
Counter *s = &(it->second);
statement_insert_into_key_combinations
- ->bind_text(tags_iterator->first)
- ->bind_text(it->first)
- ->bind_int64(s->all())
- ->bind_int64(s->nodes())
- ->bind_int64(s->ways())
- ->bind_int64(s->relations())
+ ->bind_text(tags_iterator->first) // column: key1
+ ->bind_text(it->first) // column: key2
+ ->bind_int64(s->all()) // column: count_all
+ ->bind_int64(s->nodes()) // column: count_nodes
+ ->bind_int64(s->ways()) // column: count_ways
+ ->bind_int64(s->relations()) // column: count_relations
->execute();
}
#endif // TAGSTATS_COUNT_KEY_COMBINATIONS