|
|
|
@ -4,7 +4,8 @@ using namespace std;
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
|
std::vector<double> numbers;
|
|
|
|
@ -12,57 +13,63 @@ struct Input {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input input_data(istream& in, bool promt);
|
|
|
|
|
Input download(const string& address);
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
Input input;
|
|
|
|
|
if(argc > 1 ){
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if(curl) {
|
|
|
|
|
CURLcode res;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
if(res!=0){
|
|
|
|
|
cout << curl_easy_strerror(res) << endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
input = download(argv[1]);
|
|
|
|
|
}else{
|
|
|
|
|
input = input_data(cin,true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input in = input_data(cin,true);
|
|
|
|
|
std::vector<size_t> bins = make_histogram(in.numbers, in.bin_count);
|
|
|
|
|
std::vector<size_t> bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
Input
|
|
|
|
|
download(const string& address) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if(curl) {
|
|
|
|
|
CURLcode res;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address);
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
if(res!=0){
|
|
|
|
|
cout << curl_easy_strerror(res) << endl;
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
}
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input input_data(istream& in, bool promt) {
|
|
|
|
|
|
|
|
|
|
Input input_struct;
|
|
|
|
|
size_t countOfNumbers;
|
|
|
|
|
if(promt){cerr << "Input your count of numbers:\n";}
|
|
|
|
|
|
|
|
|
|
cin >> countOfNumbers;
|
|
|
|
|
in >> countOfNumbers;
|
|
|
|
|
|
|
|
|
|
input_struct.numbers.resize(countOfNumbers);
|
|
|
|
|
if(promt){cerr << "Input numbers:\n";}
|
|
|
|
|
for (int i = 0; i < countOfNumbers; i++) {
|
|
|
|
|
if(promt){cerr << i << ":" << endl;}
|
|
|
|
|
cin >> input_struct.numbers[i];
|
|
|
|
|
in >> input_struct.numbers[i];
|
|
|
|
|
}
|
|
|
|
|
if(promt){
|
|
|
|
|
cerr << endl;
|
|
|
|
|
cerr << "Input bin count:\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cin >> input_struct.bin_count;
|
|
|
|
|
in >> input_struct.bin_count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|