Сравнить коммиты
7 Коммитов
c37b1fed88
...
master
| Автор | SHA1 | Дата | |
|---|---|---|---|
| 7449ef860f | |||
| 1b1311833a | |||
| 5135699b21 | |||
| 2eaf794295 | |||
| bcc61042de | |||
| d5a9d78924 | |||
| 7bd4bee170 |
1
.gitignore
поставляемый
1
.gitignore
поставляемый
@@ -1,2 +1,3 @@
|
|||||||
/bin
|
/bin
|
||||||
/obj
|
/obj
|
||||||
|
/curl
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "hist_proc.h"
|
#include "hist_proc.h"
|
||||||
|
#include "hist_proc_internal.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
vector<size_t> make_histogram_proc(const vector<double> numbers, size_t bin_count, vector<size_t> bins){
|
vector<size_t> make_histogram_proc(const vector<double> numbers, size_t bin_count, vector<size_t> bins){
|
||||||
vector<size_t> procent(bin_count);
|
vector<size_t> procent(bin_count);
|
||||||
|
|||||||
@@ -4,11 +4,17 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
static void
|
bool
|
||||||
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
find_minmax(const vector<double>& numbers, double& min, double& max) {
|
||||||
min = numbers[0];
|
bool flag;
|
||||||
max = numbers[0];
|
if (numbers.size() == 0){
|
||||||
for (double x : numbers) {
|
flag=false;
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
min = numbers[0];
|
||||||
|
max = numbers[0];
|
||||||
|
for (double x : numbers) {
|
||||||
if (x < min) {
|
if (x < min) {
|
||||||
min = x;
|
min = x;
|
||||||
}
|
}
|
||||||
@@ -18,6 +24,9 @@ find_minmax(const vector<double>& numbers, double& min, double& max) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
|
||||||
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){
|
||||||
vector<size_t> bins(bin_count);
|
vector<size_t> bins(bin_count);
|
||||||
double max, min = 0;
|
double max, min = 0;
|
||||||
|
|||||||
@@ -13,7 +13,11 @@
|
|||||||
<Option compiler="gcc" />
|
<Option compiler="gcc" />
|
||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-g" />
|
<Add option="-g" />
|
||||||
|
<Add directory="curl/include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add library="curl/include" />
|
||||||
|
</Linker>
|
||||||
</Target>
|
</Target>
|
||||||
<Target title="Release">
|
<Target title="Release">
|
||||||
<Option output="bin/Release/lab003" prefix_auto="1" extension_auto="1" />
|
<Option output="bin/Release/lab003" prefix_auto="1" extension_auto="1" />
|
||||||
@@ -31,7 +35,11 @@
|
|||||||
<Compiler>
|
<Compiler>
|
||||||
<Add option="-Wall" />
|
<Add option="-Wall" />
|
||||||
<Add option="-fexceptions" />
|
<Add option="-fexceptions" />
|
||||||
|
<Add directory="curl/include" />
|
||||||
</Compiler>
|
</Compiler>
|
||||||
|
<Linker>
|
||||||
|
<Add directory="curl/include" />
|
||||||
|
</Linker>
|
||||||
<Unit filename="hist_proc.cpp" />
|
<Unit filename="hist_proc.cpp" />
|
||||||
<Unit filename="hist_proc.h" />
|
<Unit filename="hist_proc.h" />
|
||||||
<Unit filename="histogram.cpp" />
|
<Unit filename="histogram.cpp" />
|
||||||
|
|||||||
87
main.cpp
87
main.cpp
@@ -5,6 +5,8 @@
|
|||||||
#include "histogram.h"
|
#include "histogram.h"
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <svg.h>
|
#include <svg.h>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -20,30 +22,95 @@ struct Input {
|
|||||||
|
|
||||||
|
|
||||||
Input
|
Input
|
||||||
input_data() {
|
input_data(istream& in, bool prompt) {
|
||||||
|
if (prompt == true){
|
||||||
size_t number_count;
|
size_t number_count;
|
||||||
cin >> number_count;
|
cerr << "input number count";
|
||||||
Input in;
|
in >> number_count;
|
||||||
in.numbers.resize(number_count);
|
Input inn;
|
||||||
|
inn.numbers.resize(number_count);
|
||||||
vector<double> numbers(number_count);
|
vector<double> numbers(number_count);
|
||||||
|
cerr << "input numbers";
|
||||||
for (size_t i = 0; i < number_count; i++) {
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
cin >> in.numbers[i];
|
in >> inn.numbers[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t bin_count;
|
size_t bin_count;
|
||||||
cin >> in.bin_count;
|
cerr << "input amount of bins";
|
||||||
return in;
|
in >> inn.bin_count;
|
||||||
|
return inn;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
size_t number_count;
|
||||||
|
cout << "input number count";
|
||||||
|
in >> number_count;
|
||||||
|
Input inn;
|
||||||
|
inn.numbers.resize(number_count);
|
||||||
|
vector<double> numbers(number_count);
|
||||||
|
cout << "input numbers";
|
||||||
|
for (size_t i = 0; i < number_count; i++) {
|
||||||
|
in >> inn.numbers[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t bin_count;
|
||||||
|
cout << "input amount of bins";
|
||||||
|
in >> inn.bin_count;
|
||||||
|
return inn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
|
||||||
|
buffer->write(reinterpret_cast<const char*>(items), data_size);
|
||||||
|
return data_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
Input
|
||||||
|
download(const string& address, bool proverka_skorosti) {
|
||||||
|
stringstream buffer;
|
||||||
|
CURL* curl = curl_easy_init();
|
||||||
|
if(curl)
|
||||||
|
{
|
||||||
|
CURLcode res;
|
||||||
|
const char* res2;
|
||||||
|
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) {
|
||||||
|
curl_off_t speed;
|
||||||
|
res = curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD_T, &speed);
|
||||||
|
if(!res) {
|
||||||
|
cerr << "Upload speed "<< speed << " bytes/sec\n";
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_easy_cleanup(curl);
|
||||||
|
}
|
||||||
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
|
return input_data(buffer, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
int main()
|
|
||||||
{
|
{
|
||||||
auto in = input_data();
|
|
||||||
|
Input in;
|
||||||
|
CURL *curl = curl_easy_init();
|
||||||
|
if (argc > 1) {
|
||||||
|
in = download(argv[1], false);
|
||||||
|
} else {
|
||||||
|
in = input_data(cin, true);
|
||||||
|
}
|
||||||
auto bins = make_histogram(in.numbers, in.bin_count);
|
auto bins = make_histogram(in.numbers, in.bin_count);
|
||||||
auto procent = make_histogram_proc(in.numbers, in.bin_count, bins);
|
auto procent = make_histogram_proc(in.numbers, in.bin_count, bins);
|
||||||
show_histogram_svg(bins, procent);
|
show_histogram_svg(bins, procent);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,9 @@ TEST_CASE("distinct positive numbers") {
|
|||||||
CHECK(procent[0] == 33);
|
CHECK(procent[0] == 33);
|
||||||
CHECK(procent[1] == 33);
|
CHECK(procent[1] == 33);
|
||||||
CHECK(procent[2] == 34);
|
CHECK(procent[2] == 34);
|
||||||
|
|
||||||
|
procent = make_histogram_proc({1}, 3, {1, 0, 0});
|
||||||
|
CHECK(procent[0] == 100);
|
||||||
|
CHECK(procent[1] == 0);
|
||||||
|
CHECK(procent[2] == 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user