Skip to content

Commit

Permalink
Linting
Browse files Browse the repository at this point in the history
  • Loading branch information
motin committed Jan 21, 2019
1 parent 7bc28d5 commit 309d5d1
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
14 changes: 7 additions & 7 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

**GM_AGGREGATE**(table_range_with_headers: *`string`[][]*, prop: *`string`*): `any`[][]

*Defined in [GM_AGGREGATE.ts:30](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/GM_AGGREGATE.ts#L30)*
*Defined in [GM_AGGREGATE.ts:27](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/GM_AGGREGATE.ts#L27)*

Aggregates an input table by property and time, returning a table with the aggregated values of the input table.

Expand Down Expand Up @@ -52,7 +52,7 @@ ___

**GM_ID**(column_range_with_headers: *`string`[][]*, concept_id: *`string`*): `string`[][]

*Defined in [GM_ID.ts:10](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/GM_ID.ts#L10)*
*Defined in [GM_ID.ts:10](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/GM_ID.ts#L10)*

Inserts a matching column, including a header row, with Gapminder’s geo ids matched against the input column range, based on all spellings we have seen before. It should be entered in the header cell under which you want the first first id to appear and it uses as input another range of cells, which should start with the header of the column with names of a geography you want to identify.

Expand All @@ -73,7 +73,7 @@ ___

**GM_INTERPOLATE**(table_range_with_headers: *`string`[][]*, method: *`string`*): `any`[][]

*Defined in [GM_INTERPOLATE.ts:23](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/GM_INTERPOLATE.ts#L23)*
*Defined in [GM_INTERPOLATE.ts:23](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/GM_INTERPOLATE.ts#L23)*

Interpolates an input table, inserting a sorted table with additional rows, where the gaps (missing rows or empty values) in the input table have been filled in. This function works on data with two primary key columns: usually geo and time. (If we want to use this on data that has more keys: geo, time, age, gender, etc - we need a different formula)

Expand Down Expand Up @@ -101,7 +101,7 @@ ___

**GM_NAME**(column_range_with_headers: *`string`[][]*, concept_id: *`string`*): `string`[][]

*Defined in [GM_NAME.ts:10](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/GM_NAME.ts#L10)*
*Defined in [GM_NAME.ts:10](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/GM_NAME.ts#L10)*

Inserts a matching column, including a header row, with Gapminder’s common name for the geo matched against the input column range, based on all spellings we have seen before. (Like GM\_ID but inserts Gapminder’s common name for the geo instead of its id.)

Expand All @@ -122,7 +122,7 @@ ___

**GM_PROP**(column_range_with_headers: *`string`[][]*, prop: *`string`*): `string`[][]

*Defined in [GM_PROP.ts:10](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/GM_PROP.ts#L10)*
*Defined in [GM_PROP.ts:10](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/GM_PROP.ts#L10)*

Inserts a property column, including a header row, with a common Gapminder property matched against the input column range.

Expand All @@ -146,15 +146,15 @@ ___

**gapminderPropertyToConceptIdMap**: *`object`*

*Defined in [hardcodedConstants.ts:1](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/hardcodedConstants.ts#L1)*
*Defined in [hardcodedConstants.ts:1](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/hardcodedConstants.ts#L1)*

<a id="gapminderpropertytoconceptidmap.four_regions"></a>

#### four_regions

**● four_regions**: *`string`* = "world_4region"

*Defined in [hardcodedConstants.ts:2](https://github.com/Gapminder/gsheets-gm-functions/blob/cb32224/src/hardcodedConstants.ts#L2)*
*Defined in [hardcodedConstants.ts:2](https://github.com/Gapminder/gsheets-gm-functions/blob/a493994/src/hardcodedConstants.ts#L2)*

___

Expand Down
26 changes: 17 additions & 9 deletions src/GM_INTERPOLATE.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { exponential, linear, step } from "everpolate";
import range from "lodash/range";
import round from "lodash/round";
import {
GmTable,
GmTableRow,
GmTableRowsByGeoAndTime
} from "./gmTableStructure";
import { linear, exponential, step } from "everpolate";
import range from "lodash/range";
import round from "lodash/round";

/**
* Interpolates an input table, inserting a sorted table with additional rows, where the gaps (missing rows or empty values) in the input table have been filled in. This function works on data with two primary key columns: usually geo and time. (If we want to use this on data that has more keys: geo, time, age, gender, etc - we need a different formula)
Expand Down Expand Up @@ -80,12 +80,16 @@ export function GM_INTERPOLATE(
for (const geo of geos) {
const inputTableRowsByTime = inputTableRowsByGeoAndTime[geo];
// Gather all existing values in this geo, separately for each value column to be interpolated
let valuesByColumnIndexAndTime: ValuesByColumnIndexAndTime = {};
const valuesByColumnIndexAndTime: ValuesByColumnIndexAndTime = {};
const geoTimes = Object.keys(inputTableRowsByTime);
for (const time of geoTimes.sort()) {
const inputTableRow: GmTableRow = inputTableRowsByTime[time];
// foreach value column
for (const columnIndex in inputTableRow.data) {
for (
let columnIndex = 0;
columnIndex < inputTableRow.data.length;
columnIndex++
) {
if (!valuesByColumnIndexAndTime[columnIndex]) {
valuesByColumnIndexAndTime[columnIndex] = {};
}
Expand All @@ -97,8 +101,8 @@ export function GM_INTERPOLATE(
}
}
// Interpolate
let interpolatedValuesByColumnIndexAndTime: ValuesByColumnIndexAndTime = {};
for (const columnIndexString in Object.keys(valuesByColumnIndexAndTime)) {
const interpolatedValuesByColumnIndexAndTime: ValuesByColumnIndexAndTime = {};
for (const columnIndexString of Object.keys(valuesByColumnIndexAndTime)) {
const columnIndex = Number(columnIndexString);
const valuesByTime = valuesByColumnIndexAndTime[columnIndex];
const times = Object.keys(valuesByTime).map(timeString =>
Expand All @@ -120,7 +124,7 @@ export function GM_INTERPOLATE(
const roundedInterpolationResults = interpolationResults.map(result =>
round(result, 8)
);
for (const i in timesToEvaluate) {
for (let i = 0; i < timesToEvaluate.length; i++) {
const time = timesToEvaluate[i];
if (!interpolatedValuesByColumnIndexAndTime[columnIndex]) {
interpolatedValuesByColumnIndexAndTime[columnIndex] = {};
Expand All @@ -142,7 +146,11 @@ export function GM_INTERPOLATE(

for (const time of geoTimesToIncludeInOutput) {
const data = [];
for (const columnIndex in inputTableHeaderRow.data) {
for (
let columnIndex = 0;
columnIndex < inputTableHeaderRow.data.length;
columnIndex++
) {
let value;
// If the value existed in the input data, use it
if (
Expand Down
1 change: 1 addition & 0 deletions src/MinimalUrlFetchApp.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* tslint:disable:max-classes-per-file */
import request from "sync-request";

// Implement a minimal UrlFetchApp to be able to test outside of the google apps script environment
Expand Down
2 changes: 1 addition & 1 deletion src/everpolate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import test, { ExecutionContext, Macro } from "ava";
import { linear, exponential, polynomial, step } from "everpolate";
import { exponential, linear, polynomial, step } from "everpolate";
import round from "lodash/round";

/**
Expand Down
2 changes: 2 additions & 0 deletions src/geoAliasesAndSynonyms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ const geoAliasesAndSynonymsDocSpreadsheetId =
* @hidden
*/
const geoAliasesAndSynonymsDocWorksheetReferences = {
/* tslint:disable:object-literal-sort-keys */
global: 4,
world_4region: 5,
countries_etc: 6
/* tslint:enable:object-literal-sort-keys */
};
// Note: Custom functions can not reference named ranges in foreign spreadsheets, but we can reference the name of the worksheet (TODO)
/*
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { GM_INTERPOLATE } from "./GM_INTERPOLATE";
import { GM_NAME } from "./GM_NAME";
import { GM_PROP } from "./GM_PROP";

/* tslint:disable:only-arrow-functions */

// Expose as custom functions (picked up by gas-webpack-plugin).
//
// Note: The jsdoc below is manually curated based on the master
Expand Down

0 comments on commit 309d5d1

Please sign in to comment.