Skip to content

Commit

Permalink
Arbitrary numbers in arithmetic columns
Browse files Browse the repository at this point in the history
  • Loading branch information
francoismg committed Oct 2, 2024
1 parent 5231e8c commit 9eabaf6
Show file tree
Hide file tree
Showing 3 changed files with 222,238 additions and 9 deletions.
88 changes: 82 additions & 6 deletions prototypes/jsvis/data_processors/DataPreProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {SpectrumProcessor} from "./SpectrumProcessor";
import {DataProcessorContainer} from "../containers/DataProcessorContainer";
import {ExpressionParser} from "../utils/ExpressionParser";
import {ColumnUtils} from "../utils/ColumnUtils";
import {curveStep} from "../../d3/js/d3.v7";

export class DataPreProcessor {

Expand Down Expand Up @@ -39,18 +40,54 @@ export class DataPreProcessor {
let operator_array = this.parseColumnsOperators(axis.column_expression);

expression_array.forEach((operand) => {
column_array.push(ColumnUtils.getColumnSettings(operand));
if(!operand.includes('&')) {
column_array.push(ColumnUtils.getColumnSettings(operand));
} else {
column_array.push(operand);
}
});

let frw = WrapperContainer.getFITSReaderWrapper();

column_array.forEach((column) => {
let col_data = this.getProcessedColumnData(column.file_id, column.hdu_index, column.column_name, frw);
let col_data;

if(typeof column === 'object') {
col_data = this.getProcessedColumnData(column.file_id, column.hdu_index, column.column_name, frw);
} else {
col_data = column.replace('&', '');
}
temp_column_data.push(col_data);
})

let temp_processed_data = [];

column_array.forEach((column) => {
let col_data;

if(typeof column !== 'string') {
col_data = this.getProcessedColumnData(column.file_id, column.hdu_index, column.column_name, frw);
} else {
col_data = [];
col_data[0] = column.replace('&', '');
}

temp_column_data.push(col_data);
temp_processed_data.push(col_data);
})

let processed_data = this.getCustomColumnProcessedData(temp_column_data, operator_array);
let max_col_size = temp_column_data.map(column => column.length).reduce((max, current) => Math.max(max, current), 0);

temp_processed_data.forEach((column) => {
if (column.length === 1) {
let base_value = column[0];
while (column.length < max_col_size) {
column.push(base_value);
}
}
});

let processed_data = this.getCustomColumnProcessedData(temp_processed_data, operator_array);

column_data = processed_data;

Expand Down Expand Up @@ -95,21 +132,58 @@ export class DataPreProcessor {
let operator_array = this.parseColumnsOperators(error_bar.column_expression);

expression_array.forEach((operand) => {
column_array.push(ColumnUtils.getColumnSettings(operand));
if(!operand.includes('&')) {
column_array.push(ColumnUtils.getColumnSettings(operand));
} else {
column_array.push(operand);
}
});

let frw = WrapperContainer.getFITSReaderWrapper();

column_array.forEach((column) => {
let col_data = this.getProcessedColumnData(column.file_id, column.hdu_index, column.column_name, frw);
let col_data;

if(typeof column === 'object') {
col_data = this.getProcessedColumnData(column.file_id, column.hdu_index, column.column_name, frw);
} else {
col_data = column.replace('&', '');
}
temp_column_data.push(col_data);
})

let temp_processed_data = [];

column_array.forEach((column) => {
let col_data;

if(typeof column !== 'string') {
col_data = this.getProcessedColumnData(column.file_id, column.hdu_index, column.column_name, frw);
} else {
col_data = [];
col_data[0] = column.replace('&', '');
}

temp_column_data.push(col_data);
temp_processed_data.push(col_data);
})

let processed_data = this.getCustomColumnProcessedData(temp_column_data, operator_array);
let max_col_size = temp_column_data.map(column => column.length).reduce((max, current) => Math.max(max, current), 0);

temp_processed_data.forEach((column) => {
if (column.length === 1) {
let base_value = column[0];
while (column.length < max_col_size) {
column.push(base_value);
}
}
});

let processed_data = this.getCustomColumnProcessedData(temp_processed_data, operator_array);

column_data = processed_data;
} else {
let frw = WrapperContainer.getFITSReaderWrapper();
column_data = frw.getColumnDataFromHDU(error_bar.hdu_index, error_bar.column_name);
}

Expand Down Expand Up @@ -229,6 +303,8 @@ export class DataPreProcessor {
expression_string += operator + operands[index + 1][i];
})

console.log(expression_string);

data.push(eval(expression_string));

}
Expand Down
222,148 changes: 222,146 additions & 2 deletions prototypes/jsvis/dist/astrovis/astrovis.js

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion prototypes/jsvis/utils/ExpressionParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,19 @@ export class ExpressionParser {

parseStandardExpressionOperand(expression) {
const operator_regex = /[\+\-\*\/]/g;
let filtered_parts = [];

let parts = expression.split(operator_regex);

let filtered_parts = parts.filter(part => part.trim() !== '');
let temp_filtered_parts = parts.filter(part => part.trim() !== '');

temp_filtered_parts.forEach(operand => {
if(!operand.includes('$')) {
operand = '&'+operand;
}

filtered_parts.push(operand)
})

return filtered_parts;
}
Expand Down

0 comments on commit 9eabaf6

Please sign in to comment.