Created
January 21, 2013 21:48
-
-
Save daemonfire300/4589783 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* | |
* Super Duper Copyright by Jul Foi, do not cropy | |
*/ | |
// win_visdata.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. | |
// | |
#include "stdafx.h" | |
#include <algorithm> | |
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <fstream> | |
#include "CImg-1.5.3/CImg.h" | |
using namespace std; | |
using namespace cimg_library; | |
enum Country | |
{ | |
Australia, | |
Canada, | |
Czech_Rep, | |
Estonia, | |
Finland, | |
France, | |
Germany, | |
Hong_Kong_China, | |
Ireland, | |
Japan, | |
Korea_Rep, | |
Latvia, | |
Lithuania, | |
Netherlands, | |
New_Zealand, | |
Norway, | |
Philippines, | |
Poland, | |
Portugal, | |
Romania, | |
Singapore, | |
Slovak_Republic, | |
Slovenia, | |
Spain, | |
Sweden, | |
Switzerland, | |
Turkey, | |
United_Kingdom, | |
United_States | |
}; | |
struct CountryData | |
{ | |
//Country id; | |
int id; | |
float* rate; // rate[YEAR] = data_entry; | |
}; | |
struct CSVTable | |
{ | |
string title; | |
int start_year; | |
int end_year; | |
CountryData* data; | |
}; | |
/*Country getCountry(string s_country) | |
{ | |
}*/ | |
int main() | |
{ | |
ifstream fs_datafile; | |
string line; | |
int c = 0; | |
int abs_rows; | |
fs_datafile.open("data.csv"); | |
if(fs_datafile.is_open()) | |
{ | |
abs_rows = std::count(std::istreambuf_iterator<char>(fs_datafile), | |
std::istreambuf_iterator<char>(), '\n'); | |
cout << "abs_rows: " << abs_rows << endl; | |
} | |
else | |
{ | |
cout << "Could not determine file size, will exit now..." << endl; | |
return 0; | |
} | |
fs_datafile.close(); | |
fs_datafile.open("data.csv"); | |
if(fs_datafile.is_open()) | |
{ | |
CSVTable* table = new CSVTable; | |
table->title = "Unemployment Rate"; | |
table->start_year = 0; | |
table->end_year = 0; | |
table->data = new CountryData[abs_rows]; | |
CImg<float> A(24, abs_rows-1, 1, 1, 0); | |
int row = 0, column = 0; | |
while(fs_datafile.good()) | |
{ | |
//if(c > 3) | |
// break; | |
if(getline(fs_datafile, line)) | |
{ | |
//cout << line << endl << endl; | |
cout << "row: " << row << endl; | |
stringstream sstream(line); | |
string value = ""; | |
//int year = 1; | |
if(row == 0) | |
{ | |
while(getline(sstream, value, ';')) | |
{ | |
//float f_rate = 0.0f; | |
switch(column) | |
{ | |
case 0: | |
table->title = value; | |
break; | |
default: | |
if(table->start_year == 0) | |
{ | |
istringstream(value) >> table->start_year; | |
istringstream(value) >> table->end_year; | |
} | |
else | |
{ | |
table->end_year++; | |
} | |
break; | |
} | |
cout << "(f)" << value << "(" << column << ")" << endl; | |
column++; | |
} | |
} | |
else | |
{ | |
CountryData* ctry = new CountryData; | |
ctry->rate = new float[table->end_year-table->start_year]; | |
while(getline(sstream, value, ';')) | |
{ | |
if(column == 0) | |
{ | |
cout << "Country: " << value << "(" << column << ")" << endl; | |
ctry->id = row-1; | |
} | |
else | |
{ | |
float f_rate = 0.0f; | |
istringstream(value) >> f_rate; | |
ctry->rate[column-1] = f_rate; | |
A(column-1, row-1) = f_rate; | |
cout << f_rate << "(" << column << ")" << endl; | |
} | |
column++; | |
} | |
table->data[row-1] = *ctry; | |
} | |
} | |
c++; | |
row++; | |
column = 0; | |
} | |
int data_entries = abs_rows-1; | |
cout << endl << endl << endl; | |
cout << "----------------------------------------------" << endl; | |
cout << "Title: \t" << table->title << endl; | |
cout << "Starting year: \t" << table->start_year << endl; | |
cout << "Ending year: \t" << table->end_year << endl; | |
cout << "Data Entries: \t" << data_entries << endl; | |
cout << "----------------------------------------------" << endl; | |
cout << endl << endl << endl; | |
cout << "id: " << table->data[0].id << " rate " << table->data[0].rate[5] << endl; | |
// A = U'*S*V | |
//A.display(); | |
CImgList<float> USV = A.get_SVD(); //USV[0] = U and so forth | |
cout << *USV[0] << " * " << *USV[1] << " * " << *USV[2] << endl; | |
CImgDisplay disp(500, 500); | |
CImgDisplay disp2(500, 500); | |
CImgDisplay disp3(500, 500); | |
disp.display(USV[0]); | |
disp2.display(USV[1]); | |
disp3.display(USV[2]); | |
//USV[2].display(disp); | |
string abc; | |
cin >> abc; | |
delete table; | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment