Skip to content

Commit

Permalink
Table no longer shows more than two digits, but entering such values …
Browse files Browse the repository at this point in the history
…is possible
  • Loading branch information
kocatepedogu committed Sep 21, 2023
1 parent b2b3e37 commit ab8d070
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 49 deletions.
12 changes: 6 additions & 6 deletions src/renderer/gsd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,12 @@ export class GSD implements Iterable<sounding.LevelSource> {

for (const lev of gsd.levels) {
const newLine = lev.lineType.toString() + ' ' +
(lev.pressure * 10).toFixed(2) + ' ' +
(lev.height).toFixed(2) + ' ' +
(lev.temp * 10).toFixed(2) + ' ' +
(lev.dewpt * 10).toFixed(2) + ' ' +
(lev.winddir).toFixed(0) + ' ' +
(lev.windspd).toFixed(0);
(lev.pressure * 10).toString() + ' ' +
(lev.height).toString() + ' ' +
(lev.temp * 10).toString() + ' ' +
(lev.dewpt * 10).toString() + ' ' +
(lev.winddir).toString() + ' ' +
(lev.windspd).toString();

result += newLine + '\n';
}
Expand Down
13 changes: 1 addition & 12 deletions src/renderer/indices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ export class IndexTable {
let MU: number = NaN;
let MUCAPE: number = NaN;
let MUCIN: number = NaN;
let MULFC: number = NaN;
let MUEL: number = NaN;

this.indices = [
{func: () => {
Expand All @@ -89,21 +87,12 @@ export class IndexTable {
name: "Most unstable parcel (mb)"},

{func: () => {
[MUCAPE, MUCIN, MULFC, MUEL] = numerical.computeCAPE(fnTemp, fnDewp, MU, pEnd());
[MUCAPE, MUCIN] = numerical.computeCAPE(fnTemp, fnDewp, MU, pEnd()).slice(0, 2);
return MUCAPE;
}, name: "MU CAPE"},

{func: () => MUCIN,
name: "MU CIN"},

{func: () => Math.sqrt(2 * MUCAPE),
name: "MU Maximum updraft (m/s)"},

{func: () => sounding.getValueAt(MULFC, 'height'),
name: "MU LFC (m)"},

{func: () => sounding.getValueAt(MUEL, 'height'),
name: "MU EL (m)"},

{func: () => numerical.computeLiftedIndex(fnTemp, fnDewp, MU),
name: "MU Lifted Index"},
Expand Down
24 changes: 12 additions & 12 deletions src/renderer/nomads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ class GRIBData {
const u10m = this.get(above10mLevel, GRIBValueType.WindUComponent);
const v10m = this.get(above10mLevel, GRIBValueType.WindVComponent);
const firstLevel: LevelSource = {
pressure: parseFloat((this.get(surfaceLevel, GRIBValueType.Pressure) / 100).toFixed(0)),
height: parseFloat((this.get(surfaceLevel, GRIBValueType.Height)).toFixed(0)),
temp: parseFloat((this.get(above2mLevel, GRIBValueType.Temperature) - 273.15).toFixed(2)),
dewpt: parseFloat((this.get(above2mLevel, GRIBValueType.Dewpoint) - 273.15).toFixed(2)),
winddir: parseFloat(numerical.windDirection(u10m, v10m).toFixed(0)),
windspd: parseFloat((numerical.windSpeed(u10m, v10m) * 3.6).toFixed(0))
pressure: this.get(surfaceLevel, GRIBValueType.Pressure) / 100,
height: this.get(surfaceLevel, GRIBValueType.Height),
temp: this.get(above2mLevel, GRIBValueType.Temperature) - 273.15,
dewpt: this.get(above2mLevel, GRIBValueType.Dewpoint) - 273.15,
winddir: numerical.windDirection(u10m, v10m),
windspd: numerical.windSpeed(u10m, v10m) * 3.6
}

/* The first level in the result is the surface level */
Expand All @@ -120,12 +120,12 @@ class GRIBData {
const dpt = numerical.dewpointTemperature(tmp, rh);

result.push({
pressure: parseFloat(pressureValue.toFixed(0)),
height: parseFloat((this.get(pressureLevel, GRIBValueType.Height)).toFixed(0)),
temp: parseFloat(tmp.toFixed(2)),
dewpt: parseFloat(dpt.toFixed(2)),
winddir: parseFloat(numerical.windDirection(u, v).toFixed(0)),
windspd: parseFloat((numerical.windSpeed(u, v) * 3.6).toFixed(0))
pressure: pressureValue,
height: this.get(pressureLevel, GRIBValueType.Height),
temp: tmp,
dewpt: dpt,
winddir: numerical.windDirection(u, v),
windspd: numerical.windSpeed(u, v) * 3.6
});
}

Expand Down
8 changes: 4 additions & 4 deletions src/renderer/sounding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ export class Sounding implements Iterable<Level> {
}

// Fill missing data by linear interpolation
for (const prop of [['height',0], ['temp',2], ['dewpt',2], ['winddir',0], ['windspd',0]]) {
this.levels.forEach((lev) => {lev.enabled = Number.isNaN(lev[prop[0]]) ? 0 : 1;});
for (const prop of ['height', 'temp', 'dewpt', 'winddir', 'windspd']) {
this.levels.forEach((lev) => {lev.enabled = Number.isNaN(lev[prop]) ? 0 : 1;});
this.updateEnabledLevels();
for (const level of this.levels) {
if (Number.isNaN(level[<string>prop[0]])) {
if (Number.isNaN(level[prop])) {
try {
level[prop[0]] = parseFloat(this.getValueAt(level.pressure, <string>prop[0]).toFixed(<number>prop[1]));
level[prop[0]] = this.getValueAt(level.pressure, <string>prop);
} catch (e) {
continue;
}
Expand Down
31 changes: 16 additions & 15 deletions src/renderer/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,27 @@
import * as data from "./sounding"

export class SoundingTable {
private sounding: data.Sounding;
private observers: Array<(lev: number) => void> = [];
private previousActiveLevel: number;

/* Level properties that will be displayed together with their titles */
private readonly levelProperties = ["pressure", "height", "temp", "dewpt", "windspd", "winddir"];
private readonly levelPropertyTitles = [
"P",
"Z",
"T",
"Td",
"km/h",
"Dir",
"Vec"
];
private readonly levelPropertyDigits = [0, 0, 2, 2, 1, 0];
private readonly levelPropertyTitles = ["P", "Z", "T", "Td", "km/h", "Dir", "Vec"];

/* Currently edited cell */
private lastEdited: HTMLDivElement | undefined = undefined;

/* Closes currently edited cell */
private closeInputBox() {
if (this.lastEdited) {
const previousInput: HTMLInputElement = this.lastEdited.firstElementChild! as HTMLInputElement;
this.lastEdited.innerText = previousInput.value;
const levelprop = this.lastEdited.id.split('-');
const levelID = parseInt(levelprop[0]);
const prop = levelprop[1];
const propIndex = this.levelProperties.indexOf(prop);

this.lastEdited.innerText = this.sounding.find(levelID)[prop].toFixed(this.levelPropertyDigits[propIndex]);
this.lastEdited = undefined;
}
}
Expand Down Expand Up @@ -75,9 +73,11 @@ export class SoundingTable {
`<div class="sounding-table-data-rows" id="${level.id}">
<div class="sounding-table-check-cells"><input type="checkbox" id="check-${level.id}" ${level.enabled ? "checked" : ""}/></div>`;

this.levelProperties.forEach(prop => {
newRow += `<div class="sounding-table-data-cells" id="${level.id + '-' + prop}">${level[prop]}</div>`;
});
for (let i = 0; i < this.levelProperties.length; i++) {
const prop = this.levelProperties[i];
const digits = this.levelPropertyDigits[i];
newRow += `<div class="sounding-table-data-cells" id="${level.id + '-' + prop}">${level[prop].toFixed(digits)}</div>`;
}

newRow += `<div class="sounding-table-wind-cells" id="${level.id + '-arrow'}">
<object data="../../resources/arrow.svg" width="16px" height="16px" style="transform: rotate(${(-90 + level.winddir) % 360}deg);">
Expand All @@ -102,7 +102,7 @@ export class SoundingTable {

// Create a text box in the cell.
const currentContent = targetElement.innerText;
targetElement.innerHTML = `<input id="sounding-table-edit" type="text" value="${currentContent}" size="${currentContent.length}">`;
targetElement.innerHTML = `<input id="sounding-table-edit" type="text" value="${sounding.find(targetLevel)[targetParameter]}" size="${currentContent.length}">`;
this.lastEdited = targetElement;

const inputbox: HTMLInputElement = this.lastEdited.firstElementChild! as HTMLInputElement;
Expand Down Expand Up @@ -202,6 +202,7 @@ export class SoundingTable {

/* Fills table with given data and sets event handlers */
constructor(sounding: data.Sounding) {
this.sounding = sounding;
this.previousActiveLevel = sounding.first().pressure;

/* Get sounding table element */
Expand Down

0 comments on commit ab8d070

Please sign in to comment.