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

..

4 Коммитов

Автор SHA1 Сообщение Дата
4c8bcace15 add connect time 2025-06-12 15:18:32 +03:00
99972b93c5 end 4 2025-06-12 00:14:02 +03:00
30b4711b88 add argv argc 2025-06-11 17:56:38 +03:00
0ddf8637e3 настройка curl 2025-06-11 04:33:02 +03:00
9 изменённых файлов: 130 добавлений и 16 удалений

Двоичные данные
bin/Debug/lab01.exe

Двоичный файл не отображается.

Просмотреть файл

@@ -18,9 +18,6 @@ Input input_data(std::istream& in, bool prompt) {
if (prompt) std::cerr << "Enter bin count: "; if (prompt) std::cerr << "Enter bin count: ";
in >> data.bin_count; in >> data.bin_count;
if (prompt) std::cerr << "Enter text width : ";
in >> data.width;
return data; return data;
} }

Просмотреть файл

@@ -5,7 +5,6 @@
struct Input { struct Input {
std::vector<double> numbers; std::vector<double> numbers;
size_t bin_count{}; size_t bin_count{};
int width;
}; };
Input input_data(std::istream& in, bool prompt); Input input_data(std::istream& in, bool prompt);

Просмотреть файл

@@ -13,7 +13,12 @@
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler> <Compiler>
<Add option="-g" /> <Add option="-g" />
<Add directory="C:/Mpei/Programming/C++ 2sem/lab03/alex/project/curl/include" />
</Compiler> </Compiler>
<Linker>
<Add library="C:/Mpei/Programming/C++ 2sem/lab03/alex/project/curl/lib/libcurl.dll.a" />
<Add directory="C:/Mpei/Programming/C++ 2sem/lab03/alex/project/curl/lib" />
</Linker>
</Target> </Target>
<Target title="Release"> <Target title="Release">
<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" /> <Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />
@@ -32,7 +37,15 @@
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
</Compiler> </Compiler>
<Unit filename="doctest.h" />
<Unit filename="histogram.cpp" />
<Unit filename="histogram.h" />
<Unit filename="histogram_internal.h" />
<Unit filename="main.cpp" /> <Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions> <Extensions>
<lib_finder disable_auto="1" /> <lib_finder disable_auto="1" />
</Extensions> </Extensions>

Просмотреть файл

@@ -34,12 +34,14 @@
1746175715 source:c:\users\gajda\onedrive\Đŕáî÷čé ńňîë\lab03\alex\project\text.cpp 1746175715 source:c:\users\gajda\onedrive\Đŕáî÷čé ńňîë\lab03\alex\project\text.cpp
"text.h" "text.h"
1749594511 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\main.cpp 1749674358 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\main.cpp
"histogram.h" "histogram.h"
"svg.h" "svg.h"
<sstream> <sstream>
<curl/curl.h>
<string>
1749593919 c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.h 1749676301 c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.h
<iostream> <iostream>
<vector> <vector>
@@ -47,16 +49,16 @@
<iostream> <iostream>
<vector> <vector>
1749584700 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h 1749676301 c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.h
<vector> <vector>
<iostream> <iostream>
1749596419 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.cpp 1749676301 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\histogram.cpp
"histogram.h" "histogram.h"
<iostream> <iostream>
<limits> <limits>
1749584700 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.cpp 1749676301 source:c:\mpei\programming\c++ 2sem\lab03\alex\project\svg.cpp
"svg.h" "svg.h"
"text.h" "text.h"
@@ -70,3 +72,56 @@
<vector> <vector>
<iostream> <iostream>
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\curl.h
"curlver.h"
"system.h"
<stdio.h>
<limits.h>
<sys/param.h>
<sys/types.h>
<time.h>
<winsock2.h>
<ws2tcpip.h>
<sys/select.h>
<sys/socket.h>
<sys/time.h>
"easy.h"
"multi.h"
"urlapi.h"
"options.h"
"header.h"
"websockets.h"
"mprintf.h"
"typecheck-gcc.h"
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\curlver.h
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\system.h
<ConditionalMacros.h>
<inttypes.h>
<inttypes.h>
<sys/types.h>
<sys/socket.h>
<sys/poll.h>
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\easy.h
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\multi.h
"curl.h"
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\urlapi.h
"curl.h"
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\options.h
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\header.h
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\websockets.h
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\mprintf.h
<stdarg.h>
<stdio.h>
"curl.h"
1749603772 c:\mpei\programming\c++ 2sem\lab03\alex\project\curl\include\curl\typecheck-gcc.h

Просмотреть файл

@@ -1,10 +1,56 @@
#include "histogram.h" #include "histogram.h"
#include "svg.h" #include "svg.h"
#include <sstream> #include <sstream>
#include <curl/curl.h>
#include <string>
int main() {
auto in = input_data(std::cin, true); size_t write_data(void* ptr, size_t size, size_t nmemb, std::stringstream* stream) {
auto bins = make_histogram(in.numbers, in.bin_count); size_t data_size = size * nmemb;
show_histogram_svg(bins, in.width); stream->write(static_cast<const char*>(ptr), data_size);
return data_size;
}
Input download(const std::string& url) {
std::stringstream buffer;
CURL* curl = curl_easy_init();
if (!curl) {
std::cerr << "Failed to initialize cURL\n";
exit(1);
}
curl_easy_setopt(curl, CURLOPT_URL, url.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) {
std::cerr << "cURL error: " << curl_easy_strerror(res) << "\n";
exit(1);
}
double connect_time = 0.0;
if (curl_easy_getinfo(curl, CURLINFO_CONNECT_TIME, &connect_time) == CURLE_OK) {
std::cerr << "Connect time: " << connect_time << " seconds\n";
} else {
std::cerr << "Could not get connect time info.\n";
}
curl_easy_cleanup(curl);
return input_data(buffer, false);
}
int main(int argc, char* argv[]) {
curl_global_init(CURL_GLOBAL_ALL);
Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(std::cin, true);
}
auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins);
curl_global_cleanup();
return 0; return 0;
} }

Двоичные данные
obj/Debug/main.o

Двоичный файл не отображается.

Просмотреть файл

@@ -13,21 +13,25 @@ void svg_end() {
std::cout << "</svg>\n"; std::cout << "</svg>\n";
} }
void svg_text(double left, double baseline, std::string text) { void svg_text(double left, double baseline, std::string text) {
std::cout << "<text x='" << left << "' y='"<< baseline <<"'>" << text<<"</text>"; std::cout << "<text x='" << left << "' y='" << baseline
<< "' font-family='Arial' font-size='12' fill='black'>"
<< text << "</text>";
} }
void show_histogram_svg(const std::vector<size_t>& bins, int TEXT_WIDTH) { void show_histogram_svg(const std::vector<size_t>& bins) {
const auto IMAGE_WIDTH = 400; const auto IMAGE_WIDTH = 400;
const auto IMAGE_HEIGHT = 300; const auto IMAGE_HEIGHT = 300;
const auto TEXT_LEFT = 20; const auto TEXT_LEFT = 20;
const auto TEXT_BASELINE = 20; const auto TEXT_BASELINE = 20;
const auto BIN_HEIGHT = 30; const auto BIN_HEIGHT = 30;
const auto TEXT_GAP = 10; const auto TEXT_GAP = 10;
const auto TEXT_WIDTH = 50;
svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT); svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
size_t maxCount = maxBin(bins); size_t maxCount = maxBin(bins);
double top = 0; double top = 0;
double current_y = TEXT_GAP;
for (size_t bin : bins) { for (size_t bin : bins) {
const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH - TEXT_GAP) * (bin / double(maxCount)); const double bin_width = (IMAGE_WIDTH - TEXT_WIDTH - TEXT_GAP) * (bin / double(maxCount));
svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin)); svg_text(TEXT_LEFT, top + TEXT_BASELINE, std::to_string(bin));

2
svg.h
Просмотреть файл

@@ -5,7 +5,7 @@
#include <iostream> #include <iostream>
void svg_begin(double width, double height); void svg_begin(double width, double height);
void svg_end(); void svg_end();
void show_histogram_svg(const std::vector<size_t>& bins, int width); void show_histogram_svg(const std::vector<size_t>& bins);
void svg_text(double left, double baseline, std::string text); void svg_text(double left, double baseline, std::string text);
void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills); void svg_rect(double x, double y, double width, double height,std::string stroke, std::string fills);