Added comments

This commit is contained in:
2025-06-09 09:48:31 +02:00
parent f984a5c241
commit 9f20458b19
6 changed files with 51 additions and 4 deletions
+13 -2
View File
@@ -5,10 +5,12 @@ const uuid = require("uuid");
const map_conf = require("../config/map.conf");
const logger = require("./logger.util");
// Creates new map
async function addMap(filename, meta, throttle, motor) {
var total = "";
var map = [[[]]];
// Get the new map metadata
if (meta) {
if ("name" in meta) {
total += `#name:${meta["name"]}\n`;
@@ -21,7 +23,9 @@ async function addMap(filename, meta, throttle, motor) {
}
}
// Check if the required data has been received
if (throttle && motor && ("0" in motor) && ("1" in motor)) {
// Creating csv and storing it
const throttle_values = Object.values(throttle);
const current_values = Object.values(motor["0"]);
const brake_values = Object.values(motor["1"]);
@@ -39,10 +43,13 @@ async function addMap(filename, meta, throttle, motor) {
}
}
// Update current map file
async function updateMap(filename, meta, throttle, motor) {
// Get merged map comments and data
var total = await generateComments(filename, meta);
const map = await generateData(filename, throttle, motor);
// Create and store file
try {
await csv.writeToString(map).then(data => total += data);
fs.writeFileSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename), total);
@@ -55,6 +62,7 @@ async function updateMap(filename, meta, throttle, motor) {
}
}
// Merges data from a stored map and a new map
async function generateData(filename, throttle, motor) {
const map = await parseMap(filename, 0);
@@ -80,6 +88,7 @@ async function generateData(filename, throttle, motor) {
return map;
}
// Merges comments from stored map and new map
async function generateComments(filename, meta) {
const comments = await parseMapJson(filename, 1);
var comment_string = "";
@@ -105,6 +114,7 @@ async function generateComments(filename, meta) {
return comment_string;
}
// Check if a map exists
function mapExists(filename) {
if (path.extname(filename) != ".csv") {
return false;
@@ -112,7 +122,7 @@ function mapExists(filename) {
return fs.existsSync(path.join(path.dirname(require.main.filename), map_conf.map_storage_path, filename));
}
// mode: comments 1 or data 0
// Parse a map and returns it as array. On 1 returns comments on 0 returns data
function parseMap(filename, mode) {
var result = [];
@@ -131,6 +141,7 @@ function parseMap(filename, mode) {
});
}
// Parse map data as JSON
async function parseMapJson(filename, mode) {
const map = await parseMap(filename, mode);
var json_map = {};
@@ -150,8 +161,8 @@ async function parseMapJson(filename, mode) {
return json_map
}
// Get available map names in storage directory
async function getAvailableMaps() {
// path in app_conf
var available_maps = {};
try {