kopia lustrzana https://gitlab.com/tomaszg/geostat
Refactor code around textual data field in Cache class
rodzic
0ce9b0d817
commit
1f5338ffd2
17
cache.cpp
17
cache.cpp
|
@ -13,7 +13,7 @@ static float degtorad(float x) {
|
|||
|
||||
void Cache::show() const {
|
||||
std::cout << "Cache:\t" << code << ' ' << name << " (type: " << type << ", owned by " << owner << ")\n";
|
||||
std::cout << '\t' << pos.lat << " " << pos.lon << "\t\tD/T: " << diff << '/' << terr << "\t\tSize: " << size << "\t\tFound on " << date() << '\n';
|
||||
std::cout << '\t' << pos.lat << " " << pos.lon << "\t\tD/T: " << diff << '/' << terr << "\t\tSize: " << size << "\t\tFound on " << date << '\n';
|
||||
}
|
||||
|
||||
std::string Cache::link() const {
|
||||
|
@ -24,6 +24,17 @@ float Cache::distance() const {
|
|||
return 2 * Earth_radius * asin(sqrt(pow(sin(degtorad((pos.lat - home.lat) / 2)), 2) + cos(degtorad(pos.lat)) * cos(degtorad(home.lat)) * pow(sin(degtorad((pos.lon - home.lon) / 2)), 2)));
|
||||
}
|
||||
|
||||
std::string Cache::date() const {
|
||||
return std::to_string(date_found.tm_year+1900) + '-' + std::to_string(date_found.tm_mon) + "-" + std::to_string(date_found.tm_mday);
|
||||
void Cache::set_date(std::tm* t) {
|
||||
char tmp[20];
|
||||
|
||||
date_tm = *t;
|
||||
|
||||
year = std::to_string(1900+date_tm.tm_year);
|
||||
std::strftime(tmp, 20, "(%m) %B", &date_tm);
|
||||
mon = tmp;
|
||||
day = std::to_string(date_tm.tm_mday);
|
||||
hour = std::to_string(date_tm.tm_hour);
|
||||
|
||||
std::strftime(tmp, 20, "%x", &date_tm);
|
||||
date = tmp;
|
||||
}
|
||||
|
|
6
cache.h
6
cache.h
|
@ -51,18 +51,20 @@ public:
|
|||
std::string origin;
|
||||
std::string owner;
|
||||
std::string owner_uuid;
|
||||
std::tm date_found;
|
||||
std::tm date_tm;
|
||||
std::string year;
|
||||
std::string mon;
|
||||
std::string day;
|
||||
std::string hour;
|
||||
std::string date;
|
||||
|
||||
void set_date(std::tm* t);
|
||||
|
||||
static Position home;
|
||||
|
||||
void show() const;
|
||||
std::string link() const;
|
||||
float distance() const;
|
||||
std::string date() const;
|
||||
};
|
||||
|
||||
class CacheCmp {
|
||||
|
|
|
@ -16,7 +16,7 @@ endif
|
|||
|
||||
link = ['-lgpx', '-lheatmap']
|
||||
src = ['geostat.cpp', 'okapi.cpp', 'gpx.cpp', 'cache.cpp', 'debug.cpp', 'heat.cpp', 'ocdb.cpp']
|
||||
src_db = ['geodb.cpp', 'debug.cpp', 'ocdb.cpp', 'okapi.cpp']
|
||||
src_db = ['geodb.cpp', 'debug.cpp', 'ocdb.cpp', 'okapi.cpp', 'cache.cpp']
|
||||
|
||||
executable('geostat', src, dependencies : [curl_dep, json_dep, magick_dep, sqlite_dep], link_args: link, install: true)
|
||||
executable('geodb', src_db, dependencies : [sqlite_dep, json_dep, curl_dep], install: true)
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "okapi.h"
|
||||
#include "cache.h"
|
||||
#include "debug.h"
|
||||
|
||||
#include <iostream>
|
||||
|
@ -105,7 +104,6 @@ std::string Okapi::get_caches_json(std::string codes) {
|
|||
Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
|
||||
Cache c;
|
||||
Caches cc;
|
||||
char month[20];
|
||||
|
||||
uint n = 0;
|
||||
while (n < codes.size()) {
|
||||
|
@ -136,12 +134,7 @@ Caches Okapi::get_caches(std::vector<std::pair<std::string, std::tm>> codes) {
|
|||
//ugly way to handle date...
|
||||
for (auto& el2 : codes) {
|
||||
if (el2.first == c.code) {
|
||||
c.date_found = el2.second;
|
||||
c.year = std::to_string(1900+el2.second.tm_year);
|
||||
std::strftime(month, 20, "(%m) %B", &el2.second);
|
||||
c.mon = month;
|
||||
c.day = std::to_string(el2.second.tm_mday);
|
||||
c.hour = std::to_string(el2.second.tm_hour);
|
||||
c.set_date(&el2.second);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue