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

sfc-aqua / quisp / 8099990924

29 Feb 2024 05:17PM UTC coverage: 41.578% (-0.8%) from 42.352%
8099990924

Pull #545

github

web-flow
Merge c2570a20a into 274af93d1
Pull Request #545: Add satellite links

82 of 404 new or added lines in 13 files covered. (20.3%)

6 existing lines in 4 files now uncovered.

2799 of 6732 relevant lines covered (41.58%)

38008.3 hits per line

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

0.0
/quisp/channels/CSVParser.cc
1
/** \file CSVParser.cc
2
 *
3
 *  \brief CSVParser
4
 *
5
 *
6
 *  Quick parser for CSVs, written for csv-based Free-space channels.
7
 */
8

9
#include "CSVParser.h"
10

NEW
11
CSVParser::CSVParser(const string filename) {
×
NEW
12
  file.open(filename);
×
NEW
13
  if (!file.is_open()) throw cRuntimeError("Couldn't find CSV file!");
×
NEW
14
  string line;
×
NEW
15
  double key = 0;
×
NEW
16
  double val = 0;
×
NEW
17
  char sep;  // throwaway
×
NEW
18
  while (file >> line) {
×
NEW
19
    std::istringstream ss(line);
×
NEW
20
    ss >> key >> sep >> val;
×
NEW
21
    property.insert(std::pair<double, double>(key, val));
×
NEW
22
  }
×
NEW
23
  return;
×
NEW
24
}
×
25

NEW
26
double CSVParser::getPropertyAtTime(const double time) {
×
NEW
27
  if (time < getLowestDatapoint()) return getLowestDatavalue();
×
NEW
28
  if (time > getHighestDatapoint()) return getHighestDatavalue();
×
29

30
  // These two first lines are there just to provide mathematically sound results.
31
  // They should never be used in actual simulation, as they are NOT in any way
32
  // guaranteed to be accurate.
33

NEW
34
  if (time != last_polled_time) {
×
NEW
35
    last_polled_time = time;
×
NEW
36
    auto u_b = property.upper_bound(time);
×
NEW
37
    if (u_b == property.end()) {
×
NEW
38
      last_polled_value = (--u_b)->second;
×
NEW
39
    } else if (u_b == property.begin()) {
×
NEW
40
      last_polled_value = u_b->second;
×
NEW
41
    } else {
×
NEW
42
      auto l_b = u_b;
×
NEW
43
      --l_b;
×
NEW
44
      const double delta = (time - l_b->first) / (u_b->first - l_b->first);
×
NEW
45
      last_polled_value = delta * u_b->second + (1 - delta) * l_b->second;
×
NEW
46
    }
×
NEW
47
  }
×
NEW
48
  return last_polled_value;
×
NEW
49
}
×
50

NEW
51
int CSVParser::getLowestDatapoint() { return property.begin()->first; }
×
52

NEW
53
int CSVParser::getHighestDatapoint() { return property.rbegin()->first; }
×
54

NEW
55
double CSVParser::getLowestDatavalue() { return property.begin()->second; }
×
56

NEW
57
double CSVParser::getHighestDatavalue() { return property.rbegin()->second; }
×
58

NEW
59
CSVParser::~CSVParser() {}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc