add basic timetable structure

This commit is contained in:
PoliEcho 2025-03-06 18:54:51 +01:00
parent 87c9b1e125
commit af5252f732

View File

@ -1,32 +1,43 @@
#include "timetable.h"
#include <cstdint>
#include <nlohmann/json.hpp>
#include "net.h"
#include <cstdint>
#include <format>
#include <fstream>
#include <iostream>
#include <ncurses.h>
#include <nlohmann/json.hpp>
using nlohmann::json;
#define NLINES 10
#define NCOLS 40
#define DEFAULT_X_OFFSET 10
#define DEFAULT_Y_OFFSET 2
#define DEFAULT_PADDING 4
void timetable_page() {
// DONT FORGET TO UNCOMMENT
// json resp_from_api = bakaapi::get_data_from_endpoint("api/3/timetable/actual");
std::ifstream f("test-data/timetable.json");
json resp_from_api = json::parse(f);
// DONT FORGET TO UNCOMMENT
// json resp_from_api =
// bakaapi::get_data_from_endpoint("api/3/timetable/actual");
std::ifstream f("test-data/timetable.json");
json resp_from_api = json::parse(f);
// calculate table size
uint8_t column_number = 0;
for(uint8_t i = 0; i < resp_from_api["Days"].size(); i++) {
(resp_from_api["Days"][i]["Atoms"].size() > column_number) ? (column_number = resp_from_api["Days"][i]["Atoms"].size());
// calculate table size
// some lambda dark magic
const uint8_t num_of_columns = [&]() -> uint8_t {
uint8_t result = 0;
for (uint8_t i = 0; i < resp_from_api["Days"].size(); i++) {
uint8_t currentSize = resp_from_api["Days"][i]["Atoms"].size();
if (currentSize > result) {
result = currentSize;
}
}
return result;
}();
const uint8_t num_of_rows = resp_from_api["Days"].size();
setlocale(LC_ALL, "");
/* Initialize curses */
initscr();
start_color();
cbreak();
noecho();
keypad(stdscr, TRUE);
printw("LINES: %d COLS: %d", LINES, COLS);
}