Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
dfe95445
Commit
dfe95445
authored
Aug 11, 2020
by
Michael Ott
Browse files
Remove getSensorPattern() and getSensorListForPattern() functions
parent
4e33a5ff
Changes
5
Hide whitespace changes
Inline
Side-by-side
lib/include/dcdb/sensorconfig.h
View file @
dfe95445
...
...
@@ -233,40 +233,6 @@ public:
*/
SCError
isVirtual
(
bool
&
isVirtual
,
std
::
string
publicName
);
/**
* @brief Get the SensorID pattern for a given public sensor.
*
* @param pattern Reference to a string which holds the result.
* @param publicName Name of the sensor whose information should be retrieved.
* @return See SCError.
*/
SCError
getSensorPattern
(
std
::
string
&
pattern
,
std
::
string
publicName
);
/**
* @brief Get the list of SensorIDs (available in the database) that match a given pattern.
*
* @param sensorIDs Reference to a list of SensorID which holds the result.
* @param pattern The SensorID pattern which should be matched by the resulting sensors.
* @return See SCError.
*/
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
);
/**
* @brief Get the list of SensorIDs (available in the database) that match a given pattern - optimized version.
*
* @param pattern Reference to a string which holds the result.
* @param publicName Name of the sensor whose information should be retrieved.
* @param start Start of the time window
* @param end End of the time window
* @return See SCError.
*
* @details Since seeking the list of SensorIDs that match a given SensorID pattern is often
* used before querying the database in a given time window, this optimized version
* will be helpful in that it only returns SensorIDs that provide data in the given
* time window.
*/
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
TimeStamp
start
,
TimeStamp
end
);
/**
* @brief Set the scaling factor for a public sensor. (FIXME: Scaling factors system is not in use!)
*
...
...
lib/include_internal/sensorconfig_internal.h
View file @
dfe95445
...
...
@@ -72,10 +72,6 @@ public:
SCError
isVirtual
(
bool
&
isVirtual
,
std
::
string
publicName
);
SCError
getSensorPattern
(
std
::
string
&
pattern
,
std
::
string
publicName
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
);
SCError
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
TimeStamp
start
,
TimeStamp
end
);
SCError
setSensorScalingFactor
(
std
::
string
publicName
,
double
scalingFactor
);
SCError
setSensorUnit
(
std
::
string
publicName
,
std
::
string
unit
);
SCError
setSensorMask
(
std
::
string
publicName
,
uint64_t
mask
);
...
...
lib/src/sensor.cpp
View file @
dfe95445
...
...
@@ -73,28 +73,20 @@ namespace DCDB {
vSen
.
query
(
result
,
start
,
end
);
}
else
{
/* Expand the pattern into a list of existing sensors in the time range */
std
::
list
<
SensorId
>
sensorIds
;
switch
(
sensorConfig
->
getSensorListForPattern
(
sensorIds
,
publicSensor
.
pattern
,
start
,
end
))
{
case
DCDB
::
SC_OK
:
break
;
case
DCDB
::
SC_INVALIDPATTERN
:
std
::
cout
<<
"Invalid pattern."
<<
std
::
endl
;
return
;
default:
std
::
cout
<<
"Unknown error."
<<
std
::
endl
;
return
;
}
/* Iterate over the expanded list of sensorIds and output the results in CSV format */
/* Iterate over the sensorIds within the query interval and output the results in CSV format */
if
(
start
.
getRaw
()
!=
end
.
getRaw
())
{
for
(
std
::
list
<
SensorId
>::
iterator
sit
=
sensorIds
.
begin
();
sit
!=
sensorIds
.
end
();
sit
++
)
{
sensorDataStore
.
query
(
result
,
*
sit
,
start
,
end
,
aggregate
);
uint16_t
wsStart
=
start
.
getWeekstamp
();
uint16_t
wsEnd
=
end
.
getWeekstamp
();
SensorId
sid
(
publicSensor
.
name
);
for
(
uint16_t
ws
=
wsStart
;
ws
<=
wsEnd
;
ws
++
)
{
sid
.
setRsvd
(
ws
);
sensorDataStore
.
query
(
result
,
sid
,
start
,
end
,
aggregate
);
}
}
else
{
for
(
std
::
list
<
SensorId
>::
iterator
sit
=
sensorIds
.
begin
();
sit
!=
sensorIds
.
end
();
sit
++
)
{
sensorDataStore
.
fuzzyQuery
(
result
,
*
sit
,
start
,
tol_ns
);
}
SensorId
sid
(
publicSensor
.
name
);
sid
.
setRsvd
(
start
.
getWeekstamp
()
);
sensorDataStore
.
fuzzyQuery
(
result
,
sid
,
start
,
tol_ns
);
}
}
}
...
...
lib/src/sensorconfig.cpp
View file @
dfe95445
...
...
@@ -189,21 +189,6 @@ SCError SensorConfig::isVirtual(bool& isVirtual, std::string publicName)
return
impl
->
isVirtual
(
isVirtual
,
publicName
);
}
SCError
SensorConfig
::
getSensorPattern
(
std
::
string
&
pattern
,
std
::
string
publicName
)
{
return
impl
->
getSensorPattern
(
pattern
,
publicName
);
}
SCError
SensorConfig
::
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
)
{
return
impl
->
getSensorListForPattern
(
sensorIds
,
pattern
);
}
SCError
SensorConfig
::
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
TimeStamp
start
,
TimeStamp
end
)
{
return
impl
->
getSensorListForPattern
(
sensorIds
,
pattern
,
start
,
end
);
}
SCError
SensorConfig
::
setSensorScalingFactor
(
std
::
string
publicName
,
double
scalingFactor
)
{
return
impl
->
setSensorScalingFactor
(
publicName
,
scalingFactor
);
}
...
...
@@ -1222,202 +1207,6 @@ SCError SensorConfigImpl::isVirtual(bool& isVirtual, std::string publicName)
return
SC_OK
;
}
SCError
SensorConfigImpl
::
getSensorPattern
(
std
::
string
&
pattern
,
std
::
string
publicName
)
{
/* Check if the session is valid */
if
(
!
session
)
{
return
SC_INVALIDSESSION
;
}
/* Ensure that the public sensor is not virtual */
bool
virt
;
SCError
err
=
isVirtual
(
virt
,
publicName
);
if
(
err
!=
SC_OK
)
{
return
err
;
}
if
(
virt
)
{
return
SC_WRONGTYPE
;
}
/* Read the Pattern string from the database */
CassError
rc
=
CASS_OK
;
CassStatement
*
statement
=
nullptr
;
CassFuture
*
future
=
nullptr
;
const
CassPrepared
*
prepared
=
nullptr
;
const
char
*
query
=
"SELECT pattern FROM "
CONFIG_KEYSPACE_NAME
"."
CF_PUBLISHEDSENSORS
" WHERE name = ? ;"
;
future
=
cass_session_prepare
(
session
,
query
);
cass_future_wait
(
future
);
rc
=
cass_future_error_code
(
future
);
if
(
rc
!=
CASS_OK
)
{
connection
->
printError
(
future
);
cass_future_free
(
future
);
return
SC_UNKNOWNERROR
;
}
else
{
prepared
=
cass_future_get_prepared
(
future
);
}
cass_future_free
(
future
);
statement
=
cass_prepared_bind
(
prepared
);
cass_statement_bind_string_by_name
(
statement
,
"name"
,
publicName
.
c_str
());
future
=
cass_session_execute
(
session
,
statement
);
cass_future_wait
(
future
);
rc
=
cass_future_error_code
(
future
);
if
(
rc
!=
CASS_OK
)
{
connection
->
printError
(
future
);
}
else
{
const
CassResult
*
result
=
cass_future_get_result
(
future
);
CassIterator
*
iterator
=
cass_iterator_from_result
(
result
);
if
(
cass_iterator_next
(
iterator
))
{
const
char
*
pattern_cstr
;
size_t
pattern_len
;
const
CassRow
*
row
=
cass_iterator_get_row
(
iterator
);
cass_value_get_string
(
cass_row_get_column_by_name
(
row
,
"pattern"
),
&
pattern_cstr
,
&
pattern_len
);
pattern
=
std
::
string
(
pattern_cstr
,
pattern_len
);
}
else
{
cass_result_free
(
result
);
cass_iterator_free
(
iterator
);
cass_future_free
(
future
);
cass_statement_free
(
statement
);
cass_prepared_free
(
prepared
);
return
SC_UNKNOWNSENSOR
;
}
cass_result_free
(
result
);
cass_iterator_free
(
iterator
);
}
cass_future_free
(
future
);
cass_statement_free
(
statement
);
cass_prepared_free
(
prepared
);
return
SC_OK
;
}
SCError
SensorConfigImpl
::
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
)
{
/* Tiny hack to call the long version of this function */
TimeStamp
start
((
uint64_t
)
0x0
);
TimeStamp
end
((
uint64_t
)
0x260DD31906D70000
);
return
getSensorListForPattern
(
sensorIds
,
pattern
,
start
,
end
);
}
SCError
SensorConfigImpl
::
getSensorListForPattern
(
std
::
list
<
SensorId
>&
sensorIds
,
std
::
string
pattern
,
TimeStamp
start
,
TimeStamp
end
)
{
/* Clear the list of sensorIds */
sensorIds
.
clear
();
/* Strip all slashes from publishedSensorName */
//pattern.erase(std::remove(pattern.begin(), pattern.end(), '/'), pattern.end());
uint16_t
wsStart
=
start
.
getWeekstamp
();
uint16_t
wsEnd
=
end
.
getWeekstamp
();
for
(
uint16_t
ws
=
wsStart
;
ws
<=
wsEnd
;
ws
++
)
{
SensorId
sensor
;
sensor
.
setId
(
pattern
);
sensor
.
setRsvd
(
ws
);
sensorIds
.
push_back
(
sensor
);
}
return
SC_OK
;
// /* Clear the list of sensorIds */
// sensorIds.clear();
//
// /* Strip all slashes from publishedSensorName */
// pattern.erase(std::remove(pattern.begin(), pattern.end(), '/'), pattern.end());
//
// /* Calculate lower and upper boundaries for the expansion of the pattern */
// std::string low = pattern;
// std::string high = pattern;
// if (pattern.find("*") != std::string::npos) {
// low.replace(pattern.find("*"), 1, MAX_PATTERN_LENGTH-pattern.length(), 0);
// high.replace(pattern.find("*"), 1, MAX_PATTERN_LENGTH-pattern.length(), 127);
// }
//
// SensorId lowId, highId;
// if (!lowId.mqttTopicConvert(low)) {
// return SC_INVALIDPATTERN;
// }
// if (!highId.mqttTopicConvert(high)) {
// return SC_INVALIDPATTERN;
// }
//
// std::cout << "Lower boundary for sensor scan: " << std::hex << std::setfill('0') << std::setw(16) << lowId.raw[0] << " " << std::hex << std::setfill('0') << std::setw(16) << lowId.raw[1] << std::endl;
// std::cout << "Upper boundary for sensor scan: " << std::hex << std::setfill('0') << std::setw(16) << highId.raw[0] << " " << std::hex << std::setfill('0') << std::setw(16) << highId.raw[1] << std::endl;
//
// /* Query the database to see which raw sensors actually exist in the interval between low and high */
// CassError rc = CASS_OK;
// CassStatement* statement = nullptr;
// CassFuture* future = nullptr;
// const CassPrepared* prepared = nullptr;
// const char* query = "SELECT DISTINCT sid,ws FROM " KEYSPACE_NAME "." CF_SENSORDATA " WHERE TOKEN(sid) >= TOKEN(?) and TOKEN(sid) <= TOKEN(?) and ws >= ? and ws <= ?;";
//
// future = cass_session_prepare(session, query);
// cass_future_wait(future);
//
// rc = cass_future_error_code(future);
// if (rc != CASS_OK) {
// connection->printError(future);
// return SC_UNKNOWNERROR;
// }
//
// prepared = cass_future_get_prepared(future);
// cass_future_free(future);
//
// statement = cass_prepared_bind(prepared);
//
// cass_statement_bind_string(statement, 0, low.c_str());
// cass_statement_bind_string(statement, 1, high.c_str());
// cass_statement_bind_int16(statement, 2, (cass_int16_t)start.getWeekstamp());
// cass_statement_bind_int16(statement, 3, (cass_int16_t)end.getWeekstamp());
//
// future = cass_session_execute(session, statement);
// cass_future_wait(future);
//
// rc = cass_future_error_code(future);
// if (rc != CASS_OK) {
// connection->printError(future);
// return SC_UNKNOWNERROR;
// }
//
// const CassResult* result = cass_future_get_result(future);
// cass_future_free(future);
//
// CassIterator* iterator = cass_iterator_from_result(result);
// while (cass_iterator_next(iterator)) {
// const CassRow* row = cass_iterator_get_row(iterator);
// const char* res;
// size_t res_len;
// cass_int16_t res_ws;
// cass_value_get_string(cass_row_get_column_by_name(row, "sid"), &res, &res_len);
// cass_value_get_int16(cass_row_get_column_by_name(row, "ws"), &res_ws);
//
// SensorId sensor;
// std::string id(res, res_len);
// sensor.setId(id);
//
// /* Check if the sensorId matches the pattern and append to result */
// if (sensor.patternMatch(pattern)) {
// /* Only append if within the weekstamp window */
// if ((res_ws >= start.getWeekstamp()) && (res_ws <= end.getWeekstamp())) {
// sensorIds.push_back(sensor);
// }
// }
// }
// cass_result_free(result);
// cass_iterator_free(iterator);
// cass_statement_free(statement);
// cass_prepared_free(prepared);
//
// return SC_OK;
}
SCError
SensorConfigImpl
::
setSensorScalingFactor
(
std
::
string
publicName
,
double
scalingFactor
)
{
SCError
error
=
SC_UNKNOWNERROR
;
...
...
lib/src/virtualsensor.cpp
View file @
dfe95445
...
...
@@ -124,21 +124,8 @@ void PhysicalSensorCache::populate(Connection* connection, SensorConfig& sc, uin
CassSession
*
session
=
connection
->
getSessionHandle
();
/* Expand the sensor's public name into its internal SensorId */
std
::
list
<
DCDB
::
SensorId
>
sensorIds
;
switch
(
sc
.
getSensorListForPattern
(
sensorIds
,
s
.
pattern
,
t
,
t
))
{
case
DCDB
::
SC_OK
:
break
;
case
DCDB
::
SC_INVALIDPATTERN
:
std
::
cout
<<
"Invalid pattern."
<<
std
::
endl
;
return
;
default:
std
::
cout
<<
"Unknown error."
<<
std
::
endl
;
return
;
}
/* The sensorIds list should only contain one entry */
std
::
list
<
DCDB
::
SensorId
>::
iterator
sit
=
sensorIds
.
begin
();
// std::cout << "Raw sensor id: " << std::hex << std::setfill('0') << std::setw(16) << sit->getRaw()[0] << " " << std::hex << std::setfill('0') << std::setw(16) << sit->getRaw()[1] << std::dec << std::endl;
DCDB
::
SensorId
sid
(
s
.
name
);
sid
.
setRsvd
(
DCDB
::
TimeStamp
(
t
).
getWeekstamp
());
/* Find the readings before and after time t */
CassError
rc
=
CASS_OK
;
...
...
@@ -163,8 +150,8 @@ void PhysicalSensorCache::populate(Connection* connection, SensorConfig& sc, uin
cass_future_free
(
future
);
statement
=
cass_prepared_bind
(
prepared
);
cass_statement_bind_string
(
statement
,
0
,
si
t
->
getId
().
c_str
());
cass_statement_bind_int16
(
statement
,
1
,
si
t
->
getRsvd
());
cass_statement_bind_string
(
statement
,
0
,
si
d
.
getId
().
c_str
());
cass_statement_bind_int16
(
statement
,
1
,
si
d
.
getRsvd
());
cass_statement_bind_int64
(
statement
,
2
,
t
);
future
=
cass_session_execute
(
session
,
statement
);
...
...
@@ -182,7 +169,7 @@ void PhysicalSensorCache::populate(Connection* connection, SensorConfig& sc, uin
cass_value_get_int64
(
cass_row_get_column_by_name
(
row
,
"value"
),
&
value
);
SensorDataStoreReading
r
;
r
.
sensorId
=
*
si
t
;
r
.
sensorId
=
si
d
;
r
.
timeStamp
=
(
uint64_t
)
ts
;
r
.
value
=
(
int64_t
)
value
;
...
...
@@ -211,8 +198,8 @@ void PhysicalSensorCache::populate(Connection* connection, SensorConfig& sc, uin
cass_future_free
(
future
);
statement
=
cass_prepared_bind
(
prepared
);
cass_statement_bind_string
(
statement
,
0
,
si
t
->
getId
().
c_str
());
cass_statement_bind_int16
(
statement
,
1
,
si
t
->
getRsvd
());
cass_statement_bind_string
(
statement
,
0
,
si
d
.
getId
().
c_str
());
cass_statement_bind_int16
(
statement
,
1
,
si
d
.
getRsvd
());
cass_statement_bind_int64
(
statement
,
2
,
t
);
future
=
cass_session_execute
(
session
,
statement
);
...
...
@@ -230,7 +217,7 @@ void PhysicalSensorCache::populate(Connection* connection, SensorConfig& sc, uin
cass_value_get_int64
(
cass_row_get_column_by_name
(
row
,
"value"
),
&
value
);
SensorDataStoreReading
r
;
r
.
sensorId
=
*
si
t
;
r
.
sensorId
=
si
d
;
r
.
timeStamp
=
(
uint64_t
)
ts
;
r
.
value
=
(
int64_t
)
value
;
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment