|
|
|
@ -6,46 +6,96 @@
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
//Ñîçäàíèå ñòðóêòóðû Input äëÿ âõîäíûõ äàííûõ
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> Numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
struct Input
|
|
|
|
|
{
|
|
|
|
|
vector<double> Numbers;
|
|
|
|
|
size_t bin_count{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Ôóíêöèÿ ââîäà
|
|
|
|
|
Input input_data(){
|
|
|
|
|
Input input_data(istream& in, bool prompt)
|
|
|
|
|
{
|
|
|
|
|
size_t number_count;
|
|
|
|
|
Input stct;
|
|
|
|
|
//Ââîä êîëè÷åñòâà ýëåìåíòîâ ìàññèâà
|
|
|
|
|
cerr << "Enter number count ";
|
|
|
|
|
cin >> number_count;
|
|
|
|
|
if (prompt)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Enter number count ";
|
|
|
|
|
}
|
|
|
|
|
in >> number_count;
|
|
|
|
|
//Ââîä ìàññèâà
|
|
|
|
|
vector<double> Numbers(number_count);
|
|
|
|
|
stct.Numbers.resize(number_count);
|
|
|
|
|
cerr << "Enter array:\n";
|
|
|
|
|
cin >> stct.Numbers[0];
|
|
|
|
|
for (int i = 1; i < number_count; i++) {
|
|
|
|
|
cin >> stct.Numbers[i];
|
|
|
|
|
}
|
|
|
|
|
//Ââîä êîëè÷åñòâà êîðçèí
|
|
|
|
|
cerr << "Enter bin count\n";
|
|
|
|
|
cin >> stct.bin_count;
|
|
|
|
|
//Âîçâðàùàåì ñòðóêòóðó
|
|
|
|
|
return stct;
|
|
|
|
|
vector<double> Numbers(number_count);
|
|
|
|
|
stct.Numbers.resize(number_count);
|
|
|
|
|
if (prompt)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Enter array:\n";
|
|
|
|
|
}
|
|
|
|
|
in >> stct.Numbers[0];
|
|
|
|
|
for (int i = 1; i < number_count; i++)
|
|
|
|
|
{
|
|
|
|
|
in >> stct.Numbers[i];
|
|
|
|
|
}
|
|
|
|
|
//Ââîä êîëè÷åñòâà êîðçèí
|
|
|
|
|
if (prompt)
|
|
|
|
|
{
|
|
|
|
|
cerr << "Enter bin count\n";
|
|
|
|
|
}
|
|
|
|
|
in >> stct.bin_count;
|
|
|
|
|
//Âîçâðàùàåì ñòðóêòóðó
|
|
|
|
|
return stct;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
|
|
|
|
size_t data_size = item_size * item_count;
|
|
|
|
|
//buffer.write(items, data_size);
|
|
|
|
|
(*buffer).write(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
return data_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
//Ââîä ìàññèâà è êîëè÷åñòâà êîðçèí
|
|
|
|
|
Input in = input_data();
|
|
|
|
|
Input
|
|
|
|
|
download(const string& address)
|
|
|
|
|
{
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
|
|
|
|
|
CURL *curl = curl_easy_init();
|
|
|
|
|
if(curl)
|
|
|
|
|
{
|
|
|
|
|
CURLcode res;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK)
|
|
|
|
|
{
|
|
|
|
|
cerr << curl_easy_strerror(res);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
}
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Ñîçäàíèå âåêòîðà bins äëÿ ãèñòîãðàììû
|
|
|
|
|
vector<size_t> bins = make_histogram(in.Numbers, in.bin_count);
|
|
|
|
|
|
|
|
|
|
//Âûâîä ãèñòîãðàììû
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
//show_histogram_text(bins);
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char* argv[]) {
|
|
|
|
|
Input input;
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
input = download(argv[1]);
|
|
|
|
|
} else {
|
|
|
|
|
input = input_data(cin, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
const auto bins = make_histogram(input.Numbers, input.bin_count);
|
|
|
|
|
show_histogram_svg(bins);
|
|
|
|
|
}
|
|
|
|
|