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 1.97 KB
Newer Older
1
2
3
4
/*
 * Sensor.cpp
 *
 *  Created on: 28 Apr 2017
5
 *      Author: Michael Ott, Daniele Tafani
6
7
8
9
10
11
12
13
 */

#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
    sensorConfig = new SensorConfig(connection);

    this->connection = connection;
19
20
      
    /* Retrieve publicSensor info */
Michael Ott's avatar
Michael Ott committed
21
    switch (sensorConfig->getPublicSensorByName(publicSensor, publicName.c_str())) {
22
23
24
25
26
27
28
29
30
31
32
33
    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
34
35
36
37
38
39
  }

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

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

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

} /* namespace DCDB */