• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wirenboard / wb-mqtt-db / 1

09 Oct 2026 07:06AM UTC coverage: 79.788% (-2.2%) from 82.03%
1

Pull #70

github

4957c0
sikmir
Fix boolean value aggregation
Pull Request #70: Fix boolean value aggregation

2465 of 6264 branches covered (39.35%)

87 of 87 new or added lines in 2 files covered. (100.0%)

146 existing lines in 8 files now uncovered.

1654 of 2073 relevant lines covered (79.79%)

20.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.89
/src/utils.cpp
1
#include <chrono>
2
#include <fstream>
3

4
#include "utils.h"
5

6
namespace Utils
7
{
8
    const int UID_COLUMN = 0;
9
    const int VALUE_COLUMN = 2;
10
    const int TIMESTAMP_COLUMN = 3;
11
    const int MIN_COLUMN = 4;
12
    const int MAX_COLUMN = 5;
13
    const int RETAINED_COLUMN = 6;
14
    const int AVERAGE_VALUE_COLUMN = 7;
15

16
    void CopyFile(const std::string& from, const std::string& to)
×
17
    {
18
        std::ifstream src(from, std::ios::binary);
×
19
        std::ofstream dst(to, std::ios::binary);
×
20

21
        dst << src.rdbuf();
×
UNCOV
22
    }
×
23

24
    bool isNumber(const std::string& str)
103 ✔
25
    {
26
        const char* s = str.c_str();
103 ✔
27
        char* end = nullptr;
103 ✔
28
        strtod(s, &end);
103 ✔
29
        return (end != s && end == s + str.length());
103 ✔
30
    }
31

32
    bool CallVisitor(IRecordsVisitor& visitor, SQLite::Statement& query, bool withAverage, const TChannelInfo& channel)
95 ✔
33
    {
34
        int recordId = query.getColumn(UID_COLUMN).getInt();
95 !
35
        bool retain = (query.getColumn(RETAINED_COLUMN).getInt() > 0);
95 !
36
        std::chrono::system_clock::time_point timestamp(
37
            std::chrono::milliseconds(query.getColumn(TIMESTAMP_COLUMN).getInt64()));
95 !
38

39
        if (withAverage && !isNumber(query.getColumn(VALUE_COLUMN).getString())) {
95 !
40
            return visitor.ProcessRecord(recordId,
22 !
41
                                         channel,
42
                                         query.getColumn(VALUE_COLUMN).getString(),
44 !
43
                                         timestamp,
44
                                         retain);
22 ✔
45
        }
46
        if (query.getColumn(MAX_COLUMN).isNull()) {
73 !
47
            return visitor.ProcessRecord(recordId,
58 !
48
                                         channel,
49
                                         query.getColumn(AVERAGE_VALUE_COLUMN).getString(),
116 !
50
                                         timestamp,
51
                                         retain);
58 ✔
52
        }
53
        return visitor.ProcessRecord(recordId,
45 !
54
                                     channel,
55
                                     query.getColumn(withAverage ? AVERAGE_VALUE_COLUMN : VALUE_COLUMN).getDouble(),
30 !
56
                                     timestamp,
57
                                     query.getColumn(MIN_COLUMN).getDouble(),
30 !
58
                                     query.getColumn(MAX_COLUMN).getDouble(),
30 !
59
                                     retain);
15 ✔
60
    }
61

62
    void AddCommonWhereClause(std::string& queryStr, size_t channelsCount)
32 ✔
63
    {
64
        queryStr += "channel IN (";
32 ✔
65
        if (channelsCount > 0) {
32 ✔
66
            for (size_t i = 0; i < channelsCount - 1; ++i) {
45 ✔
67
                queryStr += "?,";
16 ✔
68
            }
69
            queryStr += "?";
29 ✔
70
        }
71
        queryStr += ") AND timestamp > ? AND timestamp < ?";
32 ✔
72
    }
32 ✔
73

74
    void AddWithAverageQuery(std::string& queryStr, size_t channelsCount)
5 ✔
75
    {
76
        queryStr += "SELECT MAX(uid), channel, value, MAX(timestamp), MIN(min), "
77
                    "MAX(max), retained, AVG(value) "
78
                    "FROM data INDEXED BY data_topic_timestamp WHERE ";
5 ✔
79
        AddCommonWhereClause(queryStr, channelsCount);
5 ✔
80
        queryStr += " AND uid > ? GROUP BY (round(timestamp/?)), channel";
5 ✔
81
    }
5 ✔
82

83
    void AddWithoutAverageQuery(std::string& queryStr, size_t channelsCount)
18 ✔
84
    {
85
        queryStr += "SELECT uid, channel, value, timestamp, min, max, retained, value "
86
                    "FROM data INDEXED BY data_topic_timestamp WHERE ";
18 ✔
87
        AddCommonWhereClause(queryStr, channelsCount);
18 ✔
88
        queryStr += " AND uid > ?";
18 ✔
89
    }
18 ✔
90
} // namespace Utils
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc