Сравнить коммиты

..

22 Коммитов

Автор SHA1 Сообщение Дата
ef0fcfca11 code:Защита 2025-05-19 16:10:13 +03:00
e32d622ada code:Работа с буфером, загруженным по сети(final) 2025-05-19 05:01:03 +03:00
ce1828c63b code:Обработка ошибок 2025-05-19 03:02:11 +03:00
2a9b70a833 code:добавлена также глобальная очистка 2025-05-19 02:55:12 +03:00
928e229a58 code:Загрузка файла по сети 2025-05-19 02:32:16 +03:00
c89c94151c code:Получение аргументов программы 2025-05-19 01:56:37 +03:00
663e485fdb code:исправлены все ошибки при добавлении curl 2025-05-19 01:00:02 +03:00
4813bf8c13 code:исправлены все ошибки при добавлении curl 2025-05-19 00:59:37 +03:00
09c75c3057 git:curl уже занесен по gitignore 2025-05-19 00:34:20 +03:00
2e7cc7b34b upd:Добавлен флаг на вывод подсказок 2025-05-09 00:20:39 +03:00
2817ee274c upd:Ввод из произвольного потока 2025-05-09 00:16:21 +03:00
0c00522f14 upd: Откат до конца ЛР3 2025-05-08 23:29:52 +03:00
5867964daa upd: Откат до конца ЛР3 2025-05-08 23:29:38 +03:00
90318f8151 code:Установка динамических библиотек 2025-05-08 20:18:47 +03:00
83e2103ca7 code:Установка динамических библиотек 2025-05-08 20:18:03 +03:00
2f22e192b3 git:Занесено под игнор curl 2025-05-08 18:34:59 +03:00
f021197658 code: в input_data добавлен новый параметр bool promt 2025-05-08 17:37:33 +03:00
d16031c3f4 code:Код откачен до момента защиты и переписана функция input_data на istream 2025-05-08 17:34:01 +03:00
80f146ba36 upd:Код откачен до момента защиты 2025-05-08 17:30:08 +03:00
c250c10e38 upd:Код откачен до момента защиты 2025-05-08 17:29:45 +03:00
abf30f27d1 upd:Код откачен до момента защиты 2025-05-08 17:29:28 +03:00
d5f702afa3 upd:Код откачен до момента защиты 2025-05-08 17:29:12 +03:00
7 изменённых файлов: 103 добавлений и 61 удалений

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;
}
static size_t write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
size_t data_size = item_size * item_count;
auto* 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();
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
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);
} }
cerr << "Enter bin count: "; double download_speed = 0.0;
cin >> in.bin_count; curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &download_speed);
cerr << "Download speed: " << download_speed << " bytes/sec\n";
return in; curl_easy_cleanup(curl);
return input_data(buffer, false);
} }
int main() { int main(int argc, char* argv[]) {
auto in = input_data(); curl_global_init(CURL_GLOBAL_ALL);
Input in;
double min_val, max_val; if (argc > 1) {
find_minmax(in.numbers, min_val, max_val); in = download(argv[1]);
}
double bin_size = compute_bin_size(in.numbers, in.bin_count); else {
auto bins = make_histogram(in.numbers, in.bin_count); in = input_data(cin, true);
}
show_histogram_svg(bins, bin_size, min_val); 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
Просмотреть файл

@@ -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
Просмотреть файл

@@ -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);