feat(09): now key in number of the line
This commit is contained in:
parent
93530c269a
commit
64695b9deb
2 changed files with 51 additions and 75 deletions
|
|
@ -6,11 +6,7 @@
|
||||||
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
# By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ #
|
||||||
# +#+#+#+#+#+ +#+ #
|
# +#+#+#+#+#+ +#+ #
|
||||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||||
<<<<<<< Updated upstream
|
# Updated: 2025/04/12 16:01:22 by rparodi ### ########.fr #
|
||||||
# Updated: 2025/04/11 15:55:49 by rparodi ### ########.fr #
|
|
||||||
=======
|
|
||||||
# Updated: 2025/04/12 12:53:27 by rparodi ### ########.fr #
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
# #
|
# #
|
||||||
# **************************************************************************** #
|
# **************************************************************************** #
|
||||||
|
|
||||||
|
|
@ -37,8 +33,6 @@ CXXFLAGS += $(DEBUG)
|
||||||
SRC = BitcoinExchange.cpp \
|
SRC = BitcoinExchange.cpp \
|
||||||
main.cpp
|
main.cpp
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
=======
|
|
||||||
INC_DIR = .
|
INC_DIR = .
|
||||||
|
|
||||||
CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP
|
CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP
|
||||||
|
|
@ -47,7 +41,6 @@ CPPFLAGS = $(addprefix -I, $(INC_DIR)) -MMD -MP
|
||||||
# DEBUG = -g3
|
# DEBUG = -g3
|
||||||
# CPPFLAGS += $(DEBUG)
|
# CPPFLAGS += $(DEBUG)
|
||||||
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
# Objects
|
# Objects
|
||||||
OBJDIRNAME = ./build
|
OBJDIRNAME = ./build
|
||||||
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o))
|
OBJ = $(addprefix $(OBJDIRNAME)/,$(SRC:.cpp=.o))
|
||||||
|
|
@ -131,15 +124,6 @@ footer:
|
||||||
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
|
@printf ' $(GREY)The compilation is$(END) $(GOLD)finish$(END)\n $(GREY)Have a good $(END)$(GOLD)correction !$(END)\n'
|
||||||
|
|
||||||
clangd:
|
clangd:
|
||||||
<<<<<<< Updated upstream
|
|
||||||
@echo -e \
|
|
||||||
"CompileFlags:\n" \
|
|
||||||
" Add:\n" \
|
|
||||||
" - \"-std=c++98 -Wall -Wextra -Werror\"\n" \
|
|
||||||
" - \"-I"$(shell pwd)"/includes\"\n" \
|
|
||||||
" - \"-xc++\"\n" \
|
|
||||||
> .clangd
|
|
||||||
=======
|
|
||||||
@printf "CompileFlags:\n" > ./.clangd
|
@printf "CompileFlags:\n" > ./.clangd
|
||||||
@printf " Add:\n" >> ./.clangd
|
@printf " Add:\n" >> ./.clangd
|
||||||
@printf " - \"-std=c++98 -Wall -Wextra -Werror\"\n" >> ./.clangd
|
@printf " - \"-std=c++98 -Wall -Wextra -Werror\"\n" >> ./.clangd
|
||||||
|
|
@ -150,7 +134,6 @@ clangd:
|
||||||
done
|
done
|
||||||
@printf "\n" >> ./.clangd
|
@printf "\n" >> ./.clangd
|
||||||
@printf '$(GREY) Now parsing settings is set in $(END)$(GREEN)./.clangd$(END)\n'
|
@printf '$(GREY) Now parsing settings is set in $(END)$(GREEN)./.clangd$(END)\n'
|
||||||
>>>>>>> Stashed changes
|
|
||||||
|
|
||||||
# Phony
|
# Phony
|
||||||
.PHONY: all clean fclean re get_db clangd
|
.PHONY: all clean fclean re get_db clangd
|
||||||
|
|
|
||||||
|
|
@ -6,17 +6,15 @@
|
||||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */
|
/* Created: 2025/04/08 12:15:32 by rparodi #+# #+# */
|
||||||
<<<<<<< Updated upstream
|
/* Updated: 2025/04/12 18:07:03 by rparodi ### ########.fr */
|
||||||
/* Updated: 2025/04/11 16:06:02 by rparodi ### ########.fr */
|
|
||||||
=======
|
|
||||||
/* Updated: 2025/04/12 15:58:47 by rparodi ### ########.fr */
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "BitcoinExchange.hpp"
|
#include "BitcoinExchange.hpp"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <regex.h>
|
#include <regex.h>
|
||||||
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
enum error_code {
|
enum error_code {
|
||||||
NO_ERROR = 0,
|
NO_ERROR = 0,
|
||||||
|
|
@ -31,68 +29,72 @@ enum error_code {
|
||||||
typedef struct s_value {
|
typedef struct s_value {
|
||||||
enum error_code reason;
|
enum error_code reason;
|
||||||
float value;
|
float value;
|
||||||
|
std::string date;
|
||||||
} value;
|
} value;
|
||||||
|
|
||||||
value convertValue (enum error_code error, float value) {
|
value convertValue (enum error_code error, float value, std::string date) {
|
||||||
s_value to_return;
|
s_value to_return;
|
||||||
to_return.reason = error;
|
to_return.reason = error;
|
||||||
to_return.value = value;
|
to_return.value = value;
|
||||||
|
to_return.date = date;
|
||||||
return to_return;
|
return to_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
<<<<<<< Updated upstream
|
|
||||||
bool is_valid_format_date(std::string str) {
|
|
||||||
regex_t regex;
|
|
||||||
=======
|
|
||||||
std::string error_code_to_string(enum error_code code) {
|
std::string error_code_to_string(enum error_code code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case NO_ERROR: return "NO_ERROR";
|
case NO_ERROR:
|
||||||
case NEGATIVE: return "NEGATIVE";
|
return "NO_ERROR";
|
||||||
case NO_FORMAT: return "NO_FORMAT";
|
case NEGATIVE:
|
||||||
case NO_LIMIT: return "NO_LIMIT";
|
return "NEGATIVE";
|
||||||
case TOO_LARGE: return "TOO_LARGE";
|
case NO_FORMAT:
|
||||||
default: return "UNKNOWN";
|
return "NO_FORMAT";
|
||||||
|
case NO_DATE:
|
||||||
|
return "NO_DATE";
|
||||||
|
case NO_LIMIT:
|
||||||
|
return "NO_LIMIT";
|
||||||
|
case NO_FLOAT:
|
||||||
|
return "NO_FLOAT";
|
||||||
|
case TOO_LARGE:
|
||||||
|
return "TOO_LARGE";
|
||||||
|
default:
|
||||||
|
return "UNKNOWN";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_print_map(const std::map<size_t, std::map<std::string, value> >& data) {
|
void debug_print_map(const std::map<size_t, value>& data) {
|
||||||
std::cout << "========== Debug: Parsed Entries ==========" << std::endl;
|
std::cout << "===== Debug: Contents of map =====" << std::endl;
|
||||||
|
|
||||||
// En-têtes de colonnes
|
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(8) << "Line"
|
<< std::setw(15) << "Key"
|
||||||
<< std::setw(15) << "Date"
|
|
||||||
<< std::setw(10) << "Value"
|
<< std::setw(10) << "Value"
|
||||||
|
<< std::setw(15) << "Date"
|
||||||
<< std::setw(15) << "Reason"
|
<< std::setw(15) << "Reason"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
std::cout << std::string(48, '-') << std::endl;
|
std::cout << std::string(40, '-') << std::endl;
|
||||||
|
|
||||||
// Parcours de la map extérieure (par ligne)
|
|
||||||
for (size_t i = 0; i < data.size(); ++i) {
|
|
||||||
size_t line = it->first;
|
|
||||||
const std::map<std::string, value>& inner = it[line]->second;
|
|
||||||
const value& val = inner_it->second;
|
|
||||||
|
|
||||||
|
for (std::map<size_t, value>::const_iterator it = data.begin(); it != data.end(); ++it) {
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(8) << line
|
<< std::setw(15) << it->first
|
||||||
<< std::setw(15) << date
|
<< std::setw(10) << std::fixed << std::setprecision(2) << it->second.value
|
||||||
<< std::setw(10) << std::fixed << std::setprecision(2) << val.value
|
<< std::setw(15) << std::fixed << it->second.date
|
||||||
<< std::setw(15) << error_code_to_string(val.reason)
|
<< std::setw(15) << error_code_to_string(it->second.reason)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout << "===========================================" << std::endl;
|
std::cout << "===================================" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
>>>>>>> Stashed changes
|
std::string itoa_home(int i) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "0000" << i;
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool is_valid_format_date(std::string str) {
|
bool is_valid_format_date(std::string str) {
|
||||||
regex_t regex;
|
regex_t regex;
|
||||||
|
|
||||||
int ret = regcomp(®ex, "^[0-9]{4}-[0-9]-[0-9]{2}$", REG_EXTENDED);
|
int ret = regcomp(®ex, "^[0-9]{4}-[0-9]{2}-[0-9]{2}$", REG_EXTENDED);
|
||||||
if (ret)
|
if (ret)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -159,42 +161,32 @@ float check_value(std::string value, enum error_code *error_code) {
|
||||||
return (atof(value.c_str()));
|
return (atof(value.c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<std::string, value>parse_input(std::string name) {
|
std::map<size_t, value>parse_input(std::string name) {
|
||||||
enum error_code tmpError;
|
enum error_code tmpError;
|
||||||
|
|
||||||
std::ifstream file(name.c_str());
|
std::ifstream file(name.c_str());
|
||||||
|
|
||||||
std::map<std::string, value> to_ret;
|
std::map<size_t, value> to_ret;
|
||||||
|
|
||||||
std::string tmpLine;
|
std::string tmpLine;
|
||||||
std::string tmpDate;
|
std::string tmpDate;
|
||||||
float tmpValue = 0;
|
float tmpValue = 0;
|
||||||
|
size_t line = 0;
|
||||||
|
|
||||||
while (std::getline(file, tmpLine)) {
|
while (std::getline(file, tmpLine)) {
|
||||||
|
line++;
|
||||||
tmpError = NO_ERROR;
|
tmpError = NO_ERROR;
|
||||||
|
tmpDate.clear();
|
||||||
|
tmpValue = 0;
|
||||||
std::size_t limit = tmpLine.find(" | ");
|
std::size_t limit = tmpLine.find(" | ");
|
||||||
if (limit == std::string::npos) {
|
if (limit == std::string::npos) {
|
||||||
tmpError = NO_FORMAT;
|
tmpError = NO_FORMAT;
|
||||||
<<<<<<< Updated upstream
|
to_ret.insert(std::make_pair(line, convertValue(tmpError, tmpValue, tmpLine)));
|
||||||
=======
|
|
||||||
to_ret[line].insert(std::make_pair(tmpLine, convertValue(line, tmpError, tmpValue)));
|
|
||||||
continue;
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
} else {
|
} else {
|
||||||
tmpDate = check_date(tmpLine.substr(0, limit), &tmpError);
|
tmpDate = check_date(tmpLine.substr(0, limit), &tmpError);
|
||||||
if (tmpError == NO_ERROR) {
|
tmpValue = check_value(tmpLine.substr(limit + 3).c_str(), &tmpError);
|
||||||
tmpValue = check_value(tmpLine.substr(limit + 3).c_str(), &tmpError);
|
to_ret.insert(std::make_pair(line, convertValue(tmpError, tmpValue, tmpDate)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
<<<<<<< Updated upstream
|
|
||||||
to_ret.insert(std::pair<std::string, value>(tmpDate, convertValue(tmpError, tmpValue)));
|
|
||||||
=======
|
|
||||||
if (tmpError != NO_ERROR)
|
|
||||||
to_ret[line].insert(std::make_pair(itoa_home(line), convertValue(line, tmpError, tmpValue)));
|
|
||||||
else
|
|
||||||
to_ret[line].insert(std::make_pair(tmpLine, convertValue(line, tmpError, tmpValue)));
|
|
||||||
line++;
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
}
|
}
|
||||||
return to_ret;
|
return to_ret;
|
||||||
}
|
}
|
||||||
|
|
@ -220,5 +212,6 @@ int main(int argc, char *argv[]) {
|
||||||
std::cerr << CLR_RED << "The program have to read on the file `data.csv`" << CLR_RESET << std::endl;
|
std::cerr << CLR_RED << "The program have to read on the file `data.csv`" << CLR_RESET << std::endl;
|
||||||
exit( 1);
|
exit( 1);
|
||||||
}
|
}
|
||||||
std::map<std::string, value> user_db = parse_input(argv[1]);
|
std::map<size_t, value> user_db = parse_input(argv[1]);
|
||||||
|
debug_print_map(user_db);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue