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

wirenboard / wb-mqtt-db / 96

31 Jul 2026 10:43AM UTC coverage: 78.543% (-1.8%) from 80.337%
96

push

github

web-flow
Use exported vars instead of MAKEFLAGS for coverage options (#66)

938 of 1102 branches covered (85.12%)

1563 of 1990 relevant lines covered (78.54%)

13.11 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();
×
22
    }
×
23

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

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

39
        if (withAverage && !isNumber(query.getColumn(VALUE_COLUMN).getString())) {
65✔
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()) {
43✔
47
            return visitor.ProcessRecord(recordId,
28✔
48
                                         channel,
49
                                         query.getColumn(AVERAGE_VALUE_COLUMN).getString(),
56✔
50
                                         timestamp,
51
                                         retain);
28✔
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)
26✔
63
    {
64
        queryStr += "channel IN (";
26✔
65
        if (channelsCount > 0) {
26✔
66
            for (size_t i = 0; i < channelsCount - 1; ++i) {
39✔
67
                queryStr += "?,";
16✔
68
            }
69
            queryStr += "?";
23✔
70
        }
71
        queryStr += ") AND timestamp > ? AND timestamp < ?";
26✔
72
    }
26✔
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)
12✔
84
    {
85
        queryStr += "SELECT uid, channel, value, timestamp, min, max, retained, value "
86
                    "FROM data INDEXED BY data_topic_timestamp WHERE ";
12✔
87
        AddCommonWhereClause(queryStr, channelsCount);
12✔
88
        queryStr += " AND uid > ?";
12✔
89
    }
12✔
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