The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

sensor.cpp 2.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
 * Sensor.cpp
 *
 *  Created on: 28 Apr 2017
 *      Author: ottmi
 */

#include <iostream>
#include <dcdb/sensor.h>
#include <dcdb/virtualsensor.h>

namespace DCDB {

Michael Ott's avatar
Michael Ott committed
14
  Sensor::Sensor(Connection* connection, std::string publicName) {
15
    /* Initialize the SensorConfig interface */
Michael Ott's avatar
Michael Ott committed
16
17
18
19
    sensorConfig = new SensorConfig(connection);

    this->connection = connection;
    scalingFactor = 1;
20

Michael Ott's avatar
Michael Ott committed
21
22
    /* Retrieve publicSensor ifno */
    switch (sensorConfig->getPublicSensorByName(publicSensor, publicName.c_str())) {
23
24
25
26
27
28
29
30
31
32
33
34
    case DCDB::SC_OK:
      break;
    case DCDB::SC_INVALIDSESSION:
      std::cout << "Invalid session." << std::endl;
      return;
    case DCDB::SC_UNKNOWNSENSOR:
      std::cout << "Unknown sensor: " << publicName << std::endl;
      return;
    default:
      std::cout << "Unknown error." << std::endl;
      return;
    }
Michael Ott's avatar
Michael Ott committed
35
36
37
38
39
40
  }

  Sensor::~Sensor() {
    delete sensorConfig;
  }

41
  void Sensor::query(std::list<SensorDataStoreReading>& result, TimeStamp& start, TimeStamp& end, QueryAggregate aggregate) {
Michael Ott's avatar
Michael Ott committed
42
    SensorDataStore sensorDataStore(connection);
43
44

    if (publicSensor.is_virtual) {
Michael Ott's avatar
Michael Ott committed
45
        VSensor vSen(connection, publicSensor);
46
47
48
49
        vSen.query(result, start, end);
    }
    else {
        /* Expand the pattern into a list of existing sensors in the time range */
Michael Ott's avatar
Michael Ott committed
50
51
        std::list<SensorId> sensorIds;
        switch (sensorConfig->getSensorListForPattern(sensorIds, publicSensor.pattern, start, end)) {
52
53
54
55
56
57
58
59
60
61
62
        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 */
Michael Ott's avatar
Michael Ott committed
63
        for (std::list<SensorId>::iterator sit = sensorIds.begin(); sit != sensorIds.end(); sit++) {
64
            sensorDataStore.query(result, *sit, start, end, aggregate);
65
        }
Michael Ott's avatar
Michael Ott committed
66
67
68
69
70
71

        if (scalingFactor != 1.0 || publicSensor.scaling_factor != 1.0) {
          for (std::list<SensorDataStoreReading>::iterator reading = result.begin(); reading != result.end(); reading++) {
            reading->value = ((double) reading->value) * scalingFactor * publicSensor.scaling_factor;
          }
        }
72
73
74
75
    }
  }

} /* namespace DCDB */