Parallel Coordinate System with Time Series Data
Calendar.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QtWidgets/QWidget>
4 #include <qdebug.h>
5 #include <string>
6 #include <iostream>
7 #include <filesystem>
8 #include <unordered_map>
9 #include "qtcsv/stringdata.h"
10 #include "qtcsv/reader.h"
11 #include "qtcsv/writer.h"
12 #include "qstring.h"
13 #include <qvector3d.h>
14 
15 //using namespace std;
16 namespace fs = std::filesystem;
17 
27 struct Date {
28  int year, month, day;
29  Date() {}
30 
31  Date(int y, int m, int d)
32  {
33  year = y;
34  month = m;
35  day = d;
36  }
37 
38  // Match both first and last names in case
39  // of collisions.
40  bool operator==(const Date& o) const {
41  return year == o.year && month == o.month && day == o.day;
42  }
43 
44  bool operator<(const Date& o) const {
45  return year < o.year || (year == o.year && month < o.month) || (year == o.year && month == o.month && day < o.day);
46  }
47 
48  std::string toString() {
49  return std::to_string(day) + "." + std::to_string(month) + "." + std::to_string(year);
50  }
51 };
52 
53 namespace std {
54 
55  template <>
56  struct hash<Date>
57  {
58  std::size_t operator()(const Date& d) const
59  {
60  using std::size_t;
61  using std::hash;
62 
63  // Compute individual hash values for first,
64  // second and third and combine them using XOR
65  // and bit shifting:
66 
67  return (hash<int>()(d.year) << 1)
68  ^ (hash<int>()(d.month) << 1)
69  ^ (hash<int>()(d.day) << 1);
70  }
71  };
72 }
73 
83 class Calendar {/*class to load and access time series data*/
84 private:
91  int decideLimit(int year, int month);
92 
98  void initData(std::string filespath);
99 
103  void testData();
104 public:
110  Calendar(std::string filespath);
111  ~Calendar();
112 
117 
121  std::unordered_map<Date, std::vector<std::vector<std::string>>> data;
122 
127  std::unordered_map<std::string, std::pair<float, float>> minMax; //first value of pair is min, second is max
128 
132  std::vector<std::string> attribute_names;
133 
137  std::unordered_map<std::string, int> attr_to_index_map;
138 
143  std::unordered_map<std::string, QVector3D> entity_colors = {
144  /*std::make_pair("Bitcoin", QVector3D(0.0, 0.0, 0.0)),
145  std::make_pair("Dogecoin", QVector3D(0.0, 0.0, 1.0)),
146  std::make_pair("Etherum", QVector3D(0.0, 1.0, 0.0)),
147  std::make_pair("Litecoin", QVector3D(0.0, 1.0, 1.0)),
148  std::make_pair("Monero", QVector3D(1.0, 0.0, 0.0)),
149  std::make_pair("Stellar", QVector3D(1.0, 0.0, 1.0)),
150  std::make_pair("Tether", QVector3D(1.0, 1.0, 0.0)),
151  std::make_pair("XRP", QVector3D(0.0, 0.0, 0.5))*/
152  };
153 
160  Date addDaysToDate(Date date, int daysToAdd);
161 };
A Calendar from which you can access the whole data.
Definition: Calendar.h:83
std::unordered_map< Date, std::vector< std::vector< std::string > > > data
Definition: Calendar.h:121
~Calendar()
Destructor.
Definition: Calendar.cpp:29
std::unordered_map< std::string, QVector3D > entity_colors
Definition: Calendar.h:143
std::unordered_map< std::string, std::pair< float, float > > minMax
Definition: Calendar.h:127
Date minDate
Definition: Calendar.h:116
std::unordered_map< std::string, int > attr_to_index_map
Definition: Calendar.h:137
Date addDaysToDate(Date date, int daysToAdd)
Adds the days to date to 'daysToAdd'.
Definition: Calendar.cpp:93
Calendar(std::string filespath)
Constructor.
Definition: Calendar.cpp:14
std::vector< std::string > attribute_names
Definition: Calendar.h:132
Date maxDate
Definition: Calendar.h:116
Definition: Calendar.h:53
representing a Date
Definition: Calendar.h:27
Date(int y, int m, int d)
Definition: Calendar.h:31
int year
Definition: Calendar.h:28
bool operator<(const Date &o) const
Definition: Calendar.h:44
Date()
Definition: Calendar.h:29
int month
Definition: Calendar.h:28
int day
Definition: Calendar.h:28
bool operator==(const Date &o) const
Definition: Calendar.h:40
std::string toString()
Definition: Calendar.h:48
std::size_t operator()(const Date &d) const
Definition: Calendar.h:58