|
|
@ -1,48 +1,42 @@
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include "histogram.h"
|
|
|
|
#include "histogram.h"
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
#include "text.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "svg.h"
|
|
|
|
#include "svg.h"
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
struct Input {
|
|
|
|
|
|
|
|
|
|
|
|
struct Input
|
|
|
|
|
|
|
|
{
|
|
|
|
vector<double> numbers;
|
|
|
|
vector<double> numbers;
|
|
|
|
size_t bin_count{};
|
|
|
|
size_t bin_count{};
|
|
|
|
vector<string> colors;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
|
|
|
input_data(istream& inn, bool promt) {
|
|
|
|
Input input_data(istream& stream, bool prompt) {
|
|
|
|
if (promt == true) {
|
|
|
|
|
|
|
|
cerr << "Sovet:" << endl;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t number_count;
|
|
|
|
|
|
|
|
cerr << "Enter number_count: ";
|
|
|
|
|
|
|
|
inn >> number_count;
|
|
|
|
|
|
|
|
Input in;
|
|
|
|
Input in;
|
|
|
|
cerr << "Enter numbers: ";
|
|
|
|
size_t number_count;
|
|
|
|
|
|
|
|
if (prompt) {
|
|
|
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stream >> number_count;
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
in.numbers.resize(number_count);
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
for (size_t i = 0; i < number_count; i++) {
|
|
|
|
inn >> in.numbers[i];
|
|
|
|
if (prompt) {
|
|
|
|
|
|
|
|
cerr << "Enter number " << i + 1 << ": ";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
stream >> in.numbers[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cerr << "Enter bin_count: ";
|
|
|
|
if (prompt) {
|
|
|
|
inn >> in.bin_count;
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
in.colors.resize(in.bin_count);
|
|
|
|
|
|
|
|
sort(begin(in.numbers), end(in.numbers));
|
|
|
|
|
|
|
|
in.numbers.erase(unique(begin(in.numbers), end(in.numbers)), end(in.numbers));
|
|
|
|
|
|
|
|
number_count = in.numbers.size();
|
|
|
|
|
|
|
|
cerr << "Enter colors: ";
|
|
|
|
|
|
|
|
for (size_t i = 0; i < in.bin_count; i++) {
|
|
|
|
|
|
|
|
inn >> in.colors[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stream >> in.bin_count;
|
|
|
|
return in;
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
size_t
|
|
|
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
size_t data_size = item_size * item_count;
|
|
|
|
size_t data_size = item_size * item_count;
|
|
|
@ -57,21 +51,23 @@ download(const string& address) {
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
if (curl) {
|
|
|
|
if (curl) {
|
|
|
|
CURLcode res;
|
|
|
|
CURLcode res;
|
|
|
|
|
|
|
|
double start;
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
if (res == CURLE_OK) {
|
|
|
|
cerr << curl_easy_strerror(res);
|
|
|
|
res = curl_easy_getinfo(curl, CURLINFO_STARTTRANSFER_TIME, &start);
|
|
|
|
exit(1);
|
|
|
|
if (CURLE_OK == res) {
|
|
|
|
|
|
|
|
cerr<<"Time: " << start;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return input_data(buffer, false);
|
|
|
|
return input_data(buffer, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
Input input;
|
|
|
|
Input input;
|
|
|
|
if (argc > 1) {
|
|
|
|
if (argc > 1) {
|
|
|
|
input = download(argv[1]);
|
|
|
|
input = download(argv[1]);
|
|
|
@ -80,5 +76,5 @@ int main(int argc, char* argv[]) {
|
|
|
|
input = input_data(cin, true);
|
|
|
|
input = input_data(cin, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
show_histogram_svg(bins, input.colors);
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
}
|
|
|
|
}
|