Сравнить коммиты
22 Коммитов
07c73e5335
...
main
| Автор | SHA1 | Дата | |
|---|---|---|---|
| ef0fcfca11 | |||
| e32d622ada | |||
| ce1828c63b | |||
| 2a9b70a833 | |||
| 928e229a58 | |||
| c89c94151c | |||
| 663e485fdb | |||
| 4813bf8c13 | |||
| 09c75c3057 | |||
| 2e7cc7b34b | |||
| 2817ee274c | |||
| 0c00522f14 | |||
| 5867964daa | |||
| 90318f8151 | |||
| 83e2103ca7 | |||
| 2f22e192b3 | |||
| f021197658 | |||
| d16031c3f4 | |||
| 80f146ba36 | |||
| c250c10e38 | |||
| abf30f27d1 | |||
| d5f702afa3 |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,5 +1,6 @@
|
|||||||
/bin/
|
/bin/
|
||||||
/obj/
|
/obj/
|
||||||
|
/curl/
|
||||||
*.rsuser
|
*.rsuser
|
||||||
*.suo
|
*.suo
|
||||||
*.user
|
*.user
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
|
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "histogram_internal.h"
|
#include "histogram_internal.h"
|
||||||
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
bool find_minmax(const vector<double>& numbers, double& min, double& max) {
|
bool find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||||
if (numbers.empty())
|
if (numbers.empty()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
min = numbers[0];
|
min = numbers[0];
|
||||||
max = numbers[0];
|
max = numbers[0];
|
||||||
for (double x : numbers) {
|
for (double x : numbers) {
|
||||||
@@ -16,7 +16,7 @@ bool find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|||||||
if (x > max)
|
if (x > max)
|
||||||
max = x;
|
max = x;
|
||||||
}
|
}
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
||||||
@@ -27,6 +27,7 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|||||||
|
|
||||||
for (size_t i = 0; i < numbers.size(); i++) {
|
for (size_t i = 0; i < numbers.size(); i++) {
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
for (size_t j = 0; j < bin_count - 1 && !found; j++) {
|
for (size_t j = 0; j < bin_count - 1 && !found; j++) {
|
||||||
double lo = min + j * bin_size;
|
double lo = min + j * bin_size;
|
||||||
double hi = min + (j + 1) * bin_size;
|
double hi = min + (j + 1) * bin_size;
|
||||||
@@ -35,15 +36,9 @@ vector<size_t> make_histogram(const vector<double>& numbers, size_t bin_count) {
|
|||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (!found)
|
||||||
bins[bin_count - 1]++;
|
bins[bin_count - 1]++;
|
||||||
}
|
}
|
||||||
return bins;
|
return bins;
|
||||||
}
|
}
|
||||||
|
|
||||||
double compute_bin_size(const std::vector<double>& numbers, size_t bin_count) {
|
|
||||||
double min, max;
|
|
||||||
if (!find_minmax(numbers, min, max))
|
|
||||||
return 0.0;
|
|
||||||
return (max - min) / bin_count;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,5 +2,3 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
std::vector<size_t> make_histogram(const std::vector<double>& numbers, size_t bin_count);
|
||||||
double compute_bin_size(const std::vector<double>& numbers, size_t bin_count);
|
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins, double bin_size, double min_val);
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include "histogram_internal.h"
|
|
||||||
#include "svg.h"
|
#include "svg.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include <string>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -13,35 +14,62 @@ struct Input {
|
|||||||
size_t bin_count{};
|
size_t bin_count{};
|
||||||
};
|
};
|
||||||
|
|
||||||
Input input_data() {
|
Input input_data(istream& in, bool prompt) {
|
||||||
|
if (prompt) cerr << "Enter number count: ";
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cerr << "Enter number count: ";
|
in >> number_count;
|
||||||
cin >> number_count;
|
Input data;
|
||||||
|
data.numbers.resize(number_count);
|
||||||
Input in;
|
if (prompt) cerr << "Enter " << number_count << " numbers: ";
|
||||||
in.numbers.resize(number_count);
|
|
||||||
cerr << "Enter " << number_count << " numbers: ";
|
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
cin >> in.numbers[i];
|
in >> data.numbers[i];
|
||||||
|
}
|
||||||
|
if (prompt) cerr << "Enter bin count: ";
|
||||||
|
in >> data.bin_count;
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
cerr << "Enter bin count: ";
|
static size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
|
||||||
cin >> in.bin_count;
|
size_t data_size = item_size * item_count;
|
||||||
|
auto* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
return in;
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
Input download(const string& address) {
|
||||||
auto in = input_data();
|
stringstream buffer;
|
||||||
|
CURL* curl = curl_easy_init();
|
||||||
|
|
||||||
double min_val, max_val;
|
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
|
||||||
find_minmax(in.numbers, min_val, max_val);
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
|
||||||
|
CURLcode res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << "\n";
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
double bin_size = compute_bin_size(in.numbers, in.bin_count);
|
double download_speed = 0.0;
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &download_speed);
|
||||||
|
cerr << "Download speed: " << download_speed << " bytes/sec\n";
|
||||||
|
|
||||||
show_histogram_svg(bins, bin_size, min_val);
|
curl_easy_cleanup(curl);
|
||||||
|
return input_data(buffer, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char* argv[]) {
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
Input in;
|
||||||
|
if (argc > 1) {
|
||||||
|
in = download(argv[1]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
in = input_data(cin, true);
|
||||||
|
}
|
||||||
|
const auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
|
show_histogram_svg(bins);
|
||||||
show_histogram_text(bins);
|
show_histogram_text(bins);
|
||||||
|
curl_global_cleanup();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,10 +76,16 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>
|
||||||
|
</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
@@ -90,12 +96,18 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>
|
||||||
|
</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>
|
||||||
|
</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>
|
||||||
|
</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@@ -104,11 +116,18 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>C:\Users\brega\OneDrive\Рабочий стол\lab03\laba01upd3\curl\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>C:\Users\brega\OneDrive\Рабочий стол\lab03\laba01upd3\curl\lib</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>;libcurl.dll.a;libcurl.dll.a;libcrypto.a;libssl.a</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
|
<PostBuildEvent>
|
||||||
|
<Command>
|
||||||
|
</Command>
|
||||||
|
</PostBuildEvent>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
@@ -118,12 +137,15 @@
|
|||||||
<SDLCheck>true</SDLCheck>
|
<SDLCheck>true</SDLCheck>
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
|
<AdditionalIncludeDirectories>C:\Users\brega\OneDrive\Рабочий стол\lab03\laba01upd3\curl\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>C:\Users\brega\OneDrive\Рабочий стол\lab03\laba01upd3\curl\lib</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>libcurl.lib;%(AdditionalDependencies);libcurl.dll.a;libcurl.dll.a;libcrypto.a;libssl.a</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
44
svg.cpp
44
svg.cpp
@@ -4,11 +4,11 @@ using namespace std;
|
|||||||
|
|
||||||
void svg_begin(double width, double height) {
|
void svg_begin(double width, double height) {
|
||||||
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
cout << "<?xml version='1.0' encoding='UTF-8'?>\n";
|
||||||
cout << "<svg "
|
cout << "<svg ";
|
||||||
<< "width='" << width << "' "
|
cout << "width='" << width << "' ";
|
||||||
<< "height='" << height << "' "
|
cout << "height='" << height << "' ";
|
||||||
<< "viewBox='0 0 " << width << " " << height << "' "
|
cout << "viewBox='0 0 " << width << " " << height << "' ";
|
||||||
<< "xmlns='http://www.w3.org/2000/svg'>\n";
|
cout << "xmlns='http://www.w3.org/2000/svg'>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void svg_end() {
|
void svg_end() {
|
||||||
@@ -33,40 +33,38 @@ void svg_rect(double x, double y, double width, double height,
|
|||||||
<< "' />\n";
|
<< "' />\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins, double bin_size, double min_val) {
|
void show_histogram_svg(const vector<size_t>& bins) {
|
||||||
const double IMAGE_WIDTH = 400;
|
const double IMAGE_WIDTH = 400;
|
||||||
const double IMAGE_HEIGHT = 300;
|
const double IMAGE_HEIGHT = 300;
|
||||||
const double TEXT_LEFT = 20;
|
const double TEXT_LEFT = 20;
|
||||||
const double TEXT_BASELINE = 20;
|
const double TEXT_BASELINE = 20;
|
||||||
const double TEXT_WIDTH = 50;
|
const double TEXT_WIDTH = 50;
|
||||||
const double BIN_HEIGHT = 30;
|
const double BIN_HEIGHT = 30;
|
||||||
const double VSPACE = BIN_HEIGHT + TEXT_BASELINE * 2 + 5;
|
const double BLOCK_WIDTH = 10;
|
||||||
|
|
||||||
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
|
||||||
|
|
||||||
size_t max_count = 0;
|
size_t max_count = 0;
|
||||||
for (size_t c : bins)
|
for (size_t count : bins) {
|
||||||
if (c > max_count)
|
if (count > max_count) {
|
||||||
max_count = c;
|
max_count = count;
|
||||||
double max_width = IMAGE_WIDTH - TEXT_WIDTH - 100;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (size_t j = 0; j < bins.size(); ++j) {
|
double max_width = IMAGE_WIDTH - TEXT_WIDTH;
|
||||||
size_t count = bins[j];
|
double top = 0;
|
||||||
double y = j * VSPACE;
|
for (size_t count : bins) {
|
||||||
|
double bin_width;
|
||||||
double width;
|
|
||||||
if (max_count > 0) {
|
if (max_count > 0) {
|
||||||
width = static_cast<double>(count) / max_count * max_width;
|
bin_width = static_cast<double>(count) / max_count * max_width;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
width = 0.0;
|
bin_width = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
svg_text(TEXT_LEFT, y + TEXT_BASELINE, to_string(count));
|
svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(count));
|
||||||
svg_rect(TEXT_WIDTH, y, width, BIN_HEIGHT, "blue", "blue");
|
svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "blue");
|
||||||
double boundary = min_val + bin_size * (j + 1);
|
top += BIN_HEIGHT;
|
||||||
svg_text(TEXT_WIDTH,y + BIN_HEIGHT + TEXT_BASELINE,to_string(boundary)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
svg_end();
|
svg_end();
|
||||||
|
|||||||
2
svg.h
2
svg.h
@@ -9,4 +9,4 @@ void svg_text(double left, double baseline, const std::string& text);
|
|||||||
void svg_rect(double x, double y, double width, double height,
|
void svg_rect(double x, double y, double width, double height,
|
||||||
const std::string& stroke = "black",
|
const std::string& stroke = "black",
|
||||||
const std::string& fill = "black");
|
const std::string& fill = "black");
|
||||||
void show_histogram_svg(const std::vector<size_t>& bins, double bin_size, double min_val);
|
void show_histogram_svg(const std::vector<size_t>& bins);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user