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