-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateDataset.cpp
88 lines (73 loc) · 1.87 KB
/
generateDataset.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/*-------------------------For Reading csv file----------------*/
int len(string str)
{
int length = 0;
for (int i = 0; str[i] != '\0'; i++)
length++;
return length;
}
// create custom split() function
void split(string str, char seperator, vector<string> &strings)
{
int currIndex = 0, i = 0;
int startIndex = 0, endIndex = 0;
while (i <= len(str))
{
if (str[i] == seperator || i == len(str))
{
endIndex = i;
string subStr = "";
subStr.append(str, startIndex, endIndex - startIndex);
// strings[currIndex] = subStr;
strings.push_back(subStr);
currIndex += 1;
startIndex = endIndex + 1;
}
i++;
}
}
char random_string()
{
string str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
return str[(int)(rand() % str.size())];
}
int main()
{
vector<string> v;
string line, word;
// fstream file("Stock_data.csv", ios::in);
// fstream file("ADANIPORTS.csv", ios::in);
fstream file("dataset.csv", ios::in);
// fstream file("NIFTY50_all.csv", ios::in);
vector<string> strings;
char seperator = ',';
int i = 0;
if (file.is_open())
{
while (getline(file, line))
{
i++;
if (i == 1)
continue;
split(line, seperator, strings);
// cout << strings[2] << endl;
strings.clear();
string d = strings[0];
d += ",";
string randomstring;
for (int i = 0; i < 22; i++)
randomstring += random_string();
v.push_back(d + randomstring);
}
}
else
cout << "Could not open the file\n";
for (int i =0 ; i<v.size();i++)
{
cout<<v[i]<<endl;
}
return 0;
}