Skip to content

Instantly share code, notes, and snippets.

@jason790228
Last active December 6, 2017 02:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jason790228/b27ddc9da15e46adcc5ad7300feb7851 to your computer and use it in GitHub Desktop.
Save jason790228/b27ddc9da15e46adcc5ad7300feb7851 to your computer and use it in GitHub Desktop.
RemakeReport
#include "DataTansfer.h"
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
using namespace std;
void DataTransfer::read_data(string filename)
{
ifstream f(filename.c_str());
string line;
bool data_sec(false);
if (f.is_open())
{
int time_count(0);
while (getline(f, line))
{
if (nullptr != strstr(line.c_str(), "Table")) continue;
if (nullptr != strstr(line.c_str(), "Datetime")) continue;
if ( nullptr != strstr(line.c_str(), "Server Name")
&& nullptr != strstr(line.c_str(), "Service Name")
&& nullptr != strstr(line.c_str(), "Device Name")
&& nullptr != strstr(line.c_str(), "Counter Name"))
{
data_sec = true;
continue;
}
if (nullptr != strstr(line.c_str(), "Total"))
{
data_sec = false;
continue;
}
if (data_sec)
{
size_t pos(0);
int count(0);
InputDataInfo temp_data;
while ((pos = line.find(",")) != string::npos)
{
string token = line.substr(0, pos); line.erase(0, pos + 1);
if (count == 0) temp_data.server_name = token;
else if (count == 1) temp_data.service_name = token;
else if (count == 2) temp_data.device_name = token;
else if (count == 3) temp_data.counter_name = token;
else temp_data.data.push_back(stoi(token));
count++;
}
m_input_data_info.push_back(temp_data);
}
}
f.close();
}
}
bool DataTransfer::date_translate(const std::string date1, std::string& date2)
{
return 0;
}
void DataTransfer::analysis_data()
{
for (size_t i = 0; i < m_input_data_info.size(); i++)
{
bool found(false);
for (size_t j = 0; j < m_output_data_info.size(); j++)
{
if (m_output_data_info[j].branch_code == m_input_data_info[i].server_name)
{
found = true;
for (size_t k = 0; k < m_output_data_info[j].in.size(); k++) m_output_data_info[j].in[k] += m_input_data_info[i].data[k];
break;
}
}
if (!found)
{
OutputDataInfo temp_output;
temp_output.branch_code = m_input_data_info[i].server_name;
for (size_t j = 0; j < m_input_data_info[i].data.size(); j++) temp_output.in.push_back(m_input_data_info[i].data[j]);
m_output_data_info.push_back(temp_output);
}
}
}
void DataTransfer::generate_report()
{
cout << "Datetime,Branch Code,In\n";
string prefixed = "11-30-17 ";
string postfixed = ":00";
for (size_t j = 0; j < m_output_data_info[0].in.size(); j++)
{
stringstream ss;
if (j < 9) { ss << "0"; ss << j+1; }
else ss << j+1;
for (size_t i = 0; i < m_output_data_info.size(); i++)
cout << prefixed + ss.str() + postfixed << "," << m_output_data_info[i].branch_code << "," << m_output_data_info[i].in[j] << endl;
}
}
#include <string>
#include <vector>
#include <map>
struct InputDataInfo
{
std::string server_name;
std::string service_name;
std::string device_name;
std::string counter_name;
std::vector<int> data;
};
struct OutputDataInfo
{
std::string branch_code;
std::vector<int> in;
};
class DataTransfer
{
public:
DataTransfer() : server_type(0) {};
void read_data(std::string file_name);
void analysis_data();
void generate_report();
private:
bool date_translate(const std::string date1, std::string& date2);
int server_type;
std::vector<InputDataInfo> m_input_data_info;
std::vector<OutputDataInfo> m_output_data_info;
};
#include "DataTansfer.h"
int main()
{
DataTransfer test;
test.read_data("C:\\Users\\Jason\\Documents\\Visual Studio 2013\\Projects\\ReportGenReport\\Debug\\input.csv");
test.analysis_data();
test.generate_report();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment