Сравнить коммиты
Ничего общего в коммитах. '4a3c7e648b589055c691ac01025effb5b99505bb' и '0ff87f78ba1dc18f6ae66537f3b5127e5f1b67cd' имеют совершенно разные истории.
4a3c7e648b
...
0ff87f78ba
@ -0,0 +1,4 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
*.o
|
||||||
|
*.exe
|
||||||
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
@ -1,65 +0,0 @@
|
|||||||
#include "histogram.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
//std::vector<size_t>
|
|
||||||
bool find_minmax(const vector<double>& numbers, double& minN, double& maxN)
|
|
||||||
{
|
|
||||||
if (numbers.empty()) {
|
|
||||||
minN = maxN = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
minN = numbers[0];
|
|
||||||
maxN = numbers[0];
|
|
||||||
|
|
||||||
for (double x: numbers)
|
|
||||||
{
|
|
||||||
if (minN > x)
|
|
||||||
{
|
|
||||||
minN = x;
|
|
||||||
}
|
|
||||||
if (maxN < x)
|
|
||||||
{
|
|
||||||
maxN = x;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count)
|
|
||||||
{
|
|
||||||
double minN, maxN;
|
|
||||||
find_minmax( numbers, minN, maxN);
|
|
||||||
|
|
||||||
vector <size_t> bins(bin_count);
|
|
||||||
double diff = (maxN - minN) / bin_count;
|
|
||||||
size_t max_count = 0;
|
|
||||||
for (size_t i = 0; i <numbers.size() ; i++)
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
|
||||||
{
|
|
||||||
auto lo = minN + j * diff;
|
|
||||||
auto hi = minN + (j + 1) * diff;
|
|
||||||
if ((lo <= numbers[i]) && (hi > numbers[i]))
|
|
||||||
{
|
|
||||||
bins[j]++;
|
|
||||||
if (bins[j] > max_count)
|
|
||||||
{
|
|
||||||
max_count = bins[j];
|
|
||||||
}
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!found)
|
|
||||||
{
|
|
||||||
bins[bin_count - 1]++;
|
|
||||||
if (bins[bin_count - 1] > max_count)
|
|
||||||
{
|
|
||||||
max_count = bins[bin_count - 1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bins;
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
#ifndef HISTOGRAM_H_INCLUDED
|
|
||||||
#define HISTOGRAM_H_INCLUDED
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
std::vector<size_t>
|
|
||||||
make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
|
||||||
|
|
||||||
#endif // HISTOGRAM_H_INCLUDED
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
#ifndef HISTOGRAM_INTERNAL_H_INCLUDED
|
|
||||||
#define HISTOGRAM_INTERNAL_H_INCLUDED
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
//std::vector<size_t>
|
|
||||||
bool find_minmax(const std::vector<double>& numbers, double& minN, double& maxN);
|
|
||||||
|
|
||||||
#endif // HISTOGRAM_INTERNAL_H_INCLUDED
|
|
||||||
@ -0,0 +1 @@
|
|||||||
|
Subproject commit ed81237874dcb6059b4798cc73cccc900d4c9c9a
|
||||||
@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_project_file>
|
||||||
|
<FileVersion major="1" minor="6" />
|
||||||
|
<Project>
|
||||||
|
<Option title="lab01" />
|
||||||
|
<Option pch_mode="2" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Build>
|
||||||
|
<Target title="Debug">
|
||||||
|
<Option output="bin/Debug/lab01" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Debug/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-g" />
|
||||||
|
</Compiler>
|
||||||
|
</Target>
|
||||||
|
<Target title="Release">
|
||||||
|
<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />
|
||||||
|
<Option object_output="obj/Release/" />
|
||||||
|
<Option type="1" />
|
||||||
|
<Option compiler="gcc" />
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-O2" />
|
||||||
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add option="-s" />
|
||||||
|
</Linker>
|
||||||
|
</Target>
|
||||||
|
</Build>
|
||||||
|
<Compiler>
|
||||||
|
<Add option="-Wall" />
|
||||||
|
<Add option="-fexceptions" />
|
||||||
|
</Compiler>
|
||||||
|
<Unit filename="main.cpp" />
|
||||||
|
<Extensions>
|
||||||
|
<lib_finder disable_auto="1" />
|
||||||
|
</Extensions>
|
||||||
|
</Project>
|
||||||
|
</CodeBlocks_project_file>
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
|
<CodeBlocks_layout_file>
|
||||||
|
<FileVersion major="1" minor="0" />
|
||||||
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1461" topLine="0" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
</CodeBlocks_layout_file>
|
||||||
@ -1,96 +1,68 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "histogram.h"
|
|
||||||
#include "text.h"
|
|
||||||
#include "svg.h"
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
int main()
|
||||||
struct Input
|
|
||||||
{
|
{
|
||||||
vector<double> numbers;
|
size_t number_count,bin_count;
|
||||||
size_t bin_count{};
|
|
||||||
};
|
|
||||||
|
|
||||||
Input
|
cout << "Enter number count: ";
|
||||||
input_data(istream& in, bool prompt)
|
cin >> number_count;
|
||||||
{
|
|
||||||
Input cin;
|
|
||||||
string numbCntPrmt, numbsPrmt, binCntPrmt;
|
|
||||||
if (prompt == true) {
|
|
||||||
numbCntPrmt = "Enter number count: ";
|
|
||||||
numbsPrmt = "Enter numbers: ";
|
|
||||||
binCntPrmt = "Enter bin count: ";
|
|
||||||
}
|
|
||||||
size_t number_count;
|
|
||||||
cerr << numbCntPrmt;
|
|
||||||
in >> number_count;
|
|
||||||
cin.numbers.resize(number_count);
|
|
||||||
|
|
||||||
vector<double> numbers(number_count);
|
vector<double> numbers(number_count);
|
||||||
|
|
||||||
cerr << numbsPrmt;
|
|
||||||
for (size_t i = 0; i < number_count; i++)
|
for (size_t i = 0; i < number_count; i++)
|
||||||
{
|
{
|
||||||
in >> cin.numbers[i];
|
cout <<"Enter number: ";
|
||||||
|
cin >> numbers[i];
|
||||||
}
|
}
|
||||||
|
cout <<"Enter number of bins: ";
|
||||||
|
cin >> bin_count;
|
||||||
|
|
||||||
cerr << binCntPrmt;
|
vector<size_t> bins(bin_count);
|
||||||
in >> cin.bin_count;
|
double min = numbers[0];
|
||||||
return cin;
|
double max = numbers[0];
|
||||||
|
for (double x : numbers) {
|
||||||
|
if (x < min) {
|
||||||
|
min = x;
|
||||||
|
}
|
||||||
|
else if (x > max) {
|
||||||
|
max = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
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){
|
|
||||||
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) {
|
double bin_size = (max - min) / bin_count;
|
||||||
curl_off_t ul;
|
for (size_t i = 0; i < number_count; i++)
|
||||||
res = curl_easy_getinfo(curl, CURLINFO_SIZE_DOWNLOAD_T, &ul);
|
{
|
||||||
if(!res) {
|
bool found = false;
|
||||||
cerr<<"Uploaded bytes" << ul << endl;
|
for (size_t j = 0; (j < bin_count - 1) && !found; j++)
|
||||||
|
{
|
||||||
|
auto low = min + j * bin_size;
|
||||||
|
auto high = min + (j + 1) * bin_size;
|
||||||
|
if ((low <= numbers[i]) && (numbers[i] < high))
|
||||||
|
{
|
||||||
|
bins[j]++;
|
||||||
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!found)
|
||||||
if (res != 0){
|
{
|
||||||
cerr << curl_easy_strerror(res);
|
bins[bin_count - 1]++;
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
}
|
}
|
||||||
return input_data(buffer, false);
|
|
||||||
|
/*for (size_t i = 0; i < bins.size(); ++i) {
|
||||||
|
cout << "Bin " << i + 1 << ": " << bins[i] << " |";
|
||||||
|
for (size_t j = 0; j < bins[i]; ++j) {
|
||||||
|
cout << "*";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
return 0;*/
|
||||||
{
|
|
||||||
CURL* curl = curl_easy_init();
|
|
||||||
Input input;
|
|
||||||
if (argc > 1) {
|
|
||||||
input = download(argv[1]);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
input = input_data(cin, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto bins = make_histogram(input.numbers, input.bin_count);
|
|
||||||
show_histogram_svg(bins);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,92 +0,0 @@
|
|||||||
#include "svg.h"
|
|
||||||
#include <string>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void svg_begin(double width, double height) {
|
|
||||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
|
||||||
cout << "<svg ";
|
|
||||||
cout << "width='" << width << "' ";
|
|
||||||
cout << "height='" << height << "' ";
|
|
||||||
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
|
||||||
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void svg_end() {
|
|
||||||
cout << "</svg>\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void svg_text(double left, double baseline, string text) {
|
|
||||||
cout << "<text x='" << left << "' y='" << baseline << "'>" << text << "</text>";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black")
|
|
||||||
{
|
|
||||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width
|
|
||||||
<< "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << " '/>";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Çàùèòà
|
|
||||||
/*
|
|
||||||
void svg_rect(double x, double y, double width, double height, string stroke = "black", string fill = "black", double fill_opacity = 1.0) {
|
|
||||||
cout << "<rect x='" << x << "' y='" << y << "' width='" << width
|
|
||||||
<< "' height='" << height << "' stroke='" << stroke
|
|
||||||
<< "' fill='" << fill << "' fill-opacity='" << fill_opacity << "'/>";
|
|
||||||
}
|
|
||||||
|
|
||||||
void show_histogram_svg(const vector<size_t>& bins) {
|
|
||||||
const auto IMAGE_WIDTH = 400;
|
|
||||||
const auto IMAGE_HEIGHT = 300;
|
|
||||||
const auto TEXT_LEFT = 20;
|
|
||||||
const auto TEXT_BASELINE = 20;
|
|
||||||
const auto TEXT_WIDTH = 50;
|
|
||||||
const auto BIN_HEIGHT = 30;
|
|
||||||
const auto BLOCK_WIDTH = 10;
|
|
||||||
|
|
||||||
size_t max_count = *max_element(bins.begin(), bins.end());
|
|
||||||
if (max_count == 0) max_count = 1;
|
|
||||||
|
|
||||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
|
||||||
double top = 0;
|
|
||||||
|
|
||||||
for (size_t bin : bins) {
|
|
||||||
const double bin_width = min(static_cast<double>(BLOCK_WIDTH * bin), static_cast<double>(IMAGE_WIDTH - TEXT_WIDTH));
|
|
||||||
double opacity = static_cast<double>(bin) / max_count;
|
|
||||||
|
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT,
|
|
||||||
"blue", "green", opacity);
|
|
||||||
top += BIN_HEIGHT;
|
|
||||||
}
|
|
||||||
|
|
||||||
svg_end();
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
void show_histogram_svg(const vector<size_t>& bins) {
|
|
||||||
const auto IMAGE_WIDTH = 400;
|
|
||||||
const auto IMAGE_HEIGHT = 300;
|
|
||||||
const auto TEXT_LEFT = 20;
|
|
||||||
const auto TEXT_BASELINE = 20;
|
|
||||||
const auto TEXT_WIDTH = 50;
|
|
||||||
const auto BIN_HEIGHT = 30;
|
|
||||||
const auto BLOCK_WIDTH = 10;
|
|
||||||
|
|
||||||
svg_begin(400, 300);
|
|
||||||
double top = 0;
|
|
||||||
|
|
||||||
for (size_t bin : bins) {
|
|
||||||
const double bin_width = BLOCK_WIDTH * bin;
|
|
||||||
if(bin_width> IMAGE_WIDTH) {
|
|
||||||
const double bin_width= IMAGE_WIDTH - TEXT_WIDTH;
|
|
||||||
}
|
|
||||||
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
|
|
||||||
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "green");
|
|
||||||
top += BIN_HEIGHT;
|
|
||||||
}
|
|
||||||
svg_end();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
#ifndef SVG_H_INCLUDED
|
|
||||||
#define SVG_H_INCLUDED
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
void show_histogram_svg(const std::vector<size_t> &bins);
|
|
||||||
|
|
||||||
#endif // SVG_H_INCLUDED
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
#include "text.h"
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
void show_histogram_text(const vector <size_t>& bins,size_t bin_count, size_t max_count)
|
|
||||||
{
|
|
||||||
const size_t SCREEN_WIDTH = 80;
|
|
||||||
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
|
|
||||||
|
|
||||||
bool scaling = false;
|
|
||||||
|
|
||||||
if (max_count > MAX_ASTERISK)
|
|
||||||
{
|
|
||||||
scaling = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < bin_count; i++)
|
|
||||||
{
|
|
||||||
if (bins[i] < 10)
|
|
||||||
{
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
else if (bins[i] < 100)
|
|
||||||
{
|
|
||||||
cout << " ";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cout << "";
|
|
||||||
}
|
|
||||||
cout << bins[i] << '|';
|
|
||||||
|
|
||||||
size_t number_of_stars = bins[i];
|
|
||||||
|
|
||||||
if (scaling)
|
|
||||||
{
|
|
||||||
if (bins[i] == max_count)
|
|
||||||
{
|
|
||||||
number_of_stars = MAX_ASTERISK * 1.0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
number_of_stars = MAX_ASTERISK * (static_cast<double>(bins[i]) / max_count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t j = 0; j < number_of_stars; j++)
|
|
||||||
{
|
|
||||||
cout << '*';
|
|
||||||
}
|
|
||||||
cout << endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
#ifndef TEXT_H_INCLUDED
|
|
||||||
#define TEXT_H_INCLUDED
|
|
||||||
#include <vector>
|
|
||||||
void show_histogram_text(const std::vector <size_t>& bins,size_t bin_count, size_t max_count);
|
|
||||||
|
|
||||||
#endif // TEXT_H_INCLUDED
|
|
||||||
Загрузка…
Ссылка в новой задаче