Skip to content

Commit

Permalink
Fix bins to start from 0
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela committed Feb 5, 2024
1 parent f42cbd8 commit 652fce4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions api/src/modules/h3-data/h3-data.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ export class H3DataRepository extends Repository<H3Data> {
* has been don't for the time being to unblock FE. Check with Data if calculus is accurate
*/
private async calculateQuantiles(tmpTableName: string): Promise<number[]> {
const N_BINS: number = 7;
const N_BINS: number = 6;
// TODO: make threshold configurable by unit
const DISPLAY_THRESHOLD: number = 0.01;
try {
Expand All @@ -775,7 +775,8 @@ export class H3DataRepository extends Repository<H3Data> {
);
// DISPLAY_THRESHOLD is the threshold for the smallest value to be displayed in the map and legend
const max = Math.max(max_q[0]["value"], DISPLAY_THRESHOLD)
let bins: number[] = [];
this.logger.debug(`Computed 99th percentile for ${tmpTableName}: ${max}`);
let bins: number[] = [0];
for (let i = 1; i <= N_BINS; i++) {
// Log scale binning value shifted with + 1
// to avoid values < 1, the zone where log behaves badly (rush to -inf for ->0).
Expand All @@ -787,7 +788,7 @@ export class H3DataRepository extends Repository<H3Data> {
let precision: number = bin >= 10? 1: 2;
bins.push(Number(bin.toPrecision(precision)));
}
this.logger.debug(`Computed data Bins: ${bins}`);
this.logger.debug(`Computed data Bins for ${tmpTableName}: ${bins}`);
return bins;

} catch (err) {
Expand Down
2 changes: 1 addition & 1 deletion client/src/utils/number-format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const SMALL_NUMBER_FORMAT = format('.2~g');

export function formatNumber(number: number): string {
if (Math.abs(number) < 1) {
if (Math.abs(number) < 0.001) {
if (Math.abs(number) < 0.001 && Math.abs(number) > 0){
return "< 0.001";
}
return SMALL_NUMBER_FORMAT(number)
Expand Down

0 comments on commit 652fce4

Please sign in to comment.