|
|
@ -1,32 +1,44 @@
|
|
|
|
//main.cpp -- the program gets number count, numbers and bin size, then builds a histogram.
|
|
|
|
#include <curl/curl.h>
|
|
|
|
//Task 15 -- make a scale under the histogram.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
#include <curl/curl.h>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include "histogram.h"
|
|
|
|
#include "histogram.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "text.h"
|
|
|
|
#include "svg.h"
|
|
|
|
#include "svg.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
struct Input { //data input
|
|
|
|
|
|
|
|
|
|
|
|
struct Input {
|
|
|
|
vector<double> numbers;
|
|
|
|
vector<double> numbers;
|
|
|
|
size_t bin_count{};
|
|
|
|
size_t bin_count{};
|
|
|
|
size_t interval_task{};
|
|
|
|
size_t interval_task{};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
|
|
|
write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
|
|
|
|
|
|
|
size_t data_size = item_size * item_count;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//struct Input *i = (struct Input *)ctx;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
|
|
|
|
|
|
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return data_size;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
|
|
|
input_data(istream& in, bool prompt) { //input data structure
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
|
|
|
input_data(istream& in, bool prompt)
|
|
|
|
|
|
|
|
{
|
|
|
|
if (prompt == false) { //prompt output
|
|
|
|
if (prompt == false) { //prompt output
|
|
|
|
cerr.rdbuf(NULL);
|
|
|
|
cerr.rdbuf(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
size_t number_count;
|
|
|
|
size_t number_count;
|
|
|
|
cerr << "Enter number count: \n";
|
|
|
|
cerr << "Enter number count: \n";
|
|
|
|
cerr.flush();
|
|
|
|
|
|
|
|
in >> number_count;
|
|
|
|
in >> number_count;
|
|
|
|
|
|
|
|
|
|
|
|
Input in_data_struct;
|
|
|
|
Input in_data_struct;
|
|
|
@ -51,21 +63,51 @@ input_data(istream& in, bool prompt) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Input
|
|
|
|
|
|
|
|
download(const string& address) {
|
|
|
|
|
|
|
|
stringstream buffer;
|
|
|
|
|
|
|
|
stringstream temp;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_HEADERFUNCTION, write_data);
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_HEADERDATA, &temp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res = curl_easy_perform(curl);
|
|
|
|
|
|
|
|
if (CURLE_OK != 0) {
|
|
|
|
|
|
|
|
cerr << curl_easy_strerror(res);
|
|
|
|
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cerr << temp.str();
|
|
|
|
|
|
|
|
curl_easy_cleanup(curl);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return input_data(buffer, false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
int
|
|
|
|
|
|
|
|
main(int argc, char* argv[]) {
|
|
|
|
|
|
|
|
Input input;
|
|
|
|
if (argc > 1) {
|
|
|
|
if (argc > 1) {
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
input = download(argv[1]);
|
|
|
|
cerr << "argv[" << i << "] = " << argv[i] << endl;
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
input = input_data(cin, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
const auto bins = make_histogram(input.numbers, input.bin_count);
|
|
|
|
|
|
|
|
show_histogram_svg(bins, input.interval_task);
|
|
|
|
|
|
|
|
|
|
|
|
curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
//[OUTDATED]
|
|
|
|
auto in = input_data(cin, true); //input data
|
|
|
|
//curl_global_init(CURL_GLOBAL_ALL);
|
|
|
|
auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram
|
|
|
|
// in = input_data(cin, true); //input data
|
|
|
|
show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code
|
|
|
|
//auto bins = make_histogram(in.numbers, in.bin_count); //calculating bin size for the histogram
|
|
|
|
|
|
|
|
//show_histogram_svg(bins, in.interval_task); //histogram output in the format svg code
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|