Родитель
3818146131
Сommit
112373a5bd
@ -1,62 +1,120 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "vector"
|
#include <vector>
|
||||||
#include "svg.h"
|
#include <conio.h>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "curl/curl.h"
|
#include "text.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{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data(istream& inn, bool promt) {
|
input_data(istream& in, bool promt)
|
||||||
|
{
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
if (promt)
|
if (promt)
|
||||||
{
|
{
|
||||||
cerr << "Enter number count: ";
|
cerr << "Enter number count: ";
|
||||||
}
|
}
|
||||||
cin >> number_count;
|
in >> number_count;
|
||||||
Input in;
|
|
||||||
in.numbers.resize(number_count);
|
|
||||||
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
Input ik;
|
||||||
cin >> in.numbers[i];
|
ik.numbers.resize(number_count);
|
||||||
|
for (size_t i = 0; i < number_count; i++)
|
||||||
|
{
|
||||||
|
in >> ik.numbers[i];
|
||||||
}
|
}
|
||||||
if (promt)
|
if (promt)
|
||||||
{
|
{
|
||||||
cerr << "Enter bins number: ";
|
cerr << "Enter bin count: ";
|
||||||
}
|
}
|
||||||
cin >> in.bin_count;
|
in>> ik.bin_count;
|
||||||
return in;
|
return ik;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx)
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
|
||||||
if (argc > 1)
|
|
||||||
{
|
{
|
||||||
|
size_t data_size = item_size * item_count;
|
||||||
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Input
|
||||||
|
download(const string& address)
|
||||||
|
{
|
||||||
|
stringstream buffer;
|
||||||
CURL *curl = curl_easy_init();
|
CURL *curl = curl_easy_init();
|
||||||
if(curl)
|
if(curl)
|
||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
|
double file_size;
|
||||||
|
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);
|
res = curl_easy_perform(curl);
|
||||||
curl_easy_cleanup(curl);
|
if (res != CURLE_OK)
|
||||||
if (res != CURLE_OK){
|
{
|
||||||
cout << curl_easy_strerror;
|
fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
return input_data(buffer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
Input input;
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
input = download(argv[3]);
|
||||||
|
int bins_cnt = atoi(argv[2]);
|
||||||
|
string check = typeid(atoi(argv[2])).name();
|
||||||
|
if(check != "int"){
|
||||||
|
cout << "Ââåäèòå ÷èñëî ïîñëå -bins";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
auto in = input_data(cin, true);
|
const auto bins = make_histogram(input.numbers, bins_cnt);
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
|
||||||
//show_histogram_text(bins, in.bin_count);
|
|
||||||
show_histogram_svg(bins);
|
show_histogram_svg(bins);
|
||||||
return 0;
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
input = input_data(cin, true);
|
||||||
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
|
show_histogram_svg(bins);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
Input input;
|
||||||
|
if (argc > 1)
|
||||||
|
{
|
||||||
|
int bins_cnt = atoi(argv[2]);
|
||||||
|
input = download(argv[3]);
|
||||||
|
const auto bins = make_histogram(input.numbers, bins_cnt);
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
input = input_data(cin, true);
|
||||||
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
Загрузка…
Ссылка в новой задаче