From d398de7076b5fbe08fd452c912f8d4bf97b17fdd Mon Sep 17 00:00:00 2001
From: BobrovnikYA <BobrovnikYA@mpei.ru>
Date: Fri, 6 Jun 2025 14:59:45 +0300
Subject: [PATCH] after

---
 .gitignore      |  1 +
 lab01.cbp       | 12 +++++++
 lab01.depend    | 76 +++++++++++++++++++++++++++++++++++++++--
 lab01.layout    | 38 ++++++++++++++++++---
 main.cpp        | 90 ++++++++++++++++++++++++++++++++++++++++---------
 svg.cpp         | 39 +++++++++++----------
 text.cpp        |  1 +
 unittest.layout |  8 ++---
 8 files changed, 222 insertions(+), 43 deletions(-)

diff --git a/.gitignore b/.gitignore
index 4c7473d..0a4fc6b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
 /bin
 /obj
+/curl
diff --git a/lab01.cbp b/lab01.cbp
index dbd06a2..de880fe 100644
--- a/lab01.cbp
+++ b/lab01.cbp
@@ -14,6 +14,10 @@
 				<Compiler>
 					<Add option="-g" />
 				</Compiler>
+				<Linker>
+					<Add option="-static-libstdc++" />
+					<Add option="-static" />
+				</Linker>
 			</Target>
 			<Target title="Release">
 				<Option output="bin/Release/lab01" prefix_auto="1" extension_auto="1" />
@@ -31,7 +35,15 @@
 		<Compiler>
 			<Add option="-Wall" />
 			<Add option="-fexceptions" />
+			<Add directory="curl/include" />
 		</Compiler>
+		<Linker>
+			<Add option="-static-libstdc++" />
+			<Add option="-static-libgcc" />
+			<Add option="-static" />
+			<Add library="curl/lib/libcurl.dll.a" />
+			<Add directory="curl/lib" />
+		</Linker>
 		<Unit filename=".gitignore" />
 		<Unit filename="histogram.cpp" />
 		<Unit filename="histogram.h" />
diff --git a/lab01.depend b/lab01.depend
index 40af0b3..4cca5ef 100644
--- a/lab01.depend
+++ b/lab01.depend
@@ -30,12 +30,15 @@
 	"svg.h"
 	<string>
 
-1745706239 source:c:\users\liza\desktop\lab01\lab01\main.cpp
+1749210284 source:c:\users\liza\desktop\lab01\lab01\main.cpp
 	<iostream>
 	<vector>
+	<sstream>
+	<string>
 	"histogram.h"
-	"text.h"
 	"svg.h"
+	"text.h"
+	<curl/curl.h>
 
 1746171356 c:\users\liza\desktop\lab01\lab01\histogram.h
 	<vector>
@@ -50,3 +53,72 @@
 	<vector>
 	<cstddef>
 
+1746171356 source:c:\users\liza\desktop\lab01\lab01\histogram.cpp
+	"histogram.h"
+	<iostream>
+	<cstddef>
+
+1748597934 source:c:\users\liza\desktop\lab01\lab01\svg.cpp
+	"svg.h"
+	<iostream>
+	<vector>
+
+1746177922 source:c:\users\liza\desktop\lab01\lab01\text.cpp
+	"text.h"
+	<iostream>
+	<vector>
+	<cstddef>
+
+1748873299 c:\users\liza\desktop\lab01\lab01\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"
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\curlver.h
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\system.h
+	<ConditionalMacros.h>
+	<inttypes.h>
+	<inttypes.h>
+	<sys/types.h>
+	<sys/socket.h>
+	<sys/poll.h>
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\easy.h
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\multi.h
+	"curl.h"
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\urlapi.h
+	"curl.h"
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\options.h
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\header.h
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\websockets.h
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\mprintf.h
+	<stdarg.h>
+	<stdio.h>
+	"curl.h"
+
+1748873299 c:\users\liza\desktop\lab01\lab01\curl\include\curl\typecheck-gcc.h
+
diff --git a/lab01.layout b/lab01.layout
index efaea0a..332a0d5 100644
--- a/lab01.layout
+++ b/lab01.layout
@@ -2,19 +2,49 @@
 <CodeBlocks_layout_file>
 	<FileVersion major="1" minor="0" />
 	<ActiveTarget name="Debug" />
+	<File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="195" topLine="0" />
+		</Cursor>
+	</File>
+	<File name="histogram_internal.h" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="37" topLine="0" />
+		</Cursor>
+	</File>
 	<File name="histogram.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
 			<Cursor1 position="0" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="text.cpp" open="1" top="1" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="svg.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="77" topLine="0" />
+			<Cursor1 position="356" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="svg.cpp" open="1" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="histogram.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="201" topLine="0" />
+		</Cursor>
+	</File>
+	<File name=".gitignore" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="0" topLine="0" />
+		</Cursor>
+	</File>
+	<File name="text.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="214" topLine="0" />
+		</Cursor>
+	</File>
+	<File name="text.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+		<Cursor>
+			<Cursor1 position="79" topLine="6" />
+		</Cursor>
+	</File>
+	<File name="main.cpp" open="1" top="1" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="55" topLine="0" />
+			<Cursor1 position="1822" topLine="60" />
 		</Cursor>
 	</File>
 </CodeBlocks_layout_file>
diff --git a/main.cpp b/main.cpp
index f39d4d7..e237399 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,8 +1,11 @@
 #include <iostream>
 #include <vector>
+#include <sstream>
+#include <string>
 #include "histogram.h"
-#include "text.h"
 #include "svg.h"
+#include "text.h"
+#include <curl/curl.h>
 
 using namespace std;
 
@@ -12,27 +15,82 @@ struct Input
     size_t bin_count{};
 };
 
-Input input_data(istream& ine)
-{
+Input input_data(istream& in, bool prompt = true) {
+    Input data;
     size_t number_count;
-    cerr << "Number count: ";
-    ine >> number_count;
-    Input in;
-    in.numbers.resize(number_count);
 
-    cerr << "Numbers: ";
+    if (prompt) {
+        cerr << "Enter number count: ";
+    }
+    in >> number_count;
+
+    data.numbers.resize(number_count);
+    if (prompt) {
+        cerr << "Enter numbers: ";
+    }
     for (size_t i = 0; i < number_count; i++) {
-        ine >> in.numbers[i];
+        in >> data.numbers[i];
     }
-    cerr << "Enter bin count:";
-    ine >> in.bin_count;
-    return in;
+
+    if (prompt) {
+        cerr << "Enter number of bins: ";
+    }
+    in >> data.bin_count;
+
+    return data;
 }
 
-int main()
-{
+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();
+
+    if (!curl) {
+        cerr << "Error: Failed to invent cURL" << endl;
+        exit(1);
+    }
+
+    curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
+    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, Write_data);
+    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
+    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
+    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
+
+    CURLcode res = curl_easy_perform(curl);
+    if (res != CURLE_OK) {
+        cerr << "Loading error: " << curl_easy_strerror(res) << endl;
+        exit(1);
+    }
+
+    // ��������� ������� name lookup
+    double name_lookup_time;
+    curl_easy_getinfo(curl, CURLINFO_NAMELOOKUP_TIME, &name_lookup_time);
+    cerr << "Name lookup time: " << name_lookup_time << " seconds" << endl;
+
+    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(cin, true);
+    }
     size_t max_count;
-    auto in = input_data(cin);
-    auto bins = make_histogram(in.numbers, in.bin_count);
+    auto bins = make_histogram(input.numbers, input.bin_count);
     show_histogram_svg(bins);
+    curl_global_cleanup();
+    return 0;
 }
diff --git a/svg.cpp b/svg.cpp
index 3cb2050..d528968 100644
--- a/svg.cpp
+++ b/svg.cpp
@@ -1,6 +1,7 @@
 #include "svg.h"
-#include <string>
-#include <cstddef>
+#include <iostream>
+#include <vector>
+
 using namespace std;
 
 void svg_begin(double width, double height) {
@@ -20,10 +21,8 @@ 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") {
+    cout << "<rect x='" << x << "' y='" << y << "' width='" << width << "' height='" << height << "' stroke='" << stroke << "' fill='" << fill << "'/>";
 }
 
 void show_histogram_svg(const vector<size_t>& bins) {
@@ -34,22 +33,28 @@ void show_histogram_svg(const vector<size_t>& bins) {
     const auto TEXT_WIDTH = 50;
     const auto BIN_HEIGHT = 30;
     const auto BLOCK_WIDTH = 10;
+    const auto MAX_BIN_WIDTH = IMAGE_WIDTH - 2.3 * TEXT_WIDTH;
+    auto max_bins = bins[0];
+    size_t sum_bins = 0;
 
-    svg_begin(400, 300);
-    double top = 0;
+    for (size_t bin : bins) sum_bins += bin;
+
+    for (size_t bin : bins) {
+        if (bin > max_bins) max_bins = bin;
+    }
 
+    auto koef = MAX_BIN_WIDTH / BLOCK_WIDTH / max_bins;
+
+    svg_begin(IMAGE_WIDTH, IMAGE_HEIGHT);
+    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;
-        }
+        const double bin_width = BLOCK_WIDTH * bin * koef;
+
+        size_t percent = bin * 100 / sum_bins;
         svg_text(TEXT_LEFT, top + TEXT_BASELINE, to_string(bin));
-        svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT, "blue", "green");
+        svg_rect(TEXT_WIDTH, top, bin_width, BIN_HEIGHT);
+        svg_text((IMAGE_WIDTH - TEXT_WIDTH), top + TEXT_BASELINE, to_string(percent));
         top += BIN_HEIGHT;
     }
-
-    //svg_text(20, 20, to_string(bins[0]));
-    //svg_rect(50, 0, bins[0] * 10, 30);
     svg_end();
 }
-
diff --git a/text.cpp b/text.cpp
index d2606f7..965ca6e 100644
--- a/text.cpp
+++ b/text.cpp
@@ -2,6 +2,7 @@
 #include <iostream>
 #include <vector>
 #include <cstddef>
+
 using namespace std;
 
 void show_histogram_text(const vector <size_t>& bins,size_t bin_count, size_t max_count)
diff --git a/unittest.layout b/unittest.layout
index e6083f4..8855773 100644
--- a/unittest.layout
+++ b/unittest.layout
@@ -7,14 +7,14 @@
 			<Cursor1 position="250" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="histogram.cpp" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="histogram.cpp" open="0" top="0" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="205" topLine="0" />
+			<Cursor1 position="223" topLine="0" />
 		</Cursor>
 	</File>
-	<File name="unittest.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
+	<File name="unittest.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
 		<Cursor>
-			<Cursor1 position="623" topLine="6" />
+			<Cursor1 position="372" topLine="0" />
 		</Cursor>
 	</File>
 </CodeBlocks_layout_file>