|
|
|
@ -4,34 +4,27 @@
|
|
|
|
|
#include "histogram.h"
|
|
|
|
|
#include "text.h"
|
|
|
|
|
#include "svg.h"
|
|
|
|
|
#include <curl/curl.h>
|
|
|
|
|
#include <sstream>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
|
vector<double> Numbers;
|
|
|
|
|
size_t BinCount{};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
InputData(istream& in, bool prompt) {
|
|
|
|
|
Input inp;
|
|
|
|
|
InputData() {
|
|
|
|
|
Input in;
|
|
|
|
|
size_t NumberCount;
|
|
|
|
|
if (prompt) {
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
}
|
|
|
|
|
in >> NumberCount;
|
|
|
|
|
inp.Numbers.resize(NumberCount);
|
|
|
|
|
cerr << "Enter number count: ";
|
|
|
|
|
cin >> NumberCount;
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
cin >> in.BinCount;
|
|
|
|
|
in.Numbers.resize(NumberCount);
|
|
|
|
|
for (int i = 0; i < NumberCount; i++) {
|
|
|
|
|
in >> inp.Numbers[i];
|
|
|
|
|
cin >> in.Numbers[i];
|
|
|
|
|
}
|
|
|
|
|
if (prompt) {
|
|
|
|
|
cerr << "Enter bin count: ";
|
|
|
|
|
}
|
|
|
|
|
in >> inp.BinCount;
|
|
|
|
|
return inp;
|
|
|
|
|
return in;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FindMinMax(const vector<double>& Numbers, double& minn, double& maxx);
|
|
|
|
@ -40,64 +33,11 @@ vector<size_t> MakeHistogram(vector<double> Numbers, size_t BinCount, double& Ma
|
|
|
|
|
|
|
|
|
|
void ShowHistogrammText(vector<size_t> Bins);
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
WriteData(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(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
return data_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
Download(const string& address, const string& option) {
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
if ((option != "") && (address != "-verbose") && (option != "-verbose")) {
|
|
|
|
|
cout << "Invalid argument, please use -verbose" << endl;
|
|
|
|
|
exit(2);
|
|
|
|
|
}
|
|
|
|
|
CURL* curl = curl_easy_init();
|
|
|
|
|
if (curl) {
|
|
|
|
|
CURLcode res;
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_URL, (option == "" || option == "-verbose") ? address.c_str() : option.c_str());
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteData);
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
if (address == "-verbose" || option == "-verbose") {
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_VERBOSE, option == "-verbose" ? option.c_str() : address.c_str());
|
|
|
|
|
}
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
if (res != CURLE_OK) {
|
|
|
|
|
cout << curl_easy_strerror(res);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return InputData(buffer, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
|
setlocale(LC_ALL, "Russian");
|
|
|
|
|
int main() {
|
|
|
|
|
double MaxCount = 0;
|
|
|
|
|
Input in;
|
|
|
|
|
if (argc > 1) {
|
|
|
|
|
if (argc == 2) {
|
|
|
|
|
in = Download(argv[1], "");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
in = Download(argv[1], argv[2]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
in = InputData(cin, true);
|
|
|
|
|
}
|
|
|
|
|
Input in = InputData();
|
|
|
|
|
vector <size_t> Bins(in.BinCount);
|
|
|
|
|
Bins = MakeHistogram(in.Numbers, in.BinCount, MaxCount);
|
|
|
|
|
ShowHistogramSvg(Bins);
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|